]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
lib: pretty ip_masklen and masklen2ip
[mirror_frr.git] / bgpd / bgp_route.c
1 /* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4 This file is part of GNU Zebra.
5
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-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"
36 #include "workqueue.h"
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"
56 #include "bgpd/bgp_vty.h"
57
58 /* Extern from bgp_dump.c */
59 extern const char *bgp_origin_str[];
60 extern const char *bgp_origin_long_str[];
61 \f
62 static struct bgp_node *
63 bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
64 struct prefix_rd *prd)
65 {
66 struct bgp_node *rn;
67 struct bgp_node *prn = NULL;
68
69 assert (table);
70 if (!table)
71 return NULL;
72
73 if (safi == SAFI_MPLS_VPN)
74 {
75 prn = bgp_node_get (table, (struct prefix *) prd);
76
77 if (prn->info == NULL)
78 prn->info = bgp_table_init (afi, safi);
79 else
80 bgp_unlock_node (prn);
81 table = prn->info;
82 }
83
84 rn = bgp_node_get (table, p);
85
86 if (safi == SAFI_MPLS_VPN)
87 rn->prn = prn;
88
89 return rn;
90 }
91 \f
92 /* Allocate bgp_info_extra */
93 static struct bgp_info_extra *
94 bgp_info_extra_new (void)
95 {
96 struct bgp_info_extra *new;
97 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
98 return new;
99 }
100
101 static void
102 bgp_info_extra_free (struct bgp_info_extra **extra)
103 {
104 if (extra && *extra)
105 {
106 if ((*extra)->damp_info)
107 bgp_damp_info_free ((*extra)->damp_info, 0);
108
109 (*extra)->damp_info = NULL;
110
111 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
112
113 *extra = NULL;
114 }
115 }
116
117 /* Get bgp_info extra information for the given bgp_info, lazy allocated
118 * if required.
119 */
120 struct bgp_info_extra *
121 bgp_info_extra_get (struct bgp_info *ri)
122 {
123 if (!ri->extra)
124 ri->extra = bgp_info_extra_new();
125 return ri->extra;
126 }
127
128 /* Allocate new bgp info structure. */
129 static struct bgp_info *
130 bgp_info_new (void)
131 {
132 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
133 }
134
135 /* Free bgp route information. */
136 static void
137 bgp_info_free (struct bgp_info *binfo)
138 {
139 if (binfo->attr)
140 bgp_attr_unintern (&binfo->attr);
141
142 bgp_info_extra_free (&binfo->extra);
143
144 peer_unlock (binfo->peer); /* bgp_info peer reference */
145
146 XFREE (MTYPE_BGP_ROUTE, binfo);
147 }
148
149 struct bgp_info *
150 bgp_info_lock (struct bgp_info *binfo)
151 {
152 binfo->lock++;
153 return binfo;
154 }
155
156 struct bgp_info *
157 bgp_info_unlock (struct bgp_info *binfo)
158 {
159 assert (binfo && binfo->lock > 0);
160 binfo->lock--;
161
162 if (binfo->lock == 0)
163 {
164 #if 0
165 zlog_debug ("%s: unlocked and freeing", __func__);
166 zlog_backtrace (LOG_DEBUG);
167 #endif
168 bgp_info_free (binfo);
169 return NULL;
170 }
171
172 #if 0
173 if (binfo->lock == 1)
174 {
175 zlog_debug ("%s: unlocked to 1", __func__);
176 zlog_backtrace (LOG_DEBUG);
177 }
178 #endif
179
180 return binfo;
181 }
182
183 void
184 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
185 {
186 struct bgp_info *top;
187
188 top = rn->info;
189
190 ri->next = rn->info;
191 ri->prev = NULL;
192 if (top)
193 top->prev = ri;
194 rn->info = ri;
195
196 bgp_info_lock (ri);
197 bgp_lock_node (rn);
198 peer_lock (ri->peer); /* bgp_info peer reference */
199 }
200
201 /* Do the actual removal of info from RIB, for use by bgp_process
202 completion callback *only* */
203 static void
204 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
205 {
206 if (ri->next)
207 ri->next->prev = ri->prev;
208 if (ri->prev)
209 ri->prev->next = ri->next;
210 else
211 rn->info = ri->next;
212
213 bgp_info_unlock (ri);
214 bgp_unlock_node (rn);
215 }
216
217 void
218 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
219 {
220 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
221 /* set of previous already took care of pcount */
222 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
223 }
224
225 /* undo the effects of a previous call to bgp_info_delete; typically
226 called when a route is deleted and then quickly re-added before the
227 deletion has been processed */
228 static void
229 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
230 {
231 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
232 /* unset of previous already took care of pcount */
233 SET_FLAG (ri->flags, BGP_INFO_VALID);
234 }
235
236 /* Adjust pcount as required */
237 static void
238 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
239 {
240 assert (rn && rn->table);
241 assert (ri && ri->peer && ri->peer->bgp);
242
243 /* Ignore 'pcount' for RS-client tables */
244 if (rn->table->type != BGP_TABLE_MAIN
245 || ri->peer == ri->peer->bgp->peer_self)
246 return;
247
248 if (BGP_INFO_HOLDDOWN (ri)
249 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
250 {
251
252 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
253
254 /* slight hack, but more robust against errors. */
255 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
256 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
257 else
258 {
259 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
260 __func__, ri->peer->host);
261 zlog_backtrace (LOG_WARNING);
262 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
263 }
264 }
265 else if (!BGP_INFO_HOLDDOWN (ri)
266 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
267 {
268 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
269 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
270 }
271 }
272
273
274 /* Set/unset bgp_info flags, adjusting any other state as needed.
275 * This is here primarily to keep prefix-count in check.
276 */
277 void
278 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
279 {
280 SET_FLAG (ri->flags, flag);
281
282 /* early bath if we know it's not a flag that changes useability state */
283 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
284 return;
285
286 bgp_pcount_adjust (rn, ri);
287 }
288
289 void
290 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
291 {
292 UNSET_FLAG (ri->flags, flag);
293
294 /* early bath if we know it's not a flag that changes useability state */
295 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
296 return;
297
298 bgp_pcount_adjust (rn, ri);
299 }
300
301 /* Get MED value. If MED value is missing and "bgp bestpath
302 missing-as-worst" is specified, treat it as the worst value. */
303 static u_int32_t
304 bgp_med_value (struct attr *attr, struct bgp *bgp)
305 {
306 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
307 return attr->med;
308 else
309 {
310 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
311 return BGP_MED_MAX;
312 else
313 return 0;
314 }
315 }
316
317 /* Compare two bgp route entity. br is preferable then return 1. */
318 static int
319 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
320 {
321 u_int32_t new_pref;
322 u_int32_t exist_pref;
323 u_int32_t new_med;
324 u_int32_t exist_med;
325 u_int32_t new_weight = 0;
326 u_int32_t exist_weight = 0;
327 struct in_addr new_id;
328 struct in_addr exist_id;
329 int new_cluster;
330 int exist_cluster;
331 int internal_as_route = 0;
332 int confed_as_route = 0;
333 int ret;
334
335 /* 0. Null check. */
336 if (new == NULL)
337 return 0;
338 if (exist == NULL)
339 return 1;
340
341 /* 1. Weight check. */
342 if (new->attr->extra)
343 new_weight = new->attr->extra->weight;
344 if (exist->attr->extra)
345 exist_weight = exist->attr->extra->weight;
346 if (new_weight > exist_weight)
347 return 1;
348 if (new_weight < exist_weight)
349 return 0;
350
351 /* 2. Local preference check. */
352 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
353 new_pref = new->attr->local_pref;
354 else
355 new_pref = bgp->default_local_pref;
356
357 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
358 exist_pref = exist->attr->local_pref;
359 else
360 exist_pref = bgp->default_local_pref;
361
362 if (new_pref > exist_pref)
363 return 1;
364 if (new_pref < exist_pref)
365 return 0;
366
367 /* 3. Local route check. */
368 if (new->sub_type == BGP_ROUTE_STATIC)
369 return 1;
370 if (exist->sub_type == BGP_ROUTE_STATIC)
371 return 0;
372
373 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
374 return 1;
375 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
376 return 0;
377
378 if (new->sub_type == BGP_ROUTE_AGGREGATE)
379 return 1;
380 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
381 return 0;
382
383 /* 4. AS path length check. */
384 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
385 {
386 int exist_hops = aspath_count_hops (exist->attr->aspath);
387 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
388
389 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
390 {
391 int aspath_hops;
392
393 aspath_hops = aspath_count_hops (new->attr->aspath);
394 aspath_hops += aspath_count_confeds (new->attr->aspath);
395
396 if ( aspath_hops < (exist_hops + exist_confeds))
397 return 1;
398 if ( aspath_hops > (exist_hops + exist_confeds))
399 return 0;
400 }
401 else
402 {
403 int newhops = aspath_count_hops (new->attr->aspath);
404
405 if (newhops < exist_hops)
406 return 1;
407 if (newhops > exist_hops)
408 return 0;
409 }
410 }
411
412 /* 5. Origin check. */
413 if (new->attr->origin < exist->attr->origin)
414 return 1;
415 if (new->attr->origin > exist->attr->origin)
416 return 0;
417
418 /* 6. MED check. */
419 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
420 && aspath_count_hops (exist->attr->aspath) == 0);
421 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
422 && aspath_count_confeds (exist->attr->aspath) > 0
423 && aspath_count_hops (new->attr->aspath) == 0
424 && aspath_count_hops (exist->attr->aspath) == 0);
425
426 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
427 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
428 && confed_as_route)
429 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
430 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
431 || internal_as_route)
432 {
433 new_med = bgp_med_value (new->attr, bgp);
434 exist_med = bgp_med_value (exist->attr, bgp);
435
436 if (new_med < exist_med)
437 return 1;
438 if (new_med > exist_med)
439 return 0;
440 }
441
442 /* 7. Peer type check. */
443 if (peer_sort (new->peer) == BGP_PEER_EBGP
444 && peer_sort (exist->peer) == BGP_PEER_IBGP)
445 return 1;
446 if (peer_sort (new->peer) == BGP_PEER_EBGP
447 && peer_sort (exist->peer) == BGP_PEER_CONFED)
448 return 1;
449 if (peer_sort (new->peer) == BGP_PEER_IBGP
450 && peer_sort (exist->peer) == BGP_PEER_EBGP)
451 return 0;
452 if (peer_sort (new->peer) == BGP_PEER_CONFED
453 && peer_sort (exist->peer) == BGP_PEER_EBGP)
454 return 0;
455
456 /* 8. IGP metric check. */
457 if (new->extra || exist->extra)
458 {
459 uint32_t newm = (new->extra ? new->extra->igpmetric : 0);
460 uint32_t existm = (exist->extra ? exist->extra->igpmetric : 0);
461
462 if (newm < existm)
463 return 1;
464 if (newm > existm)
465 return 0;
466 }
467
468 /* 9. Maximum path check. */
469
470 /* 10. If both paths are external, prefer the path that was received
471 first (the oldest one). This step minimizes route-flap, since a
472 newer path won't displace an older one, even if it was the
473 preferred route based on the additional decision criteria below. */
474 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
475 && peer_sort (new->peer) == BGP_PEER_EBGP
476 && peer_sort (exist->peer) == BGP_PEER_EBGP)
477 {
478 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
479 return 1;
480 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
481 return 0;
482 }
483
484 /* 11. Rourter-ID comparision. */
485 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
486 new_id.s_addr = new->attr->extra->originator_id.s_addr;
487 else
488 new_id.s_addr = new->peer->remote_id.s_addr;
489 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
490 exist_id.s_addr = exist->attr->extra->originator_id.s_addr;
491 else
492 exist_id.s_addr = exist->peer->remote_id.s_addr;
493
494 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
495 return 1;
496 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
497 return 0;
498
499 /* 12. Cluster length comparision. */
500 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
501 new_cluster = new->attr->extra->cluster->length;
502 else
503 new_cluster = 0;
504 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
505 exist_cluster = exist->attr->extra->cluster->length;
506 else
507 exist_cluster = 0;
508
509 if (new_cluster < exist_cluster)
510 return 1;
511 if (new_cluster > exist_cluster)
512 return 0;
513
514 /* 13. Neighbor address comparision. */
515 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
516
517 if (ret == 1)
518 return 0;
519 if (ret == -1)
520 return 1;
521
522 return 1;
523 }
524
525 static enum filter_type
526 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
527 afi_t afi, safi_t safi)
528 {
529 struct bgp_filter *filter;
530
531 filter = &peer->filter[afi][safi];
532
533 #define FILTER_EXIST_WARN(F,f,filter) \
534 if (BGP_DEBUG (update, UPDATE_IN) \
535 && !(F ## _IN (filter))) \
536 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
537 peer->host, #f, F ## _IN_NAME(filter));
538
539 if (DISTRIBUTE_IN_NAME (filter)) {
540 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
541
542 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
543 return FILTER_DENY;
544 }
545
546 if (PREFIX_LIST_IN_NAME (filter)) {
547 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
548
549 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
550 return FILTER_DENY;
551 }
552
553 if (FILTER_LIST_IN_NAME (filter)) {
554 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
555
556 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
557 return FILTER_DENY;
558 }
559
560 return FILTER_PERMIT;
561 #undef FILTER_EXIST_WARN
562 }
563
564 static enum filter_type
565 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
566 afi_t afi, safi_t safi)
567 {
568 struct bgp_filter *filter;
569
570 filter = &peer->filter[afi][safi];
571
572 #define FILTER_EXIST_WARN(F,f,filter) \
573 if (BGP_DEBUG (update, UPDATE_OUT) \
574 && !(F ## _OUT (filter))) \
575 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
576 peer->host, #f, F ## _OUT_NAME(filter));
577
578 if (DISTRIBUTE_OUT_NAME (filter)) {
579 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
580
581 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
582 return FILTER_DENY;
583 }
584
585 if (PREFIX_LIST_OUT_NAME (filter)) {
586 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
587
588 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
589 return FILTER_DENY;
590 }
591
592 if (FILTER_LIST_OUT_NAME (filter)) {
593 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
594
595 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
596 return FILTER_DENY;
597 }
598
599 return FILTER_PERMIT;
600 #undef FILTER_EXIST_WARN
601 }
602
603 /* If community attribute includes no_export then return 1. */
604 static int
605 bgp_community_filter (struct peer *peer, struct attr *attr)
606 {
607 if (attr->community)
608 {
609 /* NO_ADVERTISE check. */
610 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
611 return 1;
612
613 /* NO_EXPORT check. */
614 if (peer_sort (peer) == BGP_PEER_EBGP &&
615 community_include (attr->community, COMMUNITY_NO_EXPORT))
616 return 1;
617
618 /* NO_EXPORT_SUBCONFED check. */
619 if (peer_sort (peer) == BGP_PEER_EBGP
620 || peer_sort (peer) == BGP_PEER_CONFED)
621 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
622 return 1;
623 }
624 return 0;
625 }
626
627 /* Route reflection loop check. */
628 static int
629 bgp_cluster_filter (struct peer *peer, struct attr *attr)
630 {
631 struct in_addr cluster_id;
632
633 if (attr->extra && attr->extra->cluster)
634 {
635 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
636 cluster_id = peer->bgp->cluster_id;
637 else
638 cluster_id = peer->bgp->router_id;
639
640 if (cluster_loop_check (attr->extra->cluster, cluster_id))
641 return 1;
642 }
643 return 0;
644 }
645 \f
646 static int
647 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
648 afi_t afi, safi_t safi)
649 {
650 struct bgp_filter *filter;
651 struct bgp_info info;
652 route_map_result_t ret;
653
654 filter = &peer->filter[afi][safi];
655
656 /* Apply default weight value. */
657 if (peer->weight)
658 (bgp_attr_extra_get (attr))->weight = peer->weight;
659
660 /* Route map apply. */
661 if (ROUTE_MAP_IN_NAME (filter))
662 {
663 /* Duplicate current value to new strucutre for modification. */
664 info.peer = peer;
665 info.attr = attr;
666
667 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
668
669 /* Apply BGP route map to the attribute. */
670 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
671
672 peer->rmap_type = 0;
673
674 if (ret == RMAP_DENYMATCH)
675 {
676 /* Free newly generated AS path and community by route-map. */
677 bgp_attr_flush (attr);
678 return RMAP_DENY;
679 }
680 }
681 return RMAP_PERMIT;
682 }
683 \f
684 static int
685 bgp_export_modifier (struct peer *rsclient, struct peer *peer,
686 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
687 {
688 struct bgp_filter *filter;
689 struct bgp_info info;
690 route_map_result_t ret;
691
692 filter = &peer->filter[afi][safi];
693
694 /* Route map apply. */
695 if (ROUTE_MAP_EXPORT_NAME (filter))
696 {
697 /* Duplicate current value to new strucutre for modification. */
698 info.peer = rsclient;
699 info.attr = attr;
700
701 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
702
703 /* Apply BGP route map to the attribute. */
704 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
705
706 rsclient->rmap_type = 0;
707
708 if (ret == RMAP_DENYMATCH)
709 {
710 /* Free newly generated AS path and community by route-map. */
711 bgp_attr_flush (attr);
712 return RMAP_DENY;
713 }
714 }
715 return RMAP_PERMIT;
716 }
717
718 static int
719 bgp_import_modifier (struct peer *rsclient, struct peer *peer,
720 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
721 {
722 struct bgp_filter *filter;
723 struct bgp_info info;
724 route_map_result_t ret;
725
726 filter = &rsclient->filter[afi][safi];
727
728 /* Apply default weight value. */
729 if (peer->weight)
730 (bgp_attr_extra_get (attr))->weight = peer->weight;
731
732 /* Route map apply. */
733 if (ROUTE_MAP_IMPORT_NAME (filter))
734 {
735 /* Duplicate current value to new strucutre for modification. */
736 info.peer = peer;
737 info.attr = attr;
738
739 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
740
741 /* Apply BGP route map to the attribute. */
742 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
743
744 peer->rmap_type = 0;
745
746 if (ret == RMAP_DENYMATCH)
747 {
748 /* Free newly generated AS path and community by route-map. */
749 bgp_attr_flush (attr);
750 return RMAP_DENY;
751 }
752 }
753 return RMAP_PERMIT;
754 }
755 \f
756 static int
757 bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
758 struct attr *attr, afi_t afi, safi_t safi)
759 {
760 int ret;
761 char buf[SU_ADDRSTRLEN];
762 struct bgp_filter *filter;
763 struct peer *from;
764 struct bgp *bgp;
765 int transparent;
766 int reflect;
767
768 from = ri->peer;
769 filter = &peer->filter[afi][safi];
770 bgp = peer->bgp;
771
772 if (DISABLE_BGP_ANNOUNCE)
773 return 0;
774
775 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
776 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
777 return 0;
778
779 /* Do not send back route to sender. */
780 if (from == peer)
781 return 0;
782
783 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
784 if (p->family == AF_INET
785 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
786 return 0;
787 #ifdef HAVE_IPV6
788 if (p->family == AF_INET6
789 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
790 return 0;
791 #endif
792
793 /* Aggregate-address suppress check. */
794 if (ri->extra && ri->extra->suppress)
795 if (! UNSUPPRESS_MAP_NAME (filter))
796 return 0;
797
798 /* Default route check. */
799 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
800 {
801 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
802 return 0;
803 #ifdef HAVE_IPV6
804 else if (p->family == AF_INET6 && p->prefixlen == 0)
805 return 0;
806 #endif /* HAVE_IPV6 */
807 }
808
809 /* Transparency check. */
810 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
811 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
812 transparent = 1;
813 else
814 transparent = 0;
815
816 /* If community is not disabled check the no-export and local. */
817 if (! transparent && bgp_community_filter (peer, ri->attr))
818 return 0;
819
820 /* If the attribute has originator-id and it is same as remote
821 peer's id. */
822 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
823 {
824 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->extra->originator_id))
825 {
826 if (BGP_DEBUG (filter, FILTER))
827 zlog (peer->log, LOG_DEBUG,
828 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
829 peer->host,
830 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
831 p->prefixlen);
832 return 0;
833 }
834 }
835
836 /* ORF prefix-list filter check */
837 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
838 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
839 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
840 if (peer->orf_plist[afi][safi])
841 {
842 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
843 return 0;
844 }
845
846 /* Output filter check. */
847 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
848 {
849 if (BGP_DEBUG (filter, FILTER))
850 zlog (peer->log, LOG_DEBUG,
851 "%s [Update:SEND] %s/%d is filtered",
852 peer->host,
853 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
854 p->prefixlen);
855 return 0;
856 }
857
858 #ifdef BGP_SEND_ASPATH_CHECK
859 /* AS path loop check. */
860 if (aspath_loop_check (ri->attr->aspath, peer->as))
861 {
862 if (BGP_DEBUG (filter, FILTER))
863 zlog (peer->log, LOG_DEBUG,
864 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
865 peer->host, peer->as);
866 return 0;
867 }
868 #endif /* BGP_SEND_ASPATH_CHECK */
869
870 /* If we're a CONFED we need to loop check the CONFED ID too */
871 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
872 {
873 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
874 {
875 if (BGP_DEBUG (filter, FILTER))
876 zlog (peer->log, LOG_DEBUG,
877 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
878 peer->host,
879 bgp->confed_id);
880 return 0;
881 }
882 }
883
884 /* Route-Reflect check. */
885 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
886 reflect = 1;
887 else
888 reflect = 0;
889
890 /* IBGP reflection check. */
891 if (reflect)
892 {
893 /* A route from a Client peer. */
894 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
895 {
896 /* Reflect to all the Non-Client peers and also to the
897 Client peers other than the originator. Originator check
898 is already done. So there is noting to do. */
899 /* no bgp client-to-client reflection check. */
900 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
901 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
902 return 0;
903 }
904 else
905 {
906 /* A route from a Non-client peer. Reflect to all other
907 clients. */
908 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
909 return 0;
910 }
911 }
912
913 /* For modify attribute, copy it to temporary structure. */
914 bgp_attr_dup (attr, ri->attr);
915
916 /* If local-preference is not set. */
917 if ((peer_sort (peer) == BGP_PEER_IBGP
918 || peer_sort (peer) == BGP_PEER_CONFED)
919 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
920 {
921 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
922 attr->local_pref = bgp->default_local_pref;
923 }
924
925 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
926 if (peer_sort (peer) == BGP_PEER_EBGP
927 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
928 {
929 if (ri->peer != bgp->peer_self && ! transparent
930 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
931 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
932 }
933
934 /* next-hop-set */
935 if (transparent || reflect
936 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
937 && ((p->family == AF_INET && attr->nexthop.s_addr)
938 #ifdef HAVE_IPV6
939 || (p->family == AF_INET6 &&
940 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
941 #endif /* HAVE_IPV6 */
942 )))
943 {
944 /* NEXT-HOP Unchanged. */
945 }
946 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
947 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
948 #ifdef HAVE_IPV6
949 || (p->family == AF_INET6 &&
950 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
951 #endif /* HAVE_IPV6 */
952 || (peer_sort (peer) == BGP_PEER_EBGP
953 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
954 {
955 /* Set IPv4 nexthop. */
956 if (p->family == AF_INET)
957 {
958 if (safi == SAFI_MPLS_VPN)
959 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
960 IPV4_MAX_BYTELEN);
961 else
962 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
963 }
964 #ifdef HAVE_IPV6
965 /* Set IPv6 nexthop. */
966 if (p->family == AF_INET6)
967 {
968 /* IPv6 global nexthop must be included. */
969 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
970 IPV6_MAX_BYTELEN);
971 attr->extra->mp_nexthop_len = 16;
972 }
973 #endif /* HAVE_IPV6 */
974 }
975
976 #ifdef HAVE_IPV6
977 if (p->family == AF_INET6)
978 {
979 /* Left nexthop_local unchanged if so configured. */
980 if ( CHECK_FLAG (peer->af_flags[afi][safi],
981 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
982 {
983 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
984 attr->extra->mp_nexthop_len=32;
985 else
986 attr->extra->mp_nexthop_len=16;
987 }
988
989 /* Default nexthop_local treatment for non-RS-Clients */
990 else
991 {
992 /* Link-local address should not be transit to different peer. */
993 attr->extra->mp_nexthop_len = 16;
994
995 /* Set link-local address for shared network peer. */
996 if (peer->shared_network
997 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
998 {
999 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
1000 IPV6_MAX_BYTELEN);
1001 attr->extra->mp_nexthop_len = 32;
1002 }
1003
1004 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1005 address.*/
1006 if (reflect)
1007 attr->extra->mp_nexthop_len = 16;
1008
1009 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1010 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
1011 attr->extra->mp_nexthop_len = 16;
1012 }
1013
1014 }
1015 #endif /* HAVE_IPV6 */
1016
1017 /* If this is EBGP peer and remove-private-AS is set. */
1018 if (peer_sort (peer) == BGP_PEER_EBGP
1019 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1020 && aspath_private_as_check (attr->aspath))
1021 attr->aspath = aspath_empty_get ();
1022
1023 /* Route map & unsuppress-map apply. */
1024 if (ROUTE_MAP_OUT_NAME (filter)
1025 || (ri->extra && ri->extra->suppress) )
1026 {
1027 struct bgp_info info;
1028 struct attr dummy_attr = { 0 };
1029
1030 info.peer = peer;
1031 info.attr = attr;
1032
1033 /* The route reflector is not allowed to modify the attributes
1034 of the reflected IBGP routes. */
1035 if (peer_sort (from) == BGP_PEER_IBGP
1036 && peer_sort (peer) == BGP_PEER_IBGP)
1037 {
1038 bgp_attr_dup (&dummy_attr, attr);
1039 info.attr = &dummy_attr;
1040 }
1041
1042 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1043
1044 if (ri->extra && ri->extra->suppress)
1045 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1046 else
1047 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1048
1049 peer->rmap_type = 0;
1050
1051 if (dummy_attr.extra)
1052 bgp_attr_extra_free (&dummy_attr);
1053
1054 if (ret == RMAP_DENYMATCH)
1055 {
1056 bgp_attr_flush (attr);
1057 return 0;
1058 }
1059 }
1060 return 1;
1061 }
1062
1063 static int
1064 bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1065 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1066 {
1067 int ret;
1068 char buf[SU_ADDRSTRLEN];
1069 struct bgp_filter *filter;
1070 struct bgp_info info;
1071 struct peer *from;
1072
1073 from = ri->peer;
1074 filter = &rsclient->filter[afi][safi];
1075
1076 if (DISABLE_BGP_ANNOUNCE)
1077 return 0;
1078
1079 /* Do not send back route to sender. */
1080 if (from == rsclient)
1081 return 0;
1082
1083 /* Aggregate-address suppress check. */
1084 if (ri->extra && ri->extra->suppress)
1085 if (! UNSUPPRESS_MAP_NAME (filter))
1086 return 0;
1087
1088 /* Default route check. */
1089 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1090 PEER_STATUS_DEFAULT_ORIGINATE))
1091 {
1092 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1093 return 0;
1094 #ifdef HAVE_IPV6
1095 else if (p->family == AF_INET6 && p->prefixlen == 0)
1096 return 0;
1097 #endif /* HAVE_IPV6 */
1098 }
1099
1100 /* If the attribute has originator-id and it is same as remote
1101 peer's id. */
1102 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1103 {
1104 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1105 &ri->attr->extra->originator_id))
1106 {
1107 if (BGP_DEBUG (filter, FILTER))
1108 zlog (rsclient->log, LOG_DEBUG,
1109 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1110 rsclient->host,
1111 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1112 p->prefixlen);
1113 return 0;
1114 }
1115 }
1116
1117 /* ORF prefix-list filter check */
1118 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1119 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1120 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1121 if (rsclient->orf_plist[afi][safi])
1122 {
1123 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1124 return 0;
1125 }
1126
1127 /* Output filter check. */
1128 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1129 {
1130 if (BGP_DEBUG (filter, FILTER))
1131 zlog (rsclient->log, LOG_DEBUG,
1132 "%s [Update:SEND] %s/%d is filtered",
1133 rsclient->host,
1134 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1135 p->prefixlen);
1136 return 0;
1137 }
1138
1139 #ifdef BGP_SEND_ASPATH_CHECK
1140 /* AS path loop check. */
1141 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1142 {
1143 if (BGP_DEBUG (filter, FILTER))
1144 zlog (rsclient->log, LOG_DEBUG,
1145 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1146 rsclient->host, rsclient->as);
1147 return 0;
1148 }
1149 #endif /* BGP_SEND_ASPATH_CHECK */
1150
1151 /* For modify attribute, copy it to temporary structure. */
1152 bgp_attr_dup (attr, ri->attr);
1153
1154 /* next-hop-set */
1155 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1156 #ifdef HAVE_IPV6
1157 || (p->family == AF_INET6 &&
1158 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1159 #endif /* HAVE_IPV6 */
1160 )
1161 {
1162 /* Set IPv4 nexthop. */
1163 if (p->family == AF_INET)
1164 {
1165 if (safi == SAFI_MPLS_VPN)
1166 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
1167 IPV4_MAX_BYTELEN);
1168 else
1169 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1170 }
1171 #ifdef HAVE_IPV6
1172 /* Set IPv6 nexthop. */
1173 if (p->family == AF_INET6)
1174 {
1175 /* IPv6 global nexthop must be included. */
1176 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
1177 IPV6_MAX_BYTELEN);
1178 attr->extra->mp_nexthop_len = 16;
1179 }
1180 #endif /* HAVE_IPV6 */
1181 }
1182
1183 #ifdef HAVE_IPV6
1184 if (p->family == AF_INET6)
1185 {
1186 struct attr_extra *attre = attr->extra;
1187
1188 assert (attr->extra);
1189
1190 /* Left nexthop_local unchanged if so configured. */
1191 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1192 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1193 {
1194 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1195 attre->mp_nexthop_len=32;
1196 else
1197 attre->mp_nexthop_len=16;
1198 }
1199
1200 /* Default nexthop_local treatment for RS-Clients */
1201 else
1202 {
1203 /* Announcer and RS-Client are both in the same network */
1204 if (rsclient->shared_network && from->shared_network &&
1205 (rsclient->ifindex == from->ifindex))
1206 {
1207 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1208 attre->mp_nexthop_len=32;
1209 else
1210 attre->mp_nexthop_len=16;
1211 }
1212
1213 /* Set link-local address for shared network peer. */
1214 else if (rsclient->shared_network
1215 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1216 {
1217 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
1218 IPV6_MAX_BYTELEN);
1219 attre->mp_nexthop_len = 32;
1220 }
1221
1222 else
1223 attre->mp_nexthop_len = 16;
1224 }
1225
1226 }
1227 #endif /* HAVE_IPV6 */
1228
1229
1230 /* If this is EBGP peer and remove-private-AS is set. */
1231 if (peer_sort (rsclient) == BGP_PEER_EBGP
1232 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1233 && aspath_private_as_check (attr->aspath))
1234 attr->aspath = aspath_empty_get ();
1235
1236 /* Route map & unsuppress-map apply. */
1237 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
1238 {
1239 info.peer = rsclient;
1240 info.attr = attr;
1241
1242 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1243
1244 if (ri->extra && ri->extra->suppress)
1245 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1246 else
1247 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1248
1249 rsclient->rmap_type = 0;
1250
1251 if (ret == RMAP_DENYMATCH)
1252 {
1253 bgp_attr_flush (attr);
1254 return 0;
1255 }
1256 }
1257
1258 return 1;
1259 }
1260
1261 struct bgp_info_pair
1262 {
1263 struct bgp_info *old;
1264 struct bgp_info *new;
1265 };
1266
1267 static void
1268 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1269 {
1270 struct bgp_info *new_select;
1271 struct bgp_info *old_select;
1272 struct bgp_info *ri;
1273 struct bgp_info *ri1;
1274 struct bgp_info *ri2;
1275 struct bgp_info *nextri = NULL;
1276
1277 /* bgp deterministic-med */
1278 new_select = NULL;
1279 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1280 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1281 {
1282 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1283 continue;
1284 if (BGP_INFO_HOLDDOWN (ri1))
1285 continue;
1286
1287 new_select = ri1;
1288 if (ri1->next)
1289 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1290 {
1291 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1292 continue;
1293 if (BGP_INFO_HOLDDOWN (ri2))
1294 continue;
1295
1296 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1297 || aspath_cmp_left_confed (ri1->attr->aspath,
1298 ri2->attr->aspath))
1299 {
1300 if (bgp_info_cmp (bgp, ri2, new_select))
1301 {
1302 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1303 new_select = ri2;
1304 }
1305
1306 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1307 }
1308 }
1309 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1310 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1311 }
1312
1313 /* Check old selected route and new selected route. */
1314 old_select = NULL;
1315 new_select = NULL;
1316 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1317 {
1318 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1319 old_select = ri;
1320
1321 if (BGP_INFO_HOLDDOWN (ri))
1322 {
1323 /* reap REMOVED routes, if needs be
1324 * selected route must stay for a while longer though
1325 */
1326 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1327 && (ri != old_select))
1328 bgp_info_reap (rn, ri);
1329
1330 continue;
1331 }
1332
1333 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1334 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1335 {
1336 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1337 continue;
1338 }
1339 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1340 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
1341
1342 if (bgp_info_cmp (bgp, ri, new_select))
1343 new_select = ri;
1344 }
1345
1346 result->old = old_select;
1347 result->new = new_select;
1348
1349 return;
1350 }
1351
1352 static int
1353 bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1354 struct bgp_node *rn, afi_t afi, safi_t safi)
1355 {
1356 struct prefix *p;
1357 struct attr attr = { 0 };
1358
1359 p = &rn->p;
1360
1361 /* Announce route to Established peer. */
1362 if (peer->status != Established)
1363 return 0;
1364
1365 /* Address family configuration check. */
1366 if (! peer->afc_nego[afi][safi])
1367 return 0;
1368
1369 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1370 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1371 PEER_STATUS_ORF_WAIT_REFRESH))
1372 return 0;
1373
1374 switch (rn->table->type)
1375 {
1376 case BGP_TABLE_MAIN:
1377 /* Announcement to peer->conf. If the route is filtered,
1378 withdraw it. */
1379 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1380 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1381 else
1382 bgp_adj_out_unset (rn, peer, p, afi, safi);
1383 break;
1384 case BGP_TABLE_RSCLIENT:
1385 /* Announcement to peer->conf. If the route is filtered,
1386 withdraw it. */
1387 if (selected &&
1388 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1389 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1390 else
1391 bgp_adj_out_unset (rn, peer, p, afi, safi);
1392 break;
1393 }
1394
1395 bgp_attr_extra_free (&attr);
1396
1397 return 0;
1398 }
1399
1400 struct bgp_process_queue
1401 {
1402 struct bgp *bgp;
1403 struct bgp_node *rn;
1404 afi_t afi;
1405 safi_t safi;
1406 };
1407
1408 static wq_item_status
1409 bgp_process_rsclient (struct work_queue *wq, void *data)
1410 {
1411 struct bgp_process_queue *pq = data;
1412 struct bgp *bgp = pq->bgp;
1413 struct bgp_node *rn = pq->rn;
1414 afi_t afi = pq->afi;
1415 safi_t safi = pq->safi;
1416 struct bgp_info *new_select;
1417 struct bgp_info *old_select;
1418 struct bgp_info_pair old_and_new;
1419 struct listnode *node, *nnode;
1420 struct peer *rsclient = rn->table->owner;
1421
1422 /* Best path selection. */
1423 bgp_best_selection (bgp, rn, &old_and_new);
1424 new_select = old_and_new.new;
1425 old_select = old_and_new.old;
1426
1427 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1428 {
1429 if (rsclient->group)
1430 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1431 {
1432 /* Nothing to do. */
1433 if (old_select && old_select == new_select)
1434 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1435 continue;
1436
1437 if (old_select)
1438 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1439 if (new_select)
1440 {
1441 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1442 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1443 }
1444
1445 bgp_process_announce_selected (rsclient, new_select, rn,
1446 afi, safi);
1447 }
1448 }
1449 else
1450 {
1451 if (old_select)
1452 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1453 if (new_select)
1454 {
1455 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1456 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1457 }
1458 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
1459 }
1460
1461 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1462 bgp_info_reap (rn, old_select);
1463
1464 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1465 return WQ_SUCCESS;
1466 }
1467
1468 static wq_item_status
1469 bgp_process_main (struct work_queue *wq, void *data)
1470 {
1471 struct bgp_process_queue *pq = data;
1472 struct bgp *bgp = pq->bgp;
1473 struct bgp_node *rn = pq->rn;
1474 afi_t afi = pq->afi;
1475 safi_t safi = pq->safi;
1476 struct prefix *p = &rn->p;
1477 struct bgp_info *new_select;
1478 struct bgp_info *old_select;
1479 struct bgp_info_pair old_and_new;
1480 struct listnode *node, *nnode;
1481 struct peer *peer;
1482
1483 /* Best path selection. */
1484 bgp_best_selection (bgp, rn, &old_and_new);
1485 old_select = old_and_new.old;
1486 new_select = old_and_new.new;
1487
1488 /* Nothing to do. */
1489 if (old_select && old_select == new_select)
1490 {
1491 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1492 {
1493 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1494 bgp_zebra_announce (p, old_select, bgp, safi);
1495
1496 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1497 return WQ_SUCCESS;
1498 }
1499 }
1500
1501 if (old_select)
1502 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1503 if (new_select)
1504 {
1505 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1506 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1507 }
1508
1509
1510 /* Check each BGP peer. */
1511 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
1512 {
1513 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
1514 }
1515
1516 /* FIB update. */
1517 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1518 ! bgp_option_check (BGP_OPT_NO_FIB)))
1519 {
1520 if (new_select
1521 && new_select->type == ZEBRA_ROUTE_BGP
1522 && new_select->sub_type == BGP_ROUTE_NORMAL)
1523 bgp_zebra_announce (p, new_select, bgp, safi);
1524 else
1525 {
1526 /* Withdraw the route from the kernel. */
1527 if (old_select
1528 && old_select->type == ZEBRA_ROUTE_BGP
1529 && old_select->sub_type == BGP_ROUTE_NORMAL)
1530 bgp_zebra_withdraw (p, old_select, safi);
1531 }
1532 }
1533
1534 /* Reap old select bgp_info, it it has been removed */
1535 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1536 bgp_info_reap (rn, old_select);
1537
1538 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1539 return WQ_SUCCESS;
1540 }
1541
1542 static void
1543 bgp_processq_del (struct work_queue *wq, void *data)
1544 {
1545 struct bgp_process_queue *pq = data;
1546 struct bgp_table *table = pq->rn->table;
1547
1548 bgp_unlock (pq->bgp);
1549 bgp_unlock_node (pq->rn);
1550 bgp_table_unlock (table);
1551 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1552 }
1553
1554 static void
1555 bgp_process_queue_init (void)
1556 {
1557 bm->process_main_queue
1558 = work_queue_new (bm->master, "process_main_queue");
1559 bm->process_rsclient_queue
1560 = work_queue_new (bm->master, "process_rsclient_queue");
1561
1562 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1563 {
1564 zlog_err ("%s: Failed to allocate work queue", __func__);
1565 exit (1);
1566 }
1567
1568 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1569 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1570 bm->process_main_queue->spec.max_retries = 0;
1571 bm->process_main_queue->spec.hold = 50;
1572
1573 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1574 sizeof (struct work_queue *));
1575 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1576 }
1577
1578 void
1579 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1580 {
1581 struct bgp_process_queue *pqnode;
1582
1583 /* already scheduled for processing? */
1584 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1585 return;
1586
1587 if ( (bm->process_main_queue == NULL) ||
1588 (bm->process_rsclient_queue == NULL) )
1589 bgp_process_queue_init ();
1590
1591 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1592 sizeof (struct bgp_process_queue));
1593 if (!pqnode)
1594 return;
1595
1596 /* all unlocked in bgp_processq_del */
1597 bgp_table_lock (rn->table);
1598 pqnode->rn = bgp_lock_node (rn);
1599 pqnode->bgp = bgp;
1600 bgp_lock (bgp);
1601 pqnode->afi = afi;
1602 pqnode->safi = safi;
1603
1604 switch (rn->table->type)
1605 {
1606 case BGP_TABLE_MAIN:
1607 work_queue_add (bm->process_main_queue, pqnode);
1608 break;
1609 case BGP_TABLE_RSCLIENT:
1610 work_queue_add (bm->process_rsclient_queue, pqnode);
1611 break;
1612 }
1613
1614 return;
1615 }
1616
1617 static int
1618 bgp_maximum_prefix_restart_timer (struct thread *thread)
1619 {
1620 struct peer *peer;
1621
1622 peer = THREAD_ARG (thread);
1623 peer->t_pmax_restart = NULL;
1624
1625 if (BGP_DEBUG (events, EVENTS))
1626 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1627 peer->host);
1628
1629 peer_clear (peer);
1630
1631 return 0;
1632 }
1633
1634 int
1635 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1636 safi_t safi, int always)
1637 {
1638 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1639 return 0;
1640
1641 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
1642 {
1643 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1644 && ! always)
1645 return 0;
1646
1647 zlog (peer->log, LOG_INFO,
1648 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1649 "limit %ld", afi_safi_print (afi, safi), peer->host,
1650 peer->pcount[afi][safi], peer->pmax[afi][safi]);
1651 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1652
1653 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1654 return 0;
1655
1656 {
1657 u_int8_t ndata[7];
1658
1659 if (safi == SAFI_MPLS_VPN)
1660 safi = SAFI_MPLS_LABELED_VPN;
1661
1662 ndata[0] = (afi >> 8);
1663 ndata[1] = afi;
1664 ndata[2] = safi;
1665 ndata[3] = (peer->pmax[afi][safi] >> 24);
1666 ndata[4] = (peer->pmax[afi][safi] >> 16);
1667 ndata[5] = (peer->pmax[afi][safi] >> 8);
1668 ndata[6] = (peer->pmax[afi][safi]);
1669
1670 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1671 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1672 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1673 }
1674
1675 /* restart timer start */
1676 if (peer->pmax_restart[afi][safi])
1677 {
1678 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1679
1680 if (BGP_DEBUG (events, EVENTS))
1681 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1682 peer->host, peer->v_pmax_restart);
1683
1684 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1685 peer->v_pmax_restart);
1686 }
1687
1688 return 1;
1689 }
1690 else
1691 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1692
1693 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1694 {
1695 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1696 && ! always)
1697 return 0;
1698
1699 zlog (peer->log, LOG_INFO,
1700 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1701 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1702 peer->pmax[afi][safi]);
1703 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1704 }
1705 else
1706 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1707 return 0;
1708 }
1709
1710 /* Unconditionally remove the route from the RIB, without taking
1711 * damping into consideration (eg, because the session went down)
1712 */
1713 static void
1714 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1715 afi_t afi, safi_t safi)
1716 {
1717 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1718
1719 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1720 bgp_info_delete (rn, ri); /* keep historical info */
1721
1722 bgp_process (peer->bgp, rn, afi, safi);
1723 }
1724
1725 static void
1726 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1727 afi_t afi, safi_t safi)
1728 {
1729 int status = BGP_DAMP_NONE;
1730
1731 /* apply dampening, if result is suppressed, we'll be retaining
1732 * the bgp_info in the RIB for historical reference.
1733 */
1734 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1735 && peer_sort (peer) == BGP_PEER_EBGP)
1736 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1737 == BGP_DAMP_SUPPRESSED)
1738 {
1739 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1740 return;
1741 }
1742
1743 bgp_rib_remove (rn, ri, peer, afi, safi);
1744 }
1745
1746 static void
1747 bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1748 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1749 int sub_type, struct prefix_rd *prd, u_char *tag)
1750 {
1751 struct bgp_node *rn;
1752 struct bgp *bgp;
1753 struct attr new_attr = { 0 };
1754 struct attr *attr_new;
1755 struct attr *attr_new2;
1756 struct bgp_info *ri;
1757 struct bgp_info *new;
1758 const char *reason;
1759 char buf[SU_ADDRSTRLEN];
1760
1761 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1762 if (peer == rsclient)
1763 return;
1764
1765 bgp = peer->bgp;
1766 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1767
1768 /* Check previously received route. */
1769 for (ri = rn->info; ri; ri = ri->next)
1770 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1771 break;
1772
1773 /* AS path loop check. */
1774 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1775 {
1776 reason = "as-path contains our own AS;";
1777 goto filtered;
1778 }
1779
1780 /* Route reflector originator ID check. */
1781 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1782 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
1783 {
1784 reason = "originator is us;";
1785 goto filtered;
1786 }
1787
1788 bgp_attr_dup (&new_attr, attr);
1789
1790 /* Apply export policy. */
1791 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1792 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1793 {
1794 reason = "export-policy;";
1795 goto filtered;
1796 }
1797
1798 attr_new2 = bgp_attr_intern (&new_attr);
1799
1800 /* Apply import policy. */
1801 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1802 {
1803 bgp_attr_unintern (&attr_new2);
1804
1805 reason = "import-policy;";
1806 goto filtered;
1807 }
1808
1809 attr_new = bgp_attr_intern (&new_attr);
1810 bgp_attr_unintern (&attr_new2);
1811
1812 /* IPv4 unicast next hop check. */
1813 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
1814 {
1815 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
1816 if (new_attr.nexthop.s_addr == 0
1817 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
1818 {
1819 bgp_attr_unintern (&attr_new);
1820
1821 reason = "martian next-hop;";
1822 goto filtered;
1823 }
1824 }
1825
1826 /* new_attr isn't passed to any functions after here */
1827 bgp_attr_extra_free (&new_attr);
1828
1829 /* If the update is implicit withdraw. */
1830 if (ri)
1831 {
1832 ri->uptime = bgp_clock ();
1833
1834 /* Same attribute comes in. */
1835 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1836 && attrhash_cmp (ri->attr, attr_new))
1837 {
1838
1839 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
1840
1841 if (BGP_DEBUG (update, UPDATE_IN))
1842 zlog (peer->log, LOG_DEBUG,
1843 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1844 peer->host,
1845 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1846 p->prefixlen, rsclient->host);
1847
1848 bgp_unlock_node (rn);
1849 bgp_attr_unintern (&attr_new);
1850
1851 return;
1852 }
1853
1854 /* Withdraw/Announce before we fully processed the withdraw */
1855 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1856 bgp_info_restore (rn, ri);
1857
1858 /* Received Logging. */
1859 if (BGP_DEBUG (update, UPDATE_IN))
1860 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
1861 peer->host,
1862 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1863 p->prefixlen, rsclient->host);
1864
1865 /* The attribute is changed. */
1866 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
1867
1868 /* Update to new attribute. */
1869 bgp_attr_unintern (&ri->attr);
1870 ri->attr = attr_new;
1871
1872 /* Update MPLS tag. */
1873 if (safi == SAFI_MPLS_VPN)
1874 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
1875
1876 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
1877
1878 /* Process change. */
1879 bgp_process (bgp, rn, afi, safi);
1880 bgp_unlock_node (rn);
1881
1882 return;
1883 }
1884
1885 /* Received Logging. */
1886 if (BGP_DEBUG (update, UPDATE_IN))
1887 {
1888 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
1889 peer->host,
1890 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1891 p->prefixlen, rsclient->host);
1892 }
1893
1894 /* Make new BGP info. */
1895 new = bgp_info_new ();
1896 new->type = type;
1897 new->sub_type = sub_type;
1898 new->peer = peer;
1899 new->attr = attr_new;
1900 new->uptime = bgp_clock ();
1901
1902 /* Update MPLS tag. */
1903 if (safi == SAFI_MPLS_VPN)
1904 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
1905
1906 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
1907
1908 /* Register new BGP information. */
1909 bgp_info_add (rn, new);
1910
1911 /* route_node_get lock */
1912 bgp_unlock_node (rn);
1913
1914 /* Process change. */
1915 bgp_process (bgp, rn, afi, safi);
1916
1917 bgp_attr_extra_free (&new_attr);
1918
1919 return;
1920
1921 filtered:
1922
1923 /* This BGP update is filtered. Log the reason then update BGP entry. */
1924 if (BGP_DEBUG (update, UPDATE_IN))
1925 zlog (peer->log, LOG_DEBUG,
1926 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1927 peer->host,
1928 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1929 p->prefixlen, rsclient->host, reason);
1930
1931 if (ri)
1932 bgp_rib_remove (rn, ri, peer, afi, safi);
1933
1934 bgp_unlock_node (rn);
1935
1936 if (new_attr.extra)
1937 bgp_attr_extra_free (&new_attr);
1938
1939 return;
1940 }
1941
1942 static void
1943 bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1944 struct peer *peer, struct prefix *p, int type, int sub_type,
1945 struct prefix_rd *prd, u_char *tag)
1946 {
1947 struct bgp_node *rn;
1948 struct bgp_info *ri;
1949 char buf[SU_ADDRSTRLEN];
1950
1951 if (rsclient == peer)
1952 return;
1953
1954 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1955
1956 /* Lookup withdrawn route. */
1957 for (ri = rn->info; ri; ri = ri->next)
1958 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1959 break;
1960
1961 /* Withdraw specified route from routing table. */
1962 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1963 bgp_rib_withdraw (rn, ri, peer, afi, safi);
1964 else if (BGP_DEBUG (update, UPDATE_IN))
1965 zlog (peer->log, LOG_DEBUG,
1966 "%s Can't find the route %s/%d", peer->host,
1967 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1968 p->prefixlen);
1969
1970 /* Unlock bgp_node_get() lock. */
1971 bgp_unlock_node (rn);
1972 }
1973
1974 static int
1975 bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
1976 afi_t afi, safi_t safi, int type, int sub_type,
1977 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1978 {
1979 int ret;
1980 int aspath_loop_count = 0;
1981 struct bgp_node *rn;
1982 struct bgp *bgp;
1983 struct attr new_attr = { 0 };
1984 struct attr *attr_new;
1985 struct bgp_info *ri;
1986 struct bgp_info *new;
1987 const char *reason;
1988 char buf[SU_ADDRSTRLEN];
1989
1990 bgp = peer->bgp;
1991 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
1992
1993 /* When peer's soft reconfiguration enabled. Record input packet in
1994 Adj-RIBs-In. */
1995 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1996 && peer != bgp->peer_self && ! soft_reconfig)
1997 bgp_adj_in_set (rn, peer, attr);
1998
1999 /* Check previously received route. */
2000 for (ri = rn->info; ri; ri = ri->next)
2001 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2002 break;
2003
2004 /* AS path local-as loop check. */
2005 if (peer->change_local_as)
2006 {
2007 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2008 aspath_loop_count = 1;
2009
2010 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2011 {
2012 reason = "as-path contains our own AS;";
2013 goto filtered;
2014 }
2015 }
2016
2017 /* AS path loop check. */
2018 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2019 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2020 && aspath_loop_check(attr->aspath, bgp->confed_id)
2021 > peer->allowas_in[afi][safi]))
2022 {
2023 reason = "as-path contains our own AS;";
2024 goto filtered;
2025 }
2026
2027 /* Route reflector originator ID check. */
2028 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2029 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2030 {
2031 reason = "originator is us;";
2032 goto filtered;
2033 }
2034
2035 /* Route reflector cluster ID check. */
2036 if (bgp_cluster_filter (peer, attr))
2037 {
2038 reason = "reflected from the same cluster;";
2039 goto filtered;
2040 }
2041
2042 /* Apply incoming filter. */
2043 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2044 {
2045 reason = "filter;";
2046 goto filtered;
2047 }
2048
2049 /* Apply incoming route-map. */
2050 bgp_attr_dup (&new_attr, attr);
2051
2052 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2053 {
2054 reason = "route-map;";
2055 goto filtered;
2056 }
2057
2058 /* IPv4 unicast next hop check. */
2059 if (afi == AFI_IP && safi == SAFI_UNICAST)
2060 {
2061 /* If the peer is EBGP and nexthop is not on connected route,
2062 discard it. */
2063 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2064 && ! bgp_nexthop_onlink (afi, &new_attr)
2065 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
2066 {
2067 reason = "non-connected next-hop;";
2068 goto filtered;
2069 }
2070
2071 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
2072 must not be my own address. */
2073 if (bgp_nexthop_self (afi, &new_attr)
2074 || new_attr.nexthop.s_addr == 0
2075 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
2076 {
2077 reason = "martian next-hop;";
2078 goto filtered;
2079 }
2080 }
2081
2082 attr_new = bgp_attr_intern (&new_attr);
2083
2084 /* If the update is implicit withdraw. */
2085 if (ri)
2086 {
2087 ri->uptime = bgp_clock ();
2088
2089 /* Same attribute comes in. */
2090 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2091 && attrhash_cmp (ri->attr, attr_new))
2092 {
2093 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2094
2095 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2096 && peer_sort (peer) == BGP_PEER_EBGP
2097 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2098 {
2099 if (BGP_DEBUG (update, UPDATE_IN))
2100 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2101 peer->host,
2102 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2103 p->prefixlen);
2104
2105 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2106 {
2107 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2108 bgp_process (bgp, rn, afi, safi);
2109 }
2110 }
2111 else /* Duplicate - odd */
2112 {
2113 if (BGP_DEBUG (update, UPDATE_IN))
2114 zlog (peer->log, LOG_DEBUG,
2115 "%s rcvd %s/%d...duplicate ignored",
2116 peer->host,
2117 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2118 p->prefixlen);
2119
2120 /* graceful restart STALE flag unset. */
2121 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2122 {
2123 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2124 bgp_process (bgp, rn, afi, safi);
2125 }
2126 }
2127
2128 bgp_unlock_node (rn);
2129 bgp_attr_unintern (&attr_new);
2130 bgp_attr_extra_free (&new_attr);
2131
2132 return 0;
2133 }
2134
2135 /* Withdraw/Announce before we fully processed the withdraw */
2136 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2137 {
2138 if (BGP_DEBUG (update, UPDATE_IN))
2139 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2140 peer->host,
2141 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2142 p->prefixlen);
2143 bgp_info_restore (rn, ri);
2144 }
2145
2146 /* Received Logging. */
2147 if (BGP_DEBUG (update, UPDATE_IN))
2148 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2149 peer->host,
2150 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2151 p->prefixlen);
2152
2153 /* graceful restart STALE flag unset. */
2154 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2155 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2156
2157 /* The attribute is changed. */
2158 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2159
2160 /* implicit withdraw, decrement aggregate and pcount here.
2161 * only if update is accepted, they'll increment below.
2162 */
2163 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2164
2165 /* Update bgp route dampening information. */
2166 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2167 && peer_sort (peer) == BGP_PEER_EBGP)
2168 {
2169 /* This is implicit withdraw so we should update dampening
2170 information. */
2171 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2172 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2173 }
2174
2175 /* Update to new attribute. */
2176 bgp_attr_unintern (&ri->attr);
2177 ri->attr = attr_new;
2178
2179 /* Update MPLS tag. */
2180 if (safi == SAFI_MPLS_VPN)
2181 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2182
2183 /* Update bgp route dampening information. */
2184 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2185 && peer_sort (peer) == BGP_PEER_EBGP)
2186 {
2187 /* Now we do normal update dampening. */
2188 ret = bgp_damp_update (ri, rn, afi, safi);
2189 if (ret == BGP_DAMP_SUPPRESSED)
2190 {
2191 bgp_unlock_node (rn);
2192 bgp_attr_extra_free (&new_attr);
2193 return 0;
2194 }
2195 }
2196
2197 /* Nexthop reachability check. */
2198 if ((afi == AFI_IP || afi == AFI_IP6)
2199 && safi == SAFI_UNICAST
2200 && (peer_sort (peer) == BGP_PEER_IBGP
2201 || peer_sort (peer) == BGP_PEER_CONFED
2202 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
2203 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
2204 {
2205 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
2206 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2207 else
2208 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2209 }
2210 else
2211 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2212
2213 /* Process change. */
2214 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2215
2216 bgp_process (bgp, rn, afi, safi);
2217 bgp_unlock_node (rn);
2218 bgp_attr_extra_free (&new_attr);
2219
2220 return 0;
2221 }
2222
2223 /* Received Logging. */
2224 if (BGP_DEBUG (update, UPDATE_IN))
2225 {
2226 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2227 peer->host,
2228 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2229 p->prefixlen);
2230 }
2231
2232 /* Make new BGP info. */
2233 new = bgp_info_new ();
2234 new->type = type;
2235 new->sub_type = sub_type;
2236 new->peer = peer;
2237 new->attr = attr_new;
2238 new->uptime = bgp_clock ();
2239
2240 /* Update MPLS tag. */
2241 if (safi == SAFI_MPLS_VPN)
2242 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2243
2244 /* Nexthop reachability check. */
2245 if ((afi == AFI_IP || afi == AFI_IP6)
2246 && safi == SAFI_UNICAST
2247 && (peer_sort (peer) == BGP_PEER_IBGP
2248 || peer_sort (peer) == BGP_PEER_CONFED
2249 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
2250 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
2251 {
2252 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
2253 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2254 else
2255 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2256 }
2257 else
2258 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2259
2260 /* Increment prefix */
2261 bgp_aggregate_increment (bgp, p, new, afi, safi);
2262
2263 /* Register new BGP information. */
2264 bgp_info_add (rn, new);
2265
2266 /* route_node_get lock */
2267 bgp_unlock_node (rn);
2268
2269 bgp_attr_extra_free (&new_attr);
2270
2271 /* If maximum prefix count is configured and current prefix
2272 count exeed it. */
2273 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2274 return -1;
2275
2276 /* Process change. */
2277 bgp_process (bgp, rn, afi, safi);
2278
2279 return 0;
2280
2281 /* This BGP update is filtered. Log the reason then update BGP
2282 entry. */
2283 filtered:
2284 if (BGP_DEBUG (update, UPDATE_IN))
2285 zlog (peer->log, LOG_DEBUG,
2286 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2287 peer->host,
2288 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2289 p->prefixlen, reason);
2290
2291 if (ri)
2292 bgp_rib_remove (rn, ri, peer, afi, safi);
2293
2294 bgp_unlock_node (rn);
2295
2296 bgp_attr_extra_free (&new_attr);
2297
2298 return 0;
2299 }
2300
2301 int
2302 bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2303 afi_t afi, safi_t safi, int type, int sub_type,
2304 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2305 {
2306 struct peer *rsclient;
2307 struct listnode *node, *nnode;
2308 struct bgp *bgp;
2309 int ret;
2310
2311 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2312 soft_reconfig);
2313
2314 bgp = peer->bgp;
2315
2316 /* Process the update for each RS-client. */
2317 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2318 {
2319 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2320 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2321 sub_type, prd, tag);
2322 }
2323
2324 return ret;
2325 }
2326
2327 int
2328 bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
2329 afi_t afi, safi_t safi, int type, int sub_type,
2330 struct prefix_rd *prd, u_char *tag)
2331 {
2332 struct bgp *bgp;
2333 char buf[SU_ADDRSTRLEN];
2334 struct bgp_node *rn;
2335 struct bgp_info *ri;
2336 struct peer *rsclient;
2337 struct listnode *node, *nnode;
2338
2339 bgp = peer->bgp;
2340
2341 /* Process the withdraw for each RS-client. */
2342 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2343 {
2344 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2345 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2346 }
2347
2348 /* Logging. */
2349 if (BGP_DEBUG (update, UPDATE_IN))
2350 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
2351 peer->host,
2352 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2353 p->prefixlen);
2354
2355 /* Lookup node. */
2356 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2357
2358 /* If peer is soft reconfiguration enabled. Record input packet for
2359 further calculation. */
2360 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2361 && peer != bgp->peer_self)
2362 bgp_adj_in_unset (rn, peer);
2363
2364 /* Lookup withdrawn route. */
2365 for (ri = rn->info; ri; ri = ri->next)
2366 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2367 break;
2368
2369 /* Withdraw specified route from routing table. */
2370 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2371 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2372 else if (BGP_DEBUG (update, UPDATE_IN))
2373 zlog (peer->log, LOG_DEBUG,
2374 "%s Can't find the route %s/%d", peer->host,
2375 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2376 p->prefixlen);
2377
2378 /* Unlock bgp_node_get() lock. */
2379 bgp_unlock_node (rn);
2380
2381 return 0;
2382 }
2383 \f
2384 void
2385 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2386 {
2387 struct bgp *bgp;
2388 struct attr attr = { 0 };
2389 struct aspath *aspath = { 0 };
2390 struct prefix p;
2391 struct bgp_info binfo;
2392 struct peer *from;
2393 int ret = RMAP_DENYMATCH;
2394
2395 if (!(afi == AFI_IP || afi == AFI_IP6))
2396 return;
2397
2398 bgp = peer->bgp;
2399 from = bgp->peer_self;
2400
2401 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2402 aspath = attr.aspath;
2403 attr.local_pref = bgp->default_local_pref;
2404 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2405
2406 if (afi == AFI_IP)
2407 str2prefix ("0.0.0.0/0", &p);
2408 #ifdef HAVE_IPV6
2409 else if (afi == AFI_IP6)
2410 {
2411 struct attr_extra *ae;
2412 attr.extra = NULL;
2413
2414 ae = bgp_attr_extra_get (&attr);
2415 attr.extra = ae;
2416
2417 str2prefix ("::/0", &p);
2418
2419 /* IPv6 global nexthop must be included. */
2420 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
2421 IPV6_MAX_BYTELEN);
2422 ae->mp_nexthop_len = 16;
2423
2424 /* If the peer is on shared nextwork and we have link-local
2425 nexthop set it. */
2426 if (peer->shared_network
2427 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2428 {
2429 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
2430 IPV6_MAX_BYTELEN);
2431 ae->mp_nexthop_len = 32;
2432 }
2433 }
2434 #endif /* HAVE_IPV6 */
2435
2436 if (peer->default_rmap[afi][safi].name)
2437 {
2438 binfo.peer = bgp->peer_self;
2439 binfo.attr = &attr;
2440
2441 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2442
2443 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2444 RMAP_BGP, &binfo);
2445
2446 bgp->peer_self->rmap_type = 0;
2447
2448 if (ret == RMAP_DENYMATCH)
2449 {
2450 bgp_attr_flush (&attr);
2451 withdraw = 1;
2452 }
2453 }
2454
2455 if (withdraw)
2456 {
2457 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2458 bgp_default_withdraw_send (peer, afi, safi);
2459 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2460 }
2461 else
2462 {
2463 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2464 bgp_default_update_send (peer, &attr, afi, safi, from);
2465 }
2466
2467 bgp_attr_extra_free (&attr);
2468 aspath_unintern (&aspath);
2469 }
2470 \f
2471 static void
2472 bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
2473 struct bgp_table *table, int rsclient)
2474 {
2475 struct bgp_node *rn;
2476 struct bgp_info *ri;
2477 struct attr attr = { 0 };
2478
2479 if (! table)
2480 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
2481
2482 if (safi != SAFI_MPLS_VPN
2483 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2484 bgp_default_originate (peer, afi, safi, 0);
2485
2486 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2487 for (ri = rn->info; ri; ri = ri->next)
2488 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2489 {
2490 if ( (rsclient) ?
2491 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2492 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
2493 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2494 else
2495 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2496
2497 bgp_attr_extra_free (&attr);
2498 }
2499 }
2500
2501 void
2502 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2503 {
2504 struct bgp_node *rn;
2505 struct bgp_table *table;
2506
2507 if (peer->status != Established)
2508 return;
2509
2510 if (! peer->afc_nego[afi][safi])
2511 return;
2512
2513 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2514 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2515 return;
2516
2517 if (safi != SAFI_MPLS_VPN)
2518 bgp_announce_table (peer, afi, safi, NULL, 0);
2519 else
2520 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2521 rn = bgp_route_next(rn))
2522 if ((table = (rn->info)) != NULL)
2523 bgp_announce_table (peer, afi, safi, table, 0);
2524
2525 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2526 bgp_announce_table (peer, afi, safi, NULL, 1);
2527 }
2528
2529 void
2530 bgp_announce_route_all (struct peer *peer)
2531 {
2532 afi_t afi;
2533 safi_t safi;
2534
2535 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2536 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2537 bgp_announce_route (peer, afi, safi);
2538 }
2539 \f
2540 static void
2541 bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2542 safi_t safi, struct bgp_table *table)
2543 {
2544 struct bgp_node *rn;
2545 struct bgp_adj_in *ain;
2546
2547 if (! table)
2548 table = rsclient->bgp->rib[afi][safi];
2549
2550 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2551 for (ain = rn->adj_in; ain; ain = ain->next)
2552 {
2553 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2554 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2555 }
2556 }
2557
2558 void
2559 bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2560 {
2561 struct bgp_table *table;
2562 struct bgp_node *rn;
2563
2564 if (safi != SAFI_MPLS_VPN)
2565 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2566
2567 else
2568 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2569 rn = bgp_route_next (rn))
2570 if ((table = rn->info) != NULL)
2571 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2572 }
2573 \f
2574 static void
2575 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2576 struct bgp_table *table)
2577 {
2578 int ret;
2579 struct bgp_node *rn;
2580 struct bgp_adj_in *ain;
2581
2582 if (! table)
2583 table = peer->bgp->rib[afi][safi];
2584
2585 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2586 for (ain = rn->adj_in; ain; ain = ain->next)
2587 {
2588 if (ain->peer == peer)
2589 {
2590 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2591 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2592 NULL, NULL, 1);
2593 if (ret < 0)
2594 {
2595 bgp_unlock_node (rn);
2596 return;
2597 }
2598 continue;
2599 }
2600 }
2601 }
2602
2603 void
2604 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2605 {
2606 struct bgp_node *rn;
2607 struct bgp_table *table;
2608
2609 if (peer->status != Established)
2610 return;
2611
2612 if (safi != SAFI_MPLS_VPN)
2613 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2614 else
2615 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2616 rn = bgp_route_next (rn))
2617 if ((table = rn->info) != NULL)
2618 bgp_soft_reconfig_table (peer, afi, safi, table);
2619 }
2620 \f
2621
2622 struct bgp_clear_node_queue
2623 {
2624 struct bgp_node *rn;
2625 enum bgp_clear_route_type purpose;
2626 };
2627
2628 static wq_item_status
2629 bgp_clear_route_node (struct work_queue *wq, void *data)
2630 {
2631 struct bgp_clear_node_queue *cnq = data;
2632 struct bgp_node *rn = cnq->rn;
2633 struct peer *peer = wq->spec.data;
2634 struct bgp_info *ri;
2635 afi_t afi = rn->table->afi;
2636 safi_t safi = rn->table->safi;
2637
2638 assert (rn && peer);
2639
2640 for (ri = rn->info; ri; ri = ri->next)
2641 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2642 {
2643 /* graceful restart STALE flag set. */
2644 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2645 && peer->nsf[afi][safi]
2646 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2647 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2648 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
2649 else
2650 bgp_rib_remove (rn, ri, peer, afi, safi);
2651 break;
2652 }
2653 return WQ_SUCCESS;
2654 }
2655
2656 static void
2657 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
2658 {
2659 struct bgp_clear_node_queue *cnq = data;
2660 struct bgp_node *rn = cnq->rn;
2661 struct bgp_table *table = rn->table;
2662
2663 bgp_unlock_node (rn);
2664 bgp_table_unlock (table);
2665 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
2666 }
2667
2668 static void
2669 bgp_clear_node_complete (struct work_queue *wq)
2670 {
2671 struct peer *peer = wq->spec.data;
2672
2673 /* Tickle FSM to start moving again */
2674 BGP_EVENT_ADD (peer, Clearing_Completed);
2675
2676 peer_unlock (peer); /* bgp_clear_route */
2677 }
2678
2679 static void
2680 bgp_clear_node_queue_init (struct peer *peer)
2681 {
2682 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
2683
2684 snprintf (wname, sizeof(wname), "clear %s", peer->host);
2685 #undef CLEAR_QUEUE_NAME_LEN
2686
2687 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
2688 {
2689 zlog_err ("%s: Failed to allocate work queue", __func__);
2690 exit (1);
2691 }
2692 peer->clear_node_queue->spec.hold = 10;
2693 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2694 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2695 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2696 peer->clear_node_queue->spec.max_retries = 0;
2697
2698 /* we only 'lock' this peer reference when the queue is actually active */
2699 peer->clear_node_queue->spec.data = peer;
2700 }
2701
2702 static void
2703 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2704 struct bgp_table *table, struct peer *rsclient,
2705 enum bgp_clear_route_type purpose)
2706 {
2707 struct bgp_node *rn;
2708
2709
2710 if (! table)
2711 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
2712
2713 /* If still no table => afi/safi isn't configured at all or smth. */
2714 if (! table)
2715 return;
2716
2717 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2718 {
2719 struct bgp_info *ri;
2720 struct bgp_adj_in *ain;
2721 struct bgp_adj_out *aout;
2722
2723 if (rn->info == NULL)
2724 continue;
2725
2726 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2727 * queued for every clearing peer, regardless of whether it is
2728 * relevant to the peer at hand.
2729 *
2730 * Overview: There are 3 different indices which need to be
2731 * scrubbed, potentially, when a peer is removed:
2732 *
2733 * 1 peer's routes visible via the RIB (ie accepted routes)
2734 * 2 peer's routes visible by the (optional) peer's adj-in index
2735 * 3 other routes visible by the peer's adj-out index
2736 *
2737 * 3 there is no hurry in scrubbing, once the struct peer is
2738 * removed from bgp->peer, we could just GC such deleted peer's
2739 * adj-outs at our leisure.
2740 *
2741 * 1 and 2 must be 'scrubbed' in some way, at least made
2742 * invisible via RIB index before peer session is allowed to be
2743 * brought back up. So one needs to know when such a 'search' is
2744 * complete.
2745 *
2746 * Ideally:
2747 *
2748 * - there'd be a single global queue or a single RIB walker
2749 * - rather than tracking which route_nodes still need to be
2750 * examined on a peer basis, we'd track which peers still
2751 * aren't cleared
2752 *
2753 * Given that our per-peer prefix-counts now should be reliable,
2754 * this may actually be achievable. It doesn't seem to be a huge
2755 * problem at this time,
2756 */
2757 for (ri = rn->info; ri; ri = ri->next)
2758 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2759 {
2760 struct bgp_clear_node_queue *cnq;
2761
2762 /* both unlocked in bgp_clear_node_queue_del */
2763 bgp_table_lock (rn->table);
2764 bgp_lock_node (rn);
2765 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2766 sizeof (struct bgp_clear_node_queue));
2767 cnq->rn = rn;
2768 cnq->purpose = purpose;
2769 work_queue_add (peer->clear_node_queue, cnq);
2770 break;
2771 }
2772
2773 for (ain = rn->adj_in; ain; ain = ain->next)
2774 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2775 {
2776 bgp_adj_in_remove (rn, ain);
2777 bgp_unlock_node (rn);
2778 break;
2779 }
2780 for (aout = rn->adj_out; aout; aout = aout->next)
2781 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2782 {
2783 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2784 bgp_unlock_node (rn);
2785 break;
2786 }
2787 }
2788 return;
2789 }
2790
2791 void
2792 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2793 enum bgp_clear_route_type purpose)
2794 {
2795 struct bgp_node *rn;
2796 struct bgp_table *table;
2797 struct peer *rsclient;
2798 struct listnode *node, *nnode;
2799
2800 if (peer->clear_node_queue == NULL)
2801 bgp_clear_node_queue_init (peer);
2802
2803 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2804 * Idle until it receives a Clearing_Completed event. This protects
2805 * against peers which flap faster than we can we clear, which could
2806 * lead to:
2807 *
2808 * a) race with routes from the new session being installed before
2809 * clear_route_node visits the node (to delete the route of that
2810 * peer)
2811 * b) resource exhaustion, clear_route_node likely leads to an entry
2812 * on the process_main queue. Fast-flapping could cause that queue
2813 * to grow and grow.
2814 */
2815 if (!peer->clear_node_queue->thread)
2816 peer_lock (peer); /* bgp_clear_node_complete */
2817
2818 switch (purpose)
2819 {
2820 case BGP_CLEAR_ROUTE_NORMAL:
2821 if (safi != SAFI_MPLS_VPN)
2822 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2823 else
2824 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2825 rn = bgp_route_next (rn))
2826 if ((table = rn->info) != NULL)
2827 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2828
2829 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2830 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2831 PEER_FLAG_RSERVER_CLIENT))
2832 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2833 break;
2834
2835 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2836 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2837 break;
2838
2839 default:
2840 assert (0);
2841 break;
2842 }
2843
2844 /* If no routes were cleared, nothing was added to workqueue, the
2845 * completion function won't be run by workqueue code - call it here.
2846 * XXX: Actually, this assumption doesn't hold, see
2847 * bgp_clear_route_table(), we queue all non-empty nodes.
2848 *
2849 * Additionally, there is a presumption in FSM that clearing is only
2850 * really needed if peer state is Established - peers in
2851 * pre-Established states shouldn't have any route-update state
2852 * associated with them (in or out).
2853 *
2854 * We still can get here in pre-Established though, through
2855 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2856 * check to ensure the assumption above holds.
2857 *
2858 * At some future point, this check could be move to the top of the
2859 * function, and do a quick early-return when state is
2860 * pre-Established, avoiding above list and table scans. Once we're
2861 * sure it is safe..
2862 */
2863 if (!peer->clear_node_queue->thread)
2864 bgp_clear_node_complete (peer->clear_node_queue);
2865 }
2866
2867 void
2868 bgp_clear_route_all (struct peer *peer)
2869 {
2870 afi_t afi;
2871 safi_t safi;
2872
2873 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2874 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2875 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
2876 }
2877
2878 void
2879 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2880 {
2881 struct bgp_table *table;
2882 struct bgp_node *rn;
2883 struct bgp_adj_in *ain;
2884
2885 table = peer->bgp->rib[afi][safi];
2886
2887 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2888 for (ain = rn->adj_in; ain ; ain = ain->next)
2889 if (ain->peer == peer)
2890 {
2891 bgp_adj_in_remove (rn, ain);
2892 bgp_unlock_node (rn);
2893 break;
2894 }
2895 }
2896
2897 void
2898 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2899 {
2900 struct bgp_node *rn;
2901 struct bgp_info *ri;
2902 struct bgp_table *table;
2903
2904 table = peer->bgp->rib[afi][safi];
2905
2906 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2907 {
2908 for (ri = rn->info; ri; ri = ri->next)
2909 if (ri->peer == peer)
2910 {
2911 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2912 bgp_rib_remove (rn, ri, peer, afi, safi);
2913 break;
2914 }
2915 }
2916 }
2917 \f
2918 /* Delete all kernel routes. */
2919 void
2920 bgp_cleanup_routes (void)
2921 {
2922 struct bgp *bgp;
2923 struct listnode *node, *nnode;
2924 struct bgp_node *rn;
2925 struct bgp_table *table;
2926 struct bgp_info *ri;
2927
2928 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
2929 {
2930 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2931
2932 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2933 for (ri = rn->info; ri; ri = ri->next)
2934 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2935 && ri->type == ZEBRA_ROUTE_BGP
2936 && ri->sub_type == BGP_ROUTE_NORMAL)
2937 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
2938
2939 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2940
2941 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2942 for (ri = rn->info; ri; ri = ri->next)
2943 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2944 && ri->type == ZEBRA_ROUTE_BGP
2945 && ri->sub_type == BGP_ROUTE_NORMAL)
2946 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
2947 }
2948 }
2949
2950 void
2951 bgp_reset (void)
2952 {
2953 vty_reset ();
2954 bgp_zclient_reset ();
2955 access_list_reset ();
2956 prefix_list_reset ();
2957 }
2958 \f
2959 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2960 value. */
2961 int
2962 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2963 {
2964 u_char *pnt;
2965 u_char *lim;
2966 struct prefix p;
2967 int psize;
2968 int ret;
2969
2970 /* Check peer status. */
2971 if (peer->status != Established)
2972 return 0;
2973
2974 pnt = packet->nlri;
2975 lim = pnt + packet->length;
2976
2977 for (; pnt < lim; pnt += psize)
2978 {
2979 /* Clear prefix structure. */
2980 memset (&p, 0, sizeof (struct prefix));
2981
2982 /* Fetch prefix length. */
2983 p.prefixlen = *pnt++;
2984 p.family = afi2family (packet->afi);
2985
2986 /* Already checked in nlri_sanity_check(). We do double check
2987 here. */
2988 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2989 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2990 return -1;
2991
2992 /* Packet size overflow check. */
2993 psize = PSIZE (p.prefixlen);
2994
2995 /* When packet overflow occur return immediately. */
2996 if (pnt + psize > lim)
2997 return -1;
2998
2999 /* Fetch prefix from NLRI packet. */
3000 memcpy (&p.u.prefix, pnt, psize);
3001
3002 /* Check address. */
3003 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3004 {
3005 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3006 {
3007 /*
3008 * From draft-ietf-idr-bgp4-22, Section 6.3:
3009 * If a BGP router receives an UPDATE message with a
3010 * semantically incorrect NLRI field, in which a prefix is
3011 * semantically incorrect (eg. an unexpected multicast IP
3012 * address), it should ignore the prefix.
3013 */
3014 zlog (peer->log, LOG_ERR,
3015 "IPv4 unicast NLRI is multicast address %s",
3016 inet_ntoa (p.u.prefix4));
3017
3018 return -1;
3019 }
3020 }
3021
3022 #ifdef HAVE_IPV6
3023 /* Check address. */
3024 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3025 {
3026 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3027 {
3028 char buf[BUFSIZ];
3029
3030 zlog (peer->log, LOG_WARNING,
3031 "IPv6 link-local NLRI received %s ignore this NLRI",
3032 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3033
3034 continue;
3035 }
3036 }
3037 #endif /* HAVE_IPV6 */
3038
3039 /* Normal process. */
3040 if (attr)
3041 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3042 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3043 else
3044 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3045 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3046
3047 /* Address family configuration mismatch or maximum-prefix count
3048 overflow. */
3049 if (ret < 0)
3050 return -1;
3051 }
3052
3053 /* Packet length consistency check. */
3054 if (pnt != lim)
3055 return -1;
3056
3057 return 0;
3058 }
3059
3060 /* NLRI encode syntax check routine. */
3061 int
3062 bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3063 bgp_size_t length)
3064 {
3065 u_char *end;
3066 u_char prefixlen;
3067 int psize;
3068
3069 end = pnt + length;
3070
3071 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3072 syntactic validity. If the field is syntactically incorrect,
3073 then the Error Subcode is set to Invalid Network Field. */
3074
3075 while (pnt < end)
3076 {
3077 prefixlen = *pnt++;
3078
3079 /* Prefix length check. */
3080 if ((afi == AFI_IP && prefixlen > 32)
3081 || (afi == AFI_IP6 && prefixlen > 128))
3082 {
3083 plog_err (peer->log,
3084 "%s [Error] Update packet error (wrong prefix length %d)",
3085 peer->host, prefixlen);
3086 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3087 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3088 return -1;
3089 }
3090
3091 /* Packet size overflow check. */
3092 psize = PSIZE (prefixlen);
3093
3094 if (pnt + psize > end)
3095 {
3096 plog_err (peer->log,
3097 "%s [Error] Update packet error"
3098 " (prefix data overflow prefix size is %d)",
3099 peer->host, psize);
3100 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3101 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3102 return -1;
3103 }
3104
3105 pnt += psize;
3106 }
3107
3108 /* Packet length consistency check. */
3109 if (pnt != end)
3110 {
3111 plog_err (peer->log,
3112 "%s [Error] Update packet error"
3113 " (prefix length mismatch with total length)",
3114 peer->host);
3115 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3116 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3117 return -1;
3118 }
3119 return 0;
3120 }
3121 \f
3122 static struct bgp_static *
3123 bgp_static_new (void)
3124 {
3125 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3126 }
3127
3128 static void
3129 bgp_static_free (struct bgp_static *bgp_static)
3130 {
3131 if (bgp_static->rmap.name)
3132 free (bgp_static->rmap.name);
3133 XFREE (MTYPE_BGP_STATIC, bgp_static);
3134 }
3135
3136 static void
3137 bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3138 struct prefix *p, afi_t afi, safi_t safi)
3139 {
3140 struct bgp_node *rn;
3141 struct bgp_info *ri;
3142
3143 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3144
3145 /* Check selected route and self inserted route. */
3146 for (ri = rn->info; ri; ri = ri->next)
3147 if (ri->peer == bgp->peer_self
3148 && ri->type == ZEBRA_ROUTE_BGP
3149 && ri->sub_type == BGP_ROUTE_STATIC)
3150 break;
3151
3152 /* Withdraw static BGP route from routing table. */
3153 if (ri)
3154 {
3155 bgp_info_delete (rn, ri);
3156 bgp_process (bgp, rn, afi, safi);
3157 }
3158
3159 /* Unlock bgp_node_lookup. */
3160 bgp_unlock_node (rn);
3161 }
3162
3163 static void
3164 bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
3165 struct bgp_static *bgp_static,
3166 afi_t afi, safi_t safi)
3167 {
3168 struct bgp_node *rn;
3169 struct bgp_info *ri;
3170 struct bgp_info *new;
3171 struct bgp_info info;
3172 struct attr *attr_new;
3173 struct attr attr = {0 };
3174 struct attr new_attr = { .extra = 0 };
3175 struct bgp *bgp;
3176 int ret;
3177 char buf[SU_ADDRSTRLEN];
3178
3179 bgp = rsclient->bgp;
3180
3181 assert (bgp_static);
3182 if (!bgp_static)
3183 return;
3184
3185 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3186
3187 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3188
3189 attr.nexthop = bgp_static->igpnexthop;
3190 attr.med = bgp_static->igpmetric;
3191 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3192
3193 if (bgp_static->atomic)
3194 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3195
3196 /* Apply network route-map for export to this rsclient. */
3197 if (bgp_static->rmap.name)
3198 {
3199 struct attr attr_tmp = attr;
3200 info.peer = rsclient;
3201 info.attr = &attr_tmp;
3202
3203 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3204 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3205
3206 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3207
3208 rsclient->rmap_type = 0;
3209
3210 if (ret == RMAP_DENYMATCH)
3211 {
3212 /* Free uninterned attribute. */
3213 bgp_attr_flush (&attr_tmp);
3214
3215 /* Unintern original. */
3216 aspath_unintern (&attr.aspath);
3217 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3218 bgp_attr_extra_free (&attr);
3219
3220 return;
3221 }
3222 attr_new = bgp_attr_intern (&attr_tmp);
3223 }
3224 else
3225 attr_new = bgp_attr_intern (&attr);
3226
3227 bgp_attr_dup(&new_attr, attr_new);
3228
3229 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3230
3231 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3232 == RMAP_DENY)
3233 {
3234 /* This BGP update is filtered. Log the reason then update BGP entry. */
3235 if (BGP_DEBUG (update, UPDATE_IN))
3236 zlog (rsclient->log, LOG_DEBUG,
3237 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3238 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3239 p->prefixlen, rsclient->host);
3240
3241 bgp->peer_self->rmap_type = 0;
3242
3243 bgp_attr_unintern (&attr_new);
3244 aspath_unintern (&attr.aspath);
3245 bgp_attr_extra_free (&attr);
3246
3247 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3248
3249 return;
3250 }
3251
3252 bgp->peer_self->rmap_type = 0;
3253
3254 bgp_attr_unintern (&attr_new);
3255 attr_new = bgp_attr_intern (&new_attr);
3256 bgp_attr_extra_free (&new_attr);
3257
3258 for (ri = rn->info; ri; ri = ri->next)
3259 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3260 && ri->sub_type == BGP_ROUTE_STATIC)
3261 break;
3262
3263 if (ri)
3264 {
3265 if (attrhash_cmp (ri->attr, attr_new) &&
3266 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3267 {
3268 bgp_unlock_node (rn);
3269 bgp_attr_unintern (&attr_new);
3270 aspath_unintern (&attr.aspath);
3271 bgp_attr_extra_free (&attr);
3272 return;
3273 }
3274 else
3275 {
3276 /* The attribute is changed. */
3277 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3278
3279 /* Rewrite BGP route information. */
3280 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3281 bgp_info_restore(rn, ri);
3282 bgp_attr_unintern (&ri->attr);
3283 ri->attr = attr_new;
3284 ri->uptime = bgp_clock ();
3285
3286 /* Process change. */
3287 bgp_process (bgp, rn, afi, safi);
3288 bgp_unlock_node (rn);
3289 aspath_unintern (&attr.aspath);
3290 bgp_attr_extra_free (&attr);
3291 return;
3292 }
3293 }
3294
3295 /* Make new BGP info. */
3296 new = bgp_info_new ();
3297 new->type = ZEBRA_ROUTE_BGP;
3298 new->sub_type = BGP_ROUTE_STATIC;
3299 new->peer = bgp->peer_self;
3300 SET_FLAG (new->flags, BGP_INFO_VALID);
3301 new->attr = attr_new;
3302 new->uptime = bgp_clock ();
3303
3304 /* Register new BGP information. */
3305 bgp_info_add (rn, new);
3306
3307 /* route_node_get lock */
3308 bgp_unlock_node (rn);
3309
3310 /* Process change. */
3311 bgp_process (bgp, rn, afi, safi);
3312
3313 /* Unintern original. */
3314 aspath_unintern (&attr.aspath);
3315 bgp_attr_extra_free (&attr);
3316 }
3317
3318 static void
3319 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3320 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3321 {
3322 struct bgp_node *rn;
3323 struct bgp_info *ri;
3324 struct bgp_info *new;
3325 struct bgp_info info;
3326 struct attr attr = { 0 };
3327 struct attr *attr_new;
3328 int ret;
3329
3330 assert (bgp_static);
3331 if (!bgp_static)
3332 return;
3333
3334 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3335
3336 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3337
3338 attr.nexthop = bgp_static->igpnexthop;
3339 attr.med = bgp_static->igpmetric;
3340 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3341
3342 if (bgp_static->atomic)
3343 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3344
3345 /* Apply route-map. */
3346 if (bgp_static->rmap.name)
3347 {
3348 struct attr attr_tmp = attr;
3349 info.peer = bgp->peer_self;
3350 info.attr = &attr_tmp;
3351
3352 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3353
3354 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3355
3356 bgp->peer_self->rmap_type = 0;
3357
3358 if (ret == RMAP_DENYMATCH)
3359 {
3360 /* Free uninterned attribute. */
3361 bgp_attr_flush (&attr_tmp);
3362
3363 /* Unintern original. */
3364 aspath_unintern (&attr.aspath);
3365 bgp_attr_extra_free (&attr);
3366 bgp_static_withdraw (bgp, p, afi, safi);
3367 return;
3368 }
3369 attr_new = bgp_attr_intern (&attr_tmp);
3370 }
3371 else
3372 attr_new = bgp_attr_intern (&attr);
3373
3374 for (ri = rn->info; ri; ri = ri->next)
3375 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3376 && ri->sub_type == BGP_ROUTE_STATIC)
3377 break;
3378
3379 if (ri)
3380 {
3381 if (attrhash_cmp (ri->attr, attr_new) &&
3382 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3383 {
3384 bgp_unlock_node (rn);
3385 bgp_attr_unintern (&attr_new);
3386 aspath_unintern (&attr.aspath);
3387 bgp_attr_extra_free (&attr);
3388 return;
3389 }
3390 else
3391 {
3392 /* The attribute is changed. */
3393 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3394
3395 /* Rewrite BGP route information. */
3396 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3397 bgp_info_restore(rn, ri);
3398 else
3399 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3400 bgp_attr_unintern (&ri->attr);
3401 ri->attr = attr_new;
3402 ri->uptime = bgp_clock ();
3403
3404 /* Process change. */
3405 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3406 bgp_process (bgp, rn, afi, safi);
3407 bgp_unlock_node (rn);
3408 aspath_unintern (&attr.aspath);
3409 bgp_attr_extra_free (&attr);
3410 return;
3411 }
3412 }
3413
3414 /* Make new BGP info. */
3415 new = bgp_info_new ();
3416 new->type = ZEBRA_ROUTE_BGP;
3417 new->sub_type = BGP_ROUTE_STATIC;
3418 new->peer = bgp->peer_self;
3419 SET_FLAG (new->flags, BGP_INFO_VALID);
3420 new->attr = attr_new;
3421 new->uptime = bgp_clock ();
3422
3423 /* Aggregate address increment. */
3424 bgp_aggregate_increment (bgp, p, new, afi, safi);
3425
3426 /* Register new BGP information. */
3427 bgp_info_add (rn, new);
3428
3429 /* route_node_get lock */
3430 bgp_unlock_node (rn);
3431
3432 /* Process change. */
3433 bgp_process (bgp, rn, afi, safi);
3434
3435 /* Unintern original. */
3436 aspath_unintern (&attr.aspath);
3437 bgp_attr_extra_free (&attr);
3438 }
3439
3440 void
3441 bgp_static_update (struct bgp *bgp, struct prefix *p,
3442 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3443 {
3444 struct peer *rsclient;
3445 struct listnode *node, *nnode;
3446
3447 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3448
3449 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
3450 {
3451 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3452 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3453 }
3454 }
3455
3456 static void
3457 bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3458 safi_t safi, struct prefix_rd *prd, u_char *tag)
3459 {
3460 struct bgp_node *rn;
3461 struct bgp_info *new;
3462
3463 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3464
3465 /* Make new BGP info. */
3466 new = bgp_info_new ();
3467 new->type = ZEBRA_ROUTE_BGP;
3468 new->sub_type = BGP_ROUTE_STATIC;
3469 new->peer = bgp->peer_self;
3470 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3471 SET_FLAG (new->flags, BGP_INFO_VALID);
3472 new->uptime = bgp_clock ();
3473 new->extra = bgp_info_extra_new();
3474 memcpy (new->extra->tag, tag, 3);
3475
3476 /* Aggregate address increment. */
3477 bgp_aggregate_increment (bgp, p, new, afi, safi);
3478
3479 /* Register new BGP information. */
3480 bgp_info_add (rn, new);
3481
3482 /* route_node_get lock */
3483 bgp_unlock_node (rn);
3484
3485 /* Process change. */
3486 bgp_process (bgp, rn, afi, safi);
3487 }
3488
3489 void
3490 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3491 safi_t safi)
3492 {
3493 struct bgp_node *rn;
3494 struct bgp_info *ri;
3495
3496 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3497
3498 /* Check selected route and self inserted route. */
3499 for (ri = rn->info; ri; ri = ri->next)
3500 if (ri->peer == bgp->peer_self
3501 && ri->type == ZEBRA_ROUTE_BGP
3502 && ri->sub_type == BGP_ROUTE_STATIC)
3503 break;
3504
3505 /* Withdraw static BGP route from routing table. */
3506 if (ri)
3507 {
3508 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3509 bgp_info_delete (rn, ri);
3510 bgp_process (bgp, rn, afi, safi);
3511 }
3512
3513 /* Unlock bgp_node_lookup. */
3514 bgp_unlock_node (rn);
3515 }
3516
3517 void
3518 bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3519 {
3520 struct bgp_static *bgp_static;
3521 struct bgp *bgp;
3522 struct bgp_node *rn;
3523 struct prefix *p;
3524
3525 bgp = rsclient->bgp;
3526
3527 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3528 if ((bgp_static = rn->info) != NULL)
3529 {
3530 p = &rn->p;
3531
3532 bgp_static_update_rsclient (rsclient, p, bgp_static,
3533 afi, safi);
3534 }
3535 }
3536
3537 static void
3538 bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3539 safi_t safi, struct prefix_rd *prd, u_char *tag)
3540 {
3541 struct bgp_node *rn;
3542 struct bgp_info *ri;
3543
3544 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3545
3546 /* Check selected route and self inserted route. */
3547 for (ri = rn->info; ri; ri = ri->next)
3548 if (ri->peer == bgp->peer_self
3549 && ri->type == ZEBRA_ROUTE_BGP
3550 && ri->sub_type == BGP_ROUTE_STATIC)
3551 break;
3552
3553 /* Withdraw static BGP route from routing table. */
3554 if (ri)
3555 {
3556 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3557 bgp_info_delete (rn, ri);
3558 bgp_process (bgp, rn, afi, safi);
3559 }
3560
3561 /* Unlock bgp_node_lookup. */
3562 bgp_unlock_node (rn);
3563 }
3564
3565 /* Configure static BGP network. When user don't run zebra, static
3566 route should be installed as valid. */
3567 static int
3568 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3569 afi_t afi, safi_t safi, const char *rmap, int backdoor)
3570 {
3571 int ret;
3572 struct prefix p;
3573 struct bgp_static *bgp_static;
3574 struct bgp_node *rn;
3575 u_char need_update = 0;
3576
3577 /* Convert IP prefix string to struct prefix. */
3578 ret = str2prefix (ip_str, &p);
3579 if (! ret)
3580 {
3581 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3582 return CMD_WARNING;
3583 }
3584 #ifdef HAVE_IPV6
3585 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3586 {
3587 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3588 VTY_NEWLINE);
3589 return CMD_WARNING;
3590 }
3591 #endif /* HAVE_IPV6 */
3592
3593 apply_mask (&p);
3594
3595 /* Set BGP static route configuration. */
3596 rn = bgp_node_get (bgp->route[afi][safi], &p);
3597
3598 if (rn->info)
3599 {
3600 /* Configuration change. */
3601 bgp_static = rn->info;
3602
3603 /* Check previous routes are installed into BGP. */
3604 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3605 need_update = 1;
3606
3607 bgp_static->backdoor = backdoor;
3608
3609 if (rmap)
3610 {
3611 if (bgp_static->rmap.name)
3612 free (bgp_static->rmap.name);
3613 bgp_static->rmap.name = strdup (rmap);
3614 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3615 }
3616 else
3617 {
3618 if (bgp_static->rmap.name)
3619 free (bgp_static->rmap.name);
3620 bgp_static->rmap.name = NULL;
3621 bgp_static->rmap.map = NULL;
3622 bgp_static->valid = 0;
3623 }
3624 bgp_unlock_node (rn);
3625 }
3626 else
3627 {
3628 /* New configuration. */
3629 bgp_static = bgp_static_new ();
3630 bgp_static->backdoor = backdoor;
3631 bgp_static->valid = 0;
3632 bgp_static->igpmetric = 0;
3633 bgp_static->igpnexthop.s_addr = 0;
3634
3635 if (rmap)
3636 {
3637 if (bgp_static->rmap.name)
3638 free (bgp_static->rmap.name);
3639 bgp_static->rmap.name = strdup (rmap);
3640 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3641 }
3642 rn->info = bgp_static;
3643 }
3644
3645 /* If BGP scan is not enabled, we should install this route here. */
3646 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3647 {
3648 bgp_static->valid = 1;
3649
3650 if (need_update)
3651 bgp_static_withdraw (bgp, &p, afi, safi);
3652
3653 if (! bgp_static->backdoor)
3654 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3655 }
3656
3657 return CMD_SUCCESS;
3658 }
3659
3660 /* Configure static BGP network. */
3661 static int
3662 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
3663 afi_t afi, safi_t safi)
3664 {
3665 int ret;
3666 struct prefix p;
3667 struct bgp_static *bgp_static;
3668 struct bgp_node *rn;
3669
3670 /* Convert IP prefix string to struct prefix. */
3671 ret = str2prefix (ip_str, &p);
3672 if (! ret)
3673 {
3674 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3675 return CMD_WARNING;
3676 }
3677 #ifdef HAVE_IPV6
3678 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3679 {
3680 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3681 VTY_NEWLINE);
3682 return CMD_WARNING;
3683 }
3684 #endif /* HAVE_IPV6 */
3685
3686 apply_mask (&p);
3687
3688 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3689 if (! rn)
3690 {
3691 vty_out (vty, "%% Can't find specified static route configuration.%s",
3692 VTY_NEWLINE);
3693 return CMD_WARNING;
3694 }
3695
3696 bgp_static = rn->info;
3697
3698 /* Update BGP RIB. */
3699 if (! bgp_static->backdoor)
3700 bgp_static_withdraw (bgp, &p, afi, safi);
3701
3702 /* Clear configuration. */
3703 bgp_static_free (bgp_static);
3704 rn->info = NULL;
3705 bgp_unlock_node (rn);
3706 bgp_unlock_node (rn);
3707
3708 return CMD_SUCCESS;
3709 }
3710
3711 /* Called from bgp_delete(). Delete all static routes from the BGP
3712 instance. */
3713 void
3714 bgp_static_delete (struct bgp *bgp)
3715 {
3716 afi_t afi;
3717 safi_t safi;
3718 struct bgp_node *rn;
3719 struct bgp_node *rm;
3720 struct bgp_table *table;
3721 struct bgp_static *bgp_static;
3722
3723 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3724 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3725 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3726 if (rn->info != NULL)
3727 {
3728 if (safi == SAFI_MPLS_VPN)
3729 {
3730 table = rn->info;
3731
3732 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3733 {
3734 bgp_static = rn->info;
3735 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3736 AFI_IP, SAFI_MPLS_VPN,
3737 (struct prefix_rd *)&rn->p,
3738 bgp_static->tag);
3739 bgp_static_free (bgp_static);
3740 rn->info = NULL;
3741 bgp_unlock_node (rn);
3742 }
3743 }
3744 else
3745 {
3746 bgp_static = rn->info;
3747 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3748 bgp_static_free (bgp_static);
3749 rn->info = NULL;
3750 bgp_unlock_node (rn);
3751 }
3752 }
3753 }
3754
3755 int
3756 bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3757 const char *tag_str)
3758 {
3759 int ret;
3760 struct prefix p;
3761 struct prefix_rd prd;
3762 struct bgp *bgp;
3763 struct bgp_node *prn;
3764 struct bgp_node *rn;
3765 struct bgp_table *table;
3766 struct bgp_static *bgp_static;
3767 u_char tag[3];
3768
3769 bgp = vty->index;
3770
3771 ret = str2prefix (ip_str, &p);
3772 if (! ret)
3773 {
3774 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3775 return CMD_WARNING;
3776 }
3777 apply_mask (&p);
3778
3779 ret = str2prefix_rd (rd_str, &prd);
3780 if (! ret)
3781 {
3782 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3783 return CMD_WARNING;
3784 }
3785
3786 ret = str2tag (tag_str, tag);
3787 if (! ret)
3788 {
3789 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3790 return CMD_WARNING;
3791 }
3792
3793 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3794 (struct prefix *)&prd);
3795 if (prn->info == NULL)
3796 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3797 else
3798 bgp_unlock_node (prn);
3799 table = prn->info;
3800
3801 rn = bgp_node_get (table, &p);
3802
3803 if (rn->info)
3804 {
3805 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3806 bgp_unlock_node (rn);
3807 }
3808 else
3809 {
3810 /* New configuration. */
3811 bgp_static = bgp_static_new ();
3812 bgp_static->valid = 1;
3813 memcpy (bgp_static->tag, tag, 3);
3814 rn->info = bgp_static;
3815
3816 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3817 }
3818
3819 return CMD_SUCCESS;
3820 }
3821
3822 /* Configure static BGP network. */
3823 int
3824 bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3825 const char *rd_str, const char *tag_str)
3826 {
3827 int ret;
3828 struct bgp *bgp;
3829 struct prefix p;
3830 struct prefix_rd prd;
3831 struct bgp_node *prn;
3832 struct bgp_node *rn;
3833 struct bgp_table *table;
3834 struct bgp_static *bgp_static;
3835 u_char tag[3];
3836
3837 bgp = vty->index;
3838
3839 /* Convert IP prefix string to struct prefix. */
3840 ret = str2prefix (ip_str, &p);
3841 if (! ret)
3842 {
3843 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3844 return CMD_WARNING;
3845 }
3846 apply_mask (&p);
3847
3848 ret = str2prefix_rd (rd_str, &prd);
3849 if (! ret)
3850 {
3851 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3852 return CMD_WARNING;
3853 }
3854
3855 ret = str2tag (tag_str, tag);
3856 if (! ret)
3857 {
3858 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3859 return CMD_WARNING;
3860 }
3861
3862 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3863 (struct prefix *)&prd);
3864 if (prn->info == NULL)
3865 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3866 else
3867 bgp_unlock_node (prn);
3868 table = prn->info;
3869
3870 rn = bgp_node_lookup (table, &p);
3871
3872 if (rn)
3873 {
3874 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3875
3876 bgp_static = rn->info;
3877 bgp_static_free (bgp_static);
3878 rn->info = NULL;
3879 bgp_unlock_node (rn);
3880 bgp_unlock_node (rn);
3881 }
3882 else
3883 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3884
3885 return CMD_SUCCESS;
3886 }
3887 \f
3888 DEFUN (bgp_network,
3889 bgp_network_cmd,
3890 "network A.B.C.D/M",
3891 "Specify a network to announce via BGP\n"
3892 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3893 {
3894 return bgp_static_set (vty, vty->index, argv[0],
3895 AFI_IP, bgp_node_safi (vty), NULL, 0);
3896 }
3897
3898 DEFUN (bgp_network_route_map,
3899 bgp_network_route_map_cmd,
3900 "network A.B.C.D/M route-map WORD",
3901 "Specify a network to announce via BGP\n"
3902 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3903 "Route-map to modify the attributes\n"
3904 "Name of the route map\n")
3905 {
3906 return bgp_static_set (vty, vty->index, argv[0],
3907 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3908 }
3909
3910 DEFUN (bgp_network_backdoor,
3911 bgp_network_backdoor_cmd,
3912 "network A.B.C.D/M backdoor",
3913 "Specify a network to announce via BGP\n"
3914 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3915 "Specify a BGP backdoor route\n")
3916 {
3917 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
3918 NULL, 1);
3919 }
3920
3921 DEFUN (bgp_network_mask,
3922 bgp_network_mask_cmd,
3923 "network A.B.C.D mask A.B.C.D",
3924 "Specify a network to announce via BGP\n"
3925 "Network number\n"
3926 "Network mask\n"
3927 "Network mask\n")
3928 {
3929 int ret;
3930 char prefix_str[BUFSIZ];
3931
3932 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3933 if (! ret)
3934 {
3935 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3936 return CMD_WARNING;
3937 }
3938
3939 return bgp_static_set (vty, vty->index, prefix_str,
3940 AFI_IP, bgp_node_safi (vty), NULL, 0);
3941 }
3942
3943 DEFUN (bgp_network_mask_route_map,
3944 bgp_network_mask_route_map_cmd,
3945 "network A.B.C.D mask A.B.C.D route-map WORD",
3946 "Specify a network to announce via BGP\n"
3947 "Network number\n"
3948 "Network mask\n"
3949 "Network mask\n"
3950 "Route-map to modify the attributes\n"
3951 "Name of the route map\n")
3952 {
3953 int ret;
3954 char prefix_str[BUFSIZ];
3955
3956 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3957 if (! ret)
3958 {
3959 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3960 return CMD_WARNING;
3961 }
3962
3963 return bgp_static_set (vty, vty->index, prefix_str,
3964 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3965 }
3966
3967 DEFUN (bgp_network_mask_backdoor,
3968 bgp_network_mask_backdoor_cmd,
3969 "network A.B.C.D mask A.B.C.D backdoor",
3970 "Specify a network to announce via BGP\n"
3971 "Network number\n"
3972 "Network mask\n"
3973 "Network mask\n"
3974 "Specify a BGP backdoor route\n")
3975 {
3976 int ret;
3977 char prefix_str[BUFSIZ];
3978
3979 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3980 if (! ret)
3981 {
3982 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3983 return CMD_WARNING;
3984 }
3985
3986 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
3987 NULL, 1);
3988 }
3989
3990 DEFUN (bgp_network_mask_natural,
3991 bgp_network_mask_natural_cmd,
3992 "network A.B.C.D",
3993 "Specify a network to announce via BGP\n"
3994 "Network number\n")
3995 {
3996 int ret;
3997 char prefix_str[BUFSIZ];
3998
3999 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4000 if (! ret)
4001 {
4002 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4003 return CMD_WARNING;
4004 }
4005
4006 return bgp_static_set (vty, vty->index, prefix_str,
4007 AFI_IP, bgp_node_safi (vty), NULL, 0);
4008 }
4009
4010 DEFUN (bgp_network_mask_natural_route_map,
4011 bgp_network_mask_natural_route_map_cmd,
4012 "network A.B.C.D route-map WORD",
4013 "Specify a network to announce via BGP\n"
4014 "Network number\n"
4015 "Route-map to modify the attributes\n"
4016 "Name of the route map\n")
4017 {
4018 int ret;
4019 char prefix_str[BUFSIZ];
4020
4021 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4022 if (! ret)
4023 {
4024 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4025 return CMD_WARNING;
4026 }
4027
4028 return bgp_static_set (vty, vty->index, prefix_str,
4029 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4030 }
4031
4032 DEFUN (bgp_network_mask_natural_backdoor,
4033 bgp_network_mask_natural_backdoor_cmd,
4034 "network A.B.C.D backdoor",
4035 "Specify a network to announce via BGP\n"
4036 "Network number\n"
4037 "Specify a BGP backdoor route\n")
4038 {
4039 int ret;
4040 char prefix_str[BUFSIZ];
4041
4042 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4043 if (! ret)
4044 {
4045 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4046 return CMD_WARNING;
4047 }
4048
4049 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4050 NULL, 1);
4051 }
4052
4053 DEFUN (no_bgp_network,
4054 no_bgp_network_cmd,
4055 "no network A.B.C.D/M",
4056 NO_STR
4057 "Specify a network to announce via BGP\n"
4058 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4059 {
4060 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4061 bgp_node_safi (vty));
4062 }
4063
4064 ALIAS (no_bgp_network,
4065 no_bgp_network_route_map_cmd,
4066 "no network A.B.C.D/M route-map WORD",
4067 NO_STR
4068 "Specify a network to announce via BGP\n"
4069 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4070 "Route-map to modify the attributes\n"
4071 "Name of the route map\n")
4072
4073 ALIAS (no_bgp_network,
4074 no_bgp_network_backdoor_cmd,
4075 "no network A.B.C.D/M backdoor",
4076 NO_STR
4077 "Specify a network to announce via BGP\n"
4078 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4079 "Specify a BGP backdoor route\n")
4080
4081 DEFUN (no_bgp_network_mask,
4082 no_bgp_network_mask_cmd,
4083 "no network A.B.C.D mask A.B.C.D",
4084 NO_STR
4085 "Specify a network to announce via BGP\n"
4086 "Network number\n"
4087 "Network mask\n"
4088 "Network mask\n")
4089 {
4090 int ret;
4091 char prefix_str[BUFSIZ];
4092
4093 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4094 if (! ret)
4095 {
4096 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4097 return CMD_WARNING;
4098 }
4099
4100 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4101 bgp_node_safi (vty));
4102 }
4103
4104 ALIAS (no_bgp_network_mask,
4105 no_bgp_network_mask_route_map_cmd,
4106 "no network A.B.C.D mask A.B.C.D route-map WORD",
4107 NO_STR
4108 "Specify a network to announce via BGP\n"
4109 "Network number\n"
4110 "Network mask\n"
4111 "Network mask\n"
4112 "Route-map to modify the attributes\n"
4113 "Name of the route map\n")
4114
4115 ALIAS (no_bgp_network_mask,
4116 no_bgp_network_mask_backdoor_cmd,
4117 "no network A.B.C.D mask A.B.C.D backdoor",
4118 NO_STR
4119 "Specify a network to announce via BGP\n"
4120 "Network number\n"
4121 "Network mask\n"
4122 "Network mask\n"
4123 "Specify a BGP backdoor route\n")
4124
4125 DEFUN (no_bgp_network_mask_natural,
4126 no_bgp_network_mask_natural_cmd,
4127 "no network A.B.C.D",
4128 NO_STR
4129 "Specify a network to announce via BGP\n"
4130 "Network number\n")
4131 {
4132 int ret;
4133 char prefix_str[BUFSIZ];
4134
4135 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4136 if (! ret)
4137 {
4138 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4139 return CMD_WARNING;
4140 }
4141
4142 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4143 bgp_node_safi (vty));
4144 }
4145
4146 ALIAS (no_bgp_network_mask_natural,
4147 no_bgp_network_mask_natural_route_map_cmd,
4148 "no network A.B.C.D route-map WORD",
4149 NO_STR
4150 "Specify a network to announce via BGP\n"
4151 "Network number\n"
4152 "Route-map to modify the attributes\n"
4153 "Name of the route map\n")
4154
4155 ALIAS (no_bgp_network_mask_natural,
4156 no_bgp_network_mask_natural_backdoor_cmd,
4157 "no network A.B.C.D backdoor",
4158 NO_STR
4159 "Specify a network to announce via BGP\n"
4160 "Network number\n"
4161 "Specify a BGP backdoor route\n")
4162
4163 #ifdef HAVE_IPV6
4164 DEFUN (ipv6_bgp_network,
4165 ipv6_bgp_network_cmd,
4166 "network X:X::X:X/M",
4167 "Specify a network to announce via BGP\n"
4168 "IPv6 prefix <network>/<length>\n")
4169 {
4170 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4171 NULL, 0);
4172 }
4173
4174 DEFUN (ipv6_bgp_network_route_map,
4175 ipv6_bgp_network_route_map_cmd,
4176 "network X:X::X:X/M route-map WORD",
4177 "Specify a network to announce via BGP\n"
4178 "IPv6 prefix <network>/<length>\n"
4179 "Route-map to modify the attributes\n"
4180 "Name of the route map\n")
4181 {
4182 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4183 bgp_node_safi (vty), argv[1], 0);
4184 }
4185
4186 DEFUN (no_ipv6_bgp_network,
4187 no_ipv6_bgp_network_cmd,
4188 "no network X:X::X:X/M",
4189 NO_STR
4190 "Specify a network to announce via BGP\n"
4191 "IPv6 prefix <network>/<length>\n")
4192 {
4193 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4194 }
4195
4196 ALIAS (no_ipv6_bgp_network,
4197 no_ipv6_bgp_network_route_map_cmd,
4198 "no network X:X::X:X/M route-map WORD",
4199 NO_STR
4200 "Specify a network to announce via BGP\n"
4201 "IPv6 prefix <network>/<length>\n"
4202 "Route-map to modify the attributes\n"
4203 "Name of the route map\n")
4204
4205 ALIAS (ipv6_bgp_network,
4206 old_ipv6_bgp_network_cmd,
4207 "ipv6 bgp network X:X::X:X/M",
4208 IPV6_STR
4209 BGP_STR
4210 "Specify a network to announce via BGP\n"
4211 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4212
4213 ALIAS (no_ipv6_bgp_network,
4214 old_no_ipv6_bgp_network_cmd,
4215 "no ipv6 bgp network X:X::X:X/M",
4216 NO_STR
4217 IPV6_STR
4218 BGP_STR
4219 "Specify a network to announce via BGP\n"
4220 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4221 #endif /* HAVE_IPV6 */
4222
4223 /* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4224 ALIAS_DEPRECATED (bgp_network,
4225 bgp_network_ttl_cmd,
4226 "network A.B.C.D/M pathlimit <0-255>",
4227 "Specify a network to announce via BGP\n"
4228 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4229 "AS-Path hopcount limit attribute\n"
4230 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4231 ALIAS_DEPRECATED (bgp_network_backdoor,
4232 bgp_network_backdoor_ttl_cmd,
4233 "network A.B.C.D/M backdoor pathlimit <0-255>",
4234 "Specify a network to announce via BGP\n"
4235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4236 "Specify a BGP backdoor route\n"
4237 "AS-Path hopcount limit attribute\n"
4238 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4239 ALIAS_DEPRECATED (bgp_network_mask,
4240 bgp_network_mask_ttl_cmd,
4241 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4242 "Specify a network to announce via BGP\n"
4243 "Network number\n"
4244 "Network mask\n"
4245 "Network mask\n"
4246 "AS-Path hopcount limit attribute\n"
4247 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4248 ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4249 bgp_network_mask_backdoor_ttl_cmd,
4250 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4251 "Specify a network to announce via BGP\n"
4252 "Network number\n"
4253 "Network mask\n"
4254 "Network mask\n"
4255 "Specify a BGP backdoor route\n"
4256 "AS-Path hopcount limit attribute\n"
4257 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4258 ALIAS_DEPRECATED (bgp_network_mask_natural,
4259 bgp_network_mask_natural_ttl_cmd,
4260 "network A.B.C.D pathlimit <0-255>",
4261 "Specify a network to announce via BGP\n"
4262 "Network number\n"
4263 "AS-Path hopcount limit attribute\n"
4264 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4265 ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4266 bgp_network_mask_natural_backdoor_ttl_cmd,
4267 "network A.B.C.D backdoor pathlimit (1-255>",
4268 "Specify a network to announce via BGP\n"
4269 "Network number\n"
4270 "Specify a BGP backdoor route\n"
4271 "AS-Path hopcount limit attribute\n"
4272 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4273 ALIAS_DEPRECATED (no_bgp_network,
4274 no_bgp_network_ttl_cmd,
4275 "no network A.B.C.D/M pathlimit <0-255>",
4276 NO_STR
4277 "Specify a network to announce via BGP\n"
4278 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4279 "AS-Path hopcount limit attribute\n"
4280 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4281 ALIAS_DEPRECATED (no_bgp_network,
4282 no_bgp_network_backdoor_ttl_cmd,
4283 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4284 NO_STR
4285 "Specify a network to announce via BGP\n"
4286 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4287 "Specify a BGP backdoor route\n"
4288 "AS-Path hopcount limit attribute\n"
4289 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4290 ALIAS_DEPRECATED (no_bgp_network,
4291 no_bgp_network_mask_ttl_cmd,
4292 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4293 NO_STR
4294 "Specify a network to announce via BGP\n"
4295 "Network number\n"
4296 "Network mask\n"
4297 "Network mask\n"
4298 "AS-Path hopcount limit attribute\n"
4299 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4300 ALIAS_DEPRECATED (no_bgp_network_mask,
4301 no_bgp_network_mask_backdoor_ttl_cmd,
4302 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4303 NO_STR
4304 "Specify a network to announce via BGP\n"
4305 "Network number\n"
4306 "Network mask\n"
4307 "Network mask\n"
4308 "Specify a BGP backdoor route\n"
4309 "AS-Path hopcount limit attribute\n"
4310 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4311 ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4312 no_bgp_network_mask_natural_ttl_cmd,
4313 "no network A.B.C.D pathlimit <0-255>",
4314 NO_STR
4315 "Specify a network to announce via BGP\n"
4316 "Network number\n"
4317 "AS-Path hopcount limit attribute\n"
4318 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4319 ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4320 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4321 "no network A.B.C.D backdoor pathlimit <0-255>",
4322 NO_STR
4323 "Specify a network to announce via BGP\n"
4324 "Network number\n"
4325 "Specify a BGP backdoor route\n"
4326 "AS-Path hopcount limit attribute\n"
4327 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4328 #ifdef HAVE_IPV6
4329 ALIAS_DEPRECATED (ipv6_bgp_network,
4330 ipv6_bgp_network_ttl_cmd,
4331 "network X:X::X:X/M pathlimit <0-255>",
4332 "Specify a network to announce via BGP\n"
4333 "IPv6 prefix <network>/<length>\n"
4334 "AS-Path hopcount limit attribute\n"
4335 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4336 ALIAS_DEPRECATED (no_ipv6_bgp_network,
4337 no_ipv6_bgp_network_ttl_cmd,
4338 "no network X:X::X:X/M pathlimit <0-255>",
4339 NO_STR
4340 "Specify a network to announce via BGP\n"
4341 "IPv6 prefix <network>/<length>\n"
4342 "AS-Path hopcount limit attribute\n"
4343 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4344 #endif /* HAVE_IPV6 */
4345 \f
4346 /* Aggreagete address:
4347
4348 advertise-map Set condition to advertise attribute
4349 as-set Generate AS set path information
4350 attribute-map Set attributes of aggregate
4351 route-map Set parameters of aggregate
4352 summary-only Filter more specific routes from updates
4353 suppress-map Conditionally filter more specific routes from updates
4354 <cr>
4355 */
4356 struct bgp_aggregate
4357 {
4358 /* Summary-only flag. */
4359 u_char summary_only;
4360
4361 /* AS set generation. */
4362 u_char as_set;
4363
4364 /* Route-map for aggregated route. */
4365 struct route_map *map;
4366
4367 /* Suppress-count. */
4368 unsigned long count;
4369
4370 /* SAFI configuration. */
4371 safi_t safi;
4372 };
4373
4374 static struct bgp_aggregate *
4375 bgp_aggregate_new (void)
4376 {
4377 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4378 }
4379
4380 static void
4381 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4382 {
4383 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4384 }
4385
4386 static void
4387 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4388 afi_t afi, safi_t safi, struct bgp_info *del,
4389 struct bgp_aggregate *aggregate)
4390 {
4391 struct bgp_table *table;
4392 struct bgp_node *top;
4393 struct bgp_node *rn;
4394 u_char origin;
4395 struct aspath *aspath = NULL;
4396 struct aspath *asmerge = NULL;
4397 struct community *community = NULL;
4398 struct community *commerge = NULL;
4399 struct in_addr nexthop;
4400 u_int32_t med = 0;
4401 struct bgp_info *ri;
4402 struct bgp_info *new;
4403 int first = 1;
4404 unsigned long match = 0;
4405
4406 /* Record adding route's nexthop and med. */
4407 if (rinew)
4408 {
4409 nexthop = rinew->attr->nexthop;
4410 med = rinew->attr->med;
4411 }
4412
4413 /* ORIGIN attribute: If at least one route among routes that are
4414 aggregated has ORIGIN with the value INCOMPLETE, then the
4415 aggregated route must have the ORIGIN attribute with the value
4416 INCOMPLETE. Otherwise, if at least one route among routes that
4417 are aggregated has ORIGIN with the value EGP, then the aggregated
4418 route must have the origin attribute with the value EGP. In all
4419 other case the value of the ORIGIN attribute of the aggregated
4420 route is INTERNAL. */
4421 origin = BGP_ORIGIN_IGP;
4422
4423 table = bgp->rib[afi][safi];
4424
4425 top = bgp_node_get (table, p);
4426 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4427 if (rn->p.prefixlen > p->prefixlen)
4428 {
4429 match = 0;
4430
4431 for (ri = rn->info; ri; ri = ri->next)
4432 {
4433 if (BGP_INFO_HOLDDOWN (ri))
4434 continue;
4435
4436 if (del && ri == del)
4437 continue;
4438
4439 if (! rinew && first)
4440 {
4441 nexthop = ri->attr->nexthop;
4442 med = ri->attr->med;
4443 first = 0;
4444 }
4445
4446 #ifdef AGGREGATE_NEXTHOP_CHECK
4447 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4448 || ri->attr->med != med)
4449 {
4450 if (aspath)
4451 aspath_free (aspath);
4452 if (community)
4453 community_free (community);
4454 bgp_unlock_node (rn);
4455 bgp_unlock_node (top);
4456 return;
4457 }
4458 #endif /* AGGREGATE_NEXTHOP_CHECK */
4459
4460 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4461 {
4462 if (aggregate->summary_only)
4463 {
4464 (bgp_info_extra_get (ri))->suppress++;
4465 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4466 match++;
4467 }
4468
4469 aggregate->count++;
4470
4471 if (aggregate->as_set)
4472 {
4473 if (origin < ri->attr->origin)
4474 origin = ri->attr->origin;
4475
4476 if (aspath)
4477 {
4478 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4479 aspath_free (aspath);
4480 aspath = asmerge;
4481 }
4482 else
4483 aspath = aspath_dup (ri->attr->aspath);
4484
4485 if (ri->attr->community)
4486 {
4487 if (community)
4488 {
4489 commerge = community_merge (community,
4490 ri->attr->community);
4491 community = community_uniq_sort (commerge);
4492 community_free (commerge);
4493 }
4494 else
4495 community = community_dup (ri->attr->community);
4496 }
4497 }
4498 }
4499 }
4500 if (match)
4501 bgp_process (bgp, rn, afi, safi);
4502 }
4503 bgp_unlock_node (top);
4504
4505 if (rinew)
4506 {
4507 aggregate->count++;
4508
4509 if (aggregate->summary_only)
4510 (bgp_info_extra_get (rinew))->suppress++;
4511
4512 if (aggregate->as_set)
4513 {
4514 if (origin < rinew->attr->origin)
4515 origin = rinew->attr->origin;
4516
4517 if (aspath)
4518 {
4519 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4520 aspath_free (aspath);
4521 aspath = asmerge;
4522 }
4523 else
4524 aspath = aspath_dup (rinew->attr->aspath);
4525
4526 if (rinew->attr->community)
4527 {
4528 if (community)
4529 {
4530 commerge = community_merge (community,
4531 rinew->attr->community);
4532 community = community_uniq_sort (commerge);
4533 community_free (commerge);
4534 }
4535 else
4536 community = community_dup (rinew->attr->community);
4537 }
4538 }
4539 }
4540
4541 if (aggregate->count > 0)
4542 {
4543 rn = bgp_node_get (table, p);
4544 new = bgp_info_new ();
4545 new->type = ZEBRA_ROUTE_BGP;
4546 new->sub_type = BGP_ROUTE_AGGREGATE;
4547 new->peer = bgp->peer_self;
4548 SET_FLAG (new->flags, BGP_INFO_VALID);
4549 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4550 new->uptime = bgp_clock ();
4551
4552 bgp_info_add (rn, new);
4553 bgp_unlock_node (rn);
4554 bgp_process (bgp, rn, afi, safi);
4555 }
4556 else
4557 {
4558 if (aspath)
4559 aspath_free (aspath);
4560 if (community)
4561 community_free (community);
4562 }
4563 }
4564
4565 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4566 struct bgp_aggregate *);
4567
4568 void
4569 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4570 struct bgp_info *ri, afi_t afi, safi_t safi)
4571 {
4572 struct bgp_node *child;
4573 struct bgp_node *rn;
4574 struct bgp_aggregate *aggregate;
4575
4576 /* MPLS-VPN aggregation is not yet supported. */
4577 if (safi == SAFI_MPLS_VPN)
4578 return;
4579
4580 if (p->prefixlen == 0)
4581 return;
4582
4583 if (BGP_INFO_HOLDDOWN (ri))
4584 return;
4585
4586 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4587
4588 /* Aggregate address configuration check. */
4589 for (rn = child; rn; rn = rn->parent)
4590 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4591 {
4592 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4593 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
4594 }
4595 bgp_unlock_node (child);
4596 }
4597
4598 void
4599 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4600 struct bgp_info *del, afi_t afi, safi_t safi)
4601 {
4602 struct bgp_node *child;
4603 struct bgp_node *rn;
4604 struct bgp_aggregate *aggregate;
4605
4606 /* MPLS-VPN aggregation is not yet supported. */
4607 if (safi == SAFI_MPLS_VPN)
4608 return;
4609
4610 if (p->prefixlen == 0)
4611 return;
4612
4613 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4614
4615 /* Aggregate address configuration check. */
4616 for (rn = child; rn; rn = rn->parent)
4617 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4618 {
4619 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4620 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
4621 }
4622 bgp_unlock_node (child);
4623 }
4624
4625 static void
4626 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4627 struct bgp_aggregate *aggregate)
4628 {
4629 struct bgp_table *table;
4630 struct bgp_node *top;
4631 struct bgp_node *rn;
4632 struct bgp_info *new;
4633 struct bgp_info *ri;
4634 unsigned long match;
4635 u_char origin = BGP_ORIGIN_IGP;
4636 struct aspath *aspath = NULL;
4637 struct aspath *asmerge = NULL;
4638 struct community *community = NULL;
4639 struct community *commerge = NULL;
4640
4641 table = bgp->rib[afi][safi];
4642
4643 /* Sanity check. */
4644 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4645 return;
4646 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4647 return;
4648
4649 /* If routes exists below this node, generate aggregate routes. */
4650 top = bgp_node_get (table, p);
4651 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4652 if (rn->p.prefixlen > p->prefixlen)
4653 {
4654 match = 0;
4655
4656 for (ri = rn->info; ri; ri = ri->next)
4657 {
4658 if (BGP_INFO_HOLDDOWN (ri))
4659 continue;
4660
4661 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4662 {
4663 /* summary-only aggregate route suppress aggregated
4664 route announcement. */
4665 if (aggregate->summary_only)
4666 {
4667 (bgp_info_extra_get (ri))->suppress++;
4668 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4669 match++;
4670 }
4671 /* as-set aggregate route generate origin, as path,
4672 community aggregation. */
4673 if (aggregate->as_set)
4674 {
4675 if (origin < ri->attr->origin)
4676 origin = ri->attr->origin;
4677
4678 if (aspath)
4679 {
4680 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4681 aspath_free (aspath);
4682 aspath = asmerge;
4683 }
4684 else
4685 aspath = aspath_dup (ri->attr->aspath);
4686
4687 if (ri->attr->community)
4688 {
4689 if (community)
4690 {
4691 commerge = community_merge (community,
4692 ri->attr->community);
4693 community = community_uniq_sort (commerge);
4694 community_free (commerge);
4695 }
4696 else
4697 community = community_dup (ri->attr->community);
4698 }
4699 }
4700 aggregate->count++;
4701 }
4702 }
4703
4704 /* If this node is suppressed, process the change. */
4705 if (match)
4706 bgp_process (bgp, rn, afi, safi);
4707 }
4708 bgp_unlock_node (top);
4709
4710 /* Add aggregate route to BGP table. */
4711 if (aggregate->count)
4712 {
4713 rn = bgp_node_get (table, p);
4714
4715 new = bgp_info_new ();
4716 new->type = ZEBRA_ROUTE_BGP;
4717 new->sub_type = BGP_ROUTE_AGGREGATE;
4718 new->peer = bgp->peer_self;
4719 SET_FLAG (new->flags, BGP_INFO_VALID);
4720 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4721 new->uptime = bgp_clock ();
4722
4723 bgp_info_add (rn, new);
4724 bgp_unlock_node (rn);
4725
4726 /* Process change. */
4727 bgp_process (bgp, rn, afi, safi);
4728 }
4729 }
4730
4731 void
4732 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4733 safi_t safi, struct bgp_aggregate *aggregate)
4734 {
4735 struct bgp_table *table;
4736 struct bgp_node *top;
4737 struct bgp_node *rn;
4738 struct bgp_info *ri;
4739 unsigned long match;
4740
4741 table = bgp->rib[afi][safi];
4742
4743 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4744 return;
4745 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4746 return;
4747
4748 /* If routes exists below this node, generate aggregate routes. */
4749 top = bgp_node_get (table, p);
4750 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4751 if (rn->p.prefixlen > p->prefixlen)
4752 {
4753 match = 0;
4754
4755 for (ri = rn->info; ri; ri = ri->next)
4756 {
4757 if (BGP_INFO_HOLDDOWN (ri))
4758 continue;
4759
4760 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4761 {
4762 if (aggregate->summary_only && ri->extra)
4763 {
4764 ri->extra->suppress--;
4765
4766 if (ri->extra->suppress == 0)
4767 {
4768 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4769 match++;
4770 }
4771 }
4772 aggregate->count--;
4773 }
4774 }
4775
4776 /* If this node was suppressed, process the change. */
4777 if (match)
4778 bgp_process (bgp, rn, afi, safi);
4779 }
4780 bgp_unlock_node (top);
4781
4782 /* Delete aggregate route from BGP table. */
4783 rn = bgp_node_get (table, p);
4784
4785 for (ri = rn->info; ri; ri = ri->next)
4786 if (ri->peer == bgp->peer_self
4787 && ri->type == ZEBRA_ROUTE_BGP
4788 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4789 break;
4790
4791 /* Withdraw static BGP route from routing table. */
4792 if (ri)
4793 {
4794 bgp_info_delete (rn, ri);
4795 bgp_process (bgp, rn, afi, safi);
4796 }
4797
4798 /* Unlock bgp_node_lookup. */
4799 bgp_unlock_node (rn);
4800 }
4801
4802 /* Aggregate route attribute. */
4803 #define AGGREGATE_SUMMARY_ONLY 1
4804 #define AGGREGATE_AS_SET 1
4805
4806 static int
4807 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4808 afi_t afi, safi_t safi)
4809 {
4810 int ret;
4811 struct prefix p;
4812 struct bgp_node *rn;
4813 struct bgp *bgp;
4814 struct bgp_aggregate *aggregate;
4815
4816 /* Convert string to prefix structure. */
4817 ret = str2prefix (prefix_str, &p);
4818 if (!ret)
4819 {
4820 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4821 return CMD_WARNING;
4822 }
4823 apply_mask (&p);
4824
4825 /* Get BGP structure. */
4826 bgp = vty->index;
4827
4828 /* Old configuration check. */
4829 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4830 if (! rn)
4831 {
4832 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4833 VTY_NEWLINE);
4834 return CMD_WARNING;
4835 }
4836
4837 aggregate = rn->info;
4838 if (aggregate->safi & SAFI_UNICAST)
4839 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4840 if (aggregate->safi & SAFI_MULTICAST)
4841 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4842
4843 /* Unlock aggregate address configuration. */
4844 rn->info = NULL;
4845 bgp_aggregate_free (aggregate);
4846 bgp_unlock_node (rn);
4847 bgp_unlock_node (rn);
4848
4849 return CMD_SUCCESS;
4850 }
4851
4852 static int
4853 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4854 afi_t afi, safi_t safi,
4855 u_char summary_only, u_char as_set)
4856 {
4857 int ret;
4858 struct prefix p;
4859 struct bgp_node *rn;
4860 struct bgp *bgp;
4861 struct bgp_aggregate *aggregate;
4862
4863 /* Convert string to prefix structure. */
4864 ret = str2prefix (prefix_str, &p);
4865 if (!ret)
4866 {
4867 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4868 return CMD_WARNING;
4869 }
4870 apply_mask (&p);
4871
4872 /* Get BGP structure. */
4873 bgp = vty->index;
4874
4875 /* Old configuration check. */
4876 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4877
4878 if (rn->info)
4879 {
4880 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4881 /* try to remove the old entry */
4882 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4883 if (ret)
4884 {
4885 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4886 bgp_unlock_node (rn);
4887 return CMD_WARNING;
4888 }
4889 }
4890
4891 /* Make aggregate address structure. */
4892 aggregate = bgp_aggregate_new ();
4893 aggregate->summary_only = summary_only;
4894 aggregate->as_set = as_set;
4895 aggregate->safi = safi;
4896 rn->info = aggregate;
4897
4898 /* Aggregate address insert into BGP routing table. */
4899 if (safi & SAFI_UNICAST)
4900 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4901 if (safi & SAFI_MULTICAST)
4902 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4903
4904 return CMD_SUCCESS;
4905 }
4906
4907 DEFUN (aggregate_address,
4908 aggregate_address_cmd,
4909 "aggregate-address A.B.C.D/M",
4910 "Configure BGP aggregate entries\n"
4911 "Aggregate prefix\n")
4912 {
4913 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4914 }
4915
4916 DEFUN (aggregate_address_mask,
4917 aggregate_address_mask_cmd,
4918 "aggregate-address A.B.C.D A.B.C.D",
4919 "Configure BGP aggregate entries\n"
4920 "Aggregate address\n"
4921 "Aggregate mask\n")
4922 {
4923 int ret;
4924 char prefix_str[BUFSIZ];
4925
4926 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4927
4928 if (! ret)
4929 {
4930 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4931 return CMD_WARNING;
4932 }
4933
4934 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4935 0, 0);
4936 }
4937
4938 DEFUN (aggregate_address_summary_only,
4939 aggregate_address_summary_only_cmd,
4940 "aggregate-address A.B.C.D/M summary-only",
4941 "Configure BGP aggregate entries\n"
4942 "Aggregate prefix\n"
4943 "Filter more specific routes from updates\n")
4944 {
4945 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4946 AGGREGATE_SUMMARY_ONLY, 0);
4947 }
4948
4949 DEFUN (aggregate_address_mask_summary_only,
4950 aggregate_address_mask_summary_only_cmd,
4951 "aggregate-address A.B.C.D A.B.C.D summary-only",
4952 "Configure BGP aggregate entries\n"
4953 "Aggregate address\n"
4954 "Aggregate mask\n"
4955 "Filter more specific routes from updates\n")
4956 {
4957 int ret;
4958 char prefix_str[BUFSIZ];
4959
4960 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4961
4962 if (! ret)
4963 {
4964 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4965 return CMD_WARNING;
4966 }
4967
4968 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4969 AGGREGATE_SUMMARY_ONLY, 0);
4970 }
4971
4972 DEFUN (aggregate_address_as_set,
4973 aggregate_address_as_set_cmd,
4974 "aggregate-address A.B.C.D/M as-set",
4975 "Configure BGP aggregate entries\n"
4976 "Aggregate prefix\n"
4977 "Generate AS set path information\n")
4978 {
4979 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4980 0, AGGREGATE_AS_SET);
4981 }
4982
4983 DEFUN (aggregate_address_mask_as_set,
4984 aggregate_address_mask_as_set_cmd,
4985 "aggregate-address A.B.C.D A.B.C.D as-set",
4986 "Configure BGP aggregate entries\n"
4987 "Aggregate address\n"
4988 "Aggregate mask\n"
4989 "Generate AS set path information\n")
4990 {
4991 int ret;
4992 char prefix_str[BUFSIZ];
4993
4994 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4995
4996 if (! ret)
4997 {
4998 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4999 return CMD_WARNING;
5000 }
5001
5002 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5003 0, AGGREGATE_AS_SET);
5004 }
5005
5006
5007 DEFUN (aggregate_address_as_set_summary,
5008 aggregate_address_as_set_summary_cmd,
5009 "aggregate-address A.B.C.D/M as-set summary-only",
5010 "Configure BGP aggregate entries\n"
5011 "Aggregate prefix\n"
5012 "Generate AS set path information\n"
5013 "Filter more specific routes from updates\n")
5014 {
5015 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5016 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5017 }
5018
5019 ALIAS (aggregate_address_as_set_summary,
5020 aggregate_address_summary_as_set_cmd,
5021 "aggregate-address A.B.C.D/M summary-only as-set",
5022 "Configure BGP aggregate entries\n"
5023 "Aggregate prefix\n"
5024 "Filter more specific routes from updates\n"
5025 "Generate AS set path information\n")
5026
5027 DEFUN (aggregate_address_mask_as_set_summary,
5028 aggregate_address_mask_as_set_summary_cmd,
5029 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5030 "Configure BGP aggregate entries\n"
5031 "Aggregate address\n"
5032 "Aggregate mask\n"
5033 "Generate AS set path information\n"
5034 "Filter more specific routes from updates\n")
5035 {
5036 int ret;
5037 char prefix_str[BUFSIZ];
5038
5039 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5040
5041 if (! ret)
5042 {
5043 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5044 return CMD_WARNING;
5045 }
5046
5047 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5048 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5049 }
5050
5051 ALIAS (aggregate_address_mask_as_set_summary,
5052 aggregate_address_mask_summary_as_set_cmd,
5053 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5054 "Configure BGP aggregate entries\n"
5055 "Aggregate address\n"
5056 "Aggregate mask\n"
5057 "Filter more specific routes from updates\n"
5058 "Generate AS set path information\n")
5059
5060 DEFUN (no_aggregate_address,
5061 no_aggregate_address_cmd,
5062 "no aggregate-address A.B.C.D/M",
5063 NO_STR
5064 "Configure BGP aggregate entries\n"
5065 "Aggregate prefix\n")
5066 {
5067 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5068 }
5069
5070 ALIAS (no_aggregate_address,
5071 no_aggregate_address_summary_only_cmd,
5072 "no aggregate-address A.B.C.D/M summary-only",
5073 NO_STR
5074 "Configure BGP aggregate entries\n"
5075 "Aggregate prefix\n"
5076 "Filter more specific routes from updates\n")
5077
5078 ALIAS (no_aggregate_address,
5079 no_aggregate_address_as_set_cmd,
5080 "no aggregate-address A.B.C.D/M as-set",
5081 NO_STR
5082 "Configure BGP aggregate entries\n"
5083 "Aggregate prefix\n"
5084 "Generate AS set path information\n")
5085
5086 ALIAS (no_aggregate_address,
5087 no_aggregate_address_as_set_summary_cmd,
5088 "no aggregate-address A.B.C.D/M as-set summary-only",
5089 NO_STR
5090 "Configure BGP aggregate entries\n"
5091 "Aggregate prefix\n"
5092 "Generate AS set path information\n"
5093 "Filter more specific routes from updates\n")
5094
5095 ALIAS (no_aggregate_address,
5096 no_aggregate_address_summary_as_set_cmd,
5097 "no aggregate-address A.B.C.D/M summary-only as-set",
5098 NO_STR
5099 "Configure BGP aggregate entries\n"
5100 "Aggregate prefix\n"
5101 "Filter more specific routes from updates\n"
5102 "Generate AS set path information\n")
5103
5104 DEFUN (no_aggregate_address_mask,
5105 no_aggregate_address_mask_cmd,
5106 "no aggregate-address A.B.C.D A.B.C.D",
5107 NO_STR
5108 "Configure BGP aggregate entries\n"
5109 "Aggregate address\n"
5110 "Aggregate mask\n")
5111 {
5112 int ret;
5113 char prefix_str[BUFSIZ];
5114
5115 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5116
5117 if (! ret)
5118 {
5119 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5120 return CMD_WARNING;
5121 }
5122
5123 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5124 }
5125
5126 ALIAS (no_aggregate_address_mask,
5127 no_aggregate_address_mask_summary_only_cmd,
5128 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5129 NO_STR
5130 "Configure BGP aggregate entries\n"
5131 "Aggregate address\n"
5132 "Aggregate mask\n"
5133 "Filter more specific routes from updates\n")
5134
5135 ALIAS (no_aggregate_address_mask,
5136 no_aggregate_address_mask_as_set_cmd,
5137 "no aggregate-address A.B.C.D A.B.C.D as-set",
5138 NO_STR
5139 "Configure BGP aggregate entries\n"
5140 "Aggregate address\n"
5141 "Aggregate mask\n"
5142 "Generate AS set path information\n")
5143
5144 ALIAS (no_aggregate_address_mask,
5145 no_aggregate_address_mask_as_set_summary_cmd,
5146 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5147 NO_STR
5148 "Configure BGP aggregate entries\n"
5149 "Aggregate address\n"
5150 "Aggregate mask\n"
5151 "Generate AS set path information\n"
5152 "Filter more specific routes from updates\n")
5153
5154 ALIAS (no_aggregate_address_mask,
5155 no_aggregate_address_mask_summary_as_set_cmd,
5156 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5157 NO_STR
5158 "Configure BGP aggregate entries\n"
5159 "Aggregate address\n"
5160 "Aggregate mask\n"
5161 "Filter more specific routes from updates\n"
5162 "Generate AS set path information\n")
5163
5164 #ifdef HAVE_IPV6
5165 DEFUN (ipv6_aggregate_address,
5166 ipv6_aggregate_address_cmd,
5167 "aggregate-address X:X::X:X/M",
5168 "Configure BGP aggregate entries\n"
5169 "Aggregate prefix\n")
5170 {
5171 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5172 }
5173
5174 DEFUN (ipv6_aggregate_address_summary_only,
5175 ipv6_aggregate_address_summary_only_cmd,
5176 "aggregate-address X:X::X:X/M summary-only",
5177 "Configure BGP aggregate entries\n"
5178 "Aggregate prefix\n"
5179 "Filter more specific routes from updates\n")
5180 {
5181 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5182 AGGREGATE_SUMMARY_ONLY, 0);
5183 }
5184
5185 DEFUN (no_ipv6_aggregate_address,
5186 no_ipv6_aggregate_address_cmd,
5187 "no aggregate-address X:X::X:X/M",
5188 NO_STR
5189 "Configure BGP aggregate entries\n"
5190 "Aggregate prefix\n")
5191 {
5192 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5193 }
5194
5195 DEFUN (no_ipv6_aggregate_address_summary_only,
5196 no_ipv6_aggregate_address_summary_only_cmd,
5197 "no aggregate-address X:X::X:X/M summary-only",
5198 NO_STR
5199 "Configure BGP aggregate entries\n"
5200 "Aggregate prefix\n"
5201 "Filter more specific routes from updates\n")
5202 {
5203 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5204 }
5205
5206 ALIAS (ipv6_aggregate_address,
5207 old_ipv6_aggregate_address_cmd,
5208 "ipv6 bgp aggregate-address X:X::X:X/M",
5209 IPV6_STR
5210 BGP_STR
5211 "Configure BGP aggregate entries\n"
5212 "Aggregate prefix\n")
5213
5214 ALIAS (ipv6_aggregate_address_summary_only,
5215 old_ipv6_aggregate_address_summary_only_cmd,
5216 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5217 IPV6_STR
5218 BGP_STR
5219 "Configure BGP aggregate entries\n"
5220 "Aggregate prefix\n"
5221 "Filter more specific routes from updates\n")
5222
5223 ALIAS (no_ipv6_aggregate_address,
5224 old_no_ipv6_aggregate_address_cmd,
5225 "no ipv6 bgp aggregate-address X:X::X:X/M",
5226 NO_STR
5227 IPV6_STR
5228 BGP_STR
5229 "Configure BGP aggregate entries\n"
5230 "Aggregate prefix\n")
5231
5232 ALIAS (no_ipv6_aggregate_address_summary_only,
5233 old_no_ipv6_aggregate_address_summary_only_cmd,
5234 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5235 NO_STR
5236 IPV6_STR
5237 BGP_STR
5238 "Configure BGP aggregate entries\n"
5239 "Aggregate prefix\n"
5240 "Filter more specific routes from updates\n")
5241 #endif /* HAVE_IPV6 */
5242 \f
5243 /* Redistribute route treatment. */
5244 void
5245 bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5246 const struct in6_addr *nexthop6,
5247 u_int32_t metric, u_char type)
5248 {
5249 struct bgp *bgp;
5250 struct listnode *node, *nnode;
5251 struct bgp_info *new;
5252 struct bgp_info *bi;
5253 struct bgp_info info;
5254 struct bgp_node *bn;
5255 struct attr attr = { 0 };
5256 struct attr attr_new = { 0 };
5257 struct attr *new_attr;
5258 afi_t afi;
5259 int ret;
5260
5261 /* Make default attribute. */
5262 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5263 if (nexthop)
5264 attr.nexthop = *nexthop;
5265
5266 #ifdef HAVE_IPV6
5267 if (nexthop6)
5268 {
5269 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5270 extra->mp_nexthop_global = *nexthop6;
5271 extra->mp_nexthop_len = 16;
5272 }
5273 #endif
5274
5275 attr.med = metric;
5276 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5277
5278 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5279 {
5280 afi = family2afi (p->family);
5281
5282 if (bgp->redist[afi][type])
5283 {
5284 /* Copy attribute for modification. */
5285 bgp_attr_dup (&attr_new, &attr);
5286
5287 if (bgp->redist_metric_flag[afi][type])
5288 attr_new.med = bgp->redist_metric[afi][type];
5289
5290 /* Apply route-map. */
5291 if (bgp->rmap[afi][type].map)
5292 {
5293 info.peer = bgp->peer_self;
5294 info.attr = &attr_new;
5295
5296 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5297
5298 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5299 &info);
5300
5301 bgp->peer_self->rmap_type = 0;
5302
5303 if (ret == RMAP_DENYMATCH)
5304 {
5305 /* Free uninterned attribute. */
5306 bgp_attr_flush (&attr_new);
5307 bgp_attr_extra_free (&attr_new);
5308
5309 /* Unintern original. */
5310 aspath_unintern (&attr.aspath);
5311 bgp_attr_extra_free (&attr);
5312 bgp_redistribute_delete (p, type);
5313 return;
5314 }
5315 }
5316
5317 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5318 afi, SAFI_UNICAST, p, NULL);
5319
5320 new_attr = bgp_attr_intern (&attr_new);
5321 bgp_attr_extra_free (&attr_new);
5322
5323 for (bi = bn->info; bi; bi = bi->next)
5324 if (bi->peer == bgp->peer_self
5325 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5326 break;
5327
5328 if (bi)
5329 {
5330 if (attrhash_cmp (bi->attr, new_attr) &&
5331 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5332 {
5333 bgp_attr_unintern (&new_attr);
5334 aspath_unintern (&attr.aspath);
5335 bgp_attr_extra_free (&attr);
5336 bgp_unlock_node (bn);
5337 return;
5338 }
5339 else
5340 {
5341 /* The attribute is changed. */
5342 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5343
5344 /* Rewrite BGP route information. */
5345 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5346 bgp_info_restore(bn, bi);
5347 else
5348 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5349 bgp_attr_unintern (&bi->attr);
5350 bi->attr = new_attr;
5351 bi->uptime = bgp_clock ();
5352
5353 /* Process change. */
5354 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5355 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5356 bgp_unlock_node (bn);
5357 aspath_unintern (&attr.aspath);
5358 bgp_attr_extra_free (&attr);
5359 return;
5360 }
5361 }
5362
5363 new = bgp_info_new ();
5364 new->type = type;
5365 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5366 new->peer = bgp->peer_self;
5367 SET_FLAG (new->flags, BGP_INFO_VALID);
5368 new->attr = new_attr;
5369 new->uptime = bgp_clock ();
5370
5371 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5372 bgp_info_add (bn, new);
5373 bgp_unlock_node (bn);
5374 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5375 }
5376 }
5377
5378 /* Unintern original. */
5379 aspath_unintern (&attr.aspath);
5380 bgp_attr_extra_free (&attr);
5381 }
5382
5383 void
5384 bgp_redistribute_delete (struct prefix *p, u_char type)
5385 {
5386 struct bgp *bgp;
5387 struct listnode *node, *nnode;
5388 afi_t afi;
5389 struct bgp_node *rn;
5390 struct bgp_info *ri;
5391
5392 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5393 {
5394 afi = family2afi (p->family);
5395
5396 if (bgp->redist[afi][type])
5397 {
5398 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5399
5400 for (ri = rn->info; ri; ri = ri->next)
5401 if (ri->peer == bgp->peer_self
5402 && ri->type == type)
5403 break;
5404
5405 if (ri)
5406 {
5407 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5408 bgp_info_delete (rn, ri);
5409 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5410 }
5411 bgp_unlock_node (rn);
5412 }
5413 }
5414 }
5415
5416 /* Withdraw specified route type's route. */
5417 void
5418 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5419 {
5420 struct bgp_node *rn;
5421 struct bgp_info *ri;
5422 struct bgp_table *table;
5423
5424 table = bgp->rib[afi][SAFI_UNICAST];
5425
5426 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5427 {
5428 for (ri = rn->info; ri; ri = ri->next)
5429 if (ri->peer == bgp->peer_self
5430 && ri->type == type)
5431 break;
5432
5433 if (ri)
5434 {
5435 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5436 bgp_info_delete (rn, ri);
5437 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5438 }
5439 }
5440 }
5441 \f
5442 /* Static function to display route. */
5443 static void
5444 route_vty_out_route (struct prefix *p, struct vty *vty)
5445 {
5446 int len;
5447 u_int32_t destination;
5448 char buf[BUFSIZ];
5449
5450 if (p->family == AF_INET)
5451 {
5452 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5453 destination = ntohl (p->u.prefix4.s_addr);
5454
5455 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5456 || (IN_CLASSB (destination) && p->prefixlen == 16)
5457 || (IN_CLASSA (destination) && p->prefixlen == 8)
5458 || p->u.prefix4.s_addr == 0)
5459 {
5460 /* When mask is natural, mask is not displayed. */
5461 }
5462 else
5463 len += vty_out (vty, "/%d", p->prefixlen);
5464 }
5465 else
5466 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5467 p->prefixlen);
5468
5469 len = 17 - len;
5470 if (len < 1)
5471 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5472 else
5473 vty_out (vty, "%*s", len, " ");
5474 }
5475
5476 enum bgp_display_type
5477 {
5478 normal_list,
5479 };
5480
5481 /* Print the short form route status for a bgp_info */
5482 static void
5483 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
5484 {
5485 /* Route status display. */
5486 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5487 vty_out (vty, "R");
5488 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5489 vty_out (vty, "S");
5490 else if (binfo->extra && binfo->extra->suppress)
5491 vty_out (vty, "s");
5492 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5493 vty_out (vty, "*");
5494 else
5495 vty_out (vty, " ");
5496
5497 /* Selected */
5498 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5499 vty_out (vty, "h");
5500 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5501 vty_out (vty, "d");
5502 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5503 vty_out (vty, ">");
5504 else
5505 vty_out (vty, " ");
5506
5507 /* Internal route. */
5508 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5509 vty_out (vty, "i");
5510 else
5511 vty_out (vty, " ");
5512 }
5513
5514 /* called from terminal list command */
5515 void
5516 route_vty_out (struct vty *vty, struct prefix *p,
5517 struct bgp_info *binfo, int display, safi_t safi)
5518 {
5519 struct attr *attr;
5520
5521 /* short status lead text */
5522 route_vty_short_status_out (vty, binfo);
5523
5524 /* print prefix and mask */
5525 if (! display)
5526 route_vty_out_route (p, vty);
5527 else
5528 vty_out (vty, "%*s", 17, " ");
5529
5530 /* Print attribute */
5531 attr = binfo->attr;
5532 if (attr)
5533 {
5534 if (p->family == AF_INET)
5535 {
5536 if (safi == SAFI_MPLS_VPN)
5537 vty_out (vty, "%-16s",
5538 inet_ntoa (attr->extra->mp_nexthop_global_in));
5539 else
5540 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5541 }
5542 #ifdef HAVE_IPV6
5543 else if (p->family == AF_INET6)
5544 {
5545 int len;
5546 char buf[BUFSIZ];
5547
5548 len = vty_out (vty, "%s",
5549 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5550 buf, BUFSIZ));
5551 len = 16 - len;
5552 if (len < 1)
5553 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5554 else
5555 vty_out (vty, "%*s", len, " ");
5556 }
5557 #endif /* HAVE_IPV6 */
5558
5559 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5560 vty_out (vty, "%10u", attr->med);
5561 else
5562 vty_out (vty, " ");
5563
5564 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5565 vty_out (vty, "%7u", attr->local_pref);
5566 else
5567 vty_out (vty, " ");
5568
5569 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
5570
5571 /* Print aspath */
5572 if (attr->aspath)
5573 aspath_print_vty (vty, "%s", attr->aspath, " ");
5574
5575 /* Print origin */
5576 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5577 }
5578 vty_out (vty, "%s", VTY_NEWLINE);
5579 }
5580
5581 /* called from terminal list command */
5582 void
5583 route_vty_out_tmp (struct vty *vty, struct prefix *p,
5584 struct attr *attr, safi_t safi)
5585 {
5586 /* Route status display. */
5587 vty_out (vty, "*");
5588 vty_out (vty, ">");
5589 vty_out (vty, " ");
5590
5591 /* print prefix and mask */
5592 route_vty_out_route (p, vty);
5593
5594 /* Print attribute */
5595 if (attr)
5596 {
5597 if (p->family == AF_INET)
5598 {
5599 if (safi == SAFI_MPLS_VPN)
5600 vty_out (vty, "%-16s",
5601 inet_ntoa (attr->extra->mp_nexthop_global_in));
5602 else
5603 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5604 }
5605 #ifdef HAVE_IPV6
5606 else if (p->family == AF_INET6)
5607 {
5608 int len;
5609 char buf[BUFSIZ];
5610
5611 assert (attr->extra);
5612
5613 len = vty_out (vty, "%s",
5614 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5615 buf, BUFSIZ));
5616 len = 16 - len;
5617 if (len < 1)
5618 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5619 else
5620 vty_out (vty, "%*s", len, " ");
5621 }
5622 #endif /* HAVE_IPV6 */
5623
5624 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5625 vty_out (vty, "%10u", attr->med);
5626 else
5627 vty_out (vty, " ");
5628
5629 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5630 vty_out (vty, "%7u", attr->local_pref);
5631 else
5632 vty_out (vty, " ");
5633
5634 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
5635
5636 /* Print aspath */
5637 if (attr->aspath)
5638 aspath_print_vty (vty, "%s", attr->aspath, " ");
5639
5640 /* Print origin */
5641 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5642 }
5643
5644 vty_out (vty, "%s", VTY_NEWLINE);
5645 }
5646
5647 void
5648 route_vty_out_tag (struct vty *vty, struct prefix *p,
5649 struct bgp_info *binfo, int display, safi_t safi)
5650 {
5651 struct attr *attr;
5652 u_int32_t label = 0;
5653
5654 if (!binfo->extra)
5655 return;
5656
5657 /* short status lead text */
5658 route_vty_short_status_out (vty, binfo);
5659
5660 /* print prefix and mask */
5661 if (! display)
5662 route_vty_out_route (p, vty);
5663 else
5664 vty_out (vty, "%*s", 17, " ");
5665
5666 /* Print attribute */
5667 attr = binfo->attr;
5668 if (attr)
5669 {
5670 if (p->family == AF_INET)
5671 {
5672 if (safi == SAFI_MPLS_VPN)
5673 vty_out (vty, "%-16s",
5674 inet_ntoa (attr->extra->mp_nexthop_global_in));
5675 else
5676 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5677 }
5678 #ifdef HAVE_IPV6
5679 else if (p->family == AF_INET6)
5680 {
5681 assert (attr->extra);
5682 char buf[BUFSIZ];
5683 char buf1[BUFSIZ];
5684 if (attr->extra->mp_nexthop_len == 16)
5685 vty_out (vty, "%s",
5686 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5687 buf, BUFSIZ));
5688 else if (attr->extra->mp_nexthop_len == 32)
5689 vty_out (vty, "%s(%s)",
5690 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5691 buf, BUFSIZ),
5692 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5693 buf1, BUFSIZ));
5694
5695 }
5696 #endif /* HAVE_IPV6 */
5697 }
5698
5699 label = decode_label (binfo->extra->tag);
5700
5701 vty_out (vty, "notag/%d", label);
5702
5703 vty_out (vty, "%s", VTY_NEWLINE);
5704 }
5705
5706 /* dampening route */
5707 static void
5708 damp_route_vty_out (struct vty *vty, struct prefix *p,
5709 struct bgp_info *binfo, int display, safi_t safi)
5710 {
5711 struct attr *attr;
5712 int len;
5713 char timebuf[BGP_UPTIME_LEN];
5714
5715 /* short status lead text */
5716 route_vty_short_status_out (vty, binfo);
5717
5718 /* print prefix and mask */
5719 if (! display)
5720 route_vty_out_route (p, vty);
5721 else
5722 vty_out (vty, "%*s", 17, " ");
5723
5724 len = vty_out (vty, "%s", binfo->peer->host);
5725 len = 17 - len;
5726 if (len < 1)
5727 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5728 else
5729 vty_out (vty, "%*s", len, " ");
5730
5731 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
5732
5733 /* Print attribute */
5734 attr = binfo->attr;
5735 if (attr)
5736 {
5737 /* Print aspath */
5738 if (attr->aspath)
5739 aspath_print_vty (vty, "%s", attr->aspath, " ");
5740
5741 /* Print origin */
5742 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5743 }
5744 vty_out (vty, "%s", VTY_NEWLINE);
5745 }
5746
5747 /* flap route */
5748 static void
5749 flap_route_vty_out (struct vty *vty, struct prefix *p,
5750 struct bgp_info *binfo, int display, safi_t safi)
5751 {
5752 struct attr *attr;
5753 struct bgp_damp_info *bdi;
5754 char timebuf[BGP_UPTIME_LEN];
5755 int len;
5756
5757 if (!binfo->extra)
5758 return;
5759
5760 bdi = binfo->extra->damp_info;
5761
5762 /* short status lead text */
5763 route_vty_short_status_out (vty, binfo);
5764
5765 /* print prefix and mask */
5766 if (! display)
5767 route_vty_out_route (p, vty);
5768 else
5769 vty_out (vty, "%*s", 17, " ");
5770
5771 len = vty_out (vty, "%s", binfo->peer->host);
5772 len = 16 - len;
5773 if (len < 1)
5774 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5775 else
5776 vty_out (vty, "%*s", len, " ");
5777
5778 len = vty_out (vty, "%d", bdi->flap);
5779 len = 5 - len;
5780 if (len < 1)
5781 vty_out (vty, " ");
5782 else
5783 vty_out (vty, "%*s ", len, " ");
5784
5785 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5786 timebuf, BGP_UPTIME_LEN));
5787
5788 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5789 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5790 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
5791 else
5792 vty_out (vty, "%*s ", 8, " ");
5793
5794 /* Print attribute */
5795 attr = binfo->attr;
5796 if (attr)
5797 {
5798 /* Print aspath */
5799 if (attr->aspath)
5800 aspath_print_vty (vty, "%s", attr->aspath, " ");
5801
5802 /* Print origin */
5803 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5804 }
5805 vty_out (vty, "%s", VTY_NEWLINE);
5806 }
5807
5808 static void
5809 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5810 struct bgp_info *binfo, afi_t afi, safi_t safi)
5811 {
5812 char buf[INET6_ADDRSTRLEN];
5813 char buf1[BUFSIZ];
5814 struct attr *attr;
5815 int sockunion_vty_out (struct vty *, union sockunion *);
5816 #ifdef HAVE_CLOCK_MONOTONIC
5817 time_t tbuf;
5818 #endif
5819
5820 attr = binfo->attr;
5821
5822 if (attr)
5823 {
5824 /* Line1 display AS-path, Aggregator */
5825 if (attr->aspath)
5826 {
5827 vty_out (vty, " ");
5828 if (aspath_count_hops (attr->aspath) == 0)
5829 vty_out (vty, "Local");
5830 else
5831 aspath_print_vty (vty, "%s", attr->aspath, "");
5832 }
5833
5834 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5835 vty_out (vty, ", (removed)");
5836 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5837 vty_out (vty, ", (stale)");
5838 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5839 vty_out (vty, ", (aggregated by %u %s)",
5840 attr->extra->aggregator_as,
5841 inet_ntoa (attr->extra->aggregator_addr));
5842 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5843 vty_out (vty, ", (Received from a RR-client)");
5844 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5845 vty_out (vty, ", (Received from a RS-client)");
5846 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5847 vty_out (vty, ", (history entry)");
5848 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5849 vty_out (vty, ", (suppressed due to dampening)");
5850 vty_out (vty, "%s", VTY_NEWLINE);
5851
5852 /* Line2 display Next-hop, Neighbor, Router-id */
5853 if (p->family == AF_INET)
5854 {
5855 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5856 inet_ntoa (attr->extra->mp_nexthop_global_in) :
5857 inet_ntoa (attr->nexthop));
5858 }
5859 #ifdef HAVE_IPV6
5860 else
5861 {
5862 assert (attr->extra);
5863 vty_out (vty, " %s",
5864 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5865 buf, INET6_ADDRSTRLEN));
5866 }
5867 #endif /* HAVE_IPV6 */
5868
5869 if (binfo->peer == bgp->peer_self)
5870 {
5871 vty_out (vty, " from %s ",
5872 p->family == AF_INET ? "0.0.0.0" : "::");
5873 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5874 }
5875 else
5876 {
5877 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5878 vty_out (vty, " (inaccessible)");
5879 else if (binfo->extra && binfo->extra->igpmetric)
5880 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
5881 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
5882 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5883 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
5884 else
5885 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5886 }
5887 vty_out (vty, "%s", VTY_NEWLINE);
5888
5889 #ifdef HAVE_IPV6
5890 /* display nexthop local */
5891 if (attr->extra && attr->extra->mp_nexthop_len == 32)
5892 {
5893 vty_out (vty, " (%s)%s",
5894 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5895 buf, INET6_ADDRSTRLEN),
5896 VTY_NEWLINE);
5897 }
5898 #endif /* HAVE_IPV6 */
5899
5900 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5901 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5902
5903 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5904 vty_out (vty, ", metric %u", attr->med);
5905
5906 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5907 vty_out (vty, ", localpref %u", attr->local_pref);
5908 else
5909 vty_out (vty, ", localpref %u", bgp->default_local_pref);
5910
5911 if (attr->extra && attr->extra->weight != 0)
5912 vty_out (vty, ", weight %u", attr->extra->weight);
5913
5914 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5915 vty_out (vty, ", valid");
5916
5917 if (binfo->peer != bgp->peer_self)
5918 {
5919 if (binfo->peer->as == binfo->peer->local_as)
5920 vty_out (vty, ", internal");
5921 else
5922 vty_out (vty, ", %s",
5923 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5924 }
5925 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5926 vty_out (vty, ", aggregated, local");
5927 else if (binfo->type != ZEBRA_ROUTE_BGP)
5928 vty_out (vty, ", sourced");
5929 else
5930 vty_out (vty, ", sourced, local");
5931
5932 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5933 vty_out (vty, ", atomic-aggregate");
5934
5935 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5936 vty_out (vty, ", best");
5937
5938 vty_out (vty, "%s", VTY_NEWLINE);
5939
5940 /* Line 4 display Community */
5941 if (attr->community)
5942 vty_out (vty, " Community: %s%s", attr->community->str,
5943 VTY_NEWLINE);
5944
5945 /* Line 5 display Extended-community */
5946 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5947 vty_out (vty, " Extended Community: %s%s",
5948 attr->extra->ecommunity->str, VTY_NEWLINE);
5949
5950 /* Line 6 display Originator, Cluster-id */
5951 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5952 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5953 {
5954 assert (attr->extra);
5955 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5956 vty_out (vty, " Originator: %s",
5957 inet_ntoa (attr->extra->originator_id));
5958
5959 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5960 {
5961 int i;
5962 vty_out (vty, ", Cluster list: ");
5963 for (i = 0; i < attr->extra->cluster->length / 4; i++)
5964 vty_out (vty, "%s ",
5965 inet_ntoa (attr->extra->cluster->list[i]));
5966 }
5967 vty_out (vty, "%s", VTY_NEWLINE);
5968 }
5969
5970 if (binfo->extra && binfo->extra->damp_info)
5971 bgp_damp_info_vty (vty, binfo);
5972
5973 /* Line 7 display Uptime */
5974 #ifdef HAVE_CLOCK_MONOTONIC
5975 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
5976 vty_out (vty, " Last update: %s", ctime(&tbuf));
5977 #else
5978 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
5979 #endif /* HAVE_CLOCK_MONOTONIC */
5980 }
5981 vty_out (vty, "%s", VTY_NEWLINE);
5982 }
5983 \f
5984 #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,%s r RIB-failure, S Stale, R Removed%s"
5985 #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
5986 #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5987 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5988 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5989
5990 enum bgp_show_type
5991 {
5992 bgp_show_type_normal,
5993 bgp_show_type_regexp,
5994 bgp_show_type_prefix_list,
5995 bgp_show_type_filter_list,
5996 bgp_show_type_route_map,
5997 bgp_show_type_neighbor,
5998 bgp_show_type_cidr_only,
5999 bgp_show_type_prefix_longer,
6000 bgp_show_type_community_all,
6001 bgp_show_type_community,
6002 bgp_show_type_community_exact,
6003 bgp_show_type_community_list,
6004 bgp_show_type_community_list_exact,
6005 bgp_show_type_flap_statistics,
6006 bgp_show_type_flap_address,
6007 bgp_show_type_flap_prefix,
6008 bgp_show_type_flap_cidr_only,
6009 bgp_show_type_flap_regexp,
6010 bgp_show_type_flap_filter_list,
6011 bgp_show_type_flap_prefix_list,
6012 bgp_show_type_flap_prefix_longer,
6013 bgp_show_type_flap_route_map,
6014 bgp_show_type_flap_neighbor,
6015 bgp_show_type_dampend_paths,
6016 bgp_show_type_damp_neighbor
6017 };
6018
6019 static int
6020 bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
6021 enum bgp_show_type type, void *output_arg)
6022 {
6023 struct bgp_info *ri;
6024 struct bgp_node *rn;
6025 int header = 1;
6026 int display;
6027 unsigned long output_count;
6028
6029 /* This is first entry point, so reset total line. */
6030 output_count = 0;
6031
6032 /* Start processing of routes. */
6033 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6034 if (rn->info != NULL)
6035 {
6036 display = 0;
6037
6038 for (ri = rn->info; ri; ri = ri->next)
6039 {
6040 if (type == bgp_show_type_flap_statistics
6041 || type == bgp_show_type_flap_address
6042 || type == bgp_show_type_flap_prefix
6043 || type == bgp_show_type_flap_cidr_only
6044 || type == bgp_show_type_flap_regexp
6045 || type == bgp_show_type_flap_filter_list
6046 || type == bgp_show_type_flap_prefix_list
6047 || type == bgp_show_type_flap_prefix_longer
6048 || type == bgp_show_type_flap_route_map
6049 || type == bgp_show_type_flap_neighbor
6050 || type == bgp_show_type_dampend_paths
6051 || type == bgp_show_type_damp_neighbor)
6052 {
6053 if (!(ri->extra && ri->extra->damp_info))
6054 continue;
6055 }
6056 if (type == bgp_show_type_regexp
6057 || type == bgp_show_type_flap_regexp)
6058 {
6059 regex_t *regex = output_arg;
6060
6061 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6062 continue;
6063 }
6064 if (type == bgp_show_type_prefix_list
6065 || type == bgp_show_type_flap_prefix_list)
6066 {
6067 struct prefix_list *plist = output_arg;
6068
6069 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6070 continue;
6071 }
6072 if (type == bgp_show_type_filter_list
6073 || type == bgp_show_type_flap_filter_list)
6074 {
6075 struct as_list *as_list = output_arg;
6076
6077 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6078 continue;
6079 }
6080 if (type == bgp_show_type_route_map
6081 || type == bgp_show_type_flap_route_map)
6082 {
6083 struct route_map *rmap = output_arg;
6084 struct bgp_info binfo;
6085 struct attr dummy_attr = { 0 };
6086 int ret;
6087
6088 bgp_attr_dup (&dummy_attr, ri->attr);
6089 binfo.peer = ri->peer;
6090 binfo.attr = &dummy_attr;
6091
6092 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
6093
6094 bgp_attr_extra_free (&dummy_attr);
6095
6096 if (ret == RMAP_DENYMATCH)
6097 continue;
6098 }
6099 if (type == bgp_show_type_neighbor
6100 || type == bgp_show_type_flap_neighbor
6101 || type == bgp_show_type_damp_neighbor)
6102 {
6103 union sockunion *su = output_arg;
6104
6105 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6106 continue;
6107 }
6108 if (type == bgp_show_type_cidr_only
6109 || type == bgp_show_type_flap_cidr_only)
6110 {
6111 u_int32_t destination;
6112
6113 destination = ntohl (rn->p.u.prefix4.s_addr);
6114 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6115 continue;
6116 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6117 continue;
6118 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6119 continue;
6120 }
6121 if (type == bgp_show_type_prefix_longer
6122 || type == bgp_show_type_flap_prefix_longer)
6123 {
6124 struct prefix *p = output_arg;
6125
6126 if (! prefix_match (p, &rn->p))
6127 continue;
6128 }
6129 if (type == bgp_show_type_community_all)
6130 {
6131 if (! ri->attr->community)
6132 continue;
6133 }
6134 if (type == bgp_show_type_community)
6135 {
6136 struct community *com = output_arg;
6137
6138 if (! ri->attr->community ||
6139 ! community_match (ri->attr->community, com))
6140 continue;
6141 }
6142 if (type == bgp_show_type_community_exact)
6143 {
6144 struct community *com = output_arg;
6145
6146 if (! ri->attr->community ||
6147 ! community_cmp (ri->attr->community, com))
6148 continue;
6149 }
6150 if (type == bgp_show_type_community_list)
6151 {
6152 struct community_list *list = output_arg;
6153
6154 if (! community_list_match (ri->attr->community, list))
6155 continue;
6156 }
6157 if (type == bgp_show_type_community_list_exact)
6158 {
6159 struct community_list *list = output_arg;
6160
6161 if (! community_list_exact_match (ri->attr->community, list))
6162 continue;
6163 }
6164 if (type == bgp_show_type_flap_address
6165 || type == bgp_show_type_flap_prefix)
6166 {
6167 struct prefix *p = output_arg;
6168
6169 if (! prefix_match (&rn->p, p))
6170 continue;
6171
6172 if (type == bgp_show_type_flap_prefix)
6173 if (p->prefixlen != rn->p.prefixlen)
6174 continue;
6175 }
6176 if (type == bgp_show_type_dampend_paths
6177 || type == bgp_show_type_damp_neighbor)
6178 {
6179 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6180 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6181 continue;
6182 }
6183
6184 if (header)
6185 {
6186 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6187 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6188 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6189 if (type == bgp_show_type_dampend_paths
6190 || type == bgp_show_type_damp_neighbor)
6191 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6192 else if (type == bgp_show_type_flap_statistics
6193 || type == bgp_show_type_flap_address
6194 || type == bgp_show_type_flap_prefix
6195 || type == bgp_show_type_flap_cidr_only
6196 || type == bgp_show_type_flap_regexp
6197 || type == bgp_show_type_flap_filter_list
6198 || type == bgp_show_type_flap_prefix_list
6199 || type == bgp_show_type_flap_prefix_longer
6200 || type == bgp_show_type_flap_route_map
6201 || type == bgp_show_type_flap_neighbor)
6202 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6203 else
6204 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
6205 header = 0;
6206 }
6207
6208 if (type == bgp_show_type_dampend_paths
6209 || type == bgp_show_type_damp_neighbor)
6210 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6211 else if (type == bgp_show_type_flap_statistics
6212 || type == bgp_show_type_flap_address
6213 || type == bgp_show_type_flap_prefix
6214 || type == bgp_show_type_flap_cidr_only
6215 || type == bgp_show_type_flap_regexp
6216 || type == bgp_show_type_flap_filter_list
6217 || type == bgp_show_type_flap_prefix_list
6218 || type == bgp_show_type_flap_prefix_longer
6219 || type == bgp_show_type_flap_route_map
6220 || type == bgp_show_type_flap_neighbor)
6221 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6222 else
6223 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6224 display++;
6225 }
6226 if (display)
6227 output_count++;
6228 }
6229
6230 /* No route is displayed */
6231 if (output_count == 0)
6232 {
6233 if (type == bgp_show_type_normal)
6234 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6235 }
6236 else
6237 vty_out (vty, "%sTotal number of prefixes %ld%s",
6238 VTY_NEWLINE, output_count, VTY_NEWLINE);
6239
6240 return CMD_SUCCESS;
6241 }
6242
6243 static int
6244 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
6245 enum bgp_show_type type, void *output_arg)
6246 {
6247 struct bgp_table *table;
6248
6249 if (bgp == NULL) {
6250 bgp = bgp_get_default ();
6251 }
6252
6253 if (bgp == NULL)
6254 {
6255 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6256 return CMD_WARNING;
6257 }
6258
6259
6260 table = bgp->rib[afi][safi];
6261
6262 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
6263 }
6264
6265 /* Header of detailed BGP route information */
6266 static void
6267 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6268 struct bgp_node *rn,
6269 struct prefix_rd *prd, afi_t afi, safi_t safi)
6270 {
6271 struct bgp_info *ri;
6272 struct prefix *p;
6273 struct peer *peer;
6274 struct listnode *node, *nnode;
6275 char buf1[INET6_ADDRSTRLEN];
6276 char buf2[INET6_ADDRSTRLEN];
6277 int count = 0;
6278 int best = 0;
6279 int suppress = 0;
6280 int no_export = 0;
6281 int no_advertise = 0;
6282 int local_as = 0;
6283 int first = 0;
6284
6285 p = &rn->p;
6286 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6287 (safi == SAFI_MPLS_VPN ?
6288 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6289 safi == SAFI_MPLS_VPN ? ":" : "",
6290 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6291 p->prefixlen, VTY_NEWLINE);
6292
6293 for (ri = rn->info; ri; ri = ri->next)
6294 {
6295 count++;
6296 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6297 {
6298 best = count;
6299 if (ri->extra && ri->extra->suppress)
6300 suppress = 1;
6301 if (ri->attr->community != NULL)
6302 {
6303 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6304 no_advertise = 1;
6305 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6306 no_export = 1;
6307 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6308 local_as = 1;
6309 }
6310 }
6311 }
6312
6313 vty_out (vty, "Paths: (%d available", count);
6314 if (best)
6315 {
6316 vty_out (vty, ", best #%d", best);
6317 if (safi == SAFI_UNICAST)
6318 vty_out (vty, ", table Default-IP-Routing-Table");
6319 }
6320 else
6321 vty_out (vty, ", no best path");
6322 if (no_advertise)
6323 vty_out (vty, ", not advertised to any peer");
6324 else if (no_export)
6325 vty_out (vty, ", not advertised to EBGP peer");
6326 else if (local_as)
6327 vty_out (vty, ", not advertised outside local AS");
6328 if (suppress)
6329 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6330 vty_out (vty, ")%s", VTY_NEWLINE);
6331
6332 /* advertised peer */
6333 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6334 {
6335 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6336 {
6337 if (! first)
6338 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6339 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6340 first = 1;
6341 }
6342 }
6343 if (! first)
6344 vty_out (vty, " Not advertised to any peer");
6345 vty_out (vty, "%s", VTY_NEWLINE);
6346 }
6347
6348 /* Display specified route of BGP table. */
6349 static int
6350 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
6351 struct bgp_table *rib, const char *ip_str,
6352 afi_t afi, safi_t safi, struct prefix_rd *prd,
6353 int prefix_check)
6354 {
6355 int ret;
6356 int header;
6357 int display = 0;
6358 struct prefix match;
6359 struct bgp_node *rn;
6360 struct bgp_node *rm;
6361 struct bgp_info *ri;
6362 struct bgp_table *table;
6363
6364 /* Check IP address argument. */
6365 ret = str2prefix (ip_str, &match);
6366 if (! ret)
6367 {
6368 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6369 return CMD_WARNING;
6370 }
6371
6372 match.family = afi2family (afi);
6373
6374 if (safi == SAFI_MPLS_VPN)
6375 {
6376 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
6377 {
6378 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6379 continue;
6380
6381 if ((table = rn->info) != NULL)
6382 {
6383 header = 1;
6384
6385 if ((rm = bgp_node_match (table, &match)) != NULL)
6386 {
6387 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6388 {
6389 bgp_unlock_node (rm);
6390 continue;
6391 }
6392
6393 for (ri = rm->info; ri; ri = ri->next)
6394 {
6395 if (header)
6396 {
6397 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6398 AFI_IP, SAFI_MPLS_VPN);
6399
6400 header = 0;
6401 }
6402 display++;
6403 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6404 }
6405
6406 bgp_unlock_node (rm);
6407 }
6408 }
6409 }
6410 }
6411 else
6412 {
6413 header = 1;
6414
6415 if ((rn = bgp_node_match (rib, &match)) != NULL)
6416 {
6417 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6418 {
6419 for (ri = rn->info; ri; ri = ri->next)
6420 {
6421 if (header)
6422 {
6423 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6424 header = 0;
6425 }
6426 display++;
6427 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6428 }
6429 }
6430
6431 bgp_unlock_node (rn);
6432 }
6433 }
6434
6435 if (! display)
6436 {
6437 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6438 return CMD_WARNING;
6439 }
6440
6441 return CMD_SUCCESS;
6442 }
6443
6444 /* Display specified route of Main RIB */
6445 static int
6446 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
6447 afi_t afi, safi_t safi, struct prefix_rd *prd,
6448 int prefix_check)
6449 {
6450 struct bgp *bgp;
6451
6452 /* BGP structure lookup. */
6453 if (view_name)
6454 {
6455 bgp = bgp_lookup_by_name (view_name);
6456 if (bgp == NULL)
6457 {
6458 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6459 return CMD_WARNING;
6460 }
6461 }
6462 else
6463 {
6464 bgp = bgp_get_default ();
6465 if (bgp == NULL)
6466 {
6467 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6468 return CMD_WARNING;
6469 }
6470 }
6471
6472 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6473 afi, safi, prd, prefix_check);
6474 }
6475
6476 /* BGP route print out function. */
6477 DEFUN (show_ip_bgp,
6478 show_ip_bgp_cmd,
6479 "show ip bgp",
6480 SHOW_STR
6481 IP_STR
6482 BGP_STR)
6483 {
6484 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6485 }
6486
6487 DEFUN (show_ip_bgp_ipv4,
6488 show_ip_bgp_ipv4_cmd,
6489 "show ip bgp ipv4 (unicast|multicast)",
6490 SHOW_STR
6491 IP_STR
6492 BGP_STR
6493 "Address family\n"
6494 "Address Family modifier\n"
6495 "Address Family modifier\n")
6496 {
6497 if (strncmp (argv[0], "m", 1) == 0)
6498 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6499 NULL);
6500
6501 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6502 }
6503
6504 ALIAS (show_ip_bgp_ipv4,
6505 show_bgp_ipv4_safi_cmd,
6506 "show bgp ipv4 (unicast|multicast)",
6507 SHOW_STR
6508 BGP_STR
6509 "Address family\n"
6510 "Address Family modifier\n"
6511 "Address Family modifier\n")
6512
6513 DEFUN (show_ip_bgp_route,
6514 show_ip_bgp_route_cmd,
6515 "show ip bgp A.B.C.D",
6516 SHOW_STR
6517 IP_STR
6518 BGP_STR
6519 "Network in the BGP routing table to display\n")
6520 {
6521 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6522 }
6523
6524 DEFUN (show_ip_bgp_ipv4_route,
6525 show_ip_bgp_ipv4_route_cmd,
6526 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6527 SHOW_STR
6528 IP_STR
6529 BGP_STR
6530 "Address family\n"
6531 "Address Family modifier\n"
6532 "Address Family modifier\n"
6533 "Network in the BGP routing table to display\n")
6534 {
6535 if (strncmp (argv[0], "m", 1) == 0)
6536 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6537
6538 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6539 }
6540
6541 ALIAS (show_ip_bgp_ipv4_route,
6542 show_bgp_ipv4_safi_route_cmd,
6543 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6544 SHOW_STR
6545 BGP_STR
6546 "Address family\n"
6547 "Address Family modifier\n"
6548 "Address Family modifier\n"
6549 "Network in the BGP routing table to display\n")
6550
6551 DEFUN (show_ip_bgp_vpnv4_all_route,
6552 show_ip_bgp_vpnv4_all_route_cmd,
6553 "show ip bgp vpnv4 all A.B.C.D",
6554 SHOW_STR
6555 IP_STR
6556 BGP_STR
6557 "Display VPNv4 NLRI specific information\n"
6558 "Display information about all VPNv4 NLRIs\n"
6559 "Network in the BGP routing table to display\n")
6560 {
6561 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6562 }
6563
6564 DEFUN (show_ip_bgp_vpnv4_rd_route,
6565 show_ip_bgp_vpnv4_rd_route_cmd,
6566 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6567 SHOW_STR
6568 IP_STR
6569 BGP_STR
6570 "Display VPNv4 NLRI specific information\n"
6571 "Display information for a route distinguisher\n"
6572 "VPN Route Distinguisher\n"
6573 "Network in the BGP routing table to display\n")
6574 {
6575 int ret;
6576 struct prefix_rd prd;
6577
6578 ret = str2prefix_rd (argv[0], &prd);
6579 if (! ret)
6580 {
6581 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6582 return CMD_WARNING;
6583 }
6584 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6585 }
6586
6587 DEFUN (show_ip_bgp_prefix,
6588 show_ip_bgp_prefix_cmd,
6589 "show ip bgp A.B.C.D/M",
6590 SHOW_STR
6591 IP_STR
6592 BGP_STR
6593 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6594 {
6595 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6596 }
6597
6598 DEFUN (show_ip_bgp_ipv4_prefix,
6599 show_ip_bgp_ipv4_prefix_cmd,
6600 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6601 SHOW_STR
6602 IP_STR
6603 BGP_STR
6604 "Address family\n"
6605 "Address Family modifier\n"
6606 "Address Family modifier\n"
6607 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6608 {
6609 if (strncmp (argv[0], "m", 1) == 0)
6610 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6611
6612 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6613 }
6614
6615 ALIAS (show_ip_bgp_ipv4_prefix,
6616 show_bgp_ipv4_safi_prefix_cmd,
6617 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6618 SHOW_STR
6619 BGP_STR
6620 "Address family\n"
6621 "Address Family modifier\n"
6622 "Address Family modifier\n"
6623 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6624
6625 DEFUN (show_ip_bgp_vpnv4_all_prefix,
6626 show_ip_bgp_vpnv4_all_prefix_cmd,
6627 "show ip bgp vpnv4 all A.B.C.D/M",
6628 SHOW_STR
6629 IP_STR
6630 BGP_STR
6631 "Display VPNv4 NLRI specific information\n"
6632 "Display information about all VPNv4 NLRIs\n"
6633 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6634 {
6635 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6636 }
6637
6638 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6639 show_ip_bgp_vpnv4_rd_prefix_cmd,
6640 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6641 SHOW_STR
6642 IP_STR
6643 BGP_STR
6644 "Display VPNv4 NLRI specific information\n"
6645 "Display information for a route distinguisher\n"
6646 "VPN Route Distinguisher\n"
6647 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6648 {
6649 int ret;
6650 struct prefix_rd prd;
6651
6652 ret = str2prefix_rd (argv[0], &prd);
6653 if (! ret)
6654 {
6655 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6656 return CMD_WARNING;
6657 }
6658 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6659 }
6660
6661 DEFUN (show_ip_bgp_view,
6662 show_ip_bgp_view_cmd,
6663 "show ip bgp view WORD",
6664 SHOW_STR
6665 IP_STR
6666 BGP_STR
6667 "BGP view\n"
6668 "BGP view name\n")
6669 {
6670 struct bgp *bgp;
6671
6672 /* BGP structure lookup. */
6673 bgp = bgp_lookup_by_name (argv[0]);
6674 if (bgp == NULL)
6675 {
6676 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6677 return CMD_WARNING;
6678 }
6679
6680 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6681 }
6682
6683 DEFUN (show_ip_bgp_view_route,
6684 show_ip_bgp_view_route_cmd,
6685 "show ip bgp view WORD A.B.C.D",
6686 SHOW_STR
6687 IP_STR
6688 BGP_STR
6689 "BGP view\n"
6690 "BGP view name\n"
6691 "Network in the BGP routing table to display\n")
6692 {
6693 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6694 }
6695
6696 DEFUN (show_ip_bgp_view_prefix,
6697 show_ip_bgp_view_prefix_cmd,
6698 "show ip bgp view WORD A.B.C.D/M",
6699 SHOW_STR
6700 IP_STR
6701 BGP_STR
6702 "BGP view\n"
6703 "BGP view name\n"
6704 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6705 {
6706 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6707 }
6708
6709 #ifdef HAVE_IPV6
6710 DEFUN (show_bgp,
6711 show_bgp_cmd,
6712 "show bgp",
6713 SHOW_STR
6714 BGP_STR)
6715 {
6716 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6717 NULL);
6718 }
6719
6720 ALIAS (show_bgp,
6721 show_bgp_ipv6_cmd,
6722 "show bgp ipv6",
6723 SHOW_STR
6724 BGP_STR
6725 "Address family\n")
6726
6727 DEFUN (show_bgp_ipv6_safi,
6728 show_bgp_ipv6_safi_cmd,
6729 "show bgp ipv6 (unicast|multicast)",
6730 SHOW_STR
6731 BGP_STR
6732 "Address family\n"
6733 "Address Family modifier\n"
6734 "Address Family modifier\n")
6735 {
6736 if (strncmp (argv[0], "m", 1) == 0)
6737 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6738 NULL);
6739
6740 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6741 }
6742
6743 /* old command */
6744 DEFUN (show_ipv6_bgp,
6745 show_ipv6_bgp_cmd,
6746 "show ipv6 bgp",
6747 SHOW_STR
6748 IP_STR
6749 BGP_STR)
6750 {
6751 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6752 NULL);
6753 }
6754
6755 DEFUN (show_bgp_route,
6756 show_bgp_route_cmd,
6757 "show bgp X:X::X:X",
6758 SHOW_STR
6759 BGP_STR
6760 "Network in the BGP routing table to display\n")
6761 {
6762 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6763 }
6764
6765 ALIAS (show_bgp_route,
6766 show_bgp_ipv6_route_cmd,
6767 "show bgp ipv6 X:X::X:X",
6768 SHOW_STR
6769 BGP_STR
6770 "Address family\n"
6771 "Network in the BGP routing table to display\n")
6772
6773 DEFUN (show_bgp_ipv6_safi_route,
6774 show_bgp_ipv6_safi_route_cmd,
6775 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6776 SHOW_STR
6777 BGP_STR
6778 "Address family\n"
6779 "Address Family modifier\n"
6780 "Address Family modifier\n"
6781 "Network in the BGP routing table to display\n")
6782 {
6783 if (strncmp (argv[0], "m", 1) == 0)
6784 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6785
6786 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6787 }
6788
6789 /* old command */
6790 DEFUN (show_ipv6_bgp_route,
6791 show_ipv6_bgp_route_cmd,
6792 "show ipv6 bgp X:X::X:X",
6793 SHOW_STR
6794 IP_STR
6795 BGP_STR
6796 "Network in the BGP routing table to display\n")
6797 {
6798 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6799 }
6800
6801 DEFUN (show_bgp_prefix,
6802 show_bgp_prefix_cmd,
6803 "show bgp X:X::X:X/M",
6804 SHOW_STR
6805 BGP_STR
6806 "IPv6 prefix <network>/<length>\n")
6807 {
6808 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6809 }
6810
6811 ALIAS (show_bgp_prefix,
6812 show_bgp_ipv6_prefix_cmd,
6813 "show bgp ipv6 X:X::X:X/M",
6814 SHOW_STR
6815 BGP_STR
6816 "Address family\n"
6817 "IPv6 prefix <network>/<length>\n")
6818
6819 DEFUN (show_bgp_ipv6_safi_prefix,
6820 show_bgp_ipv6_safi_prefix_cmd,
6821 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6822 SHOW_STR
6823 BGP_STR
6824 "Address family\n"
6825 "Address Family modifier\n"
6826 "Address Family modifier\n"
6827 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6828 {
6829 if (strncmp (argv[0], "m", 1) == 0)
6830 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6831
6832 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6833 }
6834
6835 /* old command */
6836 DEFUN (show_ipv6_bgp_prefix,
6837 show_ipv6_bgp_prefix_cmd,
6838 "show ipv6 bgp X:X::X:X/M",
6839 SHOW_STR
6840 IP_STR
6841 BGP_STR
6842 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6843 {
6844 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6845 }
6846
6847 DEFUN (show_bgp_view,
6848 show_bgp_view_cmd,
6849 "show bgp view WORD",
6850 SHOW_STR
6851 BGP_STR
6852 "BGP view\n"
6853 "View name\n")
6854 {
6855 struct bgp *bgp;
6856
6857 /* BGP structure lookup. */
6858 bgp = bgp_lookup_by_name (argv[0]);
6859 if (bgp == NULL)
6860 {
6861 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6862 return CMD_WARNING;
6863 }
6864
6865 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6866 }
6867
6868 ALIAS (show_bgp_view,
6869 show_bgp_view_ipv6_cmd,
6870 "show bgp view WORD ipv6",
6871 SHOW_STR
6872 BGP_STR
6873 "BGP view\n"
6874 "View name\n"
6875 "Address family\n")
6876
6877 DEFUN (show_bgp_view_route,
6878 show_bgp_view_route_cmd,
6879 "show bgp view WORD X:X::X:X",
6880 SHOW_STR
6881 BGP_STR
6882 "BGP view\n"
6883 "View name\n"
6884 "Network in the BGP routing table to display\n")
6885 {
6886 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6887 }
6888
6889 ALIAS (show_bgp_view_route,
6890 show_bgp_view_ipv6_route_cmd,
6891 "show bgp view WORD ipv6 X:X::X:X",
6892 SHOW_STR
6893 BGP_STR
6894 "BGP view\n"
6895 "View name\n"
6896 "Address family\n"
6897 "Network in the BGP routing table to display\n")
6898
6899 DEFUN (show_bgp_view_prefix,
6900 show_bgp_view_prefix_cmd,
6901 "show bgp view WORD X:X::X:X/M",
6902 SHOW_STR
6903 BGP_STR
6904 "BGP view\n"
6905 "View name\n"
6906 "IPv6 prefix <network>/<length>\n")
6907 {
6908 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6909 }
6910
6911 ALIAS (show_bgp_view_prefix,
6912 show_bgp_view_ipv6_prefix_cmd,
6913 "show bgp view WORD ipv6 X:X::X:X/M",
6914 SHOW_STR
6915 BGP_STR
6916 "BGP view\n"
6917 "View name\n"
6918 "Address family\n"
6919 "IPv6 prefix <network>/<length>\n")
6920
6921 /* old command */
6922 DEFUN (show_ipv6_mbgp,
6923 show_ipv6_mbgp_cmd,
6924 "show ipv6 mbgp",
6925 SHOW_STR
6926 IP_STR
6927 MBGP_STR)
6928 {
6929 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6930 NULL);
6931 }
6932
6933 /* old command */
6934 DEFUN (show_ipv6_mbgp_route,
6935 show_ipv6_mbgp_route_cmd,
6936 "show ipv6 mbgp X:X::X:X",
6937 SHOW_STR
6938 IP_STR
6939 MBGP_STR
6940 "Network in the MBGP routing table to display\n")
6941 {
6942 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6943 }
6944
6945 /* old command */
6946 DEFUN (show_ipv6_mbgp_prefix,
6947 show_ipv6_mbgp_prefix_cmd,
6948 "show ipv6 mbgp X:X::X:X/M",
6949 SHOW_STR
6950 IP_STR
6951 MBGP_STR
6952 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6953 {
6954 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6955 }
6956 #endif
6957 \f
6958
6959 static int
6960 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
6961 safi_t safi, enum bgp_show_type type)
6962 {
6963 int i;
6964 struct buffer *b;
6965 char *regstr;
6966 int first;
6967 regex_t *regex;
6968 int rc;
6969
6970 first = 0;
6971 b = buffer_new (1024);
6972 for (i = 0; i < argc; i++)
6973 {
6974 if (first)
6975 buffer_putc (b, ' ');
6976 else
6977 {
6978 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6979 continue;
6980 first = 1;
6981 }
6982
6983 buffer_putstr (b, argv[i]);
6984 }
6985 buffer_putc (b, '\0');
6986
6987 regstr = buffer_getstr (b);
6988 buffer_free (b);
6989
6990 regex = bgp_regcomp (regstr);
6991 XFREE(MTYPE_TMP, regstr);
6992 if (! regex)
6993 {
6994 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6995 VTY_NEWLINE);
6996 return CMD_WARNING;
6997 }
6998
6999 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7000 bgp_regex_free (regex);
7001 return rc;
7002 }
7003
7004 DEFUN (show_ip_bgp_regexp,
7005 show_ip_bgp_regexp_cmd,
7006 "show ip bgp regexp .LINE",
7007 SHOW_STR
7008 IP_STR
7009 BGP_STR
7010 "Display routes matching the AS path regular expression\n"
7011 "A regular-expression to match the BGP AS paths\n")
7012 {
7013 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7014 bgp_show_type_regexp);
7015 }
7016
7017 DEFUN (show_ip_bgp_flap_regexp,
7018 show_ip_bgp_flap_regexp_cmd,
7019 "show ip bgp flap-statistics regexp .LINE",
7020 SHOW_STR
7021 IP_STR
7022 BGP_STR
7023 "Display flap statistics of routes\n"
7024 "Display routes matching the AS path regular expression\n"
7025 "A regular-expression to match the BGP AS paths\n")
7026 {
7027 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7028 bgp_show_type_flap_regexp);
7029 }
7030
7031 DEFUN (show_ip_bgp_ipv4_regexp,
7032 show_ip_bgp_ipv4_regexp_cmd,
7033 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7034 SHOW_STR
7035 IP_STR
7036 BGP_STR
7037 "Address family\n"
7038 "Address Family modifier\n"
7039 "Address Family modifier\n"
7040 "Display routes matching the AS path regular expression\n"
7041 "A regular-expression to match the BGP AS paths\n")
7042 {
7043 if (strncmp (argv[0], "m", 1) == 0)
7044 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7045 bgp_show_type_regexp);
7046
7047 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7048 bgp_show_type_regexp);
7049 }
7050
7051 #ifdef HAVE_IPV6
7052 DEFUN (show_bgp_regexp,
7053 show_bgp_regexp_cmd,
7054 "show bgp regexp .LINE",
7055 SHOW_STR
7056 BGP_STR
7057 "Display routes matching the AS path regular expression\n"
7058 "A regular-expression to match the BGP AS paths\n")
7059 {
7060 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7061 bgp_show_type_regexp);
7062 }
7063
7064 ALIAS (show_bgp_regexp,
7065 show_bgp_ipv6_regexp_cmd,
7066 "show bgp ipv6 regexp .LINE",
7067 SHOW_STR
7068 BGP_STR
7069 "Address family\n"
7070 "Display routes matching the AS path regular expression\n"
7071 "A regular-expression to match the BGP AS paths\n")
7072
7073 /* old command */
7074 DEFUN (show_ipv6_bgp_regexp,
7075 show_ipv6_bgp_regexp_cmd,
7076 "show ipv6 bgp regexp .LINE",
7077 SHOW_STR
7078 IP_STR
7079 BGP_STR
7080 "Display routes matching the AS path regular expression\n"
7081 "A regular-expression to match the BGP AS paths\n")
7082 {
7083 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7084 bgp_show_type_regexp);
7085 }
7086
7087 /* old command */
7088 DEFUN (show_ipv6_mbgp_regexp,
7089 show_ipv6_mbgp_regexp_cmd,
7090 "show ipv6 mbgp regexp .LINE",
7091 SHOW_STR
7092 IP_STR
7093 BGP_STR
7094 "Display routes matching the AS path regular expression\n"
7095 "A regular-expression to match the MBGP AS paths\n")
7096 {
7097 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7098 bgp_show_type_regexp);
7099 }
7100 #endif /* HAVE_IPV6 */
7101 \f
7102 static int
7103 bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
7104 safi_t safi, enum bgp_show_type type)
7105 {
7106 struct prefix_list *plist;
7107
7108 plist = prefix_list_lookup (afi, prefix_list_str);
7109 if (plist == NULL)
7110 {
7111 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7112 prefix_list_str, VTY_NEWLINE);
7113 return CMD_WARNING;
7114 }
7115
7116 return bgp_show (vty, NULL, afi, safi, type, plist);
7117 }
7118
7119 DEFUN (show_ip_bgp_prefix_list,
7120 show_ip_bgp_prefix_list_cmd,
7121 "show ip bgp prefix-list WORD",
7122 SHOW_STR
7123 IP_STR
7124 BGP_STR
7125 "Display routes conforming to the prefix-list\n"
7126 "IP prefix-list name\n")
7127 {
7128 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7129 bgp_show_type_prefix_list);
7130 }
7131
7132 DEFUN (show_ip_bgp_flap_prefix_list,
7133 show_ip_bgp_flap_prefix_list_cmd,
7134 "show ip bgp flap-statistics prefix-list WORD",
7135 SHOW_STR
7136 IP_STR
7137 BGP_STR
7138 "Display flap statistics of routes\n"
7139 "Display routes conforming to the prefix-list\n"
7140 "IP prefix-list name\n")
7141 {
7142 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7143 bgp_show_type_flap_prefix_list);
7144 }
7145
7146 DEFUN (show_ip_bgp_ipv4_prefix_list,
7147 show_ip_bgp_ipv4_prefix_list_cmd,
7148 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7149 SHOW_STR
7150 IP_STR
7151 BGP_STR
7152 "Address family\n"
7153 "Address Family modifier\n"
7154 "Address Family modifier\n"
7155 "Display routes conforming to the prefix-list\n"
7156 "IP prefix-list name\n")
7157 {
7158 if (strncmp (argv[0], "m", 1) == 0)
7159 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7160 bgp_show_type_prefix_list);
7161
7162 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7163 bgp_show_type_prefix_list);
7164 }
7165
7166 #ifdef HAVE_IPV6
7167 DEFUN (show_bgp_prefix_list,
7168 show_bgp_prefix_list_cmd,
7169 "show bgp prefix-list WORD",
7170 SHOW_STR
7171 BGP_STR
7172 "Display routes conforming to the prefix-list\n"
7173 "IPv6 prefix-list name\n")
7174 {
7175 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7176 bgp_show_type_prefix_list);
7177 }
7178
7179 ALIAS (show_bgp_prefix_list,
7180 show_bgp_ipv6_prefix_list_cmd,
7181 "show bgp ipv6 prefix-list WORD",
7182 SHOW_STR
7183 BGP_STR
7184 "Address family\n"
7185 "Display routes conforming to the prefix-list\n"
7186 "IPv6 prefix-list name\n")
7187
7188 /* old command */
7189 DEFUN (show_ipv6_bgp_prefix_list,
7190 show_ipv6_bgp_prefix_list_cmd,
7191 "show ipv6 bgp prefix-list WORD",
7192 SHOW_STR
7193 IPV6_STR
7194 BGP_STR
7195 "Display routes matching the prefix-list\n"
7196 "IPv6 prefix-list name\n")
7197 {
7198 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7199 bgp_show_type_prefix_list);
7200 }
7201
7202 /* old command */
7203 DEFUN (show_ipv6_mbgp_prefix_list,
7204 show_ipv6_mbgp_prefix_list_cmd,
7205 "show ipv6 mbgp prefix-list WORD",
7206 SHOW_STR
7207 IPV6_STR
7208 MBGP_STR
7209 "Display routes matching the prefix-list\n"
7210 "IPv6 prefix-list name\n")
7211 {
7212 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7213 bgp_show_type_prefix_list);
7214 }
7215 #endif /* HAVE_IPV6 */
7216 \f
7217 static int
7218 bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
7219 safi_t safi, enum bgp_show_type type)
7220 {
7221 struct as_list *as_list;
7222
7223 as_list = as_list_lookup (filter);
7224 if (as_list == NULL)
7225 {
7226 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7227 return CMD_WARNING;
7228 }
7229
7230 return bgp_show (vty, NULL, afi, safi, type, as_list);
7231 }
7232
7233 DEFUN (show_ip_bgp_filter_list,
7234 show_ip_bgp_filter_list_cmd,
7235 "show ip bgp filter-list WORD",
7236 SHOW_STR
7237 IP_STR
7238 BGP_STR
7239 "Display routes conforming to the filter-list\n"
7240 "Regular expression access list name\n")
7241 {
7242 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7243 bgp_show_type_filter_list);
7244 }
7245
7246 DEFUN (show_ip_bgp_flap_filter_list,
7247 show_ip_bgp_flap_filter_list_cmd,
7248 "show ip bgp flap-statistics filter-list WORD",
7249 SHOW_STR
7250 IP_STR
7251 BGP_STR
7252 "Display flap statistics of routes\n"
7253 "Display routes conforming to the filter-list\n"
7254 "Regular expression access list name\n")
7255 {
7256 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7257 bgp_show_type_flap_filter_list);
7258 }
7259
7260 DEFUN (show_ip_bgp_ipv4_filter_list,
7261 show_ip_bgp_ipv4_filter_list_cmd,
7262 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7263 SHOW_STR
7264 IP_STR
7265 BGP_STR
7266 "Address family\n"
7267 "Address Family modifier\n"
7268 "Address Family modifier\n"
7269 "Display routes conforming to the filter-list\n"
7270 "Regular expression access list name\n")
7271 {
7272 if (strncmp (argv[0], "m", 1) == 0)
7273 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7274 bgp_show_type_filter_list);
7275
7276 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7277 bgp_show_type_filter_list);
7278 }
7279
7280 #ifdef HAVE_IPV6
7281 DEFUN (show_bgp_filter_list,
7282 show_bgp_filter_list_cmd,
7283 "show bgp filter-list WORD",
7284 SHOW_STR
7285 BGP_STR
7286 "Display routes conforming to the filter-list\n"
7287 "Regular expression access list name\n")
7288 {
7289 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7290 bgp_show_type_filter_list);
7291 }
7292
7293 ALIAS (show_bgp_filter_list,
7294 show_bgp_ipv6_filter_list_cmd,
7295 "show bgp ipv6 filter-list WORD",
7296 SHOW_STR
7297 BGP_STR
7298 "Address family\n"
7299 "Display routes conforming to the filter-list\n"
7300 "Regular expression access list name\n")
7301
7302 /* old command */
7303 DEFUN (show_ipv6_bgp_filter_list,
7304 show_ipv6_bgp_filter_list_cmd,
7305 "show ipv6 bgp filter-list WORD",
7306 SHOW_STR
7307 IPV6_STR
7308 BGP_STR
7309 "Display routes conforming to the filter-list\n"
7310 "Regular expression access list name\n")
7311 {
7312 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7313 bgp_show_type_filter_list);
7314 }
7315
7316 /* old command */
7317 DEFUN (show_ipv6_mbgp_filter_list,
7318 show_ipv6_mbgp_filter_list_cmd,
7319 "show ipv6 mbgp filter-list WORD",
7320 SHOW_STR
7321 IPV6_STR
7322 MBGP_STR
7323 "Display routes conforming to the filter-list\n"
7324 "Regular expression access list name\n")
7325 {
7326 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7327 bgp_show_type_filter_list);
7328 }
7329 #endif /* HAVE_IPV6 */
7330 \f
7331 static int
7332 bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
7333 safi_t safi, enum bgp_show_type type)
7334 {
7335 struct route_map *rmap;
7336
7337 rmap = route_map_lookup_by_name (rmap_str);
7338 if (! rmap)
7339 {
7340 vty_out (vty, "%% %s is not a valid route-map name%s",
7341 rmap_str, VTY_NEWLINE);
7342 return CMD_WARNING;
7343 }
7344
7345 return bgp_show (vty, NULL, afi, safi, type, rmap);
7346 }
7347
7348 DEFUN (show_ip_bgp_route_map,
7349 show_ip_bgp_route_map_cmd,
7350 "show ip bgp route-map WORD",
7351 SHOW_STR
7352 IP_STR
7353 BGP_STR
7354 "Display routes matching the route-map\n"
7355 "A route-map to match on\n")
7356 {
7357 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7358 bgp_show_type_route_map);
7359 }
7360
7361 DEFUN (show_ip_bgp_flap_route_map,
7362 show_ip_bgp_flap_route_map_cmd,
7363 "show ip bgp flap-statistics route-map WORD",
7364 SHOW_STR
7365 IP_STR
7366 BGP_STR
7367 "Display flap statistics of routes\n"
7368 "Display routes matching the route-map\n"
7369 "A route-map to match on\n")
7370 {
7371 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7372 bgp_show_type_flap_route_map);
7373 }
7374
7375 DEFUN (show_ip_bgp_ipv4_route_map,
7376 show_ip_bgp_ipv4_route_map_cmd,
7377 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7378 SHOW_STR
7379 IP_STR
7380 BGP_STR
7381 "Address family\n"
7382 "Address Family modifier\n"
7383 "Address Family modifier\n"
7384 "Display routes matching the route-map\n"
7385 "A route-map to match on\n")
7386 {
7387 if (strncmp (argv[0], "m", 1) == 0)
7388 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7389 bgp_show_type_route_map);
7390
7391 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7392 bgp_show_type_route_map);
7393 }
7394
7395 DEFUN (show_bgp_route_map,
7396 show_bgp_route_map_cmd,
7397 "show bgp route-map WORD",
7398 SHOW_STR
7399 BGP_STR
7400 "Display routes matching the route-map\n"
7401 "A route-map to match on\n")
7402 {
7403 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7404 bgp_show_type_route_map);
7405 }
7406
7407 ALIAS (show_bgp_route_map,
7408 show_bgp_ipv6_route_map_cmd,
7409 "show bgp ipv6 route-map WORD",
7410 SHOW_STR
7411 BGP_STR
7412 "Address family\n"
7413 "Display routes matching the route-map\n"
7414 "A route-map to match on\n")
7415 \f
7416 DEFUN (show_ip_bgp_cidr_only,
7417 show_ip_bgp_cidr_only_cmd,
7418 "show ip bgp cidr-only",
7419 SHOW_STR
7420 IP_STR
7421 BGP_STR
7422 "Display only routes with non-natural netmasks\n")
7423 {
7424 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7425 bgp_show_type_cidr_only, NULL);
7426 }
7427
7428 DEFUN (show_ip_bgp_flap_cidr_only,
7429 show_ip_bgp_flap_cidr_only_cmd,
7430 "show ip bgp flap-statistics cidr-only",
7431 SHOW_STR
7432 IP_STR
7433 BGP_STR
7434 "Display flap statistics of routes\n"
7435 "Display only routes with non-natural netmasks\n")
7436 {
7437 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7438 bgp_show_type_flap_cidr_only, NULL);
7439 }
7440
7441 DEFUN (show_ip_bgp_ipv4_cidr_only,
7442 show_ip_bgp_ipv4_cidr_only_cmd,
7443 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7444 SHOW_STR
7445 IP_STR
7446 BGP_STR
7447 "Address family\n"
7448 "Address Family modifier\n"
7449 "Address Family modifier\n"
7450 "Display only routes with non-natural netmasks\n")
7451 {
7452 if (strncmp (argv[0], "m", 1) == 0)
7453 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
7454 bgp_show_type_cidr_only, NULL);
7455
7456 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7457 bgp_show_type_cidr_only, NULL);
7458 }
7459 \f
7460 DEFUN (show_ip_bgp_community_all,
7461 show_ip_bgp_community_all_cmd,
7462 "show ip bgp community",
7463 SHOW_STR
7464 IP_STR
7465 BGP_STR
7466 "Display routes matching the communities\n")
7467 {
7468 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7469 bgp_show_type_community_all, NULL);
7470 }
7471
7472 DEFUN (show_ip_bgp_ipv4_community_all,
7473 show_ip_bgp_ipv4_community_all_cmd,
7474 "show ip bgp ipv4 (unicast|multicast) community",
7475 SHOW_STR
7476 IP_STR
7477 BGP_STR
7478 "Address family\n"
7479 "Address Family modifier\n"
7480 "Address Family modifier\n"
7481 "Display routes matching the communities\n")
7482 {
7483 if (strncmp (argv[0], "m", 1) == 0)
7484 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
7485 bgp_show_type_community_all, NULL);
7486
7487 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7488 bgp_show_type_community_all, NULL);
7489 }
7490
7491 #ifdef HAVE_IPV6
7492 DEFUN (show_bgp_community_all,
7493 show_bgp_community_all_cmd,
7494 "show bgp community",
7495 SHOW_STR
7496 BGP_STR
7497 "Display routes matching the communities\n")
7498 {
7499 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
7500 bgp_show_type_community_all, NULL);
7501 }
7502
7503 ALIAS (show_bgp_community_all,
7504 show_bgp_ipv6_community_all_cmd,
7505 "show bgp ipv6 community",
7506 SHOW_STR
7507 BGP_STR
7508 "Address family\n"
7509 "Display routes matching the communities\n")
7510
7511 /* old command */
7512 DEFUN (show_ipv6_bgp_community_all,
7513 show_ipv6_bgp_community_all_cmd,
7514 "show ipv6 bgp community",
7515 SHOW_STR
7516 IPV6_STR
7517 BGP_STR
7518 "Display routes matching the communities\n")
7519 {
7520 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
7521 bgp_show_type_community_all, NULL);
7522 }
7523
7524 /* old command */
7525 DEFUN (show_ipv6_mbgp_community_all,
7526 show_ipv6_mbgp_community_all_cmd,
7527 "show ipv6 mbgp community",
7528 SHOW_STR
7529 IPV6_STR
7530 MBGP_STR
7531 "Display routes matching the communities\n")
7532 {
7533 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
7534 bgp_show_type_community_all, NULL);
7535 }
7536 #endif /* HAVE_IPV6 */
7537 \f
7538 static int
7539 bgp_show_community (struct vty *vty, const char *view_name, int argc,
7540 const char **argv, int exact, afi_t afi, safi_t safi)
7541 {
7542 struct community *com;
7543 struct buffer *b;
7544 struct bgp *bgp;
7545 int i;
7546 char *str;
7547 int first = 0;
7548
7549 /* BGP structure lookup */
7550 if (view_name)
7551 {
7552 bgp = bgp_lookup_by_name (view_name);
7553 if (bgp == NULL)
7554 {
7555 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7556 return CMD_WARNING;
7557 }
7558 }
7559 else
7560 {
7561 bgp = bgp_get_default ();
7562 if (bgp == NULL)
7563 {
7564 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7565 return CMD_WARNING;
7566 }
7567 }
7568
7569 b = buffer_new (1024);
7570 for (i = 0; i < argc; i++)
7571 {
7572 if (first)
7573 buffer_putc (b, ' ');
7574 else
7575 {
7576 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7577 continue;
7578 first = 1;
7579 }
7580
7581 buffer_putstr (b, argv[i]);
7582 }
7583 buffer_putc (b, '\0');
7584
7585 str = buffer_getstr (b);
7586 buffer_free (b);
7587
7588 com = community_str2com (str);
7589 XFREE (MTYPE_TMP, str);
7590 if (! com)
7591 {
7592 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7593 return CMD_WARNING;
7594 }
7595
7596 return bgp_show (vty, bgp, afi, safi,
7597 (exact ? bgp_show_type_community_exact :
7598 bgp_show_type_community), com);
7599 }
7600
7601 DEFUN (show_ip_bgp_community,
7602 show_ip_bgp_community_cmd,
7603 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7604 SHOW_STR
7605 IP_STR
7606 BGP_STR
7607 "Display routes matching the communities\n"
7608 "community number\n"
7609 "Do not send outside local AS (well-known community)\n"
7610 "Do not advertise to any peer (well-known community)\n"
7611 "Do not export to next AS (well-known community)\n")
7612 {
7613 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7614 }
7615
7616 ALIAS (show_ip_bgp_community,
7617 show_ip_bgp_community2_cmd,
7618 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7619 SHOW_STR
7620 IP_STR
7621 BGP_STR
7622 "Display routes matching the communities\n"
7623 "community number\n"
7624 "Do not send outside local AS (well-known community)\n"
7625 "Do not advertise to any peer (well-known community)\n"
7626 "Do not export to next AS (well-known community)\n"
7627 "community number\n"
7628 "Do not send outside local AS (well-known community)\n"
7629 "Do not advertise to any peer (well-known community)\n"
7630 "Do not export to next AS (well-known community)\n")
7631
7632 ALIAS (show_ip_bgp_community,
7633 show_ip_bgp_community3_cmd,
7634 "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)",
7635 SHOW_STR
7636 IP_STR
7637 BGP_STR
7638 "Display routes matching the communities\n"
7639 "community number\n"
7640 "Do not send outside local AS (well-known community)\n"
7641 "Do not advertise to any peer (well-known community)\n"
7642 "Do not export to next AS (well-known community)\n"
7643 "community number\n"
7644 "Do not send outside local AS (well-known community)\n"
7645 "Do not advertise to any peer (well-known community)\n"
7646 "Do not export to next AS (well-known community)\n"
7647 "community number\n"
7648 "Do not send outside local AS (well-known community)\n"
7649 "Do not advertise to any peer (well-known community)\n"
7650 "Do not export to next AS (well-known community)\n")
7651
7652 ALIAS (show_ip_bgp_community,
7653 show_ip_bgp_community4_cmd,
7654 "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)",
7655 SHOW_STR
7656 IP_STR
7657 BGP_STR
7658 "Display routes matching the communities\n"
7659 "community number\n"
7660 "Do not send outside local AS (well-known community)\n"
7661 "Do not advertise to any peer (well-known community)\n"
7662 "Do not export to next AS (well-known community)\n"
7663 "community number\n"
7664 "Do not send outside local AS (well-known community)\n"
7665 "Do not advertise to any peer (well-known community)\n"
7666 "Do not export to next AS (well-known community)\n"
7667 "community number\n"
7668 "Do not send outside local AS (well-known community)\n"
7669 "Do not advertise to any peer (well-known community)\n"
7670 "Do not export to next AS (well-known community)\n"
7671 "community number\n"
7672 "Do not send outside local AS (well-known community)\n"
7673 "Do not advertise to any peer (well-known community)\n"
7674 "Do not export to next AS (well-known community)\n")
7675
7676 DEFUN (show_ip_bgp_ipv4_community,
7677 show_ip_bgp_ipv4_community_cmd,
7678 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7679 SHOW_STR
7680 IP_STR
7681 BGP_STR
7682 "Address family\n"
7683 "Address Family modifier\n"
7684 "Address Family modifier\n"
7685 "Display routes matching the communities\n"
7686 "community number\n"
7687 "Do not send outside local AS (well-known community)\n"
7688 "Do not advertise to any peer (well-known community)\n"
7689 "Do not export to next AS (well-known community)\n")
7690 {
7691 if (strncmp (argv[0], "m", 1) == 0)
7692 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7693
7694 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7695 }
7696
7697 ALIAS (show_ip_bgp_ipv4_community,
7698 show_ip_bgp_ipv4_community2_cmd,
7699 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7700 SHOW_STR
7701 IP_STR
7702 BGP_STR
7703 "Address family\n"
7704 "Address Family modifier\n"
7705 "Address Family modifier\n"
7706 "Display routes matching the communities\n"
7707 "community number\n"
7708 "Do not send outside local AS (well-known community)\n"
7709 "Do not advertise to any peer (well-known community)\n"
7710 "Do not export to next AS (well-known community)\n"
7711 "community number\n"
7712 "Do not send outside local AS (well-known community)\n"
7713 "Do not advertise to any peer (well-known community)\n"
7714 "Do not export to next AS (well-known community)\n")
7715
7716 ALIAS (show_ip_bgp_ipv4_community,
7717 show_ip_bgp_ipv4_community3_cmd,
7718 "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)",
7719 SHOW_STR
7720 IP_STR
7721 BGP_STR
7722 "Address family\n"
7723 "Address Family modifier\n"
7724 "Address Family modifier\n"
7725 "Display routes matching the communities\n"
7726 "community number\n"
7727 "Do not send outside local AS (well-known community)\n"
7728 "Do not advertise to any peer (well-known community)\n"
7729 "Do not export to next AS (well-known community)\n"
7730 "community number\n"
7731 "Do not send outside local AS (well-known community)\n"
7732 "Do not advertise to any peer (well-known community)\n"
7733 "Do not export to next AS (well-known community)\n"
7734 "community number\n"
7735 "Do not send outside local AS (well-known community)\n"
7736 "Do not advertise to any peer (well-known community)\n"
7737 "Do not export to next AS (well-known community)\n")
7738
7739 ALIAS (show_ip_bgp_ipv4_community,
7740 show_ip_bgp_ipv4_community4_cmd,
7741 "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)",
7742 SHOW_STR
7743 IP_STR
7744 BGP_STR
7745 "Address family\n"
7746 "Address Family modifier\n"
7747 "Address Family modifier\n"
7748 "Display routes matching the communities\n"
7749 "community number\n"
7750 "Do not send outside local AS (well-known community)\n"
7751 "Do not advertise to any peer (well-known community)\n"
7752 "Do not export to next AS (well-known community)\n"
7753 "community number\n"
7754 "Do not send outside local AS (well-known community)\n"
7755 "Do not advertise to any peer (well-known community)\n"
7756 "Do not export to next AS (well-known community)\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 "community number\n"
7762 "Do not send outside local AS (well-known community)\n"
7763 "Do not advertise to any peer (well-known community)\n"
7764 "Do not export to next AS (well-known community)\n")
7765
7766 DEFUN (show_bgp_view_afi_safi_community_all,
7767 show_bgp_view_afi_safi_community_all_cmd,
7768 #ifdef HAVE_IPV6
7769 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7770 #else
7771 "show bgp view WORD ipv4 (unicast|multicast) community",
7772 #endif
7773 SHOW_STR
7774 BGP_STR
7775 "BGP view\n"
7776 "BGP view name\n"
7777 "Address family\n"
7778 #ifdef HAVE_IPV6
7779 "Address family\n"
7780 #endif
7781 "Address Family modifier\n"
7782 "Address Family modifier\n"
7783 "Display routes containing communities\n")
7784 {
7785 int afi;
7786 int safi;
7787 struct bgp *bgp;
7788
7789 /* BGP structure lookup. */
7790 bgp = bgp_lookup_by_name (argv[0]);
7791 if (bgp == NULL)
7792 {
7793 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7794 return CMD_WARNING;
7795 }
7796
7797 #ifdef HAVE_IPV6
7798 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7799 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7800 #else
7801 afi = AFI_IP;
7802 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7803 #endif
7804 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7805 }
7806
7807 DEFUN (show_bgp_view_afi_safi_community,
7808 show_bgp_view_afi_safi_community_cmd,
7809 #ifdef HAVE_IPV6
7810 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7811 #else
7812 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7813 #endif
7814 SHOW_STR
7815 BGP_STR
7816 "BGP view\n"
7817 "BGP view name\n"
7818 "Address family\n"
7819 #ifdef HAVE_IPV6
7820 "Address family\n"
7821 #endif
7822 "Address family modifier\n"
7823 "Address family modifier\n"
7824 "Display routes matching the communities\n"
7825 "community number\n"
7826 "Do not send outside local AS (well-known community)\n"
7827 "Do not advertise to any peer (well-known community)\n"
7828 "Do not export to next AS (well-known community)\n")
7829 {
7830 int afi;
7831 int safi;
7832
7833 #ifdef HAVE_IPV6
7834 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7835 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7836 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7837 #else
7838 afi = AFI_IP;
7839 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7840 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7841 #endif
7842 }
7843
7844 ALIAS (show_bgp_view_afi_safi_community,
7845 show_bgp_view_afi_safi_community2_cmd,
7846 #ifdef HAVE_IPV6
7847 "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)",
7848 #else
7849 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7850 #endif
7851 SHOW_STR
7852 BGP_STR
7853 "BGP view\n"
7854 "BGP view name\n"
7855 "Address family\n"
7856 #ifdef HAVE_IPV6
7857 "Address family\n"
7858 #endif
7859 "Address family modifier\n"
7860 "Address family modifier\n"
7861 "Display routes matching the communities\n"
7862 "community number\n"
7863 "Do not send outside local AS (well-known community)\n"
7864 "Do not advertise to any peer (well-known community)\n"
7865 "Do not export to next AS (well-known community)\n"
7866 "community number\n"
7867 "Do not send outside local AS (well-known community)\n"
7868 "Do not advertise to any peer (well-known community)\n"
7869 "Do not export to next AS (well-known community)\n")
7870
7871 ALIAS (show_bgp_view_afi_safi_community,
7872 show_bgp_view_afi_safi_community3_cmd,
7873 #ifdef HAVE_IPV6
7874 "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)",
7875 #else
7876 "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)",
7877 #endif
7878 SHOW_STR
7879 BGP_STR
7880 "BGP view\n"
7881 "BGP view name\n"
7882 "Address family\n"
7883 #ifdef HAVE_IPV6
7884 "Address family\n"
7885 #endif
7886 "Address family modifier\n"
7887 "Address family modifier\n"
7888 "Display routes matching the communities\n"
7889 "community number\n"
7890 "Do not send outside local AS (well-known community)\n"
7891 "Do not advertise to any peer (well-known community)\n"
7892 "Do not export to next AS (well-known community)\n"
7893 "community number\n"
7894 "Do not send outside local AS (well-known community)\n"
7895 "Do not advertise to any peer (well-known community)\n"
7896 "Do not export to next AS (well-known community)\n"
7897 "community number\n"
7898 "Do not send outside local AS (well-known community)\n"
7899 "Do not advertise to any peer (well-known community)\n"
7900 "Do not export to next AS (well-known community)\n")
7901
7902 ALIAS (show_bgp_view_afi_safi_community,
7903 show_bgp_view_afi_safi_community4_cmd,
7904 #ifdef HAVE_IPV6
7905 "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)",
7906 #else
7907 "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)",
7908 #endif
7909 SHOW_STR
7910 BGP_STR
7911 "BGP view\n"
7912 "BGP view name\n"
7913 "Address family\n"
7914 #ifdef HAVE_IPV6
7915 "Address family\n"
7916 #endif
7917 "Address family modifier\n"
7918 "Address family modifier\n"
7919 "Display routes matching the communities\n"
7920 "community number\n"
7921 "Do not send outside local AS (well-known community)\n"
7922 "Do not advertise to any peer (well-known community)\n"
7923 "Do not export to next AS (well-known community)\n"
7924 "community number\n"
7925 "Do not send outside local AS (well-known community)\n"
7926 "Do not advertise to any peer (well-known community)\n"
7927 "Do not export to next AS (well-known community)\n"
7928 "community number\n"
7929 "Do not send outside local AS (well-known community)\n"
7930 "Do not advertise to any peer (well-known community)\n"
7931 "Do not export to next AS (well-known community)\n"
7932 "community number\n"
7933 "Do not send outside local AS (well-known community)\n"
7934 "Do not advertise to any peer (well-known community)\n"
7935 "Do not export to next AS (well-known community)\n")
7936
7937 DEFUN (show_ip_bgp_community_exact,
7938 show_ip_bgp_community_exact_cmd,
7939 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7940 SHOW_STR
7941 IP_STR
7942 BGP_STR
7943 "Display routes matching the communities\n"
7944 "community number\n"
7945 "Do not send outside local AS (well-known community)\n"
7946 "Do not advertise to any peer (well-known community)\n"
7947 "Do not export to next AS (well-known community)\n"
7948 "Exact match of the communities")
7949 {
7950 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7951 }
7952
7953 ALIAS (show_ip_bgp_community_exact,
7954 show_ip_bgp_community2_exact_cmd,
7955 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7956 SHOW_STR
7957 IP_STR
7958 BGP_STR
7959 "Display routes matching the communities\n"
7960 "community number\n"
7961 "Do not send outside local AS (well-known community)\n"
7962 "Do not advertise to any peer (well-known community)\n"
7963 "Do not export to next AS (well-known community)\n"
7964 "community number\n"
7965 "Do not send outside local AS (well-known community)\n"
7966 "Do not advertise to any peer (well-known community)\n"
7967 "Do not export to next AS (well-known community)\n"
7968 "Exact match of the communities")
7969
7970 ALIAS (show_ip_bgp_community_exact,
7971 show_ip_bgp_community3_exact_cmd,
7972 "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",
7973 SHOW_STR
7974 IP_STR
7975 BGP_STR
7976 "Display routes matching the communities\n"
7977 "community number\n"
7978 "Do not send outside local AS (well-known community)\n"
7979 "Do not advertise to any peer (well-known community)\n"
7980 "Do not export to next AS (well-known community)\n"
7981 "community number\n"
7982 "Do not send outside local AS (well-known community)\n"
7983 "Do not advertise to any peer (well-known community)\n"
7984 "Do not export to next AS (well-known community)\n"
7985 "community number\n"
7986 "Do not send outside local AS (well-known community)\n"
7987 "Do not advertise to any peer (well-known community)\n"
7988 "Do not export to next AS (well-known community)\n"
7989 "Exact match of the communities")
7990
7991 ALIAS (show_ip_bgp_community_exact,
7992 show_ip_bgp_community4_exact_cmd,
7993 "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",
7994 SHOW_STR
7995 IP_STR
7996 BGP_STR
7997 "Display routes matching the communities\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n"
8006 "community number\n"
8007 "Do not send outside local AS (well-known community)\n"
8008 "Do not advertise to any peer (well-known community)\n"
8009 "Do not export to next AS (well-known community)\n"
8010 "community number\n"
8011 "Do not send outside local AS (well-known community)\n"
8012 "Do not advertise to any peer (well-known community)\n"
8013 "Do not export to next AS (well-known community)\n"
8014 "Exact match of the communities")
8015
8016 DEFUN (show_ip_bgp_ipv4_community_exact,
8017 show_ip_bgp_ipv4_community_exact_cmd,
8018 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8019 SHOW_STR
8020 IP_STR
8021 BGP_STR
8022 "Address family\n"
8023 "Address Family modifier\n"
8024 "Address Family modifier\n"
8025 "Display routes matching the communities\n"
8026 "community number\n"
8027 "Do not send outside local AS (well-known community)\n"
8028 "Do not advertise to any peer (well-known community)\n"
8029 "Do not export to next AS (well-known community)\n"
8030 "Exact match of the communities")
8031 {
8032 if (strncmp (argv[0], "m", 1) == 0)
8033 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
8034
8035 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
8036 }
8037
8038 ALIAS (show_ip_bgp_ipv4_community_exact,
8039 show_ip_bgp_ipv4_community2_exact_cmd,
8040 "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",
8041 SHOW_STR
8042 IP_STR
8043 BGP_STR
8044 "Address family\n"
8045 "Address Family modifier\n"
8046 "Address Family modifier\n"
8047 "Display routes matching the communities\n"
8048 "community number\n"
8049 "Do not send outside local AS (well-known community)\n"
8050 "Do not advertise to any peer (well-known community)\n"
8051 "Do not export to next AS (well-known community)\n"
8052 "community number\n"
8053 "Do not send outside local AS (well-known community)\n"
8054 "Do not advertise to any peer (well-known community)\n"
8055 "Do not export to next AS (well-known community)\n"
8056 "Exact match of the communities")
8057
8058 ALIAS (show_ip_bgp_ipv4_community_exact,
8059 show_ip_bgp_ipv4_community3_exact_cmd,
8060 "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",
8061 SHOW_STR
8062 IP_STR
8063 BGP_STR
8064 "Address family\n"
8065 "Address Family modifier\n"
8066 "Address Family modifier\n"
8067 "Display routes matching the communities\n"
8068 "community number\n"
8069 "Do not send outside local AS (well-known community)\n"
8070 "Do not advertise to any peer (well-known community)\n"
8071 "Do not export to next AS (well-known community)\n"
8072 "community number\n"
8073 "Do not send outside local AS (well-known community)\n"
8074 "Do not advertise to any peer (well-known community)\n"
8075 "Do not export to next AS (well-known community)\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n"
8080 "Exact match of the communities")
8081
8082 ALIAS (show_ip_bgp_ipv4_community_exact,
8083 show_ip_bgp_ipv4_community4_exact_cmd,
8084 "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",
8085 SHOW_STR
8086 IP_STR
8087 BGP_STR
8088 "Address family\n"
8089 "Address Family modifier\n"
8090 "Address Family modifier\n"
8091 "Display routes matching the communities\n"
8092 "community number\n"
8093 "Do not send outside local AS (well-known community)\n"
8094 "Do not advertise to any peer (well-known community)\n"
8095 "Do not export to next AS (well-known community)\n"
8096 "community number\n"
8097 "Do not send outside local AS (well-known community)\n"
8098 "Do not advertise to any peer (well-known community)\n"
8099 "Do not export to next AS (well-known community)\n"
8100 "community number\n"
8101 "Do not send outside local AS (well-known community)\n"
8102 "Do not advertise to any peer (well-known community)\n"
8103 "Do not export to next AS (well-known community)\n"
8104 "community number\n"
8105 "Do not send outside local AS (well-known community)\n"
8106 "Do not advertise to any peer (well-known community)\n"
8107 "Do not export to next AS (well-known community)\n"
8108 "Exact match of the communities")
8109
8110 #ifdef HAVE_IPV6
8111 DEFUN (show_bgp_community,
8112 show_bgp_community_cmd,
8113 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8114 SHOW_STR
8115 BGP_STR
8116 "Display routes matching the communities\n"
8117 "community number\n"
8118 "Do not send outside local AS (well-known community)\n"
8119 "Do not advertise to any peer (well-known community)\n"
8120 "Do not export to next AS (well-known community)\n")
8121 {
8122 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8123 }
8124
8125 ALIAS (show_bgp_community,
8126 show_bgp_ipv6_community_cmd,
8127 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8128 SHOW_STR
8129 BGP_STR
8130 "Address family\n"
8131 "Display routes matching the communities\n"
8132 "community number\n"
8133 "Do not send outside local AS (well-known community)\n"
8134 "Do not advertise to any peer (well-known community)\n"
8135 "Do not export to next AS (well-known community)\n")
8136
8137 ALIAS (show_bgp_community,
8138 show_bgp_community2_cmd,
8139 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8140 SHOW_STR
8141 BGP_STR
8142 "Display routes matching the communities\n"
8143 "community number\n"
8144 "Do not send outside local AS (well-known community)\n"
8145 "Do not advertise to any peer (well-known community)\n"
8146 "Do not export to next AS (well-known community)\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
8152 ALIAS (show_bgp_community,
8153 show_bgp_ipv6_community2_cmd,
8154 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8155 SHOW_STR
8156 BGP_STR
8157 "Address family\n"
8158 "Display routes matching the communities\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 "community number\n"
8164 "Do not send outside local AS (well-known community)\n"
8165 "Do not advertise to any peer (well-known community)\n"
8166 "Do not export to next AS (well-known community)\n")
8167
8168 ALIAS (show_bgp_community,
8169 show_bgp_community3_cmd,
8170 "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)",
8171 SHOW_STR
8172 BGP_STR
8173 "Display routes matching the communities\n"
8174 "community number\n"
8175 "Do not send outside local AS (well-known community)\n"
8176 "Do not advertise to any peer (well-known community)\n"
8177 "Do not export to next AS (well-known community)\n"
8178 "community number\n"
8179 "Do not send outside local AS (well-known community)\n"
8180 "Do not advertise to any peer (well-known community)\n"
8181 "Do not export to next AS (well-known community)\n"
8182 "community number\n"
8183 "Do not send outside local AS (well-known community)\n"
8184 "Do not advertise to any peer (well-known community)\n"
8185 "Do not export to next AS (well-known community)\n")
8186
8187 ALIAS (show_bgp_community,
8188 show_bgp_ipv6_community3_cmd,
8189 "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)",
8190 SHOW_STR
8191 BGP_STR
8192 "Address family\n"
8193 "Display routes matching the communities\n"
8194 "community number\n"
8195 "Do not send outside local AS (well-known community)\n"
8196 "Do not advertise to any peer (well-known community)\n"
8197 "Do not export to next AS (well-known community)\n"
8198 "community number\n"
8199 "Do not send outside local AS (well-known community)\n"
8200 "Do not advertise to any peer (well-known community)\n"
8201 "Do not export to next AS (well-known community)\n"
8202 "community number\n"
8203 "Do not send outside local AS (well-known community)\n"
8204 "Do not advertise to any peer (well-known community)\n"
8205 "Do not export to next AS (well-known community)\n")
8206
8207 ALIAS (show_bgp_community,
8208 show_bgp_community4_cmd,
8209 "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)",
8210 SHOW_STR
8211 BGP_STR
8212 "Display routes matching the communities\n"
8213 "community number\n"
8214 "Do not send outside local AS (well-known community)\n"
8215 "Do not advertise to any peer (well-known community)\n"
8216 "Do not export to next AS (well-known community)\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
8230 ALIAS (show_bgp_community,
8231 show_bgp_ipv6_community4_cmd,
8232 "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)",
8233 SHOW_STR
8234 BGP_STR
8235 "Address family\n"
8236 "Display routes matching the communities\n"
8237 "community number\n"
8238 "Do not send outside local AS (well-known community)\n"
8239 "Do not advertise to any peer (well-known community)\n"
8240 "Do not export to next AS (well-known community)\n"
8241 "community number\n"
8242 "Do not send outside local AS (well-known community)\n"
8243 "Do not advertise to any peer (well-known community)\n"
8244 "Do not export to next AS (well-known community)\n"
8245 "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
8254 /* old command */
8255 DEFUN (show_ipv6_bgp_community,
8256 show_ipv6_bgp_community_cmd,
8257 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8258 SHOW_STR
8259 IPV6_STR
8260 BGP_STR
8261 "Display routes matching the communities\n"
8262 "community number\n"
8263 "Do not send outside local AS (well-known community)\n"
8264 "Do not advertise to any peer (well-known community)\n"
8265 "Do not export to next AS (well-known community)\n")
8266 {
8267 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8268 }
8269
8270 /* old command */
8271 ALIAS (show_ipv6_bgp_community,
8272 show_ipv6_bgp_community2_cmd,
8273 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8274 SHOW_STR
8275 IPV6_STR
8276 BGP_STR
8277 "Display routes matching the communities\n"
8278 "community number\n"
8279 "Do not send outside local AS (well-known community)\n"
8280 "Do not advertise to any peer (well-known community)\n"
8281 "Do not export to next AS (well-known community)\n"
8282 "community number\n"
8283 "Do not send outside local AS (well-known community)\n"
8284 "Do not advertise to any peer (well-known community)\n"
8285 "Do not export to next AS (well-known community)\n")
8286
8287 /* old command */
8288 ALIAS (show_ipv6_bgp_community,
8289 show_ipv6_bgp_community3_cmd,
8290 "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)",
8291 SHOW_STR
8292 IPV6_STR
8293 BGP_STR
8294 "Display routes matching the communities\n"
8295 "community number\n"
8296 "Do not send outside local AS (well-known community)\n"
8297 "Do not advertise to any peer (well-known community)\n"
8298 "Do not export to next AS (well-known community)\n"
8299 "community number\n"
8300 "Do not send outside local AS (well-known community)\n"
8301 "Do not advertise to any peer (well-known community)\n"
8302 "Do not export to next AS (well-known community)\n"
8303 "community number\n"
8304 "Do not send outside local AS (well-known community)\n"
8305 "Do not advertise to any peer (well-known community)\n"
8306 "Do not export to next AS (well-known community)\n")
8307
8308 /* old command */
8309 ALIAS (show_ipv6_bgp_community,
8310 show_ipv6_bgp_community4_cmd,
8311 "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)",
8312 SHOW_STR
8313 IPV6_STR
8314 BGP_STR
8315 "Display routes matching the communities\n"
8316 "community number\n"
8317 "Do not send outside local AS (well-known community)\n"
8318 "Do not advertise to any peer (well-known community)\n"
8319 "Do not export to next AS (well-known community)\n"
8320 "community number\n"
8321 "Do not send outside local AS (well-known community)\n"
8322 "Do not advertise to any peer (well-known community)\n"
8323 "Do not export to next AS (well-known community)\n"
8324 "community number\n"
8325 "Do not send outside local AS (well-known community)\n"
8326 "Do not advertise to any peer (well-known community)\n"
8327 "Do not export to next AS (well-known community)\n"
8328 "community number\n"
8329 "Do not send outside local AS (well-known community)\n"
8330 "Do not advertise to any peer (well-known community)\n"
8331 "Do not export to next AS (well-known community)\n")
8332
8333 DEFUN (show_bgp_community_exact,
8334 show_bgp_community_exact_cmd,
8335 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8336 SHOW_STR
8337 BGP_STR
8338 "Display routes matching the communities\n"
8339 "community number\n"
8340 "Do not send outside local AS (well-known community)\n"
8341 "Do not advertise to any peer (well-known community)\n"
8342 "Do not export to next AS (well-known community)\n"
8343 "Exact match of the communities")
8344 {
8345 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8346 }
8347
8348 ALIAS (show_bgp_community_exact,
8349 show_bgp_ipv6_community_exact_cmd,
8350 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8351 SHOW_STR
8352 BGP_STR
8353 "Address family\n"
8354 "Display routes matching the communities\n"
8355 "community number\n"
8356 "Do not send outside local AS (well-known community)\n"
8357 "Do not advertise to any peer (well-known community)\n"
8358 "Do not export to next AS (well-known community)\n"
8359 "Exact match of the communities")
8360
8361 ALIAS (show_bgp_community_exact,
8362 show_bgp_community2_exact_cmd,
8363 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8364 SHOW_STR
8365 BGP_STR
8366 "Display routes matching the communities\n"
8367 "community number\n"
8368 "Do not send outside local AS (well-known community)\n"
8369 "Do not advertise to any peer (well-known community)\n"
8370 "Do not export to next AS (well-known community)\n"
8371 "community number\n"
8372 "Do not send outside local AS (well-known community)\n"
8373 "Do not advertise to any peer (well-known community)\n"
8374 "Do not export to next AS (well-known community)\n"
8375 "Exact match of the communities")
8376
8377 ALIAS (show_bgp_community_exact,
8378 show_bgp_ipv6_community2_exact_cmd,
8379 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8380 SHOW_STR
8381 BGP_STR
8382 "Address family\n"
8383 "Display routes matching the communities\n"
8384 "community number\n"
8385 "Do not send outside local AS (well-known community)\n"
8386 "Do not advertise to any peer (well-known community)\n"
8387 "Do not export to next AS (well-known community)\n"
8388 "community number\n"
8389 "Do not send outside local AS (well-known community)\n"
8390 "Do not advertise to any peer (well-known community)\n"
8391 "Do not export to next AS (well-known community)\n"
8392 "Exact match of the communities")
8393
8394 ALIAS (show_bgp_community_exact,
8395 show_bgp_community3_exact_cmd,
8396 "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",
8397 SHOW_STR
8398 BGP_STR
8399 "Display routes matching the communities\n"
8400 "community number\n"
8401 "Do not send outside local AS (well-known community)\n"
8402 "Do not advertise to any peer (well-known community)\n"
8403 "Do not export to next AS (well-known community)\n"
8404 "community number\n"
8405 "Do not send outside local AS (well-known community)\n"
8406 "Do not advertise to any peer (well-known community)\n"
8407 "Do not export to next AS (well-known community)\n"
8408 "community number\n"
8409 "Do not send outside local AS (well-known community)\n"
8410 "Do not advertise to any peer (well-known community)\n"
8411 "Do not export to next AS (well-known community)\n"
8412 "Exact match of the communities")
8413
8414 ALIAS (show_bgp_community_exact,
8415 show_bgp_ipv6_community3_exact_cmd,
8416 "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",
8417 SHOW_STR
8418 BGP_STR
8419 "Address family\n"
8420 "Display routes matching the communities\n"
8421 "community number\n"
8422 "Do not send outside local AS (well-known community)\n"
8423 "Do not advertise to any peer (well-known community)\n"
8424 "Do not export to next AS (well-known community)\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n"
8433 "Exact match of the communities")
8434
8435 ALIAS (show_bgp_community_exact,
8436 show_bgp_community4_exact_cmd,
8437 "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",
8438 SHOW_STR
8439 BGP_STR
8440 "Display routes matching the communities\n"
8441 "community number\n"
8442 "Do not send outside local AS (well-known community)\n"
8443 "Do not advertise to any peer (well-known community)\n"
8444 "Do not export to next AS (well-known community)\n"
8445 "community number\n"
8446 "Do not send outside local AS (well-known community)\n"
8447 "Do not advertise to any peer (well-known community)\n"
8448 "Do not export to next AS (well-known community)\n"
8449 "community number\n"
8450 "Do not send outside local AS (well-known community)\n"
8451 "Do not advertise to any peer (well-known community)\n"
8452 "Do not export to next AS (well-known community)\n"
8453 "community number\n"
8454 "Do not send outside local AS (well-known community)\n"
8455 "Do not advertise to any peer (well-known community)\n"
8456 "Do not export to next AS (well-known community)\n"
8457 "Exact match of the communities")
8458
8459 ALIAS (show_bgp_community_exact,
8460 show_bgp_ipv6_community4_exact_cmd,
8461 "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",
8462 SHOW_STR
8463 BGP_STR
8464 "Address family\n"
8465 "Display routes matching the communities\n"
8466 "community number\n"
8467 "Do not send outside local AS (well-known community)\n"
8468 "Do not advertise to any peer (well-known community)\n"
8469 "Do not export to next AS (well-known community)\n"
8470 "community number\n"
8471 "Do not send outside local AS (well-known community)\n"
8472 "Do not advertise to any peer (well-known community)\n"
8473 "Do not export to next AS (well-known community)\n"
8474 "community number\n"
8475 "Do not send outside local AS (well-known community)\n"
8476 "Do not advertise to any peer (well-known community)\n"
8477 "Do not export to next AS (well-known community)\n"
8478 "community number\n"
8479 "Do not send outside local AS (well-known community)\n"
8480 "Do not advertise to any peer (well-known community)\n"
8481 "Do not export to next AS (well-known community)\n"
8482 "Exact match of the communities")
8483
8484 /* old command */
8485 DEFUN (show_ipv6_bgp_community_exact,
8486 show_ipv6_bgp_community_exact_cmd,
8487 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8488 SHOW_STR
8489 IPV6_STR
8490 BGP_STR
8491 "Display routes matching the communities\n"
8492 "community number\n"
8493 "Do not send outside local AS (well-known community)\n"
8494 "Do not advertise to any peer (well-known community)\n"
8495 "Do not export to next AS (well-known community)\n"
8496 "Exact match of the communities")
8497 {
8498 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8499 }
8500
8501 /* old command */
8502 ALIAS (show_ipv6_bgp_community_exact,
8503 show_ipv6_bgp_community2_exact_cmd,
8504 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8505 SHOW_STR
8506 IPV6_STR
8507 BGP_STR
8508 "Display routes matching the communities\n"
8509 "community number\n"
8510 "Do not send outside local AS (well-known community)\n"
8511 "Do not advertise to any peer (well-known community)\n"
8512 "Do not export to next AS (well-known community)\n"
8513 "community number\n"
8514 "Do not send outside local AS (well-known community)\n"
8515 "Do not advertise to any peer (well-known community)\n"
8516 "Do not export to next AS (well-known community)\n"
8517 "Exact match of the communities")
8518
8519 /* old command */
8520 ALIAS (show_ipv6_bgp_community_exact,
8521 show_ipv6_bgp_community3_exact_cmd,
8522 "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",
8523 SHOW_STR
8524 IPV6_STR
8525 BGP_STR
8526 "Display routes matching the communities\n"
8527 "community number\n"
8528 "Do not send outside local AS (well-known community)\n"
8529 "Do not advertise to any peer (well-known community)\n"
8530 "Do not export to next AS (well-known community)\n"
8531 "community number\n"
8532 "Do not send outside local AS (well-known community)\n"
8533 "Do not advertise to any peer (well-known community)\n"
8534 "Do not export to next AS (well-known community)\n"
8535 "community number\n"
8536 "Do not send outside local AS (well-known community)\n"
8537 "Do not advertise to any peer (well-known community)\n"
8538 "Do not export to next AS (well-known community)\n"
8539 "Exact match of the communities")
8540
8541 /* old command */
8542 ALIAS (show_ipv6_bgp_community_exact,
8543 show_ipv6_bgp_community4_exact_cmd,
8544 "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",
8545 SHOW_STR
8546 IPV6_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 "community number\n"
8562 "Do not send outside local AS (well-known community)\n"
8563 "Do not advertise to any peer (well-known community)\n"
8564 "Do not export to next AS (well-known community)\n"
8565 "Exact match of the communities")
8566
8567 /* old command */
8568 DEFUN (show_ipv6_mbgp_community,
8569 show_ipv6_mbgp_community_cmd,
8570 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8571 SHOW_STR
8572 IPV6_STR
8573 MBGP_STR
8574 "Display routes matching the communities\n"
8575 "community number\n"
8576 "Do not send outside local AS (well-known community)\n"
8577 "Do not advertise to any peer (well-known community)\n"
8578 "Do not export to next AS (well-known community)\n")
8579 {
8580 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8581 }
8582
8583 /* old command */
8584 ALIAS (show_ipv6_mbgp_community,
8585 show_ipv6_mbgp_community2_cmd,
8586 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8587 SHOW_STR
8588 IPV6_STR
8589 MBGP_STR
8590 "Display routes matching the communities\n"
8591 "community number\n"
8592 "Do not send outside local AS (well-known community)\n"
8593 "Do not advertise to any peer (well-known community)\n"
8594 "Do not export to next AS (well-known community)\n"
8595 "community number\n"
8596 "Do not send outside local AS (well-known community)\n"
8597 "Do not advertise to any peer (well-known community)\n"
8598 "Do not export to next AS (well-known community)\n")
8599
8600 /* old command */
8601 ALIAS (show_ipv6_mbgp_community,
8602 show_ipv6_mbgp_community3_cmd,
8603 "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)",
8604 SHOW_STR
8605 IPV6_STR
8606 MBGP_STR
8607 "Display routes matching the communities\n"
8608 "community number\n"
8609 "Do not send outside local AS (well-known community)\n"
8610 "Do not advertise to any peer (well-known community)\n"
8611 "Do not export to next AS (well-known community)\n"
8612 "community number\n"
8613 "Do not send outside local AS (well-known community)\n"
8614 "Do not advertise to any peer (well-known community)\n"
8615 "Do not export to next AS (well-known community)\n"
8616 "community number\n"
8617 "Do not send outside local AS (well-known community)\n"
8618 "Do not advertise to any peer (well-known community)\n"
8619 "Do not export to next AS (well-known community)\n")
8620
8621 /* old command */
8622 ALIAS (show_ipv6_mbgp_community,
8623 show_ipv6_mbgp_community4_cmd,
8624 "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)",
8625 SHOW_STR
8626 IPV6_STR
8627 MBGP_STR
8628 "Display routes matching the communities\n"
8629 "community number\n"
8630 "Do not send outside local AS (well-known community)\n"
8631 "Do not advertise to any peer (well-known community)\n"
8632 "Do not export to next AS (well-known community)\n"
8633 "community number\n"
8634 "Do not send outside local AS (well-known community)\n"
8635 "Do not advertise to any peer (well-known community)\n"
8636 "Do not export to next AS (well-known community)\n"
8637 "community number\n"
8638 "Do not send outside local AS (well-known community)\n"
8639 "Do not advertise to any peer (well-known community)\n"
8640 "Do not export to next AS (well-known community)\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
8646 /* old command */
8647 DEFUN (show_ipv6_mbgp_community_exact,
8648 show_ipv6_mbgp_community_exact_cmd,
8649 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8650 SHOW_STR
8651 IPV6_STR
8652 MBGP_STR
8653 "Display routes matching the communities\n"
8654 "community number\n"
8655 "Do not send outside local AS (well-known community)\n"
8656 "Do not advertise to any peer (well-known community)\n"
8657 "Do not export to next AS (well-known community)\n"
8658 "Exact match of the communities")
8659 {
8660 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8661 }
8662
8663 /* old command */
8664 ALIAS (show_ipv6_mbgp_community_exact,
8665 show_ipv6_mbgp_community2_exact_cmd,
8666 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8667 SHOW_STR
8668 IPV6_STR
8669 MBGP_STR
8670 "Display routes matching the communities\n"
8671 "community number\n"
8672 "Do not send outside local AS (well-known community)\n"
8673 "Do not advertise to any peer (well-known community)\n"
8674 "Do not export to next AS (well-known community)\n"
8675 "community number\n"
8676 "Do not send outside local AS (well-known community)\n"
8677 "Do not advertise to any peer (well-known community)\n"
8678 "Do not export to next AS (well-known community)\n"
8679 "Exact match of the communities")
8680
8681 /* old command */
8682 ALIAS (show_ipv6_mbgp_community_exact,
8683 show_ipv6_mbgp_community3_exact_cmd,
8684 "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",
8685 SHOW_STR
8686 IPV6_STR
8687 MBGP_STR
8688 "Display routes matching the communities\n"
8689 "community number\n"
8690 "Do not send outside local AS (well-known community)\n"
8691 "Do not advertise to any peer (well-known community)\n"
8692 "Do not export to next AS (well-known community)\n"
8693 "community number\n"
8694 "Do not send outside local AS (well-known community)\n"
8695 "Do not advertise to any peer (well-known community)\n"
8696 "Do not export to next AS (well-known community)\n"
8697 "community number\n"
8698 "Do not send outside local AS (well-known community)\n"
8699 "Do not advertise to any peer (well-known community)\n"
8700 "Do not export to next AS (well-known community)\n"
8701 "Exact match of the communities")
8702
8703 /* old command */
8704 ALIAS (show_ipv6_mbgp_community_exact,
8705 show_ipv6_mbgp_community4_exact_cmd,
8706 "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",
8707 SHOW_STR
8708 IPV6_STR
8709 MBGP_STR
8710 "Display routes matching the communities\n"
8711 "community number\n"
8712 "Do not send outside local AS (well-known community)\n"
8713 "Do not advertise to any peer (well-known community)\n"
8714 "Do not export to next AS (well-known community)\n"
8715 "community number\n"
8716 "Do not send outside local AS (well-known community)\n"
8717 "Do not advertise to any peer (well-known community)\n"
8718 "Do not export to next AS (well-known community)\n"
8719 "community number\n"
8720 "Do not send outside local AS (well-known community)\n"
8721 "Do not advertise to any peer (well-known community)\n"
8722 "Do not export to next AS (well-known community)\n"
8723 "community number\n"
8724 "Do not send outside local AS (well-known community)\n"
8725 "Do not advertise to any peer (well-known community)\n"
8726 "Do not export to next AS (well-known community)\n"
8727 "Exact match of the communities")
8728 #endif /* HAVE_IPV6 */
8729 \f
8730 static int
8731 bgp_show_community_list (struct vty *vty, const char *com, int exact,
8732 afi_t afi, safi_t safi)
8733 {
8734 struct community_list *list;
8735
8736 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
8737 if (list == NULL)
8738 {
8739 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8740 VTY_NEWLINE);
8741 return CMD_WARNING;
8742 }
8743
8744 return bgp_show (vty, NULL, afi, safi,
8745 (exact ? bgp_show_type_community_list_exact :
8746 bgp_show_type_community_list), list);
8747 }
8748
8749 DEFUN (show_ip_bgp_community_list,
8750 show_ip_bgp_community_list_cmd,
8751 "show ip bgp community-list (<1-500>|WORD)",
8752 SHOW_STR
8753 IP_STR
8754 BGP_STR
8755 "Display routes matching the community-list\n"
8756 "community-list number\n"
8757 "community-list name\n")
8758 {
8759 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8760 }
8761
8762 DEFUN (show_ip_bgp_ipv4_community_list,
8763 show_ip_bgp_ipv4_community_list_cmd,
8764 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
8765 SHOW_STR
8766 IP_STR
8767 BGP_STR
8768 "Address family\n"
8769 "Address Family modifier\n"
8770 "Address Family modifier\n"
8771 "Display routes matching the community-list\n"
8772 "community-list number\n"
8773 "community-list name\n")
8774 {
8775 if (strncmp (argv[0], "m", 1) == 0)
8776 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8777
8778 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8779 }
8780
8781 DEFUN (show_ip_bgp_community_list_exact,
8782 show_ip_bgp_community_list_exact_cmd,
8783 "show ip bgp community-list (<1-500>|WORD) exact-match",
8784 SHOW_STR
8785 IP_STR
8786 BGP_STR
8787 "Display routes matching the community-list\n"
8788 "community-list number\n"
8789 "community-list name\n"
8790 "Exact match of the communities\n")
8791 {
8792 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8793 }
8794
8795 DEFUN (show_ip_bgp_ipv4_community_list_exact,
8796 show_ip_bgp_ipv4_community_list_exact_cmd,
8797 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
8798 SHOW_STR
8799 IP_STR
8800 BGP_STR
8801 "Address family\n"
8802 "Address Family modifier\n"
8803 "Address Family modifier\n"
8804 "Display routes matching the community-list\n"
8805 "community-list number\n"
8806 "community-list name\n"
8807 "Exact match of the communities\n")
8808 {
8809 if (strncmp (argv[0], "m", 1) == 0)
8810 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8811
8812 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8813 }
8814
8815 #ifdef HAVE_IPV6
8816 DEFUN (show_bgp_community_list,
8817 show_bgp_community_list_cmd,
8818 "show bgp community-list (<1-500>|WORD)",
8819 SHOW_STR
8820 BGP_STR
8821 "Display routes matching the community-list\n"
8822 "community-list number\n"
8823 "community-list name\n")
8824 {
8825 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8826 }
8827
8828 ALIAS (show_bgp_community_list,
8829 show_bgp_ipv6_community_list_cmd,
8830 "show bgp ipv6 community-list (<1-500>|WORD)",
8831 SHOW_STR
8832 BGP_STR
8833 "Address family\n"
8834 "Display routes matching the community-list\n"
8835 "community-list number\n"
8836 "community-list name\n")
8837
8838 /* old command */
8839 DEFUN (show_ipv6_bgp_community_list,
8840 show_ipv6_bgp_community_list_cmd,
8841 "show ipv6 bgp community-list WORD",
8842 SHOW_STR
8843 IPV6_STR
8844 BGP_STR
8845 "Display routes matching the community-list\n"
8846 "community-list name\n")
8847 {
8848 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8849 }
8850
8851 /* old command */
8852 DEFUN (show_ipv6_mbgp_community_list,
8853 show_ipv6_mbgp_community_list_cmd,
8854 "show ipv6 mbgp community-list WORD",
8855 SHOW_STR
8856 IPV6_STR
8857 MBGP_STR
8858 "Display routes matching the community-list\n"
8859 "community-list name\n")
8860 {
8861 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8862 }
8863
8864 DEFUN (show_bgp_community_list_exact,
8865 show_bgp_community_list_exact_cmd,
8866 "show bgp community-list (<1-500>|WORD) exact-match",
8867 SHOW_STR
8868 BGP_STR
8869 "Display routes matching the community-list\n"
8870 "community-list number\n"
8871 "community-list name\n"
8872 "Exact match of the communities\n")
8873 {
8874 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8875 }
8876
8877 ALIAS (show_bgp_community_list_exact,
8878 show_bgp_ipv6_community_list_exact_cmd,
8879 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
8880 SHOW_STR
8881 BGP_STR
8882 "Address family\n"
8883 "Display routes matching the community-list\n"
8884 "community-list number\n"
8885 "community-list name\n"
8886 "Exact match of the communities\n")
8887
8888 /* old command */
8889 DEFUN (show_ipv6_bgp_community_list_exact,
8890 show_ipv6_bgp_community_list_exact_cmd,
8891 "show ipv6 bgp community-list WORD exact-match",
8892 SHOW_STR
8893 IPV6_STR
8894 BGP_STR
8895 "Display routes matching the community-list\n"
8896 "community-list name\n"
8897 "Exact match of the communities\n")
8898 {
8899 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8900 }
8901
8902 /* old command */
8903 DEFUN (show_ipv6_mbgp_community_list_exact,
8904 show_ipv6_mbgp_community_list_exact_cmd,
8905 "show ipv6 mbgp community-list WORD exact-match",
8906 SHOW_STR
8907 IPV6_STR
8908 MBGP_STR
8909 "Display routes matching the community-list\n"
8910 "community-list name\n"
8911 "Exact match of the communities\n")
8912 {
8913 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8914 }
8915 #endif /* HAVE_IPV6 */
8916 \f
8917 static int
8918 bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
8919 safi_t safi, enum bgp_show_type type)
8920 {
8921 int ret;
8922 struct prefix *p;
8923
8924 p = prefix_new();
8925
8926 ret = str2prefix (prefix, p);
8927 if (! ret)
8928 {
8929 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8930 return CMD_WARNING;
8931 }
8932
8933 ret = bgp_show (vty, NULL, afi, safi, type, p);
8934 prefix_free(p);
8935 return ret;
8936 }
8937
8938 DEFUN (show_ip_bgp_prefix_longer,
8939 show_ip_bgp_prefix_longer_cmd,
8940 "show ip bgp A.B.C.D/M longer-prefixes",
8941 SHOW_STR
8942 IP_STR
8943 BGP_STR
8944 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8945 "Display route and more specific routes\n")
8946 {
8947 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8948 bgp_show_type_prefix_longer);
8949 }
8950
8951 DEFUN (show_ip_bgp_flap_prefix_longer,
8952 show_ip_bgp_flap_prefix_longer_cmd,
8953 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8954 SHOW_STR
8955 IP_STR
8956 BGP_STR
8957 "Display flap statistics of routes\n"
8958 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8959 "Display route and more specific routes\n")
8960 {
8961 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8962 bgp_show_type_flap_prefix_longer);
8963 }
8964
8965 DEFUN (show_ip_bgp_ipv4_prefix_longer,
8966 show_ip_bgp_ipv4_prefix_longer_cmd,
8967 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8968 SHOW_STR
8969 IP_STR
8970 BGP_STR
8971 "Address family\n"
8972 "Address Family modifier\n"
8973 "Address Family modifier\n"
8974 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8975 "Display route and more specific routes\n")
8976 {
8977 if (strncmp (argv[0], "m", 1) == 0)
8978 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8979 bgp_show_type_prefix_longer);
8980
8981 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8982 bgp_show_type_prefix_longer);
8983 }
8984
8985 DEFUN (show_ip_bgp_flap_address,
8986 show_ip_bgp_flap_address_cmd,
8987 "show ip bgp flap-statistics A.B.C.D",
8988 SHOW_STR
8989 IP_STR
8990 BGP_STR
8991 "Display flap statistics of routes\n"
8992 "Network in the BGP routing table to display\n")
8993 {
8994 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8995 bgp_show_type_flap_address);
8996 }
8997
8998 DEFUN (show_ip_bgp_flap_prefix,
8999 show_ip_bgp_flap_prefix_cmd,
9000 "show ip bgp flap-statistics A.B.C.D/M",
9001 SHOW_STR
9002 IP_STR
9003 BGP_STR
9004 "Display flap statistics of routes\n"
9005 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9006 {
9007 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9008 bgp_show_type_flap_prefix);
9009 }
9010 #ifdef HAVE_IPV6
9011 DEFUN (show_bgp_prefix_longer,
9012 show_bgp_prefix_longer_cmd,
9013 "show bgp X:X::X:X/M longer-prefixes",
9014 SHOW_STR
9015 BGP_STR
9016 "IPv6 prefix <network>/<length>\n"
9017 "Display route and more specific routes\n")
9018 {
9019 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9020 bgp_show_type_prefix_longer);
9021 }
9022
9023 ALIAS (show_bgp_prefix_longer,
9024 show_bgp_ipv6_prefix_longer_cmd,
9025 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9026 SHOW_STR
9027 BGP_STR
9028 "Address family\n"
9029 "IPv6 prefix <network>/<length>\n"
9030 "Display route and more specific routes\n")
9031
9032 /* old command */
9033 DEFUN (show_ipv6_bgp_prefix_longer,
9034 show_ipv6_bgp_prefix_longer_cmd,
9035 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9036 SHOW_STR
9037 IPV6_STR
9038 BGP_STR
9039 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9040 "Display route and more specific routes\n")
9041 {
9042 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9043 bgp_show_type_prefix_longer);
9044 }
9045
9046 /* old command */
9047 DEFUN (show_ipv6_mbgp_prefix_longer,
9048 show_ipv6_mbgp_prefix_longer_cmd,
9049 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9050 SHOW_STR
9051 IPV6_STR
9052 MBGP_STR
9053 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9054 "Display route and more specific routes\n")
9055 {
9056 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9057 bgp_show_type_prefix_longer);
9058 }
9059 #endif /* HAVE_IPV6 */
9060
9061 static struct peer *
9062 peer_lookup_in_view (struct vty *vty, const char *view_name,
9063 const char *ip_str)
9064 {
9065 int ret;
9066 struct bgp *bgp;
9067 struct peer *peer;
9068 union sockunion su;
9069
9070 /* BGP structure lookup. */
9071 if (view_name)
9072 {
9073 bgp = bgp_lookup_by_name (view_name);
9074 if (! bgp)
9075 {
9076 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9077 return NULL;
9078 }
9079 }
9080 else
9081 {
9082 bgp = bgp_get_default ();
9083 if (! bgp)
9084 {
9085 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9086 return NULL;
9087 }
9088 }
9089
9090 /* Get peer sockunion. */
9091 ret = str2sockunion (ip_str, &su);
9092 if (ret < 0)
9093 {
9094 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9095 return NULL;
9096 }
9097
9098 /* Peer structure lookup. */
9099 peer = peer_lookup (bgp, &su);
9100 if (! peer)
9101 {
9102 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9103 return NULL;
9104 }
9105
9106 return peer;
9107 }
9108 \f
9109 enum bgp_stats
9110 {
9111 BGP_STATS_MAXBITLEN = 0,
9112 BGP_STATS_RIB,
9113 BGP_STATS_PREFIXES,
9114 BGP_STATS_TOTPLEN,
9115 BGP_STATS_UNAGGREGATEABLE,
9116 BGP_STATS_MAX_AGGREGATEABLE,
9117 BGP_STATS_AGGREGATES,
9118 BGP_STATS_SPACE,
9119 BGP_STATS_ASPATH_COUNT,
9120 BGP_STATS_ASPATH_MAXHOPS,
9121 BGP_STATS_ASPATH_TOTHOPS,
9122 BGP_STATS_ASPATH_MAXSIZE,
9123 BGP_STATS_ASPATH_TOTSIZE,
9124 BGP_STATS_ASN_HIGHEST,
9125 BGP_STATS_MAX,
9126 };
9127
9128 static const char *table_stats_strs[] =
9129 {
9130 [BGP_STATS_PREFIXES] = "Total Prefixes",
9131 [BGP_STATS_TOTPLEN] = "Average prefix length",
9132 [BGP_STATS_RIB] = "Total Advertisements",
9133 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9134 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9135 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9136 [BGP_STATS_SPACE] = "Address space advertised",
9137 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9138 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9139 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9140 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9141 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9142 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9143 [BGP_STATS_MAX] = NULL,
9144 };
9145
9146 struct bgp_table_stats
9147 {
9148 struct bgp_table *table;
9149 unsigned long long counts[BGP_STATS_MAX];
9150 };
9151
9152 #if 0
9153 #define TALLY_SIGFIG 100000
9154 static unsigned long
9155 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9156 {
9157 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9158 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9159 unsigned long ret = newtot / count;
9160
9161 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9162 return ret + 1;
9163 else
9164 return ret;
9165 }
9166 #endif
9167
9168 static int
9169 bgp_table_stats_walker (struct thread *t)
9170 {
9171 struct bgp_node *rn;
9172 struct bgp_node *top;
9173 struct bgp_table_stats *ts = THREAD_ARG (t);
9174 unsigned int space = 0;
9175
9176 if (!(top = bgp_table_top (ts->table)))
9177 return 0;
9178
9179 switch (top->p.family)
9180 {
9181 case AF_INET:
9182 space = IPV4_MAX_BITLEN;
9183 break;
9184 case AF_INET6:
9185 space = IPV6_MAX_BITLEN;
9186 break;
9187 }
9188
9189 ts->counts[BGP_STATS_MAXBITLEN] = space;
9190
9191 for (rn = top; rn; rn = bgp_route_next (rn))
9192 {
9193 struct bgp_info *ri;
9194 struct bgp_node *prn = rn->parent;
9195 unsigned int rinum = 0;
9196
9197 if (rn == top)
9198 continue;
9199
9200 if (!rn->info)
9201 continue;
9202
9203 ts->counts[BGP_STATS_PREFIXES]++;
9204 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9205
9206 #if 0
9207 ts->counts[BGP_STATS_AVGPLEN]
9208 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9209 ts->counts[BGP_STATS_AVGPLEN],
9210 rn->p.prefixlen);
9211 #endif
9212
9213 /* check if the prefix is included by any other announcements */
9214 while (prn && !prn->info)
9215 prn = prn->parent;
9216
9217 if (prn == NULL || prn == top)
9218 {
9219 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9220 /* announced address space */
9221 if (space)
9222 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9223 }
9224 else if (prn->info)
9225 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9226
9227 for (ri = rn->info; ri; ri = ri->next)
9228 {
9229 rinum++;
9230 ts->counts[BGP_STATS_RIB]++;
9231
9232 if (ri->attr &&
9233 (CHECK_FLAG (ri->attr->flag,
9234 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9235 ts->counts[BGP_STATS_AGGREGATES]++;
9236
9237 /* as-path stats */
9238 if (ri->attr && ri->attr->aspath)
9239 {
9240 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9241 unsigned int size = aspath_size (ri->attr->aspath);
9242 as_t highest = aspath_highest (ri->attr->aspath);
9243
9244 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9245
9246 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9247 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9248
9249 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9250 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9251
9252 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9253 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9254 #if 0
9255 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9256 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9257 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9258 hops);
9259 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9260 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9261 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9262 size);
9263 #endif
9264 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9265 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9266 }
9267 }
9268 }
9269 return 0;
9270 }
9271
9272 static int
9273 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9274 {
9275 struct bgp_table_stats ts;
9276 unsigned int i;
9277
9278 if (!bgp->rib[afi][safi])
9279 {
9280 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9281 return CMD_WARNING;
9282 }
9283
9284 memset (&ts, 0, sizeof (ts));
9285 ts.table = bgp->rib[afi][safi];
9286 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9287
9288 vty_out (vty, "BGP %s RIB statistics%s%s",
9289 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9290
9291 for (i = 0; i < BGP_STATS_MAX; i++)
9292 {
9293 if (!table_stats_strs[i])
9294 continue;
9295
9296 switch (i)
9297 {
9298 #if 0
9299 case BGP_STATS_ASPATH_AVGHOPS:
9300 case BGP_STATS_ASPATH_AVGSIZE:
9301 case BGP_STATS_AVGPLEN:
9302 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9303 vty_out (vty, "%12.2f",
9304 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9305 break;
9306 #endif
9307 case BGP_STATS_ASPATH_TOTHOPS:
9308 case BGP_STATS_ASPATH_TOTSIZE:
9309 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9310 vty_out (vty, "%12.2f",
9311 ts.counts[i] ?
9312 (float)ts.counts[i] /
9313 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9314 : 0);
9315 break;
9316 case BGP_STATS_TOTPLEN:
9317 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9318 vty_out (vty, "%12.2f",
9319 ts.counts[i] ?
9320 (float)ts.counts[i] /
9321 (float)ts.counts[BGP_STATS_PREFIXES]
9322 : 0);
9323 break;
9324 case BGP_STATS_SPACE:
9325 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9326 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9327 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9328 break;
9329 vty_out (vty, "%30s: ", "%% announced ");
9330 vty_out (vty, "%12.2f%s",
9331 100 * (float)ts.counts[BGP_STATS_SPACE] /
9332 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
9333 VTY_NEWLINE);
9334 vty_out (vty, "%30s: ", "/8 equivalent ");
9335 vty_out (vty, "%12.2f%s",
9336 (float)ts.counts[BGP_STATS_SPACE] /
9337 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9338 VTY_NEWLINE);
9339 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9340 break;
9341 vty_out (vty, "%30s: ", "/24 equivalent ");
9342 vty_out (vty, "%12.2f",
9343 (float)ts.counts[BGP_STATS_SPACE] /
9344 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9345 break;
9346 default:
9347 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9348 vty_out (vty, "%12llu", ts.counts[i]);
9349 }
9350
9351 vty_out (vty, "%s", VTY_NEWLINE);
9352 }
9353 return CMD_SUCCESS;
9354 }
9355
9356 static int
9357 bgp_table_stats_vty (struct vty *vty, const char *name,
9358 const char *afi_str, const char *safi_str)
9359 {
9360 struct bgp *bgp;
9361 afi_t afi;
9362 safi_t safi;
9363
9364 if (name)
9365 bgp = bgp_lookup_by_name (name);
9366 else
9367 bgp = bgp_get_default ();
9368
9369 if (!bgp)
9370 {
9371 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9372 return CMD_WARNING;
9373 }
9374 if (strncmp (afi_str, "ipv", 3) == 0)
9375 {
9376 if (strncmp (afi_str, "ipv4", 4) == 0)
9377 afi = AFI_IP;
9378 else if (strncmp (afi_str, "ipv6", 4) == 0)
9379 afi = AFI_IP6;
9380 else
9381 {
9382 vty_out (vty, "%% Invalid address family %s%s",
9383 afi_str, VTY_NEWLINE);
9384 return CMD_WARNING;
9385 }
9386 if (strncmp (safi_str, "m", 1) == 0)
9387 safi = SAFI_MULTICAST;
9388 else if (strncmp (safi_str, "u", 1) == 0)
9389 safi = SAFI_UNICAST;
9390 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9391 safi = SAFI_MPLS_LABELED_VPN;
9392 else
9393 {
9394 vty_out (vty, "%% Invalid subsequent address family %s%s",
9395 safi_str, VTY_NEWLINE);
9396 return CMD_WARNING;
9397 }
9398 }
9399 else
9400 {
9401 vty_out (vty, "%% Invalid address family %s%s",
9402 afi_str, VTY_NEWLINE);
9403 return CMD_WARNING;
9404 }
9405
9406 return bgp_table_stats (vty, bgp, afi, safi);
9407 }
9408
9409 DEFUN (show_bgp_statistics,
9410 show_bgp_statistics_cmd,
9411 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9412 SHOW_STR
9413 BGP_STR
9414 "Address family\n"
9415 "Address family\n"
9416 "Address Family modifier\n"
9417 "Address Family modifier\n"
9418 "BGP RIB advertisement statistics\n")
9419 {
9420 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9421 }
9422
9423 ALIAS (show_bgp_statistics,
9424 show_bgp_statistics_vpnv4_cmd,
9425 "show bgp (ipv4) (vpnv4) statistics",
9426 SHOW_STR
9427 BGP_STR
9428 "Address family\n"
9429 "Address Family modifier\n"
9430 "BGP RIB advertisement statistics\n")
9431
9432 DEFUN (show_bgp_statistics_view,
9433 show_bgp_statistics_view_cmd,
9434 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9435 SHOW_STR
9436 BGP_STR
9437 "BGP view\n"
9438 "Address family\n"
9439 "Address family\n"
9440 "Address Family modifier\n"
9441 "Address Family modifier\n"
9442 "BGP RIB advertisement statistics\n")
9443 {
9444 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9445 }
9446
9447 ALIAS (show_bgp_statistics_view,
9448 show_bgp_statistics_view_vpnv4_cmd,
9449 "show bgp view WORD (ipv4) (vpnv4) statistics",
9450 SHOW_STR
9451 BGP_STR
9452 "BGP view\n"
9453 "Address family\n"
9454 "Address Family modifier\n"
9455 "BGP RIB advertisement statistics\n")
9456 \f
9457 enum bgp_pcounts
9458 {
9459 PCOUNT_ADJ_IN = 0,
9460 PCOUNT_DAMPED,
9461 PCOUNT_REMOVED,
9462 PCOUNT_HISTORY,
9463 PCOUNT_STALE,
9464 PCOUNT_VALID,
9465 PCOUNT_ALL,
9466 PCOUNT_COUNTED,
9467 PCOUNT_PFCNT, /* the figure we display to users */
9468 PCOUNT_MAX,
9469 };
9470
9471 static const char *pcount_strs[] =
9472 {
9473 [PCOUNT_ADJ_IN] = "Adj-in",
9474 [PCOUNT_DAMPED] = "Damped",
9475 [PCOUNT_REMOVED] = "Removed",
9476 [PCOUNT_HISTORY] = "History",
9477 [PCOUNT_STALE] = "Stale",
9478 [PCOUNT_VALID] = "Valid",
9479 [PCOUNT_ALL] = "All RIB",
9480 [PCOUNT_COUNTED] = "PfxCt counted",
9481 [PCOUNT_PFCNT] = "Useable",
9482 [PCOUNT_MAX] = NULL,
9483 };
9484
9485 struct peer_pcounts
9486 {
9487 unsigned int count[PCOUNT_MAX];
9488 const struct peer *peer;
9489 const struct bgp_table *table;
9490 };
9491
9492 static int
9493 bgp_peer_count_walker (struct thread *t)
9494 {
9495 struct bgp_node *rn;
9496 struct peer_pcounts *pc = THREAD_ARG (t);
9497 const struct peer *peer = pc->peer;
9498
9499 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
9500 {
9501 struct bgp_adj_in *ain;
9502 struct bgp_info *ri;
9503
9504 for (ain = rn->adj_in; ain; ain = ain->next)
9505 if (ain->peer == peer)
9506 pc->count[PCOUNT_ADJ_IN]++;
9507
9508 for (ri = rn->info; ri; ri = ri->next)
9509 {
9510 char buf[SU_ADDRSTRLEN];
9511
9512 if (ri->peer != peer)
9513 continue;
9514
9515 pc->count[PCOUNT_ALL]++;
9516
9517 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
9518 pc->count[PCOUNT_DAMPED]++;
9519 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
9520 pc->count[PCOUNT_HISTORY]++;
9521 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
9522 pc->count[PCOUNT_REMOVED]++;
9523 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
9524 pc->count[PCOUNT_STALE]++;
9525 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
9526 pc->count[PCOUNT_VALID]++;
9527 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
9528 pc->count[PCOUNT_PFCNT]++;
9529
9530 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9531 {
9532 pc->count[PCOUNT_COUNTED]++;
9533 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
9534 plog_warn (peer->log,
9535 "%s [pcount] %s/%d is counted but flags 0x%x",
9536 peer->host,
9537 inet_ntop(rn->p.family, &rn->p.u.prefix,
9538 buf, SU_ADDRSTRLEN),
9539 rn->p.prefixlen,
9540 ri->flags);
9541 }
9542 else
9543 {
9544 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
9545 plog_warn (peer->log,
9546 "%s [pcount] %s/%d not counted but flags 0x%x",
9547 peer->host,
9548 inet_ntop(rn->p.family, &rn->p.u.prefix,
9549 buf, SU_ADDRSTRLEN),
9550 rn->p.prefixlen,
9551 ri->flags);
9552 }
9553 }
9554 }
9555 return 0;
9556 }
9557
9558 static int
9559 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9560 {
9561 struct peer_pcounts pcounts = { .peer = peer };
9562 unsigned int i;
9563
9564 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9565 || !peer->bgp->rib[afi][safi])
9566 {
9567 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9568 return CMD_WARNING;
9569 }
9570
9571 memset (&pcounts, 0, sizeof(pcounts));
9572 pcounts.peer = peer;
9573 pcounts.table = peer->bgp->rib[afi][safi];
9574
9575 /* in-place call via thread subsystem so as to record execution time
9576 * stats for the thread-walk (i.e. ensure this can't be blamed on
9577 * on just vty_read()).
9578 */
9579 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9580
9581 vty_out (vty, "Prefix counts for %s, %s%s",
9582 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9583 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9584 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9585 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9586
9587 for (i = 0; i < PCOUNT_MAX; i++)
9588 vty_out (vty, "%20s: %-10d%s",
9589 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
9590
9591 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
9592 {
9593 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9594 peer->host, VTY_NEWLINE);
9595 vty_out (vty, "Please report this bug, with the above command output%s",
9596 VTY_NEWLINE);
9597 }
9598
9599 return CMD_SUCCESS;
9600 }
9601
9602 DEFUN (show_ip_bgp_neighbor_prefix_counts,
9603 show_ip_bgp_neighbor_prefix_counts_cmd,
9604 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9605 SHOW_STR
9606 IP_STR
9607 BGP_STR
9608 "Detailed information on TCP and BGP neighbor connections\n"
9609 "Neighbor to display information about\n"
9610 "Neighbor to display information about\n"
9611 "Display detailed prefix count information\n")
9612 {
9613 struct peer *peer;
9614
9615 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9616 if (! peer)
9617 return CMD_WARNING;
9618
9619 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9620 }
9621
9622 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9623 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9624 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9625 SHOW_STR
9626 BGP_STR
9627 "Address family\n"
9628 "Detailed information on TCP and BGP neighbor connections\n"
9629 "Neighbor to display information about\n"
9630 "Neighbor to display information about\n"
9631 "Display detailed prefix count information\n")
9632 {
9633 struct peer *peer;
9634
9635 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9636 if (! peer)
9637 return CMD_WARNING;
9638
9639 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9640 }
9641
9642 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9643 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9644 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9645 SHOW_STR
9646 IP_STR
9647 BGP_STR
9648 "Address family\n"
9649 "Address Family modifier\n"
9650 "Address Family modifier\n"
9651 "Detailed information on TCP and BGP neighbor connections\n"
9652 "Neighbor to display information about\n"
9653 "Neighbor to display information about\n"
9654 "Display detailed prefix count information\n")
9655 {
9656 struct peer *peer;
9657
9658 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9659 if (! peer)
9660 return CMD_WARNING;
9661
9662 if (strncmp (argv[0], "m", 1) == 0)
9663 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9664
9665 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9666 }
9667
9668 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9669 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9670 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9671 SHOW_STR
9672 IP_STR
9673 BGP_STR
9674 "Address family\n"
9675 "Address Family modifier\n"
9676 "Address Family modifier\n"
9677 "Detailed information on TCP and BGP neighbor connections\n"
9678 "Neighbor to display information about\n"
9679 "Neighbor to display information about\n"
9680 "Display detailed prefix count information\n")
9681 {
9682 struct peer *peer;
9683
9684 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9685 if (! peer)
9686 return CMD_WARNING;
9687
9688 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9689 }
9690
9691
9692 static void
9693 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9694 int in)
9695 {
9696 struct bgp_table *table;
9697 struct bgp_adj_in *ain;
9698 struct bgp_adj_out *adj;
9699 unsigned long output_count;
9700 struct bgp_node *rn;
9701 int header1 = 1;
9702 struct bgp *bgp;
9703 int header2 = 1;
9704
9705 bgp = peer->bgp;
9706
9707 if (! bgp)
9708 return;
9709
9710 table = bgp->rib[afi][safi];
9711
9712 output_count = 0;
9713
9714 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9715 PEER_STATUS_DEFAULT_ORIGINATE))
9716 {
9717 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
9718 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9719 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9720
9721 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9722 VTY_NEWLINE, VTY_NEWLINE);
9723 header1 = 0;
9724 }
9725
9726 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9727 if (in)
9728 {
9729 for (ain = rn->adj_in; ain; ain = ain->next)
9730 if (ain->peer == peer)
9731 {
9732 if (header1)
9733 {
9734 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
9735 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9736 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9737 header1 = 0;
9738 }
9739 if (header2)
9740 {
9741 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9742 header2 = 0;
9743 }
9744 if (ain->attr)
9745 {
9746 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9747 output_count++;
9748 }
9749 }
9750 }
9751 else
9752 {
9753 for (adj = rn->adj_out; adj; adj = adj->next)
9754 if (adj->peer == peer)
9755 {
9756 if (header1)
9757 {
9758 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
9759 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9760 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9761 header1 = 0;
9762 }
9763 if (header2)
9764 {
9765 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9766 header2 = 0;
9767 }
9768 if (adj->attr)
9769 {
9770 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9771 output_count++;
9772 }
9773 }
9774 }
9775
9776 if (output_count != 0)
9777 vty_out (vty, "%sTotal number of prefixes %ld%s",
9778 VTY_NEWLINE, output_count, VTY_NEWLINE);
9779 }
9780
9781 static int
9782 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9783 {
9784 if (! peer || ! peer->afc[afi][safi])
9785 {
9786 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9787 return CMD_WARNING;
9788 }
9789
9790 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9791 {
9792 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9793 VTY_NEWLINE);
9794 return CMD_WARNING;
9795 }
9796
9797 show_adj_route (vty, peer, afi, safi, in);
9798
9799 return CMD_SUCCESS;
9800 }
9801
9802 DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9803 show_ip_bgp_view_neighbor_advertised_route_cmd,
9804 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9805 SHOW_STR
9806 IP_STR
9807 BGP_STR
9808 "BGP view\n"
9809 "View name\n"
9810 "Detailed information on TCP and BGP neighbor connections\n"
9811 "Neighbor to display information about\n"
9812 "Neighbor to display information about\n"
9813 "Display the routes advertised to a BGP neighbor\n")
9814 {
9815 struct peer *peer;
9816
9817 if (argc == 2)
9818 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9819 else
9820 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9821
9822 if (! peer)
9823 return CMD_WARNING;
9824
9825 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9826 }
9827
9828 ALIAS (show_ip_bgp_view_neighbor_advertised_route,
9829 show_ip_bgp_neighbor_advertised_route_cmd,
9830 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9831 SHOW_STR
9832 IP_STR
9833 BGP_STR
9834 "Detailed information on TCP and BGP neighbor connections\n"
9835 "Neighbor to display information about\n"
9836 "Neighbor to display information about\n"
9837 "Display the routes advertised to a BGP neighbor\n")
9838
9839 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9840 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9841 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9842 SHOW_STR
9843 IP_STR
9844 BGP_STR
9845 "Address family\n"
9846 "Address Family modifier\n"
9847 "Address Family modifier\n"
9848 "Detailed information on TCP and BGP neighbor connections\n"
9849 "Neighbor to display information about\n"
9850 "Neighbor to display information about\n"
9851 "Display the routes advertised to a BGP neighbor\n")
9852 {
9853 struct peer *peer;
9854
9855 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9856 if (! peer)
9857 return CMD_WARNING;
9858
9859 if (strncmp (argv[0], "m", 1) == 0)
9860 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9861
9862 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9863 }
9864
9865 #ifdef HAVE_IPV6
9866 DEFUN (show_bgp_view_neighbor_advertised_route,
9867 show_bgp_view_neighbor_advertised_route_cmd,
9868 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9869 SHOW_STR
9870 BGP_STR
9871 "BGP view\n"
9872 "View name\n"
9873 "Detailed information on TCP and BGP neighbor connections\n"
9874 "Neighbor to display information about\n"
9875 "Neighbor to display information about\n"
9876 "Display the routes advertised to a BGP neighbor\n")
9877 {
9878 struct peer *peer;
9879
9880 if (argc == 2)
9881 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9882 else
9883 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9884
9885 if (! peer)
9886 return CMD_WARNING;
9887
9888 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9889 }
9890
9891 ALIAS (show_bgp_view_neighbor_advertised_route,
9892 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9893 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9894 SHOW_STR
9895 BGP_STR
9896 "BGP view\n"
9897 "View name\n"
9898 "Address family\n"
9899 "Detailed information on TCP and BGP neighbor connections\n"
9900 "Neighbor to display information about\n"
9901 "Neighbor to display information about\n"
9902 "Display the routes advertised to a BGP neighbor\n")
9903
9904 DEFUN (show_bgp_view_neighbor_received_routes,
9905 show_bgp_view_neighbor_received_routes_cmd,
9906 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9907 SHOW_STR
9908 BGP_STR
9909 "BGP view\n"
9910 "View name\n"
9911 "Detailed information on TCP and BGP neighbor connections\n"
9912 "Neighbor to display information about\n"
9913 "Neighbor to display information about\n"
9914 "Display the received routes from neighbor\n")
9915 {
9916 struct peer *peer;
9917
9918 if (argc == 2)
9919 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9920 else
9921 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9922
9923 if (! peer)
9924 return CMD_WARNING;
9925
9926 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9927 }
9928
9929 ALIAS (show_bgp_view_neighbor_received_routes,
9930 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9931 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9932 SHOW_STR
9933 BGP_STR
9934 "BGP view\n"
9935 "View name\n"
9936 "Address family\n"
9937 "Detailed information on TCP and BGP neighbor connections\n"
9938 "Neighbor to display information about\n"
9939 "Neighbor to display information about\n"
9940 "Display the received routes from neighbor\n")
9941
9942 ALIAS (show_bgp_view_neighbor_advertised_route,
9943 show_bgp_neighbor_advertised_route_cmd,
9944 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9945 SHOW_STR
9946 BGP_STR
9947 "Detailed information on TCP and BGP neighbor connections\n"
9948 "Neighbor to display information about\n"
9949 "Neighbor to display information about\n"
9950 "Display the routes advertised to a BGP neighbor\n")
9951
9952 ALIAS (show_bgp_view_neighbor_advertised_route,
9953 show_bgp_ipv6_neighbor_advertised_route_cmd,
9954 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9955 SHOW_STR
9956 BGP_STR
9957 "Address family\n"
9958 "Detailed information on TCP and BGP neighbor connections\n"
9959 "Neighbor to display information about\n"
9960 "Neighbor to display information about\n"
9961 "Display the routes advertised to a BGP neighbor\n")
9962
9963 /* old command */
9964 ALIAS (show_bgp_view_neighbor_advertised_route,
9965 ipv6_bgp_neighbor_advertised_route_cmd,
9966 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9967 SHOW_STR
9968 IPV6_STR
9969 BGP_STR
9970 "Detailed information on TCP and BGP neighbor connections\n"
9971 "Neighbor to display information about\n"
9972 "Neighbor to display information about\n"
9973 "Display the routes advertised to a BGP neighbor\n")
9974
9975 /* old command */
9976 DEFUN (ipv6_mbgp_neighbor_advertised_route,
9977 ipv6_mbgp_neighbor_advertised_route_cmd,
9978 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9979 SHOW_STR
9980 IPV6_STR
9981 MBGP_STR
9982 "Detailed information on TCP and BGP neighbor connections\n"
9983 "Neighbor to display information about\n"
9984 "Neighbor to display information about\n"
9985 "Display the routes advertised to a BGP neighbor\n")
9986 {
9987 struct peer *peer;
9988
9989 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9990 if (! peer)
9991 return CMD_WARNING;
9992
9993 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
9994 }
9995 #endif /* HAVE_IPV6 */
9996 \f
9997 DEFUN (show_ip_bgp_view_neighbor_received_routes,
9998 show_ip_bgp_view_neighbor_received_routes_cmd,
9999 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10000 SHOW_STR
10001 IP_STR
10002 BGP_STR
10003 "BGP view\n"
10004 "View name\n"
10005 "Detailed information on TCP and BGP neighbor connections\n"
10006 "Neighbor to display information about\n"
10007 "Neighbor to display information about\n"
10008 "Display the received routes from neighbor\n")
10009 {
10010 struct peer *peer;
10011
10012 if (argc == 2)
10013 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10014 else
10015 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10016
10017 if (! peer)
10018 return CMD_WARNING;
10019
10020 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10021 }
10022
10023 ALIAS (show_ip_bgp_view_neighbor_received_routes,
10024 show_ip_bgp_neighbor_received_routes_cmd,
10025 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10026 SHOW_STR
10027 IP_STR
10028 BGP_STR
10029 "Detailed information on TCP and BGP neighbor connections\n"
10030 "Neighbor to display information about\n"
10031 "Neighbor to display information about\n"
10032 "Display the received routes from neighbor\n")
10033
10034 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10035 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10036 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10037 SHOW_STR
10038 IP_STR
10039 BGP_STR
10040 "Address family\n"
10041 "Address Family modifier\n"
10042 "Address Family modifier\n"
10043 "Detailed information on TCP and BGP neighbor connections\n"
10044 "Neighbor to display information about\n"
10045 "Neighbor to display information about\n"
10046 "Display the received routes from neighbor\n")
10047 {
10048 struct peer *peer;
10049
10050 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10051 if (! peer)
10052 return CMD_WARNING;
10053
10054 if (strncmp (argv[0], "m", 1) == 0)
10055 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10056
10057 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10058 }
10059
10060 DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10061 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10062 #ifdef HAVE_IPV6
10063 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10064 #else
10065 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10066 #endif
10067 SHOW_STR
10068 BGP_STR
10069 "BGP view\n"
10070 "BGP view name\n"
10071 "Address family\n"
10072 #ifdef HAVE_IPV6
10073 "Address family\n"
10074 #endif
10075 "Address family modifier\n"
10076 "Address family modifier\n"
10077 "Detailed information on TCP and BGP neighbor connections\n"
10078 "Neighbor to display information about\n"
10079 "Neighbor to display information about\n"
10080 "Display the advertised routes to neighbor\n"
10081 "Display the received routes from neighbor\n")
10082 {
10083 int afi;
10084 int safi;
10085 int in;
10086 struct peer *peer;
10087
10088 #ifdef HAVE_IPV6
10089 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10090 #else
10091 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10092 #endif
10093
10094 if (! peer)
10095 return CMD_WARNING;
10096
10097 #ifdef HAVE_IPV6
10098 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10099 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10100 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10101 #else
10102 afi = AFI_IP;
10103 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10104 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10105 #endif
10106
10107 return peer_adj_routes (vty, peer, afi, safi, in);
10108 }
10109
10110 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10111 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10112 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10113 SHOW_STR
10114 IP_STR
10115 BGP_STR
10116 "Detailed information on TCP and BGP neighbor connections\n"
10117 "Neighbor to display information about\n"
10118 "Neighbor to display information about\n"
10119 "Display information received from a BGP neighbor\n"
10120 "Display the prefixlist filter\n")
10121 {
10122 char name[BUFSIZ];
10123 union sockunion *su;
10124 struct peer *peer;
10125 int count;
10126
10127 su = sockunion_str2su (argv[0]);
10128 if (su == NULL)
10129 return CMD_WARNING;
10130
10131 peer = peer_lookup (NULL, su);
10132 if (! peer)
10133 return CMD_WARNING;
10134
10135 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10136 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10137 if (count)
10138 {
10139 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10140 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10141 }
10142
10143 return CMD_SUCCESS;
10144 }
10145
10146 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10147 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10148 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10149 SHOW_STR
10150 IP_STR
10151 BGP_STR
10152 "Address family\n"
10153 "Address Family modifier\n"
10154 "Address Family modifier\n"
10155 "Detailed information on TCP and BGP neighbor connections\n"
10156 "Neighbor to display information about\n"
10157 "Neighbor to display information about\n"
10158 "Display information received from a BGP neighbor\n"
10159 "Display the prefixlist filter\n")
10160 {
10161 char name[BUFSIZ];
10162 union sockunion *su;
10163 struct peer *peer;
10164 int count;
10165
10166 su = sockunion_str2su (argv[1]);
10167 if (su == NULL)
10168 return CMD_WARNING;
10169
10170 peer = peer_lookup (NULL, su);
10171 if (! peer)
10172 return CMD_WARNING;
10173
10174 if (strncmp (argv[0], "m", 1) == 0)
10175 {
10176 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10177 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10178 if (count)
10179 {
10180 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10181 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10182 }
10183 }
10184 else
10185 {
10186 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10187 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10188 if (count)
10189 {
10190 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10191 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10192 }
10193 }
10194
10195 return CMD_SUCCESS;
10196 }
10197
10198
10199 #ifdef HAVE_IPV6
10200 ALIAS (show_bgp_view_neighbor_received_routes,
10201 show_bgp_neighbor_received_routes_cmd,
10202 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10203 SHOW_STR
10204 BGP_STR
10205 "Detailed information on TCP and BGP neighbor connections\n"
10206 "Neighbor to display information about\n"
10207 "Neighbor to display information about\n"
10208 "Display the received routes from neighbor\n")
10209
10210 ALIAS (show_bgp_view_neighbor_received_routes,
10211 show_bgp_ipv6_neighbor_received_routes_cmd,
10212 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10213 SHOW_STR
10214 BGP_STR
10215 "Address family\n"
10216 "Detailed information on TCP and BGP neighbor connections\n"
10217 "Neighbor to display information about\n"
10218 "Neighbor to display information about\n"
10219 "Display the received routes from neighbor\n")
10220
10221 DEFUN (show_bgp_neighbor_received_prefix_filter,
10222 show_bgp_neighbor_received_prefix_filter_cmd,
10223 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10224 SHOW_STR
10225 BGP_STR
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 information received from a BGP neighbor\n"
10230 "Display the prefixlist filter\n")
10231 {
10232 char name[BUFSIZ];
10233 union sockunion *su;
10234 struct peer *peer;
10235 int count;
10236
10237 su = sockunion_str2su (argv[0]);
10238 if (su == NULL)
10239 return CMD_WARNING;
10240
10241 peer = peer_lookup (NULL, su);
10242 if (! peer)
10243 return CMD_WARNING;
10244
10245 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10246 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10247 if (count)
10248 {
10249 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10250 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10251 }
10252
10253 return CMD_SUCCESS;
10254 }
10255
10256 ALIAS (show_bgp_neighbor_received_prefix_filter,
10257 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10258 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10259 SHOW_STR
10260 BGP_STR
10261 "Address family\n"
10262 "Detailed information on TCP and BGP neighbor connections\n"
10263 "Neighbor to display information about\n"
10264 "Neighbor to display information about\n"
10265 "Display information received from a BGP neighbor\n"
10266 "Display the prefixlist filter\n")
10267
10268 /* old command */
10269 ALIAS (show_bgp_view_neighbor_received_routes,
10270 ipv6_bgp_neighbor_received_routes_cmd,
10271 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10272 SHOW_STR
10273 IPV6_STR
10274 BGP_STR
10275 "Detailed information on TCP and BGP neighbor connections\n"
10276 "Neighbor to display information about\n"
10277 "Neighbor to display information about\n"
10278 "Display the received routes from neighbor\n")
10279
10280 /* old command */
10281 DEFUN (ipv6_mbgp_neighbor_received_routes,
10282 ipv6_mbgp_neighbor_received_routes_cmd,
10283 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10284 SHOW_STR
10285 IPV6_STR
10286 MBGP_STR
10287 "Detailed information on TCP and BGP neighbor connections\n"
10288 "Neighbor to display information about\n"
10289 "Neighbor to display information about\n"
10290 "Display the received routes from neighbor\n")
10291 {
10292 struct peer *peer;
10293
10294 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10295 if (! peer)
10296 return CMD_WARNING;
10297
10298 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
10299 }
10300
10301 DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10302 show_bgp_view_neighbor_received_prefix_filter_cmd,
10303 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10304 SHOW_STR
10305 BGP_STR
10306 "BGP view\n"
10307 "View name\n"
10308 "Detailed information on TCP and BGP neighbor connections\n"
10309 "Neighbor to display information about\n"
10310 "Neighbor to display information about\n"
10311 "Display information received from a BGP neighbor\n"
10312 "Display the prefixlist filter\n")
10313 {
10314 char name[BUFSIZ];
10315 union sockunion *su;
10316 struct peer *peer;
10317 struct bgp *bgp;
10318 int count;
10319
10320 /* BGP structure lookup. */
10321 bgp = bgp_lookup_by_name (argv[0]);
10322 if (bgp == NULL)
10323 {
10324 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10325 return CMD_WARNING;
10326 }
10327
10328 su = sockunion_str2su (argv[1]);
10329 if (su == NULL)
10330 return CMD_WARNING;
10331
10332 peer = peer_lookup (bgp, su);
10333 if (! peer)
10334 return CMD_WARNING;
10335
10336 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10337 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10338 if (count)
10339 {
10340 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10341 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10342 }
10343
10344 return CMD_SUCCESS;
10345 }
10346
10347 ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10348 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10349 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10350 SHOW_STR
10351 BGP_STR
10352 "BGP view\n"
10353 "View name\n"
10354 "Address family\n"
10355 "Detailed information on TCP and BGP neighbor connections\n"
10356 "Neighbor to display information about\n"
10357 "Neighbor to display information about\n"
10358 "Display information received from a BGP neighbor\n"
10359 "Display the prefixlist filter\n")
10360 #endif /* HAVE_IPV6 */
10361 \f
10362 static int
10363 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
10364 safi_t safi, enum bgp_show_type type)
10365 {
10366 if (! peer || ! peer->afc[afi][safi])
10367 {
10368 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10369 return CMD_WARNING;
10370 }
10371
10372 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
10373 }
10374
10375 DEFUN (show_ip_bgp_neighbor_routes,
10376 show_ip_bgp_neighbor_routes_cmd,
10377 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10378 SHOW_STR
10379 IP_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 routes learned from neighbor\n")
10385 {
10386 struct peer *peer;
10387
10388 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10389 if (! peer)
10390 return CMD_WARNING;
10391
10392 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10393 bgp_show_type_neighbor);
10394 }
10395
10396 DEFUN (show_ip_bgp_neighbor_flap,
10397 show_ip_bgp_neighbor_flap_cmd,
10398 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10399 SHOW_STR
10400 IP_STR
10401 BGP_STR
10402 "Detailed information on TCP and BGP neighbor connections\n"
10403 "Neighbor to display information about\n"
10404 "Neighbor to display information about\n"
10405 "Display flap statistics of the routes learned from neighbor\n")
10406 {
10407 struct peer *peer;
10408
10409 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10410 if (! peer)
10411 return CMD_WARNING;
10412
10413 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10414 bgp_show_type_flap_neighbor);
10415 }
10416
10417 DEFUN (show_ip_bgp_neighbor_damp,
10418 show_ip_bgp_neighbor_damp_cmd,
10419 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10420 SHOW_STR
10421 IP_STR
10422 BGP_STR
10423 "Detailed information on TCP and BGP neighbor connections\n"
10424 "Neighbor to display information about\n"
10425 "Neighbor to display information about\n"
10426 "Display the dampened routes received from neighbor\n")
10427 {
10428 struct peer *peer;
10429
10430 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10431 if (! peer)
10432 return CMD_WARNING;
10433
10434 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10435 bgp_show_type_damp_neighbor);
10436 }
10437
10438 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10439 show_ip_bgp_ipv4_neighbor_routes_cmd,
10440 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10441 SHOW_STR
10442 IP_STR
10443 BGP_STR
10444 "Address family\n"
10445 "Address Family modifier\n"
10446 "Address Family modifier\n"
10447 "Detailed information on TCP and BGP neighbor connections\n"
10448 "Neighbor to display information about\n"
10449 "Neighbor to display information about\n"
10450 "Display routes learned from neighbor\n")
10451 {
10452 struct peer *peer;
10453
10454 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10455 if (! peer)
10456 return CMD_WARNING;
10457
10458 if (strncmp (argv[0], "m", 1) == 0)
10459 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
10460 bgp_show_type_neighbor);
10461
10462 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10463 bgp_show_type_neighbor);
10464 }
10465
10466 DEFUN (show_ip_bgp_view_rsclient,
10467 show_ip_bgp_view_rsclient_cmd,
10468 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10469 SHOW_STR
10470 IP_STR
10471 BGP_STR
10472 "BGP view\n"
10473 "BGP view name\n"
10474 "Information about Route Server Client\n"
10475 NEIGHBOR_ADDR_STR)
10476 {
10477 struct bgp_table *table;
10478 struct peer *peer;
10479
10480 if (argc == 2)
10481 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10482 else
10483 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10484
10485 if (! peer)
10486 return CMD_WARNING;
10487
10488 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10489 {
10490 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10491 VTY_NEWLINE);
10492 return CMD_WARNING;
10493 }
10494
10495 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10496 PEER_FLAG_RSERVER_CLIENT))
10497 {
10498 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10499 VTY_NEWLINE);
10500 return CMD_WARNING;
10501 }
10502
10503 table = peer->rib[AFI_IP][SAFI_UNICAST];
10504
10505 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10506 }
10507
10508 ALIAS (show_ip_bgp_view_rsclient,
10509 show_ip_bgp_rsclient_cmd,
10510 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10511 SHOW_STR
10512 IP_STR
10513 BGP_STR
10514 "Information about Route Server Client\n"
10515 NEIGHBOR_ADDR_STR)
10516
10517 DEFUN (show_bgp_view_ipv4_safi_rsclient,
10518 show_bgp_view_ipv4_safi_rsclient_cmd,
10519 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10520 SHOW_STR
10521 BGP_STR
10522 "BGP view\n"
10523 "BGP view name\n"
10524 "Address family\n"
10525 "Address Family modifier\n"
10526 "Address Family modifier\n"
10527 "Information about Route Server Client\n"
10528 NEIGHBOR_ADDR_STR)
10529 {
10530 struct bgp_table *table;
10531 struct peer *peer;
10532 safi_t safi;
10533
10534 if (argc == 3) {
10535 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10536 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10537 } else {
10538 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10539 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10540 }
10541
10542 if (! peer)
10543 return CMD_WARNING;
10544
10545 if (! peer->afc[AFI_IP][safi])
10546 {
10547 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10548 VTY_NEWLINE);
10549 return CMD_WARNING;
10550 }
10551
10552 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10553 PEER_FLAG_RSERVER_CLIENT))
10554 {
10555 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10556 VTY_NEWLINE);
10557 return CMD_WARNING;
10558 }
10559
10560 table = peer->rib[AFI_IP][safi];
10561
10562 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10563 }
10564
10565 ALIAS (show_bgp_view_ipv4_safi_rsclient,
10566 show_bgp_ipv4_safi_rsclient_cmd,
10567 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10568 SHOW_STR
10569 BGP_STR
10570 "Address family\n"
10571 "Address Family modifier\n"
10572 "Address Family modifier\n"
10573 "Information about Route Server Client\n"
10574 NEIGHBOR_ADDR_STR)
10575
10576 DEFUN (show_ip_bgp_view_rsclient_route,
10577 show_ip_bgp_view_rsclient_route_cmd,
10578 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10579 SHOW_STR
10580 IP_STR
10581 BGP_STR
10582 "BGP view\n"
10583 "BGP view name\n"
10584 "Information about Route Server Client\n"
10585 NEIGHBOR_ADDR_STR
10586 "Network in the BGP routing table to display\n")
10587 {
10588 struct bgp *bgp;
10589 struct peer *peer;
10590
10591 /* BGP structure lookup. */
10592 if (argc == 3)
10593 {
10594 bgp = bgp_lookup_by_name (argv[0]);
10595 if (bgp == NULL)
10596 {
10597 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10598 return CMD_WARNING;
10599 }
10600 }
10601 else
10602 {
10603 bgp = bgp_get_default ();
10604 if (bgp == NULL)
10605 {
10606 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10607 return CMD_WARNING;
10608 }
10609 }
10610
10611 if (argc == 3)
10612 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10613 else
10614 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10615
10616 if (! peer)
10617 return CMD_WARNING;
10618
10619 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10620 {
10621 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10622 VTY_NEWLINE);
10623 return CMD_WARNING;
10624 }
10625
10626 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10627 PEER_FLAG_RSERVER_CLIENT))
10628 {
10629 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10630 VTY_NEWLINE);
10631 return CMD_WARNING;
10632 }
10633
10634 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10635 (argc == 3) ? argv[2] : argv[1],
10636 AFI_IP, SAFI_UNICAST, NULL, 0);
10637 }
10638
10639 ALIAS (show_ip_bgp_view_rsclient_route,
10640 show_ip_bgp_rsclient_route_cmd,
10641 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10642 SHOW_STR
10643 IP_STR
10644 BGP_STR
10645 "Information about Route Server Client\n"
10646 NEIGHBOR_ADDR_STR
10647 "Network in the BGP routing table to display\n")
10648
10649 DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10650 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10651 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10652 SHOW_STR
10653 BGP_STR
10654 "BGP view\n"
10655 "BGP view name\n"
10656 "Address family\n"
10657 "Address Family modifier\n"
10658 "Address Family modifier\n"
10659 "Information about Route Server Client\n"
10660 NEIGHBOR_ADDR_STR
10661 "Network in the BGP routing table to display\n")
10662 {
10663 struct bgp *bgp;
10664 struct peer *peer;
10665 safi_t safi;
10666
10667 /* BGP structure lookup. */
10668 if (argc == 4)
10669 {
10670 bgp = bgp_lookup_by_name (argv[0]);
10671 if (bgp == NULL)
10672 {
10673 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10674 return CMD_WARNING;
10675 }
10676 }
10677 else
10678 {
10679 bgp = bgp_get_default ();
10680 if (bgp == NULL)
10681 {
10682 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10683 return CMD_WARNING;
10684 }
10685 }
10686
10687 if (argc == 4) {
10688 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10689 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10690 } else {
10691 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10692 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10693 }
10694
10695 if (! peer)
10696 return CMD_WARNING;
10697
10698 if (! peer->afc[AFI_IP][safi])
10699 {
10700 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10701 VTY_NEWLINE);
10702 return CMD_WARNING;
10703 }
10704
10705 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10706 PEER_FLAG_RSERVER_CLIENT))
10707 {
10708 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10709 VTY_NEWLINE);
10710 return CMD_WARNING;
10711 }
10712
10713 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10714 (argc == 4) ? argv[3] : argv[2],
10715 AFI_IP, safi, NULL, 0);
10716 }
10717
10718 ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10719 show_bgp_ipv4_safi_rsclient_route_cmd,
10720 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10721 SHOW_STR
10722 BGP_STR
10723 "Address family\n"
10724 "Address Family modifier\n"
10725 "Address Family modifier\n"
10726 "Information about Route Server Client\n"
10727 NEIGHBOR_ADDR_STR
10728 "Network in the BGP routing table to display\n")
10729
10730 DEFUN (show_ip_bgp_view_rsclient_prefix,
10731 show_ip_bgp_view_rsclient_prefix_cmd,
10732 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10733 SHOW_STR
10734 IP_STR
10735 BGP_STR
10736 "BGP view\n"
10737 "BGP view name\n"
10738 "Information about Route Server Client\n"
10739 NEIGHBOR_ADDR_STR
10740 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10741 {
10742 struct bgp *bgp;
10743 struct peer *peer;
10744
10745 /* BGP structure lookup. */
10746 if (argc == 3)
10747 {
10748 bgp = bgp_lookup_by_name (argv[0]);
10749 if (bgp == NULL)
10750 {
10751 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10752 return CMD_WARNING;
10753 }
10754 }
10755 else
10756 {
10757 bgp = bgp_get_default ();
10758 if (bgp == NULL)
10759 {
10760 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10761 return CMD_WARNING;
10762 }
10763 }
10764
10765 if (argc == 3)
10766 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10767 else
10768 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10769
10770 if (! peer)
10771 return CMD_WARNING;
10772
10773 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10774 {
10775 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10776 VTY_NEWLINE);
10777 return CMD_WARNING;
10778 }
10779
10780 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10781 PEER_FLAG_RSERVER_CLIENT))
10782 {
10783 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10784 VTY_NEWLINE);
10785 return CMD_WARNING;
10786 }
10787
10788 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10789 (argc == 3) ? argv[2] : argv[1],
10790 AFI_IP, SAFI_UNICAST, NULL, 1);
10791 }
10792
10793 ALIAS (show_ip_bgp_view_rsclient_prefix,
10794 show_ip_bgp_rsclient_prefix_cmd,
10795 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10796 SHOW_STR
10797 IP_STR
10798 BGP_STR
10799 "Information about Route Server Client\n"
10800 NEIGHBOR_ADDR_STR
10801 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10802
10803 DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10804 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10805 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10806 SHOW_STR
10807 BGP_STR
10808 "BGP view\n"
10809 "BGP view name\n"
10810 "Address family\n"
10811 "Address Family modifier\n"
10812 "Address Family modifier\n"
10813 "Information about Route Server Client\n"
10814 NEIGHBOR_ADDR_STR
10815 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10816 {
10817 struct bgp *bgp;
10818 struct peer *peer;
10819 safi_t safi;
10820
10821 /* BGP structure lookup. */
10822 if (argc == 4)
10823 {
10824 bgp = bgp_lookup_by_name (argv[0]);
10825 if (bgp == NULL)
10826 {
10827 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10828 return CMD_WARNING;
10829 }
10830 }
10831 else
10832 {
10833 bgp = bgp_get_default ();
10834 if (bgp == NULL)
10835 {
10836 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10837 return CMD_WARNING;
10838 }
10839 }
10840
10841 if (argc == 4) {
10842 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10843 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10844 } else {
10845 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10846 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10847 }
10848
10849 if (! peer)
10850 return CMD_WARNING;
10851
10852 if (! peer->afc[AFI_IP][safi])
10853 {
10854 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10855 VTY_NEWLINE);
10856 return CMD_WARNING;
10857 }
10858
10859 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10860 PEER_FLAG_RSERVER_CLIENT))
10861 {
10862 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10863 VTY_NEWLINE);
10864 return CMD_WARNING;
10865 }
10866
10867 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10868 (argc == 4) ? argv[3] : argv[2],
10869 AFI_IP, safi, NULL, 1);
10870 }
10871
10872 ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10873 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10874 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10875 SHOW_STR
10876 BGP_STR
10877 "Address family\n"
10878 "Address Family modifier\n"
10879 "Address Family modifier\n"
10880 "Information about Route Server Client\n"
10881 NEIGHBOR_ADDR_STR
10882 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10883
10884 #ifdef HAVE_IPV6
10885 DEFUN (show_bgp_view_neighbor_routes,
10886 show_bgp_view_neighbor_routes_cmd,
10887 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10888 SHOW_STR
10889 BGP_STR
10890 "BGP view\n"
10891 "BGP view name\n"
10892 "Detailed information on TCP and BGP neighbor connections\n"
10893 "Neighbor to display information about\n"
10894 "Neighbor to display information about\n"
10895 "Display routes learned from neighbor\n")
10896 {
10897 struct peer *peer;
10898
10899 if (argc == 2)
10900 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10901 else
10902 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10903
10904 if (! peer)
10905 return CMD_WARNING;
10906
10907 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10908 bgp_show_type_neighbor);
10909 }
10910
10911 ALIAS (show_bgp_view_neighbor_routes,
10912 show_bgp_view_ipv6_neighbor_routes_cmd,
10913 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10914 SHOW_STR
10915 BGP_STR
10916 "BGP view\n"
10917 "BGP view name\n"
10918 "Address family\n"
10919 "Detailed information on TCP and BGP neighbor connections\n"
10920 "Neighbor to display information about\n"
10921 "Neighbor to display information about\n"
10922 "Display routes learned from neighbor\n")
10923
10924 DEFUN (show_bgp_view_neighbor_damp,
10925 show_bgp_view_neighbor_damp_cmd,
10926 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10927 SHOW_STR
10928 BGP_STR
10929 "BGP view\n"
10930 "BGP view name\n"
10931 "Detailed information on TCP and BGP neighbor connections\n"
10932 "Neighbor to display information about\n"
10933 "Neighbor to display information about\n"
10934 "Display the dampened routes received from neighbor\n")
10935 {
10936 struct peer *peer;
10937
10938 if (argc == 2)
10939 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10940 else
10941 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10942
10943 if (! peer)
10944 return CMD_WARNING;
10945
10946 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10947 bgp_show_type_damp_neighbor);
10948 }
10949
10950 ALIAS (show_bgp_view_neighbor_damp,
10951 show_bgp_view_ipv6_neighbor_damp_cmd,
10952 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10953 SHOW_STR
10954 BGP_STR
10955 "BGP view\n"
10956 "BGP view name\n"
10957 "Address family\n"
10958 "Detailed information on TCP and BGP neighbor connections\n"
10959 "Neighbor to display information about\n"
10960 "Neighbor to display information about\n"
10961 "Display the dampened routes received from neighbor\n")
10962
10963 DEFUN (show_bgp_view_neighbor_flap,
10964 show_bgp_view_neighbor_flap_cmd,
10965 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10966 SHOW_STR
10967 BGP_STR
10968 "BGP view\n"
10969 "BGP view name\n"
10970 "Detailed information on TCP and BGP neighbor connections\n"
10971 "Neighbor to display information about\n"
10972 "Neighbor to display information about\n"
10973 "Display flap statistics of the routes learned from neighbor\n")
10974 {
10975 struct peer *peer;
10976
10977 if (argc == 2)
10978 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10979 else
10980 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10981
10982 if (! peer)
10983 return CMD_WARNING;
10984
10985 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10986 bgp_show_type_flap_neighbor);
10987 }
10988
10989 ALIAS (show_bgp_view_neighbor_flap,
10990 show_bgp_view_ipv6_neighbor_flap_cmd,
10991 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10992 SHOW_STR
10993 BGP_STR
10994 "BGP view\n"
10995 "BGP view name\n"
10996 "Address family\n"
10997 "Detailed information on TCP and BGP neighbor connections\n"
10998 "Neighbor to display information about\n"
10999 "Neighbor to display information about\n"
11000 "Display flap statistics of the routes learned from neighbor\n")
11001
11002 ALIAS (show_bgp_view_neighbor_routes,
11003 show_bgp_neighbor_routes_cmd,
11004 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11005 SHOW_STR
11006 BGP_STR
11007 "Detailed information on TCP and BGP neighbor connections\n"
11008 "Neighbor to display information about\n"
11009 "Neighbor to display information about\n"
11010 "Display routes learned from neighbor\n")
11011
11012
11013 ALIAS (show_bgp_view_neighbor_routes,
11014 show_bgp_ipv6_neighbor_routes_cmd,
11015 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11016 SHOW_STR
11017 BGP_STR
11018 "Address family\n"
11019 "Detailed information on TCP and BGP neighbor connections\n"
11020 "Neighbor to display information about\n"
11021 "Neighbor to display information about\n"
11022 "Display routes learned from neighbor\n")
11023
11024 /* old command */
11025 ALIAS (show_bgp_view_neighbor_routes,
11026 ipv6_bgp_neighbor_routes_cmd,
11027 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11028 SHOW_STR
11029 IPV6_STR
11030 BGP_STR
11031 "Detailed information on TCP and BGP neighbor connections\n"
11032 "Neighbor to display information about\n"
11033 "Neighbor to display information about\n"
11034 "Display routes learned from neighbor\n")
11035
11036 /* old command */
11037 DEFUN (ipv6_mbgp_neighbor_routes,
11038 ipv6_mbgp_neighbor_routes_cmd,
11039 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11040 SHOW_STR
11041 IPV6_STR
11042 MBGP_STR
11043 "Detailed information on TCP and BGP neighbor connections\n"
11044 "Neighbor to display information about\n"
11045 "Neighbor to display information about\n"
11046 "Display routes learned from neighbor\n")
11047 {
11048 struct peer *peer;
11049
11050 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11051 if (! peer)
11052 return CMD_WARNING;
11053
11054 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
11055 bgp_show_type_neighbor);
11056 }
11057
11058 ALIAS (show_bgp_view_neighbor_flap,
11059 show_bgp_neighbor_flap_cmd,
11060 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11061 SHOW_STR
11062 BGP_STR
11063 "Detailed information on TCP and BGP neighbor connections\n"
11064 "Neighbor to display information about\n"
11065 "Neighbor to display information about\n"
11066 "Display flap statistics of the routes learned from neighbor\n")
11067
11068 ALIAS (show_bgp_view_neighbor_flap,
11069 show_bgp_ipv6_neighbor_flap_cmd,
11070 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11071 SHOW_STR
11072 BGP_STR
11073 "Address family\n"
11074 "Detailed information on TCP and BGP neighbor connections\n"
11075 "Neighbor to display information about\n"
11076 "Neighbor to display information about\n"
11077 "Display flap statistics of the routes learned from neighbor\n")
11078
11079 ALIAS (show_bgp_view_neighbor_damp,
11080 show_bgp_neighbor_damp_cmd,
11081 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11082 SHOW_STR
11083 BGP_STR
11084 "Detailed information on TCP and BGP neighbor connections\n"
11085 "Neighbor to display information about\n"
11086 "Neighbor to display information about\n"
11087 "Display the dampened routes received from neighbor\n")
11088
11089 ALIAS (show_bgp_view_neighbor_damp,
11090 show_bgp_ipv6_neighbor_damp_cmd,
11091 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11092 SHOW_STR
11093 BGP_STR
11094 "Address family\n"
11095 "Detailed information on TCP and BGP neighbor connections\n"
11096 "Neighbor to display information about\n"
11097 "Neighbor to display information about\n"
11098 "Display the dampened routes received from neighbor\n")
11099
11100 DEFUN (show_bgp_view_rsclient,
11101 show_bgp_view_rsclient_cmd,
11102 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11103 SHOW_STR
11104 BGP_STR
11105 "BGP view\n"
11106 "BGP view name\n"
11107 "Information about Route Server Client\n"
11108 NEIGHBOR_ADDR_STR)
11109 {
11110 struct bgp_table *table;
11111 struct peer *peer;
11112
11113 if (argc == 2)
11114 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11115 else
11116 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11117
11118 if (! peer)
11119 return CMD_WARNING;
11120
11121 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11122 {
11123 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11124 VTY_NEWLINE);
11125 return CMD_WARNING;
11126 }
11127
11128 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11129 PEER_FLAG_RSERVER_CLIENT))
11130 {
11131 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11132 VTY_NEWLINE);
11133 return CMD_WARNING;
11134 }
11135
11136 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11137
11138 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11139 }
11140
11141 ALIAS (show_bgp_view_rsclient,
11142 show_bgp_rsclient_cmd,
11143 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11144 SHOW_STR
11145 BGP_STR
11146 "Information about Route Server Client\n"
11147 NEIGHBOR_ADDR_STR)
11148
11149 DEFUN (show_bgp_view_ipv6_safi_rsclient,
11150 show_bgp_view_ipv6_safi_rsclient_cmd,
11151 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11152 SHOW_STR
11153 BGP_STR
11154 "BGP view\n"
11155 "BGP view name\n"
11156 "Address family\n"
11157 "Address Family modifier\n"
11158 "Address Family modifier\n"
11159 "Information about Route Server Client\n"
11160 NEIGHBOR_ADDR_STR)
11161 {
11162 struct bgp_table *table;
11163 struct peer *peer;
11164 safi_t safi;
11165
11166 if (argc == 3) {
11167 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11168 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11169 } else {
11170 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11171 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11172 }
11173
11174 if (! peer)
11175 return CMD_WARNING;
11176
11177 if (! peer->afc[AFI_IP6][safi])
11178 {
11179 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11180 VTY_NEWLINE);
11181 return CMD_WARNING;
11182 }
11183
11184 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11185 PEER_FLAG_RSERVER_CLIENT))
11186 {
11187 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11188 VTY_NEWLINE);
11189 return CMD_WARNING;
11190 }
11191
11192 table = peer->rib[AFI_IP6][safi];
11193
11194 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11195 }
11196
11197 ALIAS (show_bgp_view_ipv6_safi_rsclient,
11198 show_bgp_ipv6_safi_rsclient_cmd,
11199 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11200 SHOW_STR
11201 BGP_STR
11202 "Address family\n"
11203 "Address Family modifier\n"
11204 "Address Family modifier\n"
11205 "Information about Route Server Client\n"
11206 NEIGHBOR_ADDR_STR)
11207
11208 DEFUN (show_bgp_view_rsclient_route,
11209 show_bgp_view_rsclient_route_cmd,
11210 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11211 SHOW_STR
11212 BGP_STR
11213 "BGP view\n"
11214 "BGP view name\n"
11215 "Information about Route Server Client\n"
11216 NEIGHBOR_ADDR_STR
11217 "Network in the BGP routing table to display\n")
11218 {
11219 struct bgp *bgp;
11220 struct peer *peer;
11221
11222 /* BGP structure lookup. */
11223 if (argc == 3)
11224 {
11225 bgp = bgp_lookup_by_name (argv[0]);
11226 if (bgp == NULL)
11227 {
11228 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11229 return CMD_WARNING;
11230 }
11231 }
11232 else
11233 {
11234 bgp = bgp_get_default ();
11235 if (bgp == NULL)
11236 {
11237 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11238 return CMD_WARNING;
11239 }
11240 }
11241
11242 if (argc == 3)
11243 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11244 else
11245 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11246
11247 if (! peer)
11248 return CMD_WARNING;
11249
11250 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11251 {
11252 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11253 VTY_NEWLINE);
11254 return CMD_WARNING;
11255 }
11256
11257 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11258 PEER_FLAG_RSERVER_CLIENT))
11259 {
11260 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11261 VTY_NEWLINE);
11262 return CMD_WARNING;
11263 }
11264
11265 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11266 (argc == 3) ? argv[2] : argv[1],
11267 AFI_IP6, SAFI_UNICAST, NULL, 0);
11268 }
11269
11270 ALIAS (show_bgp_view_rsclient_route,
11271 show_bgp_rsclient_route_cmd,
11272 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11273 SHOW_STR
11274 BGP_STR
11275 "Information about Route Server Client\n"
11276 NEIGHBOR_ADDR_STR
11277 "Network in the BGP routing table to display\n")
11278
11279 DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11280 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11281 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11282 SHOW_STR
11283 BGP_STR
11284 "BGP view\n"
11285 "BGP view name\n"
11286 "Address family\n"
11287 "Address Family modifier\n"
11288 "Address Family modifier\n"
11289 "Information about Route Server Client\n"
11290 NEIGHBOR_ADDR_STR
11291 "Network in the BGP routing table to display\n")
11292 {
11293 struct bgp *bgp;
11294 struct peer *peer;
11295 safi_t safi;
11296
11297 /* BGP structure lookup. */
11298 if (argc == 4)
11299 {
11300 bgp = bgp_lookup_by_name (argv[0]);
11301 if (bgp == NULL)
11302 {
11303 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11304 return CMD_WARNING;
11305 }
11306 }
11307 else
11308 {
11309 bgp = bgp_get_default ();
11310 if (bgp == NULL)
11311 {
11312 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11313 return CMD_WARNING;
11314 }
11315 }
11316
11317 if (argc == 4) {
11318 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11319 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11320 } else {
11321 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11322 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11323 }
11324
11325 if (! peer)
11326 return CMD_WARNING;
11327
11328 if (! peer->afc[AFI_IP6][safi])
11329 {
11330 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11331 VTY_NEWLINE);
11332 return CMD_WARNING;
11333 }
11334
11335 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11336 PEER_FLAG_RSERVER_CLIENT))
11337 {
11338 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11339 VTY_NEWLINE);
11340 return CMD_WARNING;
11341 }
11342
11343 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11344 (argc == 4) ? argv[3] : argv[2],
11345 AFI_IP6, safi, NULL, 0);
11346 }
11347
11348 ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11349 show_bgp_ipv6_safi_rsclient_route_cmd,
11350 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11351 SHOW_STR
11352 BGP_STR
11353 "Address family\n"
11354 "Address Family modifier\n"
11355 "Address Family modifier\n"
11356 "Information about Route Server Client\n"
11357 NEIGHBOR_ADDR_STR
11358 "Network in the BGP routing table to display\n")
11359
11360 DEFUN (show_bgp_view_rsclient_prefix,
11361 show_bgp_view_rsclient_prefix_cmd,
11362 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11363 SHOW_STR
11364 BGP_STR
11365 "BGP view\n"
11366 "BGP view name\n"
11367 "Information about Route Server Client\n"
11368 NEIGHBOR_ADDR_STR
11369 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11370 {
11371 struct bgp *bgp;
11372 struct peer *peer;
11373
11374 /* BGP structure lookup. */
11375 if (argc == 3)
11376 {
11377 bgp = bgp_lookup_by_name (argv[0]);
11378 if (bgp == NULL)
11379 {
11380 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11381 return CMD_WARNING;
11382 }
11383 }
11384 else
11385 {
11386 bgp = bgp_get_default ();
11387 if (bgp == NULL)
11388 {
11389 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11390 return CMD_WARNING;
11391 }
11392 }
11393
11394 if (argc == 3)
11395 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11396 else
11397 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11398
11399 if (! peer)
11400 return CMD_WARNING;
11401
11402 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11403 {
11404 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11405 VTY_NEWLINE);
11406 return CMD_WARNING;
11407 }
11408
11409 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11410 PEER_FLAG_RSERVER_CLIENT))
11411 {
11412 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11413 VTY_NEWLINE);
11414 return CMD_WARNING;
11415 }
11416
11417 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11418 (argc == 3) ? argv[2] : argv[1],
11419 AFI_IP6, SAFI_UNICAST, NULL, 1);
11420 }
11421
11422 ALIAS (show_bgp_view_rsclient_prefix,
11423 show_bgp_rsclient_prefix_cmd,
11424 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11425 SHOW_STR
11426 BGP_STR
11427 "Information about Route Server Client\n"
11428 NEIGHBOR_ADDR_STR
11429 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11430
11431 DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11432 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11433 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11434 SHOW_STR
11435 BGP_STR
11436 "BGP view\n"
11437 "BGP view name\n"
11438 "Address family\n"
11439 "Address Family modifier\n"
11440 "Address Family modifier\n"
11441 "Information about Route Server Client\n"
11442 NEIGHBOR_ADDR_STR
11443 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11444 {
11445 struct bgp *bgp;
11446 struct peer *peer;
11447 safi_t safi;
11448
11449 /* BGP structure lookup. */
11450 if (argc == 4)
11451 {
11452 bgp = bgp_lookup_by_name (argv[0]);
11453 if (bgp == NULL)
11454 {
11455 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11456 return CMD_WARNING;
11457 }
11458 }
11459 else
11460 {
11461 bgp = bgp_get_default ();
11462 if (bgp == NULL)
11463 {
11464 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11465 return CMD_WARNING;
11466 }
11467 }
11468
11469 if (argc == 4) {
11470 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11471 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11472 } else {
11473 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11474 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11475 }
11476
11477 if (! peer)
11478 return CMD_WARNING;
11479
11480 if (! peer->afc[AFI_IP6][safi])
11481 {
11482 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11483 VTY_NEWLINE);
11484 return CMD_WARNING;
11485 }
11486
11487 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11488 PEER_FLAG_RSERVER_CLIENT))
11489 {
11490 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11491 VTY_NEWLINE);
11492 return CMD_WARNING;
11493 }
11494
11495 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11496 (argc == 4) ? argv[3] : argv[2],
11497 AFI_IP6, safi, NULL, 1);
11498 }
11499
11500 ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11501 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11502 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11503 SHOW_STR
11504 BGP_STR
11505 "Address family\n"
11506 "Address Family modifier\n"
11507 "Address Family modifier\n"
11508 "Information about Route Server Client\n"
11509 NEIGHBOR_ADDR_STR
11510 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11511
11512 #endif /* HAVE_IPV6 */
11513 \f
11514 struct bgp_table *bgp_distance_table;
11515
11516 struct bgp_distance
11517 {
11518 /* Distance value for the IP source prefix. */
11519 u_char distance;
11520
11521 /* Name of the access-list to be matched. */
11522 char *access_list;
11523 };
11524
11525 static struct bgp_distance *
11526 bgp_distance_new (void)
11527 {
11528 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
11529 }
11530
11531 static void
11532 bgp_distance_free (struct bgp_distance *bdistance)
11533 {
11534 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11535 }
11536
11537 static int
11538 bgp_distance_set (struct vty *vty, const char *distance_str,
11539 const char *ip_str, const char *access_list_str)
11540 {
11541 int ret;
11542 struct prefix_ipv4 p;
11543 u_char distance;
11544 struct bgp_node *rn;
11545 struct bgp_distance *bdistance;
11546
11547 ret = str2prefix_ipv4 (ip_str, &p);
11548 if (ret == 0)
11549 {
11550 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11551 return CMD_WARNING;
11552 }
11553
11554 distance = atoi (distance_str);
11555
11556 /* Get BGP distance node. */
11557 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11558 if (rn->info)
11559 {
11560 bdistance = rn->info;
11561 bgp_unlock_node (rn);
11562 }
11563 else
11564 {
11565 bdistance = bgp_distance_new ();
11566 rn->info = bdistance;
11567 }
11568
11569 /* Set distance value. */
11570 bdistance->distance = distance;
11571
11572 /* Reset access-list configuration. */
11573 if (bdistance->access_list)
11574 {
11575 free (bdistance->access_list);
11576 bdistance->access_list = NULL;
11577 }
11578 if (access_list_str)
11579 bdistance->access_list = strdup (access_list_str);
11580
11581 return CMD_SUCCESS;
11582 }
11583
11584 static int
11585 bgp_distance_unset (struct vty *vty, const char *distance_str,
11586 const char *ip_str, const char *access_list_str)
11587 {
11588 int ret;
11589 struct prefix_ipv4 p;
11590 u_char distance;
11591 struct bgp_node *rn;
11592 struct bgp_distance *bdistance;
11593
11594 ret = str2prefix_ipv4 (ip_str, &p);
11595 if (ret == 0)
11596 {
11597 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11598 return CMD_WARNING;
11599 }
11600
11601 distance = atoi (distance_str);
11602
11603 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11604 if (! rn)
11605 {
11606 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11607 return CMD_WARNING;
11608 }
11609
11610 bdistance = rn->info;
11611
11612 if (bdistance->access_list)
11613 free (bdistance->access_list);
11614 bgp_distance_free (bdistance);
11615
11616 rn->info = NULL;
11617 bgp_unlock_node (rn);
11618 bgp_unlock_node (rn);
11619
11620 return CMD_SUCCESS;
11621 }
11622
11623 /* Apply BGP information to distance method. */
11624 u_char
11625 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11626 {
11627 struct bgp_node *rn;
11628 struct prefix_ipv4 q;
11629 struct peer *peer;
11630 struct bgp_distance *bdistance;
11631 struct access_list *alist;
11632 struct bgp_static *bgp_static;
11633
11634 if (! bgp)
11635 return 0;
11636
11637 if (p->family != AF_INET)
11638 return 0;
11639
11640 peer = rinfo->peer;
11641
11642 if (peer->su.sa.sa_family != AF_INET)
11643 return 0;
11644
11645 memset (&q, 0, sizeof (struct prefix_ipv4));
11646 q.family = AF_INET;
11647 q.prefix = peer->su.sin.sin_addr;
11648 q.prefixlen = IPV4_MAX_BITLEN;
11649
11650 /* Check source address. */
11651 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11652 if (rn)
11653 {
11654 bdistance = rn->info;
11655 bgp_unlock_node (rn);
11656
11657 if (bdistance->access_list)
11658 {
11659 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11660 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11661 return bdistance->distance;
11662 }
11663 else
11664 return bdistance->distance;
11665 }
11666
11667 /* Backdoor check. */
11668 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11669 if (rn)
11670 {
11671 bgp_static = rn->info;
11672 bgp_unlock_node (rn);
11673
11674 if (bgp_static->backdoor)
11675 {
11676 if (bgp->distance_local)
11677 return bgp->distance_local;
11678 else
11679 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11680 }
11681 }
11682
11683 if (peer_sort (peer) == BGP_PEER_EBGP)
11684 {
11685 if (bgp->distance_ebgp)
11686 return bgp->distance_ebgp;
11687 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11688 }
11689 else
11690 {
11691 if (bgp->distance_ibgp)
11692 return bgp->distance_ibgp;
11693 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11694 }
11695 }
11696
11697 DEFUN (bgp_distance,
11698 bgp_distance_cmd,
11699 "distance bgp <1-255> <1-255> <1-255>",
11700 "Define an administrative distance\n"
11701 "BGP distance\n"
11702 "Distance for routes external to the AS\n"
11703 "Distance for routes internal to the AS\n"
11704 "Distance for local routes\n")
11705 {
11706 struct bgp *bgp;
11707
11708 bgp = vty->index;
11709
11710 bgp->distance_ebgp = atoi (argv[0]);
11711 bgp->distance_ibgp = atoi (argv[1]);
11712 bgp->distance_local = atoi (argv[2]);
11713 return CMD_SUCCESS;
11714 }
11715
11716 DEFUN (no_bgp_distance,
11717 no_bgp_distance_cmd,
11718 "no distance bgp <1-255> <1-255> <1-255>",
11719 NO_STR
11720 "Define an administrative distance\n"
11721 "BGP distance\n"
11722 "Distance for routes external to the AS\n"
11723 "Distance for routes internal to the AS\n"
11724 "Distance for local routes\n")
11725 {
11726 struct bgp *bgp;
11727
11728 bgp = vty->index;
11729
11730 bgp->distance_ebgp= 0;
11731 bgp->distance_ibgp = 0;
11732 bgp->distance_local = 0;
11733 return CMD_SUCCESS;
11734 }
11735
11736 ALIAS (no_bgp_distance,
11737 no_bgp_distance2_cmd,
11738 "no distance bgp",
11739 NO_STR
11740 "Define an administrative distance\n"
11741 "BGP distance\n")
11742
11743 DEFUN (bgp_distance_source,
11744 bgp_distance_source_cmd,
11745 "distance <1-255> A.B.C.D/M",
11746 "Define an administrative distance\n"
11747 "Administrative distance\n"
11748 "IP source prefix\n")
11749 {
11750 bgp_distance_set (vty, argv[0], argv[1], NULL);
11751 return CMD_SUCCESS;
11752 }
11753
11754 DEFUN (no_bgp_distance_source,
11755 no_bgp_distance_source_cmd,
11756 "no distance <1-255> A.B.C.D/M",
11757 NO_STR
11758 "Define an administrative distance\n"
11759 "Administrative distance\n"
11760 "IP source prefix\n")
11761 {
11762 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11763 return CMD_SUCCESS;
11764 }
11765
11766 DEFUN (bgp_distance_source_access_list,
11767 bgp_distance_source_access_list_cmd,
11768 "distance <1-255> A.B.C.D/M WORD",
11769 "Define an administrative distance\n"
11770 "Administrative distance\n"
11771 "IP source prefix\n"
11772 "Access list name\n")
11773 {
11774 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11775 return CMD_SUCCESS;
11776 }
11777
11778 DEFUN (no_bgp_distance_source_access_list,
11779 no_bgp_distance_source_access_list_cmd,
11780 "no distance <1-255> A.B.C.D/M WORD",
11781 NO_STR
11782 "Define an administrative distance\n"
11783 "Administrative distance\n"
11784 "IP source prefix\n"
11785 "Access list name\n")
11786 {
11787 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11788 return CMD_SUCCESS;
11789 }
11790 \f
11791 DEFUN (bgp_damp_set,
11792 bgp_damp_set_cmd,
11793 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11794 "BGP Specific commands\n"
11795 "Enable route-flap dampening\n"
11796 "Half-life time for the penalty\n"
11797 "Value to start reusing a route\n"
11798 "Value to start suppressing a route\n"
11799 "Maximum duration to suppress a stable route\n")
11800 {
11801 struct bgp *bgp;
11802 int half = DEFAULT_HALF_LIFE * 60;
11803 int reuse = DEFAULT_REUSE;
11804 int suppress = DEFAULT_SUPPRESS;
11805 int max = 4 * half;
11806
11807 if (argc == 4)
11808 {
11809 half = atoi (argv[0]) * 60;
11810 reuse = atoi (argv[1]);
11811 suppress = atoi (argv[2]);
11812 max = atoi (argv[3]) * 60;
11813 }
11814 else if (argc == 1)
11815 {
11816 half = atoi (argv[0]) * 60;
11817 max = 4 * half;
11818 }
11819
11820 bgp = vty->index;
11821 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11822 half, reuse, suppress, max);
11823 }
11824
11825 ALIAS (bgp_damp_set,
11826 bgp_damp_set2_cmd,
11827 "bgp dampening <1-45>",
11828 "BGP Specific commands\n"
11829 "Enable route-flap dampening\n"
11830 "Half-life time for the penalty\n")
11831
11832 ALIAS (bgp_damp_set,
11833 bgp_damp_set3_cmd,
11834 "bgp dampening",
11835 "BGP Specific commands\n"
11836 "Enable route-flap dampening\n")
11837
11838 DEFUN (bgp_damp_unset,
11839 bgp_damp_unset_cmd,
11840 "no bgp dampening",
11841 NO_STR
11842 "BGP Specific commands\n"
11843 "Enable route-flap dampening\n")
11844 {
11845 struct bgp *bgp;
11846
11847 bgp = vty->index;
11848 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11849 }
11850
11851 ALIAS (bgp_damp_unset,
11852 bgp_damp_unset2_cmd,
11853 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11854 NO_STR
11855 "BGP Specific commands\n"
11856 "Enable route-flap dampening\n"
11857 "Half-life time for the penalty\n"
11858 "Value to start reusing a route\n"
11859 "Value to start suppressing a route\n"
11860 "Maximum duration to suppress a stable route\n")
11861
11862 DEFUN (show_ip_bgp_dampened_paths,
11863 show_ip_bgp_dampened_paths_cmd,
11864 "show ip bgp dampened-paths",
11865 SHOW_STR
11866 IP_STR
11867 BGP_STR
11868 "Display paths suppressed due to dampening\n")
11869 {
11870 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11871 NULL);
11872 }
11873
11874 DEFUN (show_ip_bgp_flap_statistics,
11875 show_ip_bgp_flap_statistics_cmd,
11876 "show ip bgp flap-statistics",
11877 SHOW_STR
11878 IP_STR
11879 BGP_STR
11880 "Display flap statistics of routes\n")
11881 {
11882 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11883 bgp_show_type_flap_statistics, NULL);
11884 }
11885 \f
11886 /* Display specified route of BGP table. */
11887 static int
11888 bgp_clear_damp_route (struct vty *vty, const char *view_name,
11889 const char *ip_str, afi_t afi, safi_t safi,
11890 struct prefix_rd *prd, int prefix_check)
11891 {
11892 int ret;
11893 struct prefix match;
11894 struct bgp_node *rn;
11895 struct bgp_node *rm;
11896 struct bgp_info *ri;
11897 struct bgp_info *ri_temp;
11898 struct bgp *bgp;
11899 struct bgp_table *table;
11900
11901 /* BGP structure lookup. */
11902 if (view_name)
11903 {
11904 bgp = bgp_lookup_by_name (view_name);
11905 if (bgp == NULL)
11906 {
11907 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11908 return CMD_WARNING;
11909 }
11910 }
11911 else
11912 {
11913 bgp = bgp_get_default ();
11914 if (bgp == NULL)
11915 {
11916 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11917 return CMD_WARNING;
11918 }
11919 }
11920
11921 /* Check IP address argument. */
11922 ret = str2prefix (ip_str, &match);
11923 if (! ret)
11924 {
11925 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11926 return CMD_WARNING;
11927 }
11928
11929 match.family = afi2family (afi);
11930
11931 if (safi == SAFI_MPLS_VPN)
11932 {
11933 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11934 {
11935 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11936 continue;
11937
11938 if ((table = rn->info) != NULL)
11939 if ((rm = bgp_node_match (table, &match)) != NULL)
11940 {
11941 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11942 {
11943 ri = rm->info;
11944 while (ri)
11945 {
11946 if (ri->extra && ri->extra->damp_info)
11947 {
11948 ri_temp = ri->next;
11949 bgp_damp_info_free (ri->extra->damp_info, 1);
11950 ri = ri_temp;
11951 }
11952 else
11953 ri = ri->next;
11954 }
11955 }
11956
11957 bgp_unlock_node (rm);
11958 }
11959 }
11960 }
11961 else
11962 {
11963 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11964 {
11965 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11966 {
11967 ri = rn->info;
11968 while (ri)
11969 {
11970 if (ri->extra && ri->extra->damp_info)
11971 {
11972 ri_temp = ri->next;
11973 bgp_damp_info_free (ri->extra->damp_info, 1);
11974 ri = ri_temp;
11975 }
11976 else
11977 ri = ri->next;
11978 }
11979 }
11980
11981 bgp_unlock_node (rn);
11982 }
11983 }
11984
11985 return CMD_SUCCESS;
11986 }
11987
11988 DEFUN (clear_ip_bgp_dampening,
11989 clear_ip_bgp_dampening_cmd,
11990 "clear ip bgp dampening",
11991 CLEAR_STR
11992 IP_STR
11993 BGP_STR
11994 "Clear route flap dampening information\n")
11995 {
11996 bgp_damp_info_clean ();
11997 return CMD_SUCCESS;
11998 }
11999
12000 DEFUN (clear_ip_bgp_dampening_prefix,
12001 clear_ip_bgp_dampening_prefix_cmd,
12002 "clear ip bgp dampening A.B.C.D/M",
12003 CLEAR_STR
12004 IP_STR
12005 BGP_STR
12006 "Clear route flap dampening information\n"
12007 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12008 {
12009 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12010 SAFI_UNICAST, NULL, 1);
12011 }
12012
12013 DEFUN (clear_ip_bgp_dampening_address,
12014 clear_ip_bgp_dampening_address_cmd,
12015 "clear ip bgp dampening A.B.C.D",
12016 CLEAR_STR
12017 IP_STR
12018 BGP_STR
12019 "Clear route flap dampening information\n"
12020 "Network to clear damping information\n")
12021 {
12022 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12023 SAFI_UNICAST, NULL, 0);
12024 }
12025
12026 DEFUN (clear_ip_bgp_dampening_address_mask,
12027 clear_ip_bgp_dampening_address_mask_cmd,
12028 "clear ip bgp dampening A.B.C.D A.B.C.D",
12029 CLEAR_STR
12030 IP_STR
12031 BGP_STR
12032 "Clear route flap dampening information\n"
12033 "Network to clear damping information\n"
12034 "Network mask\n")
12035 {
12036 int ret;
12037 char prefix_str[BUFSIZ];
12038
12039 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12040 if (! ret)
12041 {
12042 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12043 return CMD_WARNING;
12044 }
12045
12046 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12047 SAFI_UNICAST, NULL, 0);
12048 }
12049 \f
12050 static int
12051 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12052 afi_t afi, safi_t safi, int *write)
12053 {
12054 struct bgp_node *prn;
12055 struct bgp_node *rn;
12056 struct bgp_table *table;
12057 struct prefix *p;
12058 struct prefix_rd *prd;
12059 struct bgp_static *bgp_static;
12060 u_int32_t label;
12061 char buf[SU_ADDRSTRLEN];
12062 char rdbuf[RD_ADDRSTRLEN];
12063
12064 /* Network configuration. */
12065 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12066 if ((table = prn->info) != NULL)
12067 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12068 if ((bgp_static = rn->info) != NULL)
12069 {
12070 p = &rn->p;
12071 prd = (struct prefix_rd *) &prn->p;
12072
12073 /* "address-family" display. */
12074 bgp_config_write_family_header (vty, afi, safi, write);
12075
12076 /* "network" configuration display. */
12077 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12078 label = decode_label (bgp_static->tag);
12079
12080 vty_out (vty, " network %s/%d rd %s tag %d",
12081 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12082 p->prefixlen,
12083 rdbuf, label);
12084 vty_out (vty, "%s", VTY_NEWLINE);
12085 }
12086 return 0;
12087 }
12088
12089 /* Configuration of static route announcement and aggregate
12090 information. */
12091 int
12092 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12093 afi_t afi, safi_t safi, int *write)
12094 {
12095 struct bgp_node *rn;
12096 struct prefix *p;
12097 struct bgp_static *bgp_static;
12098 struct bgp_aggregate *bgp_aggregate;
12099 char buf[SU_ADDRSTRLEN];
12100
12101 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12102 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12103
12104 /* Network configuration. */
12105 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12106 if ((bgp_static = rn->info) != NULL)
12107 {
12108 p = &rn->p;
12109
12110 /* "address-family" display. */
12111 bgp_config_write_family_header (vty, afi, safi, write);
12112
12113 /* "network" configuration display. */
12114 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12115 {
12116 u_int32_t destination;
12117 struct in_addr netmask;
12118
12119 destination = ntohl (p->u.prefix4.s_addr);
12120 masklen2ip (p->prefixlen, &netmask);
12121 vty_out (vty, " network %s",
12122 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12123
12124 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12125 || (IN_CLASSB (destination) && p->prefixlen == 16)
12126 || (IN_CLASSA (destination) && p->prefixlen == 8)
12127 || p->u.prefix4.s_addr == 0)
12128 {
12129 /* Natural mask is not display. */
12130 }
12131 else
12132 vty_out (vty, " mask %s", inet_ntoa (netmask));
12133 }
12134 else
12135 {
12136 vty_out (vty, " network %s/%d",
12137 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12138 p->prefixlen);
12139 }
12140
12141 if (bgp_static->rmap.name)
12142 vty_out (vty, " route-map %s", bgp_static->rmap.name);
12143 else
12144 {
12145 if (bgp_static->backdoor)
12146 vty_out (vty, " backdoor");
12147 }
12148
12149 vty_out (vty, "%s", VTY_NEWLINE);
12150 }
12151
12152 /* Aggregate-address configuration. */
12153 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12154 if ((bgp_aggregate = rn->info) != NULL)
12155 {
12156 p = &rn->p;
12157
12158 /* "address-family" display. */
12159 bgp_config_write_family_header (vty, afi, safi, write);
12160
12161 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12162 {
12163 struct in_addr netmask;
12164
12165 masklen2ip (p->prefixlen, &netmask);
12166 vty_out (vty, " aggregate-address %s %s",
12167 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12168 inet_ntoa (netmask));
12169 }
12170 else
12171 {
12172 vty_out (vty, " aggregate-address %s/%d",
12173 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12174 p->prefixlen);
12175 }
12176
12177 if (bgp_aggregate->as_set)
12178 vty_out (vty, " as-set");
12179
12180 if (bgp_aggregate->summary_only)
12181 vty_out (vty, " summary-only");
12182
12183 vty_out (vty, "%s", VTY_NEWLINE);
12184 }
12185
12186 return 0;
12187 }
12188
12189 int
12190 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12191 {
12192 struct bgp_node *rn;
12193 struct bgp_distance *bdistance;
12194
12195 /* Distance configuration. */
12196 if (bgp->distance_ebgp
12197 && bgp->distance_ibgp
12198 && bgp->distance_local
12199 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12200 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12201 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12202 vty_out (vty, " distance bgp %d %d %d%s",
12203 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12204 VTY_NEWLINE);
12205
12206 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12207 if ((bdistance = rn->info) != NULL)
12208 {
12209 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12210 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12211 bdistance->access_list ? bdistance->access_list : "",
12212 VTY_NEWLINE);
12213 }
12214
12215 return 0;
12216 }
12217
12218 /* Allocate routing table structure and install commands. */
12219 void
12220 bgp_route_init (void)
12221 {
12222 /* Init BGP distance table. */
12223 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
12224
12225 /* IPv4 BGP commands. */
12226 install_element (BGP_NODE, &bgp_network_cmd);
12227 install_element (BGP_NODE, &bgp_network_mask_cmd);
12228 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12229 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12230 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12231 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12232 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12233 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12234 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12235 install_element (BGP_NODE, &no_bgp_network_cmd);
12236 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12237 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12238 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12239 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12240 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12241 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12242 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12243 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12244
12245 install_element (BGP_NODE, &aggregate_address_cmd);
12246 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12247 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12248 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12249 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12250 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12251 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12252 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12253 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12254 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12255 install_element (BGP_NODE, &no_aggregate_address_cmd);
12256 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12257 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12258 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12259 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12260 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12261 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12262 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12263 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12264 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12265
12266 /* IPv4 unicast configuration. */
12267 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12268 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12269 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12270 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12271 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12272 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
12273 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
12274 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12275 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12276 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12277 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12278 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12279
12280 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12281 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12282 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12283 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12284 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12285 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12286 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12287 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12288 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12289 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12290 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12291 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12292 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12293 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12294 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12295 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12296 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12297 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12298 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12299 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12300
12301 /* IPv4 multicast configuration. */
12302 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12303 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12304 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12305 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12306 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12307 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12308 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12309 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12310 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12311 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12312 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12313 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12314 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12315 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12316 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12317 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12318 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12319 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12320 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12321 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12322 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12323 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12324 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12325 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12326 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12327 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12328 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12329 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12330 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12331 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12332 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12333 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12334
12335 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12336 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
12337 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
12338 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12339 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
12340 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
12341 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12342 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12343 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12344 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
12345 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
12346 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12347 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12348 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12349 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12350 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12351 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12352 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12353 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12354 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12355 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12356 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12357 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12358 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12359 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12360 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12361 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12362 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12363 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12364 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12365 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12366 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12367 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12368 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12369 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12370 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
12371 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12372 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12373 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12374 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12375 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
12376 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12377 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12378 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12379 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12380 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12381 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12382 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12383 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12384 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12385 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12386 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12387 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12388 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12389 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12390 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12391 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12392 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12393 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
12394 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
12395 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12396 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12397 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12398 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12399 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12400 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12401 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12402 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12403 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12404 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12405 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12406 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12407 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12408 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12409 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12410 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
12411 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
12412 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
12413 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
12414 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
12415 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
12416 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
12417 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12418 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
12419 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
12420 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
12421 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
12422 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
12423 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
12424 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
12425
12426 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12427 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12428 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
12429 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
12430 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12431 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12432 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
12433 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
12434 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12435 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12436 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12437 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12438 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12439 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12440 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12441 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12442 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12443 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12444 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12445 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
12446 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12447 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12448 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12449 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12450 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
12451 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12452 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12453 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12454 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12455 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12456 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12457 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12458 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12459 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
12460 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
12461 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
12462 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
12463 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
12464 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
12465 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
12466 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
12467
12468 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12469 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
12470 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
12471 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12472 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
12473 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
12474 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12475 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12476 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12477 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
12478 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
12479 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12480 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12481 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12482 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12483 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12484 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12485 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12486 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12487 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12488 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12489 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12490 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12491 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12492 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12493 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12494 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12495 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12496 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12497 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12498 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12499 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12500 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12501 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12502 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12503 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
12504 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12505 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12506 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12507 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12508 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
12509 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12510 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12511 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12512 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12513 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12514 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12515 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12516 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12517 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12518 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12519 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12520 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12521 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12522 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12523 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12524 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12525 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12526 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
12527 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
12528 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12529 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12530 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12531 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12532 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12533 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12534 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12535 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12536 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12537 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12538 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12539 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12540 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12541 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12542 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12543 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
12544 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
12545 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
12546 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
12547 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
12548 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
12549 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
12550 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12551 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
12552 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
12553 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
12554 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
12555 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
12556 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
12557 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
12558
12559 /* BGP dampening clear commands */
12560 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12561 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12562 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12563 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12564
12565 /* prefix count */
12566 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12567 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12568 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
12569 #ifdef HAVE_IPV6
12570 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12571
12572 /* New config IPv6 BGP commands. */
12573 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12574 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12575 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12576 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12577
12578 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12579 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12580 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12581 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12582
12583 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12584 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12585
12586 /* Old config IPv6 BGP commands. */
12587 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12588 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12589
12590 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12591 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12592 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12593 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12594
12595 install_element (VIEW_NODE, &show_bgp_cmd);
12596 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
12597 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
12598 install_element (VIEW_NODE, &show_bgp_route_cmd);
12599 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
12600 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
12601 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12602 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
12603 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
12604 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12605 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12606 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12607 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12608 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12609 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12610 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12611 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12612 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12613 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12614 install_element (VIEW_NODE, &show_bgp_community_cmd);
12615 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12616 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12617 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12618 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12619 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12620 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12621 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12622 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12623 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12624 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12625 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12626 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12627 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12628 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12629 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12630 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12631 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12632 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12633 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12634 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12635 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12636 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12637 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12638 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12639 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12640 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12641 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12642 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12643 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
12644 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12645 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12646 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12647 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
12648 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
12649 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
12650 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
12651 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
12652 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
12653 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
12654 install_element (VIEW_NODE, &show_bgp_view_cmd);
12655 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12656 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12657 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12658 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12659 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12660 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12661 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12662 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12663 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12664 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12665 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12666 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12667 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12668 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12669 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12670 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12671 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
12672 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
12673 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
12674 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
12675 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
12676 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
12677 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
12678
12679 /* Restricted:
12680 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12681 */
12682 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12683 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
12684 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
12685 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12686 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
12687 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
12688 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12689 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12690 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12691 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12692 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12693 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12694 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12695 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12696 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12697 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12698 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12699 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12700 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12701 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12702 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12703 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12704 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
12705 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
12706 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
12707 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
12708 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12709 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12710 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12711 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12712 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12713 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12714 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
12715 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
12716 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
12717 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
12718
12719 install_element (ENABLE_NODE, &show_bgp_cmd);
12720 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
12721 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
12722 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12723 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
12724 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
12725 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12726 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
12727 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
12728 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12729 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12730 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12731 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12732 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12733 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12734 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12735 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12736 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12737 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12738 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12739 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12740 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12741 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12742 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12743 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12744 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12745 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12746 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12747 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12748 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12749 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12750 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12751 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12752 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12753 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12754 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12755 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12756 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12757 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12758 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12759 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12760 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12761 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12762 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12763 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12764 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12765 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12766 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12767 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
12768 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12769 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12770 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12771 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
12772 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12773 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
12774 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12775 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
12776 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
12777 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
12778 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12779 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12780 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12781 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12782 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12783 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12784 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12785 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12786 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12787 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12788 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12789 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12790 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12791 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12792 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12793 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12794 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12795 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
12796 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12797 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
12798 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12799 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
12800 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
12801 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
12802
12803 /* Statistics */
12804 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12805 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12806 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12807 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12808
12809 /* old command */
12810 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12811 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12812 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12813 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12814 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12815 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12816 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12817 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12818 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12819 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12820 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12821 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12822 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12823 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12824 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12825 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12826 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12827 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12828 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12829 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12830 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12831 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12832 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12833 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12834 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12835 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12836 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12837 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12838 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12839 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12840 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12841 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12842 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12843 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12844 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12845 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12846
12847 /* old command */
12848 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12849 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12850 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12851 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12852 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12853 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12854 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12855 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12856 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12857 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12858 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12859 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12860 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12861 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12862 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12863 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12864 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12865 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12866 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12867 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12868 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12869 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12870 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12871 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12872 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12873 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12874 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12875 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12876 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12877 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12878 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12879 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12880 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12881 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12882 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12883 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12884
12885 /* old command */
12886 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12887 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12888 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12889 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12890
12891 /* old command */
12892 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12893 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12894 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12895 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12896
12897 /* old command */
12898 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12899 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12900 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12901 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12902 #endif /* HAVE_IPV6 */
12903
12904 install_element (BGP_NODE, &bgp_distance_cmd);
12905 install_element (BGP_NODE, &no_bgp_distance_cmd);
12906 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12907 install_element (BGP_NODE, &bgp_distance_source_cmd);
12908 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12909 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12910 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12911
12912 install_element (BGP_NODE, &bgp_damp_set_cmd);
12913 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12914 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12915 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12916 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12917 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12918 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12919 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12920 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12921 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
12922
12923 /* Deprecated AS-Pathlimit commands */
12924 install_element (BGP_NODE, &bgp_network_ttl_cmd);
12925 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
12926 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
12927 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
12928 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12929 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12930
12931 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
12932 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
12933 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12934 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
12935 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12936 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12937
12938 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
12939 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
12940 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
12941 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
12942 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12943 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12944
12945 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
12946 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
12947 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12948 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
12949 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12950 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12951
12952 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
12953 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
12954 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
12955 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
12956 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12957 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12958
12959 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
12960 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
12961 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12962 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
12963 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12964 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12965
12966 #ifdef HAVE_IPV6
12967 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
12968 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
12969 #endif
12970 }
12971
12972 void
12973 bgp_route_finish (void)
12974 {
12975 bgp_table_unlock (bgp_distance_table);
12976 bgp_distance_table = NULL;
12977 }