]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
BGP: add addpath RX support
[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 #include "bgpd/bgp_mpath.h"
58 #include "bgpd/bgp_nht.h"
59
60 /* Extern from bgp_dump.c */
61 extern const char *bgp_origin_str[];
62 extern const char *bgp_origin_long_str[];
63 char csv = ',';
64
65 static struct bgp_node *
66 bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
67 struct prefix_rd *prd)
68 {
69 struct bgp_node *rn;
70 struct bgp_node *prn = NULL;
71
72 assert (table);
73 if (!table)
74 return NULL;
75
76 if (safi == SAFI_MPLS_VPN)
77 {
78 prn = bgp_node_get (table, (struct prefix *) prd);
79
80 if (prn->info == NULL)
81 prn->info = bgp_table_init (afi, safi);
82 else
83 bgp_unlock_node (prn);
84 table = prn->info;
85 }
86
87 rn = bgp_node_get (table, p);
88
89 if (safi == SAFI_MPLS_VPN)
90 rn->prn = prn;
91
92 return rn;
93 }
94
95 /* Allocate bgp_info_extra */
96 static struct bgp_info_extra *
97 bgp_info_extra_new (void)
98 {
99 struct bgp_info_extra *new;
100 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
101 return new;
102 }
103
104 static void
105 bgp_info_extra_free (struct bgp_info_extra **extra)
106 {
107 if (extra && *extra)
108 {
109 if ((*extra)->damp_info)
110 bgp_damp_info_free ((*extra)->damp_info, 0);
111
112 (*extra)->damp_info = NULL;
113
114 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
115
116 *extra = NULL;
117 }
118 }
119
120 /* Get bgp_info extra information for the given bgp_info, lazy allocated
121 * if required.
122 */
123 struct bgp_info_extra *
124 bgp_info_extra_get (struct bgp_info *ri)
125 {
126 if (!ri->extra)
127 ri->extra = bgp_info_extra_new();
128 return ri->extra;
129 }
130
131 /* Free bgp route information. */
132 static void
133 bgp_info_free (struct bgp_info *binfo)
134 {
135 if (binfo->attr)
136 bgp_attr_unintern (&binfo->attr);
137
138 bgp_unlink_nexthop(binfo);
139 bgp_info_extra_free (&binfo->extra);
140 bgp_info_mpath_free (&binfo->mpath);
141
142 peer_unlock (binfo->peer); /* bgp_info peer reference */
143
144 XFREE (MTYPE_BGP_ROUTE, binfo);
145 }
146
147 struct bgp_info *
148 bgp_info_lock (struct bgp_info *binfo)
149 {
150 binfo->lock++;
151 return binfo;
152 }
153
154 struct bgp_info *
155 bgp_info_unlock (struct bgp_info *binfo)
156 {
157 assert (binfo && binfo->lock > 0);
158 binfo->lock--;
159
160 if (binfo->lock == 0)
161 {
162 #if 0
163 zlog_debug ("%s: unlocked and freeing", __func__);
164 zlog_backtrace (LOG_DEBUG);
165 #endif
166 bgp_info_free (binfo);
167 return NULL;
168 }
169
170 #if 0
171 if (binfo->lock == 1)
172 {
173 zlog_debug ("%s: unlocked to 1", __func__);
174 zlog_backtrace (LOG_DEBUG);
175 }
176 #endif
177
178 return binfo;
179 }
180
181 void
182 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
183 {
184 struct bgp_info *top;
185
186 top = rn->info;
187
188 ri->next = rn->info;
189 ri->prev = NULL;
190 if (top)
191 top->prev = ri;
192 rn->info = ri;
193
194 bgp_info_lock (ri);
195 bgp_lock_node (rn);
196 peer_lock (ri->peer); /* bgp_info peer reference */
197 }
198
199 /* Do the actual removal of info from RIB, for use by bgp_process
200 completion callback *only* */
201 static void
202 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
203 {
204 if (ri->next)
205 ri->next->prev = ri->prev;
206 if (ri->prev)
207 ri->prev->next = ri->next;
208 else
209 rn->info = ri->next;
210
211 bgp_info_mpath_dequeue (ri);
212 bgp_info_unlock (ri);
213 bgp_unlock_node (rn);
214 }
215
216 void
217 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
218 {
219 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
220 /* set of previous already took care of pcount */
221 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
222 }
223
224 /* undo the effects of a previous call to bgp_info_delete; typically
225 called when a route is deleted and then quickly re-added before the
226 deletion has been processed */
227 static void
228 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
229 {
230 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
231 /* unset of previous already took care of pcount */
232 SET_FLAG (ri->flags, BGP_INFO_VALID);
233 }
234
235 /* Adjust pcount as required */
236 static void
237 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
238 {
239 struct bgp_table *table;
240
241 assert (rn && bgp_node_table (rn));
242 assert (ri && ri->peer && ri->peer->bgp);
243
244 table = bgp_node_table (rn);
245
246 /* Ignore 'pcount' for RS-client tables */
247 if (table->type != BGP_TABLE_MAIN
248 || ri->peer == ri->peer->bgp->peer_self)
249 return;
250
251 if (!BGP_INFO_COUNTABLE (ri)
252 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
253 {
254
255 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
256
257 /* slight hack, but more robust against errors. */
258 if (ri->peer->pcount[table->afi][table->safi])
259 ri->peer->pcount[table->afi][table->safi]--;
260 else
261 {
262 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
263 __func__, ri->peer->host);
264 zlog_backtrace (LOG_WARNING);
265 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
266 }
267 }
268 else if (BGP_INFO_COUNTABLE (ri)
269 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
270 {
271 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
272 ri->peer->pcount[table->afi][table->safi]++;
273 }
274 }
275
276
277 /* Set/unset bgp_info flags, adjusting any other state as needed.
278 * This is here primarily to keep prefix-count in check.
279 */
280 void
281 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
282 {
283 SET_FLAG (ri->flags, flag);
284
285 /* early bath if we know it's not a flag that changes countability state */
286 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
287 return;
288
289 bgp_pcount_adjust (rn, ri);
290 }
291
292 void
293 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
294 {
295 UNSET_FLAG (ri->flags, flag);
296
297 /* early bath if we know it's not a flag that changes countability state */
298 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
299 return;
300
301 bgp_pcount_adjust (rn, ri);
302 }
303
304 /* Get MED value. If MED value is missing and "bgp bestpath
305 missing-as-worst" is specified, treat it as the worst value. */
306 static u_int32_t
307 bgp_med_value (struct attr *attr, struct bgp *bgp)
308 {
309 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
310 return attr->med;
311 else
312 {
313 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
314 return BGP_MED_MAX;
315 else
316 return 0;
317 }
318 }
319
320 /* Compare two bgp route entity. br is preferable then return 1. */
321 static int
322 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
323 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg)
324 {
325 struct attr *newattr, *existattr;
326 struct attr_extra *newattre, *existattre;
327 bgp_peer_sort_t new_sort;
328 bgp_peer_sort_t exist_sort;
329 u_int32_t new_pref;
330 u_int32_t exist_pref;
331 u_int32_t new_med;
332 u_int32_t exist_med;
333 u_int32_t new_weight;
334 u_int32_t exist_weight;
335 uint32_t newm, existm;
336 struct in_addr new_id;
337 struct in_addr exist_id;
338 int new_cluster;
339 int exist_cluster;
340 int internal_as_route;
341 int confed_as_route;
342 int ret;
343
344 *paths_eq = 0;
345
346 /* 0. Null check. */
347 if (new == NULL)
348 return 0;
349 if (exist == NULL)
350 return 1;
351
352 newattr = new->attr;
353 existattr = exist->attr;
354 newattre = newattr->extra;
355 existattre = existattr->extra;
356
357 /* 1. Weight check. */
358 new_weight = exist_weight = 0;
359
360 if (newattre)
361 new_weight = newattre->weight;
362 if (existattre)
363 exist_weight = existattre->weight;
364
365 if (new_weight > exist_weight)
366 return 1;
367 if (new_weight < exist_weight)
368 return 0;
369
370 /* 2. Local preference check. */
371 new_pref = exist_pref = bgp->default_local_pref;
372
373 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
374 new_pref = newattr->local_pref;
375 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
376 exist_pref = existattr->local_pref;
377
378 if (new_pref > exist_pref)
379 return 1;
380 if (new_pref < exist_pref)
381 return 0;
382
383 /* 3. Local route check. We prefer:
384 * - BGP_ROUTE_STATIC
385 * - BGP_ROUTE_AGGREGATE
386 * - BGP_ROUTE_REDISTRIBUTE
387 */
388 if (! (new->sub_type == BGP_ROUTE_NORMAL))
389 return 1;
390 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
391 return 0;
392
393 /* 4. AS path length check. */
394 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
395 {
396 int exist_hops = aspath_count_hops (existattr->aspath);
397 int exist_confeds = aspath_count_confeds (existattr->aspath);
398
399 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
400 {
401 int aspath_hops;
402
403 aspath_hops = aspath_count_hops (newattr->aspath);
404 aspath_hops += aspath_count_confeds (newattr->aspath);
405
406 if ( aspath_hops < (exist_hops + exist_confeds))
407 return 1;
408 if ( aspath_hops > (exist_hops + exist_confeds))
409 return 0;
410 }
411 else
412 {
413 int newhops = aspath_count_hops (newattr->aspath);
414
415 if (newhops < exist_hops)
416 return 1;
417 if (newhops > exist_hops)
418 return 0;
419 }
420 }
421
422 /* 5. Origin check. */
423 if (newattr->origin < existattr->origin)
424 return 1;
425 if (newattr->origin > existattr->origin)
426 return 0;
427
428 /* 6. MED check. */
429 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
430 && aspath_count_hops (existattr->aspath) == 0);
431 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
432 && aspath_count_confeds (existattr->aspath) > 0
433 && aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
435
436 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
437 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
438 && confed_as_route)
439 || aspath_cmp_left (newattr->aspath, existattr->aspath)
440 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
441 || internal_as_route)
442 {
443 new_med = bgp_med_value (new->attr, bgp);
444 exist_med = bgp_med_value (exist->attr, bgp);
445
446 if (new_med < exist_med)
447 return 1;
448 if (new_med > exist_med)
449 return 0;
450 }
451
452 /* 7. Peer type check. */
453 new_sort = new->peer->sort;
454 exist_sort = exist->peer->sort;
455
456 if (new_sort == BGP_PEER_EBGP
457 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
458 return 1;
459 if (exist_sort == BGP_PEER_EBGP
460 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
461 return 0;
462
463 /* 8. IGP metric check. */
464 newm = existm = 0;
465
466 if (new->extra)
467 newm = new->extra->igpmetric;
468 if (exist->extra)
469 existm = exist->extra->igpmetric;
470
471 if (newm < existm)
472 ret = 1;
473 if (newm > existm)
474 ret = 0;
475
476 /* 8.1. Same IGP metric. Compare the cluster list length as
477 representative of IGP hops metric. Rewrite the metric value
478 pair (newm, existm) with the cluster list length. Prefer the
479 path with smaller cluster list length. */
480 if (newm == existm)
481 {
482 if (peer_sort (new->peer) == BGP_PEER_IBGP
483 && peer_sort (exist->peer) == BGP_PEER_IBGP
484 && CHECK_FLAG (mpath_cfg->ibgp_flags,
485 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
486 {
487 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
488 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
489 if (newm < existm)
490 ret = 1;
491 if (newm > existm)
492 ret = 0;
493 }
494 }
495
496 /* 9. Maximum path check. */
497 if (newm == existm)
498 {
499 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
500 {
501
502 /*
503 * For the two paths, all comparison steps till IGP metric
504 * have succeeded - including AS_PATH hop count. Since 'bgp
505 * bestpath as-path multipath-relax' knob is on, we don't need
506 * an exact match of AS_PATH. Thus, mark the paths are equal.
507 * That will trigger both these paths to get into the multipath
508 * array.
509 */
510 *paths_eq = 1;
511 }
512 else if (new->peer->sort == BGP_PEER_IBGP)
513 {
514 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
515 *paths_eq = 1;
516 }
517 else if (new->peer->as == exist->peer->as)
518 *paths_eq = 1;
519 }
520 else
521 {
522 /*
523 * TODO: If unequal cost ibgp multipath is enabled we can
524 * mark the paths as equal here instead of returning
525 */
526 return ret;
527 }
528
529 /* 10. If both paths are external, prefer the path that was received
530 first (the oldest one). This step minimizes route-flap, since a
531 newer path won't displace an older one, even if it was the
532 preferred route based on the additional decision criteria below. */
533 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
534 && new_sort == BGP_PEER_EBGP
535 && exist_sort == BGP_PEER_EBGP)
536 {
537 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
538 return 1;
539 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
540 return 0;
541 }
542
543 /* 11. Router-ID comparision. */
544 /* If one of the paths is "stale", the corresponding peer router-id will
545 * be 0 and would always win over the other path. If originator id is
546 * used for the comparision, it will decide which path is better.
547 */
548 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
549 new_id.s_addr = newattre->originator_id.s_addr;
550 else
551 new_id.s_addr = new->peer->remote_id.s_addr;
552 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
553 exist_id.s_addr = existattre->originator_id.s_addr;
554 else
555 exist_id.s_addr = exist->peer->remote_id.s_addr;
556
557 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
558 return 1;
559 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
560 return 0;
561
562 /* 12. Cluster length comparision. */
563 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
564 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
565
566 if (new_cluster < exist_cluster)
567 return 1;
568 if (new_cluster > exist_cluster)
569 return 0;
570
571 /* 13. Neighbor address comparision. */
572 /* Do this only if neither path is "stale" as stale paths do not have
573 * valid peer information (as the connection may or may not be up).
574 */
575 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
576 return 1;
577 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
578 return 0;
579
580 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
581
582 if (ret == 1)
583 return 0;
584 if (ret == -1)
585 return 1;
586
587 return 1;
588 }
589
590 static enum filter_type
591 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
592 afi_t afi, safi_t safi)
593 {
594 struct bgp_filter *filter;
595
596 filter = &peer->filter[afi][safi];
597
598 #define FILTER_EXIST_WARN(F,f,filter) \
599 if (BGP_DEBUG (update, UPDATE_IN) \
600 && !(F ## _IN (filter))) \
601 zlog_warn ("%s: Could not find configured input %s-list %s!", \
602 peer->host, #f, F ## _IN_NAME(filter));
603
604 if (DISTRIBUTE_IN_NAME (filter)) {
605 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
606
607 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
608 return FILTER_DENY;
609 }
610
611 if (PREFIX_LIST_IN_NAME (filter)) {
612 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
613
614 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
615 return FILTER_DENY;
616 }
617
618 if (FILTER_LIST_IN_NAME (filter)) {
619 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
620
621 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
622 return FILTER_DENY;
623 }
624
625 return FILTER_PERMIT;
626 #undef FILTER_EXIST_WARN
627 }
628
629 static enum filter_type
630 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
631 afi_t afi, safi_t safi)
632 {
633 struct bgp_filter *filter;
634
635 filter = &peer->filter[afi][safi];
636
637 #define FILTER_EXIST_WARN(F,f,filter) \
638 if (BGP_DEBUG (update, UPDATE_OUT) \
639 && !(F ## _OUT (filter))) \
640 zlog_warn ("%s: Could not find configured output %s-list %s!", \
641 peer->host, #f, F ## _OUT_NAME(filter));
642
643 if (DISTRIBUTE_OUT_NAME (filter)) {
644 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
645
646 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
647 return FILTER_DENY;
648 }
649
650 if (PREFIX_LIST_OUT_NAME (filter)) {
651 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
652
653 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
654 return FILTER_DENY;
655 }
656
657 if (FILTER_LIST_OUT_NAME (filter)) {
658 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
659
660 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
661 return FILTER_DENY;
662 }
663
664 return FILTER_PERMIT;
665 #undef FILTER_EXIST_WARN
666 }
667
668 /* If community attribute includes no_export then return 1. */
669 static int
670 bgp_community_filter (struct peer *peer, struct attr *attr)
671 {
672 if (attr->community)
673 {
674 /* NO_ADVERTISE check. */
675 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
676 return 1;
677
678 /* NO_EXPORT check. */
679 if (peer->sort == BGP_PEER_EBGP &&
680 community_include (attr->community, COMMUNITY_NO_EXPORT))
681 return 1;
682
683 /* NO_EXPORT_SUBCONFED check. */
684 if (peer->sort == BGP_PEER_EBGP
685 || peer->sort == BGP_PEER_CONFED)
686 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
687 return 1;
688 }
689 return 0;
690 }
691
692 /* Route reflection loop check. */
693 static int
694 bgp_cluster_filter (struct peer *peer, struct attr *attr)
695 {
696 struct in_addr cluster_id;
697
698 if (attr->extra && attr->extra->cluster)
699 {
700 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
701 cluster_id = peer->bgp->cluster_id;
702 else
703 cluster_id = peer->bgp->router_id;
704
705 if (cluster_loop_check (attr->extra->cluster, cluster_id))
706 return 1;
707 }
708 return 0;
709 }
710
711 static int
712 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
713 afi_t afi, safi_t safi, char *rmap_name)
714 {
715 struct bgp_filter *filter;
716 struct bgp_info info;
717 route_map_result_t ret;
718 struct route_map *rmap = NULL;
719
720 filter = &peer->filter[afi][safi];
721
722 /* Apply default weight value. */
723 if (peer->weight)
724 (bgp_attr_extra_get (attr))->weight = peer->weight;
725
726 if (rmap_name)
727 {
728 rmap = route_map_lookup_by_name(rmap_name);
729 }
730 else
731 {
732 if (ROUTE_MAP_IN_NAME(filter))
733 rmap = ROUTE_MAP_IN (filter);
734 }
735
736 /* Route map apply. */
737 if (rmap)
738 {
739 /* Duplicate current value to new strucutre for modification. */
740 info.peer = peer;
741 info.attr = attr;
742
743 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
744
745 /* Apply BGP route map to the attribute. */
746 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
747
748 peer->rmap_type = 0;
749
750 if (ret == RMAP_DENYMATCH)
751 {
752 /* Free newly generated AS path and community by route-map. */
753 bgp_attr_flush (attr);
754 return RMAP_DENY;
755 }
756 }
757 return RMAP_PERMIT;
758 }
759
760 static int
761 bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
762 afi_t afi, safi_t safi, char *rmap_name)
763 {
764 struct bgp_filter *filter;
765 struct bgp_info info;
766 route_map_result_t ret;
767 struct route_map *rmap = NULL;
768
769 filter = &peer->filter[afi][safi];
770
771 /* Apply default weight value. */
772 if (peer->weight)
773 (bgp_attr_extra_get (attr))->weight = peer->weight;
774
775 if (rmap_name)
776 {
777 rmap = route_map_lookup_by_name(rmap_name);
778 }
779 else
780 {
781 if (ROUTE_MAP_OUT_NAME(filter))
782 rmap = ROUTE_MAP_OUT (filter);
783 }
784
785 /* Route map apply. */
786 if (rmap)
787 {
788 /* Duplicate current value to new strucutre for modification. */
789 info.peer = peer;
790 info.attr = attr;
791
792 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
793
794 /* Apply BGP route map to the attribute. */
795 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
796
797 peer->rmap_type = 0;
798
799 if (ret == RMAP_DENYMATCH)
800 /* caller has multiple error paths with bgp_attr_flush() */
801 return RMAP_DENY;
802 }
803 return RMAP_PERMIT;
804 }
805
806 static int
807 bgp_export_modifier (struct peer *rsclient, struct peer *peer,
808 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
809 {
810 struct bgp_filter *filter;
811 struct bgp_info info;
812 route_map_result_t ret;
813
814 filter = &peer->filter[afi][safi];
815
816 /* Route map apply. */
817 if (ROUTE_MAP_EXPORT_NAME (filter))
818 {
819 /* Duplicate current value to new strucutre for modification. */
820 info.peer = rsclient;
821 info.attr = attr;
822
823 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
824
825 /* Apply BGP route map to the attribute. */
826 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
827
828 rsclient->rmap_type = 0;
829
830 if (ret == RMAP_DENYMATCH)
831 {
832 /* Free newly generated AS path and community by route-map. */
833 bgp_attr_flush (attr);
834 return RMAP_DENY;
835 }
836 }
837 return RMAP_PERMIT;
838 }
839
840 static int
841 bgp_import_modifier (struct peer *rsclient, struct peer *peer,
842 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
843 {
844 struct bgp_filter *filter;
845 struct bgp_info info;
846 route_map_result_t ret;
847
848 filter = &rsclient->filter[afi][safi];
849
850 /* Apply default weight value. */
851 if (peer->weight)
852 (bgp_attr_extra_get (attr))->weight = peer->weight;
853
854 /* Route map apply. */
855 if (ROUTE_MAP_IMPORT_NAME (filter))
856 {
857 /* Duplicate current value to new strucutre for modification. */
858 info.peer = peer;
859 info.attr = attr;
860
861 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
862
863 /* Apply BGP route map to the attribute. */
864 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
865
866 peer->rmap_type = 0;
867
868 if (ret == RMAP_DENYMATCH)
869 {
870 /* Free newly generated AS path and community by route-map. */
871 bgp_attr_flush (attr);
872 return RMAP_DENY;
873 }
874 }
875 return RMAP_PERMIT;
876 }
877
878
879 /* If this is an EBGP peer with remove-private-AS */
880 void
881 bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
882 struct peer *peer, struct attr *attr)
883 {
884 if (peer->sort == BGP_PEER_EBGP &&
885 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS))
886 {
887 // Take action on the entire aspath
888 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
889 {
890 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
891 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
892
893 // The entire aspath consists of private ASNs so create an empty aspath
894 else if (aspath_private_as_check (attr->aspath))
895 attr->aspath = aspath_empty_get ();
896
897 // There are some public and some private ASNs, remove the private ASNs
898 else
899 attr->aspath = aspath_remove_private_asns (attr->aspath);
900 }
901
902 // 'all' was not specified so the entire aspath must be private ASNs
903 // for us to do anything
904 else if (aspath_private_as_check (attr->aspath))
905 {
906 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
907 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
908 else
909 attr->aspath = aspath_empty_get ();
910 }
911 }
912 }
913
914 /* If this is an EBGP peer with as-override */
915 static void
916 bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
917 struct peer *peer, struct attr *attr)
918 {
919 if (peer->sort == BGP_PEER_EBGP &&
920 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
921 {
922 if (aspath_single_asn_check (attr->aspath, peer->as))
923 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
924 }
925 }
926
927 static int
928 bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
929 struct attr *attr, afi_t afi, safi_t safi)
930 {
931 int ret;
932 char buf[SU_ADDRSTRLEN];
933 struct bgp_filter *filter;
934 struct peer *from;
935 struct bgp *bgp;
936 int transparent;
937 int reflect;
938 struct attr *riattr;
939
940 from = ri->peer;
941 filter = &peer->filter[afi][safi];
942 bgp = peer->bgp;
943 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
944
945 if (DISABLE_BGP_ANNOUNCE)
946 return 0;
947
948 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
949 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
950 return 0;
951
952 /* Do not send back route to sender. */
953 if (from == peer)
954 return 0;
955
956 /* Aggregate-address suppress check. */
957 if (ri->extra && ri->extra->suppress)
958 if (! UNSUPPRESS_MAP_NAME (filter))
959 return 0;
960
961 /* Default route check. */
962 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
963 {
964 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
965 return 0;
966 #ifdef HAVE_IPV6
967 else if (p->family == AF_INET6 && p->prefixlen == 0)
968 return 0;
969 #endif /* HAVE_IPV6 */
970 }
971
972 /* Transparency check. */
973 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
974 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
975 transparent = 1;
976 else
977 transparent = 0;
978
979 /* If community is not disabled check the no-export and local. */
980 if (! transparent && bgp_community_filter (peer, riattr))
981 return 0;
982
983 /* If the attribute has originator-id and it is same as remote
984 peer's id. */
985 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
986 {
987 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
988 {
989 if (bgp_debug_update(peer, p, 0))
990 zlog_debug("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
991 peer->host,
992 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
993 p->prefixlen);
994 return 0;
995 }
996 }
997
998 /* ORF prefix-list filter check */
999 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1000 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1001 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1002 if (peer->orf_plist[afi][safi])
1003 {
1004 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1005 return 0;
1006 }
1007
1008 /* Output filter check. */
1009 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1010 {
1011 if (bgp_debug_update(peer, p, 0))
1012 zlog_debug("%s [Update:SEND] %s/%d is filtered",
1013 peer->host,
1014 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1015 p->prefixlen);
1016 return 0;
1017 }
1018
1019 #ifdef BGP_SEND_ASPATH_CHECK
1020 /* AS path loop check. */
1021 if (aspath_loop_check (riattr->aspath, peer->as))
1022 {
1023 if (bgp_debug_update(peer, p, 0))
1024 zlog_debug("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1025 peer->host, peer->as);
1026 return 0;
1027 }
1028 #endif /* BGP_SEND_ASPATH_CHECK */
1029
1030 /* If we're a CONFED we need to loop check the CONFED ID too */
1031 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1032 {
1033 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1034 {
1035 if (bgp_debug_update(peer, p, 0))
1036 zlog_debug("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1037 peer->host,
1038 bgp->confed_id);
1039 return 0;
1040 }
1041 }
1042
1043 /* Route-Reflect check. */
1044 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1045 reflect = 1;
1046 else
1047 reflect = 0;
1048
1049 /* IBGP reflection check. */
1050 if (reflect)
1051 {
1052 /* A route from a Client peer. */
1053 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1054 {
1055 /* Reflect to all the Non-Client peers and also to the
1056 Client peers other than the originator. Originator check
1057 is already done. So there is noting to do. */
1058 /* no bgp client-to-client reflection check. */
1059 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1060 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1061 return 0;
1062 }
1063 else
1064 {
1065 /* A route from a Non-client peer. Reflect to all other
1066 clients. */
1067 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1068 return 0;
1069 }
1070 }
1071
1072 /* For modify attribute, copy it to temporary structure. */
1073 bgp_attr_dup (attr, riattr);
1074
1075 /* If local-preference is not set. */
1076 if ((peer->sort == BGP_PEER_IBGP
1077 || peer->sort == BGP_PEER_CONFED)
1078 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1079 {
1080 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1081 attr->local_pref = bgp->default_local_pref;
1082 }
1083
1084 /* If originator-id is not set and the route is to be reflected,
1085 set the originator id */
1086 if (peer && from && peer->sort == BGP_PEER_IBGP &&
1087 from->sort == BGP_PEER_IBGP &&
1088 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1089 {
1090 attr->extra = bgp_attr_extra_get(attr);
1091 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1092 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1093 }
1094
1095 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1096 if (peer->sort == BGP_PEER_EBGP
1097 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1098 {
1099 if (ri->peer != bgp->peer_self && ! transparent
1100 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1101 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1102 }
1103
1104 /* next-hop-set */
1105 if (transparent
1106 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
1107 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
1108 && ((p->family == AF_INET && attr->nexthop.s_addr)
1109 #ifdef HAVE_IPV6
1110 || (p->family == AF_INET6 &&
1111 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1112 #endif /* HAVE_IPV6 */
1113 )))
1114 {
1115 /* NEXT-HOP Unchanged. */
1116 }
1117 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
1118 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
1119 #ifdef HAVE_IPV6
1120 || (p->family == AF_INET6 &&
1121 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1122 #endif /* HAVE_IPV6 */
1123 || (peer->sort == BGP_PEER_EBGP
1124 && (bgp_multiaccess_check_v4 (attr->nexthop, peer) == 0)))
1125 {
1126 /* Set IPv4 nexthop. */
1127 if (p->family == AF_INET)
1128 {
1129 if (safi == SAFI_MPLS_VPN)
1130 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1131 IPV4_MAX_BYTELEN);
1132 else
1133 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1134 }
1135 #ifdef HAVE_IPV6
1136 /* Set IPv6 nexthop. */
1137 if (p->family == AF_INET6)
1138 {
1139 /* IPv6 global nexthop must be included. */
1140 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
1141 IPV6_MAX_BYTELEN);
1142 attr->extra->mp_nexthop_len = 16;
1143 }
1144 #endif /* HAVE_IPV6 */
1145 }
1146
1147 #ifdef HAVE_IPV6
1148 if (p->family == AF_INET6)
1149 {
1150 /* Left nexthop_local unchanged if so configured. */
1151 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1152 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1153 {
1154 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1155 attr->extra->mp_nexthop_len=32;
1156 else
1157 attr->extra->mp_nexthop_len=16;
1158 }
1159
1160 /* Default nexthop_local treatment for non-RS-Clients */
1161 else
1162 {
1163 /* Link-local address should not be transit to different peer. */
1164 attr->extra->mp_nexthop_len = 16;
1165
1166 /* Set link-local address for shared network peer. */
1167 if (peer->shared_network
1168 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1169 {
1170 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
1171 IPV6_MAX_BYTELEN);
1172 attr->extra->mp_nexthop_len = 32;
1173 }
1174
1175 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1176 address.*/
1177 if (reflect)
1178 attr->extra->mp_nexthop_len = 16;
1179
1180 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1181 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
1182 attr->extra->mp_nexthop_len = 16;
1183 }
1184
1185 }
1186 #endif /* HAVE_IPV6 */
1187
1188 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1189 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1190
1191 /* Route map & unsuppress-map apply. */
1192 if (ROUTE_MAP_OUT_NAME (filter)
1193 || (ri->extra && ri->extra->suppress) )
1194 {
1195 struct bgp_info info;
1196 struct attr dummy_attr;
1197 struct attr_extra dummy_extra;
1198
1199 dummy_attr.extra = &dummy_extra;
1200
1201 info.peer = peer;
1202 info.attr = attr;
1203
1204 /* The route reflector is not allowed to modify the attributes
1205 of the reflected IBGP routes. */
1206 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) &&
1207 !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1208 {
1209 bgp_attr_dup (&dummy_attr, attr);
1210 info.attr = &dummy_attr;
1211 }
1212
1213 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1214
1215 if (ri->extra && ri->extra->suppress)
1216 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1217 else
1218 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1219
1220 peer->rmap_type = 0;
1221
1222 if (ret == RMAP_DENYMATCH)
1223 {
1224 bgp_attr_flush (attr);
1225 return 0;
1226 }
1227 }
1228 return 1;
1229 }
1230
1231 static int
1232 bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1233 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1234 {
1235 int ret;
1236 char buf[SU_ADDRSTRLEN];
1237 struct bgp_filter *filter;
1238 struct bgp_info info;
1239 struct peer *from;
1240 struct attr *riattr;
1241 struct bgp *bgp;
1242
1243 from = ri->peer;
1244 filter = &rsclient->filter[afi][safi];
1245 bgp = rsclient->bgp;
1246 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1247
1248 if (DISABLE_BGP_ANNOUNCE)
1249 return 0;
1250
1251 /* Do not send back route to sender. */
1252 if (from == rsclient)
1253 return 0;
1254
1255 /* Aggregate-address suppress check. */
1256 if (ri->extra && ri->extra->suppress)
1257 if (! UNSUPPRESS_MAP_NAME (filter))
1258 return 0;
1259
1260 /* Default route check. */
1261 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1262 PEER_STATUS_DEFAULT_ORIGINATE))
1263 {
1264 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1265 return 0;
1266 #ifdef HAVE_IPV6
1267 else if (p->family == AF_INET6 && p->prefixlen == 0)
1268 return 0;
1269 #endif /* HAVE_IPV6 */
1270 }
1271
1272 /* If the attribute has originator-id and it is same as remote
1273 peer's id. */
1274 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1275 {
1276 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1277 &riattr->extra->originator_id))
1278 {
1279 if (bgp_debug_update(rsclient, p, 0))
1280 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1281 rsclient->host,
1282 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1283 p->prefixlen);
1284 return 0;
1285 }
1286 }
1287
1288 /* ORF prefix-list filter check */
1289 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1290 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1291 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1292 if (rsclient->orf_plist[afi][safi])
1293 {
1294 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1295 return 0;
1296 }
1297
1298 /* Output filter check. */
1299 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
1300 {
1301 if (bgp_debug_update(rsclient, p, 0))
1302 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1303 rsclient->host,
1304 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1305 p->prefixlen);
1306 return 0;
1307 }
1308
1309 #ifdef BGP_SEND_ASPATH_CHECK
1310 /* AS path loop check. */
1311 if (aspath_loop_check (riattr->aspath, rsclient->as))
1312 {
1313 if (bgp_debug_update(rsclient, p, 0))
1314 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1315 rsclient->host, rsclient->as);
1316 return 0;
1317 }
1318 #endif /* BGP_SEND_ASPATH_CHECK */
1319
1320 /* For modify attribute, copy it to temporary structure. */
1321 bgp_attr_dup (attr, riattr);
1322
1323 /* next-hop-set */
1324 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1325 #ifdef HAVE_IPV6
1326 || (p->family == AF_INET6 &&
1327 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1328 #endif /* HAVE_IPV6 */
1329 )
1330 {
1331 /* Set IPv4 nexthop. */
1332 if (p->family == AF_INET)
1333 {
1334 if (safi == SAFI_MPLS_VPN)
1335 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
1336 IPV4_MAX_BYTELEN);
1337 else
1338 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1339 }
1340 #ifdef HAVE_IPV6
1341 /* Set IPv6 nexthop. */
1342 if (p->family == AF_INET6)
1343 {
1344 /* IPv6 global nexthop must be included. */
1345 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
1346 IPV6_MAX_BYTELEN);
1347 attr->extra->mp_nexthop_len = 16;
1348 }
1349 #endif /* HAVE_IPV6 */
1350 }
1351
1352 #ifdef HAVE_IPV6
1353 if (p->family == AF_INET6)
1354 {
1355 struct attr_extra *attre = attr->extra;
1356
1357 /* Left nexthop_local unchanged if so configured. */
1358 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1359 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1360 {
1361 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1362 attre->mp_nexthop_len=32;
1363 else
1364 attre->mp_nexthop_len=16;
1365 }
1366
1367 /* Default nexthop_local treatment for RS-Clients */
1368 else
1369 {
1370 /* Announcer and RS-Client are both in the same network */
1371 if (rsclient->shared_network && from->shared_network &&
1372 (rsclient->ifindex == from->ifindex))
1373 {
1374 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1375 attre->mp_nexthop_len=32;
1376 else
1377 attre->mp_nexthop_len=16;
1378 }
1379
1380 /* Set link-local address for shared network peer. */
1381 else if (rsclient->shared_network
1382 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1383 {
1384 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
1385 IPV6_MAX_BYTELEN);
1386 attre->mp_nexthop_len = 32;
1387 }
1388
1389 else
1390 attre->mp_nexthop_len = 16;
1391 }
1392
1393 }
1394 #endif /* HAVE_IPV6 */
1395
1396 bgp_peer_remove_private_as(bgp, afi, safi, rsclient, attr);
1397 bgp_peer_as_override(bgp, afi, safi, rsclient, attr);
1398
1399 /* Route map & unsuppress-map apply. */
1400 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
1401 {
1402 info.peer = rsclient;
1403 info.attr = attr;
1404
1405 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1406
1407 if (ri->extra && ri->extra->suppress)
1408 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1409 else
1410 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1411
1412 rsclient->rmap_type = 0;
1413
1414 if (ret == RMAP_DENYMATCH)
1415 {
1416 bgp_attr_flush (attr);
1417 return 0;
1418 }
1419 }
1420
1421 return 1;
1422 }
1423
1424 struct bgp_info_pair
1425 {
1426 struct bgp_info *old;
1427 struct bgp_info *new;
1428 };
1429
1430 static void
1431 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1432 struct bgp_maxpaths_cfg *mpath_cfg,
1433 struct bgp_info_pair *result)
1434 {
1435 struct bgp_info *new_select;
1436 struct bgp_info *old_select;
1437 struct bgp_info *ri;
1438 struct bgp_info *ri1;
1439 struct bgp_info *ri2;
1440 struct bgp_info *nextri = NULL;
1441 int paths_eq, do_mpath;
1442 struct list mp_list;
1443 char buf[INET6_BUFSIZ];
1444
1445 bgp_mp_list_init (&mp_list);
1446 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1447 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1448
1449 /* bgp deterministic-med */
1450 new_select = NULL;
1451 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1452 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1453 {
1454 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1455 continue;
1456 if (BGP_INFO_HOLDDOWN (ri1))
1457 continue;
1458
1459 new_select = ri1;
1460 if (do_mpath)
1461 bgp_mp_list_add (&mp_list, ri1);
1462 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
1463 if (ri1->next)
1464 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1465 {
1466 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1467 continue;
1468 if (BGP_INFO_HOLDDOWN (ri2))
1469 continue;
1470
1471 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1472 || aspath_cmp_left_confed (ri1->attr->aspath,
1473 ri2->attr->aspath))
1474 {
1475 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1476 old_select = ri2;
1477 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1478 mpath_cfg))
1479 {
1480 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1481 new_select = ri2;
1482 if (do_mpath && !paths_eq)
1483 {
1484 bgp_mp_list_clear (&mp_list);
1485 bgp_mp_list_add (&mp_list, ri2);
1486 }
1487 }
1488
1489 if (do_mpath && paths_eq)
1490 bgp_mp_list_add (&mp_list, ri2);
1491
1492 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1493 }
1494 }
1495 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1496 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1497
1498 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1499 bgp_mp_list_clear (&mp_list);
1500 }
1501
1502 /* Check old selected route and new selected route. */
1503 old_select = NULL;
1504 new_select = NULL;
1505 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1506 {
1507 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1508 old_select = ri;
1509
1510 if (BGP_INFO_HOLDDOWN (ri))
1511 {
1512 /* reap REMOVED routes, if needs be
1513 * selected route must stay for a while longer though
1514 */
1515 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1516 && (ri != old_select))
1517 bgp_info_reap (rn, ri);
1518
1519 continue;
1520 }
1521
1522 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1523 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1524 {
1525 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1526 continue;
1527 }
1528 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1529 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
1530
1531 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg))
1532 {
1533 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1534 bgp_mp_dmed_deselect (new_select);
1535
1536 new_select = ri;
1537
1538 if (do_mpath && !paths_eq)
1539 {
1540 bgp_mp_list_clear (&mp_list);
1541 bgp_mp_list_add (&mp_list, ri);
1542 }
1543 }
1544 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1545 bgp_mp_dmed_deselect (ri);
1546
1547 if (do_mpath && paths_eq)
1548 bgp_mp_list_add (&mp_list, ri);
1549 }
1550
1551
1552 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1553 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1554
1555 bgp_info_mpath_aggregate_update (new_select, old_select);
1556 bgp_mp_list_clear (&mp_list);
1557
1558 result->old = old_select;
1559 result->new = new_select;
1560
1561 return;
1562 }
1563
1564 static int
1565 bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1566 struct bgp_node *rn, afi_t afi, safi_t safi)
1567 {
1568 struct prefix *p;
1569 struct attr attr;
1570 struct attr_extra extra;
1571
1572 p = &rn->p;
1573
1574 /* Announce route to Established peer. */
1575 if (peer->status != Established)
1576 return 0;
1577
1578 /* Address family configuration check. */
1579 if (! peer->afc_nego[afi][safi])
1580 return 0;
1581
1582 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1583 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1584 PEER_STATUS_ORF_WAIT_REFRESH))
1585 return 0;
1586
1587 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1588 attr.extra = &extra;
1589
1590 switch (bgp_node_table (rn)->type)
1591 {
1592 case BGP_TABLE_MAIN:
1593 /* Announcement to peer->conf. If the route is filtered,
1594 withdraw it. */
1595 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1596 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1597 else
1598 bgp_adj_out_unset (rn, peer, p, afi, safi);
1599 break;
1600 case BGP_TABLE_RSCLIENT:
1601 /* Announcement to peer->conf. If the route is filtered,
1602 withdraw it. */
1603 if (selected &&
1604 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1605 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1606 else
1607 bgp_adj_out_unset (rn, peer, p, afi, safi);
1608 break;
1609 }
1610
1611 return 0;
1612 }
1613
1614 struct bgp_process_queue
1615 {
1616 struct bgp *bgp;
1617 struct bgp_node *rn;
1618 afi_t afi;
1619 safi_t safi;
1620 };
1621
1622 static wq_item_status
1623 bgp_process_rsclient (struct work_queue *wq, void *data)
1624 {
1625 struct bgp_process_queue *pq = data;
1626 struct bgp *bgp = pq->bgp;
1627 struct bgp_node *rn = pq->rn;
1628 afi_t afi = pq->afi;
1629 safi_t safi = pq->safi;
1630 struct bgp_info *new_select;
1631 struct bgp_info *old_select;
1632 struct bgp_info_pair old_and_new;
1633 struct listnode *node, *nnode;
1634 struct peer *rsclient;
1635
1636 /* Is it end of initial update? (after startup) */
1637 if (!rn)
1638 {
1639 /* This is just to keep the display sane in case all the peers are
1640 rsclients only */
1641 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1642 sizeof(bgp->update_delay_zebra_resume_time));
1643
1644 bgp->rsclient_peers_update_hold = 0;
1645 bgp_start_routeadv(bgp);
1646 return WQ_SUCCESS;
1647 }
1648
1649 rsclient = bgp_node_table (rn)->owner;
1650
1651 /* Best path selection. */
1652 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1653 new_select = old_and_new.new;
1654 old_select = old_and_new.old;
1655
1656 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1657 {
1658 if (rsclient->group)
1659 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1660 {
1661 /* Nothing to do. */
1662 if (old_select && old_select == new_select)
1663 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1664 continue;
1665
1666 if (old_select)
1667 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1668 if (new_select)
1669 {
1670 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1671 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1672 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1673 }
1674
1675 bgp_process_announce_selected (rsclient, new_select, rn,
1676 afi, safi);
1677 }
1678 }
1679 else
1680 {
1681 if (old_select)
1682 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1683 if (new_select)
1684 {
1685 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1686 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1687 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1688 }
1689 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
1690 }
1691
1692 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1693 bgp_info_reap (rn, old_select);
1694
1695 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1696 return WQ_SUCCESS;
1697 }
1698
1699 static wq_item_status
1700 bgp_process_main (struct work_queue *wq, void *data)
1701 {
1702 struct bgp_process_queue *pq = data;
1703 struct bgp *bgp = pq->bgp;
1704 struct bgp_node *rn = pq->rn;
1705 afi_t afi = pq->afi;
1706 safi_t safi = pq->safi;
1707 struct prefix *p = &rn->p;
1708 struct bgp_info *new_select;
1709 struct bgp_info *old_select;
1710 struct bgp_info_pair old_and_new;
1711 struct listnode *node, *nnode;
1712 struct peer *peer;
1713
1714 /* Is it end of initial update? (after startup) */
1715 if (!rn)
1716 {
1717 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1718 sizeof(bgp->update_delay_zebra_resume_time));
1719
1720 bgp->main_zebra_update_hold = 0;
1721 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1722 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1723 {
1724 bgp_zebra_announce_table(bgp, afi, safi);
1725 }
1726 bgp->main_peers_update_hold = 0;
1727
1728 bgp_start_routeadv(bgp);
1729 return WQ_SUCCESS;
1730 }
1731
1732 /* Best path selection. */
1733 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1734 old_select = old_and_new.old;
1735 new_select = old_and_new.new;
1736
1737 /* Nothing to do. */
1738 if (old_select && old_select == new_select && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
1739 {
1740 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1741 {
1742 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1743 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
1744 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1745
1746 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1747 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1748 return WQ_SUCCESS;
1749 }
1750 }
1751
1752 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1753 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1754
1755 if (old_select)
1756 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1757 if (new_select)
1758 {
1759 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1760 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1761 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1762 }
1763
1764
1765 /* Check each BGP peer. */
1766 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
1767 {
1768 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
1769 }
1770
1771 /* FIB update. */
1772 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1773 ! bgp_option_check (BGP_OPT_NO_FIB)))
1774 {
1775 if (new_select
1776 && new_select->type == ZEBRA_ROUTE_BGP
1777 && new_select->sub_type == BGP_ROUTE_NORMAL)
1778 bgp_zebra_announce (p, new_select, bgp, afi, safi);
1779 else
1780 {
1781 /* Withdraw the route from the kernel. */
1782 if (old_select
1783 && old_select->type == ZEBRA_ROUTE_BGP
1784 && old_select->sub_type == BGP_ROUTE_NORMAL)
1785 bgp_zebra_withdraw (p, old_select, safi);
1786 }
1787 }
1788
1789 /* Reap old select bgp_info, it it has been removed */
1790 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1791 bgp_info_reap (rn, old_select);
1792
1793 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1794 return WQ_SUCCESS;
1795 }
1796
1797 static void
1798 bgp_processq_del (struct work_queue *wq, void *data)
1799 {
1800 struct bgp_process_queue *pq = data;
1801 struct bgp_table *table;
1802
1803 bgp_unlock (pq->bgp);
1804 if (pq->rn)
1805 {
1806 table = bgp_node_table (pq->rn);
1807 bgp_unlock_node (pq->rn);
1808 bgp_table_unlock (table);
1809 }
1810 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1811 }
1812
1813 static void
1814 bgp_process_queue_complete (struct work_queue *wq)
1815 {
1816 struct bgp *bgp;
1817 struct peer *peer;
1818 struct listnode *node, *nnode;
1819
1820 /* Schedule write thread either directly or through the MRAI timer
1821 * if needed.
1822 */
1823 bgp = bgp_get_default ();
1824 if (!bgp)
1825 return;
1826
1827 if (BGP_ROUTE_ADV_HOLD(bgp))
1828 return;
1829
1830 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
1831 bgp_peer_schedule_updates(peer);
1832 }
1833
1834 void
1835 bgp_process_queue_init (void)
1836 {
1837 bm->process_main_queue
1838 = work_queue_new (bm->master, "process_main_queue");
1839 bm->process_rsclient_queue
1840 = work_queue_new (bm->master, "process_rsclient_queue");
1841
1842 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1843 {
1844 zlog_err ("%s: Failed to allocate work queue", __func__);
1845 exit (1);
1846 }
1847
1848 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1849 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1850 bm->process_main_queue->spec.completion_func = &bgp_process_queue_complete;
1851 bm->process_main_queue->spec.max_retries = 0;
1852 bm->process_main_queue->spec.hold = 50;
1853 /* Use a higher yield value of 50ms for main queue processing */
1854 bm->process_main_queue->spec.yield = 50 * 1000L;
1855
1856 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1857 sizeof (struct work_queue *));
1858 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1859 }
1860
1861 void
1862 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1863 {
1864 struct bgp_process_queue *pqnode;
1865
1866 /* already scheduled for processing? */
1867 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1868 return;
1869
1870 if ( (bm->process_main_queue == NULL) ||
1871 (bm->process_rsclient_queue == NULL) )
1872 bgp_process_queue_init ();
1873
1874 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1875 sizeof (struct bgp_process_queue));
1876 if (!pqnode)
1877 return;
1878
1879 /* all unlocked in bgp_processq_del */
1880 bgp_table_lock (bgp_node_table (rn));
1881 pqnode->rn = bgp_lock_node (rn);
1882 pqnode->bgp = bgp;
1883 bgp_lock (bgp);
1884 pqnode->afi = afi;
1885 pqnode->safi = safi;
1886
1887 switch (bgp_node_table (rn)->type)
1888 {
1889 case BGP_TABLE_MAIN:
1890 work_queue_add (bm->process_main_queue, pqnode);
1891 break;
1892 case BGP_TABLE_RSCLIENT:
1893 work_queue_add (bm->process_rsclient_queue, pqnode);
1894 break;
1895 }
1896
1897 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1898 return;
1899 }
1900
1901 void
1902 bgp_add_eoiu_mark (struct bgp *bgp, bgp_table_t type)
1903 {
1904 struct bgp_process_queue *pqnode;
1905
1906 if ( (bm->process_main_queue == NULL) ||
1907 (bm->process_rsclient_queue == NULL) )
1908 bgp_process_queue_init ();
1909
1910 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1911 sizeof (struct bgp_process_queue));
1912 if (!pqnode)
1913 return;
1914
1915 pqnode->rn = NULL;
1916 pqnode->bgp = bgp;
1917 bgp_lock (bgp);
1918 switch (type)
1919 {
1920 case BGP_TABLE_MAIN:
1921 work_queue_add (bm->process_main_queue, pqnode);
1922 break;
1923 case BGP_TABLE_RSCLIENT:
1924 work_queue_add (bm->process_rsclient_queue, pqnode);
1925 break;
1926 }
1927
1928 return;
1929 }
1930
1931 static int
1932 bgp_maximum_prefix_restart_timer (struct thread *thread)
1933 {
1934 struct peer *peer;
1935
1936 peer = THREAD_ARG (thread);
1937 peer->t_pmax_restart = NULL;
1938
1939 if (bgp_debug_neighbor_events(peer))
1940 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1941 peer->host);
1942
1943 peer_clear (peer, NULL);
1944
1945 return 0;
1946 }
1947
1948 int
1949 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1950 safi_t safi, int always)
1951 {
1952 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1953 return 0;
1954
1955 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
1956 {
1957 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1958 && ! always)
1959 return 0;
1960
1961 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1962 "limit %ld", afi_safi_print (afi, safi), peer->host,
1963 peer->pcount[afi][safi], peer->pmax[afi][safi]);
1964 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1965
1966 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1967 return 0;
1968
1969 {
1970 u_int8_t ndata[7];
1971
1972 if (safi == SAFI_MPLS_VPN)
1973 safi = SAFI_MPLS_LABELED_VPN;
1974
1975 ndata[0] = (afi >> 8);
1976 ndata[1] = afi;
1977 ndata[2] = safi;
1978 ndata[3] = (peer->pmax[afi][safi] >> 24);
1979 ndata[4] = (peer->pmax[afi][safi] >> 16);
1980 ndata[5] = (peer->pmax[afi][safi] >> 8);
1981 ndata[6] = (peer->pmax[afi][safi]);
1982
1983 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1984 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1985 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1986 }
1987
1988 /* restart timer start */
1989 if (peer->pmax_restart[afi][safi])
1990 {
1991 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1992
1993 if (bgp_debug_neighbor_events(peer))
1994 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1995 peer->host, peer->v_pmax_restart);
1996
1997 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1998 peer->v_pmax_restart);
1999 }
2000
2001 return 1;
2002 }
2003 else
2004 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2005
2006 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2007 {
2008 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2009 && ! always)
2010 return 0;
2011
2012 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2013 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2014 peer->pmax[afi][safi]);
2015 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2016 }
2017 else
2018 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2019 return 0;
2020 }
2021
2022 /* Unconditionally remove the route from the RIB, without taking
2023 * damping into consideration (eg, because the session went down)
2024 */
2025 static void
2026 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2027 afi_t afi, safi_t safi)
2028 {
2029 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2030
2031 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2032 bgp_info_delete (rn, ri); /* keep historical info */
2033
2034 bgp_process (peer->bgp, rn, afi, safi);
2035 }
2036
2037 static void
2038 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2039 afi_t afi, safi_t safi)
2040 {
2041 int status = BGP_DAMP_NONE;
2042
2043 /* apply dampening, if result is suppressed, we'll be retaining
2044 * the bgp_info in the RIB for historical reference.
2045 */
2046 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2047 && peer->sort == BGP_PEER_EBGP)
2048 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2049 == BGP_DAMP_SUPPRESSED)
2050 {
2051 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2052 return;
2053 }
2054
2055 bgp_rib_remove (rn, ri, peer, afi, safi);
2056 }
2057
2058 static struct bgp_info *
2059 info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
2060 struct bgp_node *rn)
2061 {
2062 struct bgp_info *new;
2063
2064 /* Make new BGP info. */
2065 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2066 new->type = type;
2067 new->instance = instance;
2068 new->sub_type = sub_type;
2069 new->peer = peer;
2070 new->attr = attr;
2071 new->uptime = bgp_clock ();
2072 new->net = rn;
2073 return new;
2074 }
2075
2076 static void
2077 bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2078 struct attr *attr, struct peer *peer, struct prefix *p, int type,
2079 int sub_type, struct prefix_rd *prd, u_char *tag)
2080 {
2081 struct bgp_node *rn;
2082 struct bgp *bgp;
2083 struct attr new_attr;
2084 struct attr_extra new_extra;
2085 struct attr *attr_new;
2086 struct attr *attr_new2;
2087 struct bgp_info *ri;
2088 struct bgp_info *new;
2089 const char *reason;
2090 char buf[SU_ADDRSTRLEN];
2091
2092 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
2093 if (peer == rsclient)
2094 return;
2095
2096 bgp = peer->bgp;
2097 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2098
2099 /* Check previously received route. */
2100 for (ri = rn->info; ri; ri = ri->next)
2101 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2102 break;
2103
2104 /* AS path loop check. */
2105 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
2106 {
2107 reason = "as-path contains our own AS;";
2108 goto filtered;
2109 }
2110
2111 /* Route reflector originator ID check. */
2112 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2113 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
2114 {
2115 reason = "originator is us;";
2116 goto filtered;
2117 }
2118
2119 new_attr.extra = &new_extra;
2120 bgp_attr_dup (&new_attr, attr);
2121
2122 /* Apply export policy. */
2123 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
2124 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2125 {
2126 reason = "export-policy;";
2127 goto filtered;
2128 }
2129
2130 attr_new2 = bgp_attr_intern (&new_attr);
2131
2132 /* Apply import policy. */
2133 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2134 {
2135 bgp_attr_unintern (&attr_new2);
2136
2137 reason = "import-policy;";
2138 goto filtered;
2139 }
2140
2141 attr_new = bgp_attr_intern (&new_attr);
2142 bgp_attr_unintern (&attr_new2);
2143
2144 /* IPv4 unicast next hop check. */
2145 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
2146 {
2147 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
2148 if (new_attr.nexthop.s_addr == 0
2149 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
2150 {
2151 bgp_attr_unintern (&attr_new);
2152
2153 reason = "martian next-hop;";
2154 goto filtered;
2155 }
2156 }
2157
2158 /* If the update is implicit withdraw. */
2159 if (ri)
2160 {
2161 ri->uptime = bgp_clock ();
2162
2163 /* Same attribute comes in. */
2164 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
2165 && attrhash_cmp (ri->attr, attr_new))
2166 {
2167
2168 if (bgp_debug_update(peer, p, 1))
2169 zlog_debug ("%s rcvd %s/%d for RS-client %s...duplicate ignored",
2170 peer->host,
2171 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2172 p->prefixlen, rsclient->host);
2173
2174
2175 bgp_unlock_node (rn);
2176 bgp_attr_unintern (&attr_new);
2177
2178 return;
2179 }
2180
2181 /* Withdraw/Announce before we fully processed the withdraw */
2182 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2183 bgp_info_restore (rn, ri);
2184
2185 /* Received Logging. */
2186 if (bgp_debug_update(peer, p, 1))
2187 zlog_debug ("%s rcvd %s/%d for RS-client %s",
2188 peer->host,
2189 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2190 p->prefixlen, rsclient->host);
2191
2192 /* The attribute is changed. */
2193 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2194
2195 /* Update to new attribute. */
2196 bgp_attr_unintern (&ri->attr);
2197 ri->attr = attr_new;
2198
2199 /* Update MPLS tag. */
2200 if (safi == SAFI_MPLS_VPN)
2201 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2202
2203 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2204
2205 /* Process change. */
2206 bgp_process (bgp, rn, afi, safi);
2207 bgp_unlock_node (rn);
2208
2209 return;
2210 }
2211
2212 /* Received Logging. */
2213 if (bgp_debug_update(peer, p, 1))
2214 {
2215 zlog_debug ("%s rcvd %s/%d for RS-client %s",
2216 peer->host,
2217 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2218 p->prefixlen, rsclient->host);
2219 }
2220
2221 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2222
2223 /* Update MPLS tag. */
2224 if (safi == SAFI_MPLS_VPN)
2225 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2226
2227 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2228
2229 /* Register new BGP information. */
2230 bgp_info_add (rn, new);
2231
2232 /* route_node_get lock */
2233 bgp_unlock_node (rn);
2234
2235 /* Process change. */
2236 bgp_process (bgp, rn, afi, safi);
2237
2238 return;
2239
2240 filtered:
2241
2242 /* This BGP update is filtered. Log the reason then update BGP entry. */
2243 if (bgp_debug_update(peer, p, 1))
2244 zlog_debug ("%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2245 peer->host,
2246 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2247 p->prefixlen, rsclient->host, reason);
2248
2249 if (ri)
2250 bgp_rib_remove (rn, ri, peer, afi, safi);
2251
2252 bgp_unlock_node (rn);
2253
2254 return;
2255 }
2256
2257 static void
2258 bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2259 struct peer *peer, struct prefix *p, int type, int sub_type,
2260 struct prefix_rd *prd, u_char *tag)
2261 {
2262 struct bgp_node *rn;
2263 struct bgp_info *ri;
2264 char buf[SU_ADDRSTRLEN];
2265
2266 if (rsclient == peer)
2267 return;
2268
2269 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2270
2271 /* Lookup withdrawn route. */
2272 for (ri = rn->info; ri; ri = ri->next)
2273 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2274 break;
2275
2276 /* Withdraw specified route from routing table. */
2277 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2278 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2279 else if (bgp_debug_update(peer, p, 1))
2280 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2281 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2282 p->prefixlen);
2283
2284 /* Unlock bgp_node_get() lock. */
2285 bgp_unlock_node (rn);
2286 }
2287
2288 static int
2289 bgp_update_main (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2290 struct attr *attr, afi_t afi, safi_t safi, int type,
2291 int sub_type, struct prefix_rd *prd, u_char *tag,
2292 int soft_reconfig)
2293 {
2294 int ret;
2295 int aspath_loop_count = 0;
2296 struct bgp_node *rn;
2297 struct bgp *bgp;
2298 struct attr new_attr;
2299 struct attr_extra new_extra;
2300 struct attr *attr_new;
2301 struct bgp_info *ri;
2302 struct bgp_info *new;
2303 const char *reason;
2304 char buf[SU_ADDRSTRLEN];
2305 int connected = 0;
2306
2307 bgp = peer->bgp;
2308 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2309
2310 /* When peer's soft reconfiguration enabled. Record input packet in
2311 Adj-RIBs-In. */
2312 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2313 && peer != bgp->peer_self)
2314 bgp_adj_in_set (rn, peer, attr);
2315
2316 /* Check previously received route. */
2317 for (ri = rn->info; ri; ri = ri->next)
2318 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2319 ri->addpath_rx_id == addpath_id)
2320 break;
2321
2322 /* AS path local-as loop check. */
2323 if (peer->change_local_as)
2324 {
2325 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2326 aspath_loop_count = 1;
2327
2328 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2329 {
2330 reason = "as-path contains our own AS;";
2331 goto filtered;
2332 }
2333 }
2334
2335 /* AS path loop check. */
2336 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2337 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2338 && aspath_loop_check(attr->aspath, bgp->confed_id)
2339 > peer->allowas_in[afi][safi]))
2340 {
2341 reason = "as-path contains our own AS;";
2342 goto filtered;
2343 }
2344
2345 /* Route reflector originator ID check. */
2346 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2347 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2348 {
2349 reason = "originator is us;";
2350 goto filtered;
2351 }
2352
2353 /* Route reflector cluster ID check. */
2354 if (bgp_cluster_filter (peer, attr))
2355 {
2356 reason = "reflected from the same cluster;";
2357 goto filtered;
2358 }
2359
2360 /* Apply incoming filter. */
2361 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2362 {
2363 reason = "filter;";
2364 goto filtered;
2365 }
2366
2367 new_attr.extra = &new_extra;
2368 bgp_attr_dup (&new_attr, attr);
2369
2370 /* Apply incoming route-map.
2371 * NB: new_attr may now contain newly allocated values from route-map "set"
2372 * commands, so we need bgp_attr_flush in the error paths, until we intern
2373 * the attr (which takes over the memory references) */
2374 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2375 {
2376 reason = "route-map;";
2377 bgp_attr_flush (&new_attr);
2378 goto filtered;
2379 }
2380
2381 /* IPv4 unicast next hop check. */
2382 if (afi == AFI_IP && safi == SAFI_UNICAST)
2383 {
2384 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
2385 must not be my own address. */
2386 if (new_attr.nexthop.s_addr == 0
2387 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2388 || bgp_nexthop_self (&new_attr))
2389 {
2390 reason = "martian next-hop;";
2391 bgp_attr_flush (&new_attr);
2392 goto filtered;
2393 }
2394 }
2395
2396 attr_new = bgp_attr_intern (&new_attr);
2397
2398 /* If the update is implicit withdraw. */
2399 if (ri)
2400 {
2401 ri->uptime = bgp_clock ();
2402
2403 /* Same attribute comes in. */
2404 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2405 && attrhash_cmp (ri->attr, attr_new))
2406 {
2407 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2408 && peer->sort == BGP_PEER_EBGP
2409 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2410 {
2411 if (bgp_debug_update(peer, p, 1))
2412 zlog_debug ("%s rcvd %s/%d",
2413 peer->host,
2414 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2415 p->prefixlen);
2416
2417 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2418 {
2419 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2420 bgp_process (bgp, rn, afi, safi);
2421 }
2422 }
2423 else /* Duplicate - odd */
2424 {
2425 if (bgp_debug_update(peer, p, 1))
2426 {
2427 if (!peer->rcvd_attr_printed)
2428 {
2429 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2430 peer->rcvd_attr_printed = 1;
2431 }
2432
2433 zlog_debug ("%s rcvd %s/%d...duplicate ignored",
2434 peer->host,
2435 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2436 p->prefixlen);
2437 }
2438
2439 /* graceful restart STALE flag unset. */
2440 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2441 {
2442 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2443 bgp_process (bgp, rn, afi, safi);
2444 }
2445 }
2446
2447 bgp_unlock_node (rn);
2448 bgp_attr_unintern (&attr_new);
2449
2450 return 0;
2451 }
2452
2453 /* Withdraw/Announce before we fully processed the withdraw */
2454 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2455 {
2456 if (bgp_debug_update(peer, p, 1))
2457 zlog_debug ("%s rcvd %s/%d, flapped quicker than processing",
2458 peer->host,
2459 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2460 p->prefixlen);
2461 bgp_info_restore (rn, ri);
2462 }
2463
2464 /* Received Logging. */
2465 if (bgp_debug_update(peer, p, 1))
2466 zlog_debug ("%s rcvd %s/%d",
2467 peer->host,
2468 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2469 p->prefixlen);
2470
2471 /* graceful restart STALE flag unset. */
2472 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2473 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2474
2475 /* The attribute is changed. */
2476 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2477
2478 /* implicit withdraw, decrement aggregate and pcount here.
2479 * only if update is accepted, they'll increment below.
2480 */
2481 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2482
2483 /* Update bgp route dampening information. */
2484 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2485 && peer->sort == BGP_PEER_EBGP)
2486 {
2487 /* This is implicit withdraw so we should update dampening
2488 information. */
2489 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2490 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2491 }
2492
2493 /* Update to new attribute. */
2494 bgp_attr_unintern (&ri->attr);
2495 ri->attr = attr_new;
2496
2497 /* Update MPLS tag. */
2498 if (safi == SAFI_MPLS_VPN)
2499 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2500
2501 /* Update bgp route dampening information. */
2502 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2503 && peer->sort == BGP_PEER_EBGP)
2504 {
2505 /* Now we do normal update dampening. */
2506 ret = bgp_damp_update (ri, rn, afi, safi);
2507 if (ret == BGP_DAMP_SUPPRESSED)
2508 {
2509 bgp_unlock_node (rn);
2510 return 0;
2511 }
2512 }
2513
2514 /* Nexthop reachability check. */
2515 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2516 {
2517 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2518 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
2519 connected = 1;
2520 else
2521 connected = 0;
2522
2523 if (bgp_find_or_add_nexthop (afi, ri, NULL, connected))
2524 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2525 else
2526 {
2527 if (BGP_DEBUG(nht, NHT))
2528 {
2529 char buf1[INET6_ADDRSTRLEN];
2530 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2531 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2532 }
2533 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2534 }
2535 }
2536 else
2537 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2538
2539 /* Process change. */
2540 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2541
2542 bgp_process (bgp, rn, afi, safi);
2543 bgp_unlock_node (rn);
2544
2545 return 0;
2546 } // End of implicit withdraw
2547
2548 /* Received Logging. */
2549 if (bgp_debug_update(peer, p, 1))
2550 {
2551 if (!peer->rcvd_attr_printed)
2552 {
2553 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2554 peer->rcvd_attr_printed = 1;
2555 }
2556
2557 zlog_debug ("%s rcvd %s/%d",
2558 peer->host,
2559 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2560 p->prefixlen);
2561 }
2562
2563 /* Make new BGP info. */
2564 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2565
2566 /* Update MPLS tag. */
2567 if (safi == SAFI_MPLS_VPN)
2568 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2569
2570 /* Nexthop reachability check. */
2571 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2572 {
2573 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2574 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
2575 connected = 1;
2576 else
2577 connected = 0;
2578
2579 if (bgp_find_or_add_nexthop (afi, new, NULL, connected))
2580 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2581 else
2582 {
2583 if (BGP_DEBUG(nht, NHT))
2584 {
2585 char buf1[INET6_ADDRSTRLEN];
2586 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2587 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2588 }
2589 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2590 }
2591 }
2592 else
2593 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2594
2595 /* Addpath ID */
2596 new->addpath_rx_id = addpath_id;
2597 new->addpath_tx_id = 0;
2598
2599 /* Increment prefix */
2600 bgp_aggregate_increment (bgp, p, new, afi, safi);
2601
2602 /* Register new BGP information. */
2603 bgp_info_add (rn, new);
2604
2605 /* route_node_get lock */
2606 bgp_unlock_node (rn);
2607
2608 /* If maximum prefix count is configured and current prefix
2609 count exeed it. */
2610 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2611 return -1;
2612
2613 /* Process change. */
2614 bgp_process (bgp, rn, afi, safi);
2615
2616 return 0;
2617
2618 /* This BGP update is filtered. Log the reason then update BGP
2619 entry. */
2620 filtered:
2621 if (bgp_debug_update(peer, p, 1))
2622 {
2623 if (!peer->rcvd_attr_printed)
2624 {
2625 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2626 peer->rcvd_attr_printed = 1;
2627 }
2628
2629 zlog_debug ("%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2630 peer->host,
2631 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2632 p->prefixlen, reason);
2633 }
2634
2635 if (ri)
2636 bgp_rib_remove (rn, ri, peer, afi, safi);
2637
2638 bgp_unlock_node (rn);
2639
2640 return 0;
2641 }
2642
2643 int
2644 bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2645 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2646 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2647 {
2648 struct peer *rsclient;
2649 struct listnode *node, *nnode;
2650 struct bgp *bgp;
2651 int ret;
2652
2653 ret = bgp_update_main (peer, p, addpath_id, attr, afi, safi, type, sub_type,
2654 prd, tag, soft_reconfig);
2655
2656 bgp = peer->bgp;
2657
2658 /* Process the update for each RS-client. */
2659 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2660 {
2661 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2662 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p,
2663 type, sub_type, prd, tag);
2664 }
2665
2666 return ret;
2667 }
2668
2669 int
2670 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2671 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2672 struct prefix_rd *prd, u_char *tag)
2673 {
2674 struct bgp *bgp;
2675 char buf[SU_ADDRSTRLEN];
2676 struct bgp_node *rn;
2677 struct bgp_info *ri;
2678 struct peer *rsclient;
2679 struct listnode *node, *nnode;
2680
2681 bgp = peer->bgp;
2682
2683 /* Process the withdraw for each RS-client. */
2684 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2685 {
2686 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2687 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type,
2688 sub_type, prd, tag);
2689 }
2690
2691 /* Logging. */
2692 if (bgp_debug_update(peer, p, 1))
2693 zlog_debug ("%s rcvd UPDATE about %s/%d -- withdrawn",
2694 peer->host,
2695 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2696 p->prefixlen);
2697
2698 /* Lookup node. */
2699 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2700
2701 /* If peer is soft reconfiguration enabled. Record input packet for
2702 further calculation. */
2703 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2704 && peer != bgp->peer_self)
2705 bgp_adj_in_unset (rn, peer);
2706
2707 /* Lookup withdrawn route. */
2708 for (ri = rn->info; ri; ri = ri->next)
2709 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2710 ri->addpath_rx_id == addpath_id)
2711 break;
2712
2713 /* Withdraw specified route from routing table. */
2714 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2715 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2716 else if (bgp_debug_update(peer, p, 1))
2717 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2718 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2719 p->prefixlen);
2720
2721 /* Unlock bgp_node_get() lock. */
2722 bgp_unlock_node (rn);
2723
2724 return 0;
2725 }
2726
2727 void
2728 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2729 {
2730 struct bgp *bgp;
2731 struct attr attr;
2732 struct aspath *aspath;
2733 struct prefix p;
2734 struct peer *from;
2735 struct bgp_node *rn;
2736 struct bgp_info *ri;
2737 int ret = RMAP_DENYMATCH;
2738
2739 if (!(afi == AFI_IP || afi == AFI_IP6))
2740 return;
2741
2742 bgp = peer->bgp;
2743 from = bgp->peer_self;
2744
2745 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2746 aspath = attr.aspath;
2747 attr.local_pref = bgp->default_local_pref;
2748 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2749
2750 if (afi == AFI_IP)
2751 str2prefix ("0.0.0.0/0", &p);
2752 #ifdef HAVE_IPV6
2753 else if (afi == AFI_IP6)
2754 {
2755 struct attr_extra *ae = attr.extra;
2756
2757 str2prefix ("::/0", &p);
2758
2759 /* IPv6 global nexthop must be included. */
2760 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
2761 IPV6_MAX_BYTELEN);
2762 ae->mp_nexthop_len = 16;
2763
2764 /* If the peer is on shared nextwork and we have link-local
2765 nexthop set it. */
2766 if (peer->shared_network
2767 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2768 {
2769 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
2770 IPV6_MAX_BYTELEN);
2771 ae->mp_nexthop_len = 32;
2772 }
2773 }
2774 #endif /* HAVE_IPV6 */
2775
2776 if (peer->default_rmap[afi][safi].name)
2777 {
2778 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2779 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2780 {
2781 for (ri = rn->info; ri; ri = ri->next)
2782 {
2783 struct attr dummy_attr;
2784 struct attr_extra dummy_extra;
2785 struct bgp_info info;
2786
2787 /* Provide dummy so the route-map can't modify the attributes */
2788 dummy_attr.extra = &dummy_extra;
2789 bgp_attr_dup(&dummy_attr, ri->attr);
2790 info.peer = ri->peer;
2791 info.attr = &dummy_attr;
2792
2793 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2794 RMAP_BGP, &info);
2795
2796 /* The route map might have set attributes. If we don't flush them
2797 * here, they will be leaked. */
2798 bgp_attr_flush(&dummy_attr);
2799 if (ret != RMAP_DENYMATCH)
2800 break;
2801 }
2802 if (ret != RMAP_DENYMATCH)
2803 break;
2804 }
2805 bgp->peer_self->rmap_type = 0;
2806
2807 if (ret == RMAP_DENYMATCH)
2808 withdraw = 1;
2809 }
2810
2811 if (withdraw)
2812 {
2813 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2814 bgp_default_withdraw_send (peer, afi, safi);
2815 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2816 }
2817 else
2818 {
2819 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2820 {
2821 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2822 bgp_default_update_send (peer, &attr, afi, safi, from);
2823 }
2824 }
2825
2826 bgp_attr_extra_free (&attr);
2827 aspath_unintern (&aspath);
2828 }
2829
2830 static void
2831 bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
2832 struct bgp_table *table, int rsclient)
2833 {
2834 struct bgp_node *rn;
2835 struct bgp_info *ri;
2836 struct attr attr;
2837 struct attr_extra extra;
2838
2839 if (! table)
2840 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
2841
2842 if (safi != SAFI_MPLS_VPN
2843 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2844 bgp_default_originate (peer, afi, safi, 0);
2845
2846 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2847 attr.extra = &extra;
2848
2849 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2850 for (ri = rn->info; ri; ri = ri->next)
2851 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2852 {
2853 if ( (rsclient) ?
2854 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2855 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
2856 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2857 else
2858 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2859 }
2860 }
2861
2862 void
2863 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2864 {
2865 struct bgp_node *rn;
2866 struct bgp_table *table;
2867
2868 if (peer->status != Established)
2869 return;
2870
2871 if (! peer->afc_nego[afi][safi])
2872 return;
2873
2874 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2875 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2876 return;
2877
2878 if (safi != SAFI_MPLS_VPN)
2879 bgp_announce_table (peer, afi, safi, NULL, 0);
2880 else
2881 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2882 rn = bgp_route_next(rn))
2883 if ((table = (rn->info)) != NULL)
2884 bgp_announce_table (peer, afi, safi, table, 0);
2885
2886 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2887 bgp_announce_table (peer, afi, safi, NULL, 1);
2888
2889 /*
2890 * The write thread needs to be scheduled since it may not be done as
2891 * part of building adj_out.
2892 */
2893 bgp_peer_schedule_updates(peer);
2894 }
2895
2896 void
2897 bgp_announce_route_all (struct peer *peer)
2898 {
2899 afi_t afi;
2900 safi_t safi;
2901
2902 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2903 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2904 bgp_announce_route (peer, afi, safi);
2905 }
2906
2907 static void
2908 bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2909 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
2910 {
2911 struct bgp_node *rn;
2912 struct bgp_adj_in *ain;
2913
2914 if (! table)
2915 table = rsclient->bgp->rib[afi][safi];
2916
2917 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2918 for (ain = rn->adj_in; ain; ain = ain->next)
2919 {
2920 struct bgp_info *ri = rn->info;
2921 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2922
2923 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2924 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
2925 }
2926 }
2927
2928 void
2929 bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2930 {
2931 struct bgp_table *table;
2932 struct bgp_node *rn;
2933
2934 if (safi != SAFI_MPLS_VPN)
2935 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
2936
2937 else
2938 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2939 rn = bgp_route_next (rn))
2940 if ((table = rn->info) != NULL)
2941 {
2942 struct prefix_rd prd;
2943 prd.family = AF_UNSPEC;
2944 prd.prefixlen = 64;
2945 memcpy(&prd.val, rn->p.u.val, 8);
2946
2947 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2948 }
2949 }
2950
2951 static void
2952 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2953 struct bgp_table *table, struct prefix_rd *prd)
2954 {
2955 int ret;
2956 struct bgp_node *rn;
2957 struct bgp_adj_in *ain;
2958
2959 if (! table)
2960 table = peer->bgp->rib[afi][safi];
2961
2962 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2963 for (ain = rn->adj_in; ain; ain = ain->next)
2964 {
2965 if (ain->peer == peer)
2966 {
2967 struct bgp_info *ri = rn->info;
2968 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2969
2970 ret = bgp_update (peer, &rn->p, ri->addpath_rx_id, ain->attr,
2971 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2972 prd, tag, 1);
2973
2974 if (ret < 0)
2975 {
2976 bgp_unlock_node (rn);
2977 return;
2978 }
2979 continue;
2980 }
2981 }
2982 }
2983
2984 void
2985 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2986 {
2987 struct bgp_node *rn;
2988 struct bgp_table *table;
2989
2990 if (peer->status != Established)
2991 return;
2992
2993 if (safi != SAFI_MPLS_VPN)
2994 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
2995 else
2996 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2997 rn = bgp_route_next (rn))
2998 if ((table = rn->info) != NULL)
2999 {
3000 struct prefix_rd prd;
3001 prd.family = AF_UNSPEC;
3002 prd.prefixlen = 64;
3003 memcpy(&prd.val, rn->p.u.val, 8);
3004
3005 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3006 }
3007 }
3008
3009
3010 struct bgp_clear_node_queue
3011 {
3012 struct bgp_node *rn;
3013 enum bgp_clear_route_type purpose;
3014 };
3015
3016 static wq_item_status
3017 bgp_clear_route_node (struct work_queue *wq, void *data)
3018 {
3019 struct bgp_clear_node_queue *cnq = data;
3020 struct bgp_node *rn = cnq->rn;
3021 struct peer *peer = wq->spec.data;
3022 struct bgp_info *ri;
3023 afi_t afi = bgp_node_table (rn)->afi;
3024 safi_t safi = bgp_node_table (rn)->safi;
3025
3026 assert (rn && peer);
3027
3028 for (ri = rn->info; ri; ri = ri->next)
3029 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3030 {
3031 /* graceful restart STALE flag set. */
3032 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3033 && peer->nsf[afi][safi]
3034 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
3035 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3036 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
3037 else
3038 bgp_rib_remove (rn, ri, peer, afi, safi);
3039 break;
3040 }
3041 return WQ_SUCCESS;
3042 }
3043
3044 static void
3045 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
3046 {
3047 struct bgp_clear_node_queue *cnq = data;
3048 struct bgp_node *rn = cnq->rn;
3049 struct bgp_table *table = bgp_node_table (rn);
3050
3051 bgp_unlock_node (rn);
3052 bgp_table_unlock (table);
3053 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
3054 }
3055
3056 static void
3057 bgp_clear_node_complete (struct work_queue *wq)
3058 {
3059 struct peer *peer = wq->spec.data;
3060
3061 /* Tickle FSM to start moving again */
3062 BGP_EVENT_ADD (peer, Clearing_Completed);
3063
3064 peer_unlock (peer); /* bgp_clear_route */
3065 }
3066
3067 static void
3068 bgp_clear_node_queue_init (struct peer *peer)
3069 {
3070 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
3071
3072 snprintf (wname, sizeof(wname), "clear %s", peer->host);
3073 #undef CLEAR_QUEUE_NAME_LEN
3074
3075 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
3076 {
3077 zlog_err ("%s: Failed to allocate work queue", __func__);
3078 exit (1);
3079 }
3080 peer->clear_node_queue->spec.hold = 10;
3081 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3082 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3083 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3084 peer->clear_node_queue->spec.max_retries = 0;
3085
3086 /* we only 'lock' this peer reference when the queue is actually active */
3087 peer->clear_node_queue->spec.data = peer;
3088 }
3089
3090 static void
3091 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
3092 struct bgp_table *table, struct peer *rsclient,
3093 enum bgp_clear_route_type purpose)
3094 {
3095 struct bgp_node *rn;
3096
3097
3098 if (! table)
3099 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
3100
3101 /* If still no table => afi/safi isn't configured at all or smth. */
3102 if (! table)
3103 return;
3104
3105 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3106 {
3107 struct bgp_info *ri;
3108 struct bgp_adj_in *ain;
3109 struct bgp_adj_out *aout;
3110
3111 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3112 * queued for every clearing peer, regardless of whether it is
3113 * relevant to the peer at hand.
3114 *
3115 * Overview: There are 3 different indices which need to be
3116 * scrubbed, potentially, when a peer is removed:
3117 *
3118 * 1 peer's routes visible via the RIB (ie accepted routes)
3119 * 2 peer's routes visible by the (optional) peer's adj-in index
3120 * 3 other routes visible by the peer's adj-out index
3121 *
3122 * 3 there is no hurry in scrubbing, once the struct peer is
3123 * removed from bgp->peer, we could just GC such deleted peer's
3124 * adj-outs at our leisure.
3125 *
3126 * 1 and 2 must be 'scrubbed' in some way, at least made
3127 * invisible via RIB index before peer session is allowed to be
3128 * brought back up. So one needs to know when such a 'search' is
3129 * complete.
3130 *
3131 * Ideally:
3132 *
3133 * - there'd be a single global queue or a single RIB walker
3134 * - rather than tracking which route_nodes still need to be
3135 * examined on a peer basis, we'd track which peers still
3136 * aren't cleared
3137 *
3138 * Given that our per-peer prefix-counts now should be reliable,
3139 * this may actually be achievable. It doesn't seem to be a huge
3140 * problem at this time,
3141 */
3142 for (ain = rn->adj_in; ain; ain = ain->next)
3143 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3144 {
3145 bgp_adj_in_remove (rn, ain);
3146 bgp_unlock_node (rn);
3147 break;
3148 }
3149 for (aout = rn->adj_out; aout; aout = aout->next)
3150 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3151 {
3152 bgp_adj_out_remove (rn, aout, peer, afi, safi);
3153 bgp_unlock_node (rn);
3154 break;
3155 }
3156
3157 for (ri = rn->info; ri; ri = ri->next)
3158 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3159 {
3160 struct bgp_clear_node_queue *cnq;
3161
3162 /* both unlocked in bgp_clear_node_queue_del */
3163 bgp_table_lock (bgp_node_table (rn));
3164 bgp_lock_node (rn);
3165 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3166 sizeof (struct bgp_clear_node_queue));
3167 cnq->rn = rn;
3168 cnq->purpose = purpose;
3169 work_queue_add (peer->clear_node_queue, cnq);
3170 break;
3171 }
3172 }
3173 return;
3174 }
3175
3176 void
3177 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
3178 enum bgp_clear_route_type purpose)
3179 {
3180 struct bgp_node *rn;
3181 struct bgp_table *table;
3182 struct peer *rsclient;
3183 struct listnode *node, *nnode;
3184
3185 if (peer->clear_node_queue == NULL)
3186 bgp_clear_node_queue_init (peer);
3187
3188 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3189 * Idle until it receives a Clearing_Completed event. This protects
3190 * against peers which flap faster than we can we clear, which could
3191 * lead to:
3192 *
3193 * a) race with routes from the new session being installed before
3194 * clear_route_node visits the node (to delete the route of that
3195 * peer)
3196 * b) resource exhaustion, clear_route_node likely leads to an entry
3197 * on the process_main queue. Fast-flapping could cause that queue
3198 * to grow and grow.
3199 */
3200 if (!peer->clear_node_queue->thread)
3201 peer_lock (peer); /* bgp_clear_node_complete */
3202
3203 switch (purpose)
3204 {
3205 case BGP_CLEAR_ROUTE_NORMAL:
3206 if (safi != SAFI_MPLS_VPN)
3207 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3208 else
3209 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3210 rn = bgp_route_next (rn))
3211 if ((table = rn->info) != NULL)
3212 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3213
3214 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3215 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3216 PEER_FLAG_RSERVER_CLIENT))
3217 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3218 break;
3219
3220 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3221 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3222 break;
3223
3224 default:
3225 assert (0);
3226 break;
3227 }
3228
3229 /* If no routes were cleared, nothing was added to workqueue, the
3230 * completion function won't be run by workqueue code - call it here.
3231 * XXX: Actually, this assumption doesn't hold, see
3232 * bgp_clear_route_table(), we queue all non-empty nodes.
3233 *
3234 * Additionally, there is a presumption in FSM that clearing is only
3235 * really needed if peer state is Established - peers in
3236 * pre-Established states shouldn't have any route-update state
3237 * associated with them (in or out).
3238 *
3239 * We still can get here in pre-Established though, through
3240 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
3241 * check to ensure the assumption above holds.
3242 *
3243 * At some future point, this check could be move to the top of the
3244 * function, and do a quick early-return when state is
3245 * pre-Established, avoiding above list and table scans. Once we're
3246 * sure it is safe..
3247 */
3248 if (!peer->clear_node_queue->thread)
3249 bgp_clear_node_complete (peer->clear_node_queue);
3250 }
3251
3252 void
3253 bgp_clear_route_all (struct peer *peer)
3254 {
3255 afi_t afi;
3256 safi_t safi;
3257
3258 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3259 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3260 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
3261 }
3262
3263 void
3264 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3265 {
3266 struct bgp_table *table;
3267 struct bgp_node *rn;
3268 struct bgp_adj_in *ain;
3269
3270 table = peer->bgp->rib[afi][safi];
3271
3272 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3273 for (ain = rn->adj_in; ain ; ain = ain->next)
3274 if (ain->peer == peer)
3275 {
3276 bgp_adj_in_remove (rn, ain);
3277 bgp_unlock_node (rn);
3278 break;
3279 }
3280 }
3281
3282 void
3283 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3284 {
3285 struct bgp_node *rn;
3286 struct bgp_info *ri;
3287 struct bgp_table *table;
3288
3289 table = peer->bgp->rib[afi][safi];
3290
3291 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3292 {
3293 for (ri = rn->info; ri; ri = ri->next)
3294 if (ri->peer == peer)
3295 {
3296 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3297 bgp_rib_remove (rn, ri, peer, afi, safi);
3298 break;
3299 }
3300 }
3301 }
3302
3303 /* Delete all kernel routes. */
3304 void
3305 bgp_cleanup_routes (void)
3306 {
3307 struct bgp *bgp;
3308 struct listnode *node, *nnode;
3309 struct bgp_node *rn;
3310 struct bgp_table *table;
3311 struct bgp_info *ri;
3312
3313 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
3314 {
3315 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3316
3317 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3318 for (ri = rn->info; ri; ri = ri->next)
3319 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3320 && ri->type == ZEBRA_ROUTE_BGP
3321 && ri->sub_type == BGP_ROUTE_NORMAL)
3322 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
3323
3324 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3325
3326 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3327 for (ri = rn->info; ri; ri = ri->next)
3328 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3329 && ri->type == ZEBRA_ROUTE_BGP
3330 && ri->sub_type == BGP_ROUTE_NORMAL)
3331 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
3332 }
3333 }
3334
3335 void
3336 bgp_reset (void)
3337 {
3338 vty_reset ();
3339 bgp_zclient_reset ();
3340 access_list_reset ();
3341 prefix_list_reset ();
3342 }
3343
3344 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3345 value. */
3346 int
3347 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3348 {
3349 u_char *pnt;
3350 u_char *lim;
3351 struct prefix p;
3352 int psize;
3353 int ret;
3354 afi_t afi;
3355 safi_t safi;
3356 u_char addpath_encoded;
3357 u_int32_t addpath_id;
3358
3359 /* Check peer status. */
3360 if (peer->status != Established)
3361 return 0;
3362
3363 pnt = packet->nlri;
3364 lim = pnt + packet->length;
3365 afi = packet->afi;
3366 safi = packet->safi;
3367 addpath_id = 0;
3368
3369 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3370 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3371
3372 for (; pnt < lim; pnt += psize)
3373 {
3374 /* Clear prefix structure. */
3375 memset (&p, 0, sizeof (struct prefix));
3376
3377 if (addpath_encoded)
3378 {
3379 addpath_id = ntohl(*((uint32_t*) pnt));
3380 pnt += BGP_ADDPATH_ID_LEN;
3381 }
3382
3383 /* Fetch prefix length. */
3384 p.prefixlen = *pnt++;
3385 p.family = afi2family (afi);
3386
3387 /* Already checked in nlri_sanity_check(). We do double check
3388 here. */
3389 if ((afi == AFI_IP && p.prefixlen > 32)
3390 || (afi == AFI_IP6 && p.prefixlen > 128))
3391 return -1;
3392
3393 /* Packet size overflow check. */
3394 psize = PSIZE (p.prefixlen);
3395
3396 /* When packet overflow occur return immediately. */
3397 if (pnt + psize > lim)
3398 return -1;
3399
3400 /* Fetch prefix from NLRI packet. */
3401 memcpy (&p.u.prefix, pnt, psize);
3402
3403 /* Check address. */
3404 if (afi == AFI_IP && safi == SAFI_UNICAST)
3405 {
3406 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3407 {
3408 /*
3409 * From draft-ietf-idr-bgp4-22, Section 6.3:
3410 * If a BGP router receives an UPDATE message with a
3411 * semantically incorrect NLRI field, in which a prefix is
3412 * semantically incorrect (eg. an unexpected multicast IP
3413 * address), it should ignore the prefix.
3414 */
3415 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3416 inet_ntoa (p.u.prefix4));
3417
3418 return -1;
3419 }
3420 }
3421
3422 #ifdef HAVE_IPV6
3423 /* Check address. */
3424 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3425 {
3426 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3427 {
3428 char buf[BUFSIZ];
3429
3430 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3431 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3432
3433 continue;
3434 }
3435 }
3436 #endif /* HAVE_IPV6 */
3437
3438 /* Normal process. */
3439 if (attr)
3440 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3441 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3442 else
3443 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3444 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3445
3446 /* Address family configuration mismatch or maximum-prefix count
3447 overflow. */
3448 if (ret < 0)
3449 return -1;
3450 }
3451
3452 /* Packet length consistency check. */
3453 if (pnt != lim)
3454 return -1;
3455
3456 return 0;
3457 }
3458
3459 /* NLRI encode syntax check routine. */
3460 int
3461 bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
3462 bgp_size_t length, int *numpfx)
3463 {
3464 u_char *end;
3465 u_char prefixlen;
3466 int psize;
3467 u_char addpath_encoded;
3468
3469 *numpfx = 0;
3470 end = pnt + length;
3471
3472 addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3473 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3474
3475 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3476 syntactic validity. If the field is syntactically incorrect,
3477 then the Error Subcode is set to Invalid Network Field. */
3478
3479 while (pnt < end)
3480 {
3481 /* If the NLRI is encoded using addpath then the first 4 bytes are
3482 * the addpath ID. */
3483 if (addpath_encoded)
3484 pnt += BGP_ADDPATH_ID_LEN;
3485
3486 prefixlen = *pnt++;
3487
3488 /* Prefix length check. */
3489 if ((afi == AFI_IP && prefixlen > 32)
3490 || (afi == AFI_IP6 && prefixlen > 128))
3491 {
3492 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
3493 peer->host, prefixlen);
3494 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3495 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3496 return -1;
3497 }
3498
3499 /* Packet size overflow check. */
3500 psize = PSIZE (prefixlen);
3501
3502 if (pnt + psize > end)
3503 {
3504 zlog_err ("%s [Error] Update packet error"
3505 " (prefix data overflow prefix size is %d)",
3506 peer->host, psize);
3507 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3508 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3509 return -1;
3510 }
3511
3512 pnt += psize;
3513 (*numpfx)++;
3514 }
3515
3516 /* Packet length consistency check. */
3517 if (pnt != end)
3518 {
3519 zlog_err ("%s [Error] Update packet error"
3520 " (prefix length mismatch with total length)",
3521 peer->host);
3522 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3523 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3524 return -1;
3525 }
3526 return 0;
3527 }
3528
3529 static struct bgp_static *
3530 bgp_static_new (void)
3531 {
3532 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3533 }
3534
3535 static void
3536 bgp_static_free (struct bgp_static *bgp_static)
3537 {
3538 if (bgp_static->rmap.name)
3539 free (bgp_static->rmap.name);
3540 XFREE (MTYPE_BGP_STATIC, bgp_static);
3541 }
3542
3543 static void
3544 bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3545 struct prefix *p, afi_t afi, safi_t safi)
3546 {
3547 struct bgp_node *rn;
3548 struct bgp_info *ri;
3549
3550 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3551
3552 /* Check selected route and self inserted route. */
3553 for (ri = rn->info; ri; ri = ri->next)
3554 if (ri->peer == bgp->peer_self
3555 && ri->type == ZEBRA_ROUTE_BGP
3556 && ri->sub_type == BGP_ROUTE_STATIC)
3557 break;
3558
3559 /* Withdraw static BGP route from routing table. */
3560 if (ri)
3561 {
3562 bgp_info_delete (rn, ri);
3563 bgp_process (bgp, rn, afi, safi);
3564 }
3565
3566 /* Unlock bgp_node_lookup. */
3567 bgp_unlock_node (rn);
3568 }
3569
3570 static void
3571 bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
3572 struct bgp_static *bgp_static,
3573 afi_t afi, safi_t safi)
3574 {
3575 struct bgp_node *rn;
3576 struct bgp_info *ri;
3577 struct bgp_info *new;
3578 struct bgp_info info;
3579 struct attr *attr_new;
3580 struct attr attr;
3581 struct attr new_attr;
3582 struct attr_extra new_extra;
3583 struct bgp *bgp;
3584 int ret;
3585 char buf[SU_ADDRSTRLEN];
3586
3587 bgp = rsclient->bgp;
3588
3589 assert (bgp_static);
3590 if (!bgp_static)
3591 return;
3592
3593 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3594
3595 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3596
3597 attr.nexthop = bgp_static->igpnexthop;
3598 attr.med = bgp_static->igpmetric;
3599 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3600
3601 if (bgp_static->atomic)
3602 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3603
3604 /* Apply network route-map for export to this rsclient. */
3605 if (bgp_static->rmap.name)
3606 {
3607 struct attr attr_tmp = attr;
3608 info.peer = rsclient;
3609 info.attr = &attr_tmp;
3610
3611 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3612 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3613
3614 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3615
3616 rsclient->rmap_type = 0;
3617
3618 if (ret == RMAP_DENYMATCH)
3619 {
3620 /* Free uninterned attribute. */
3621 bgp_attr_flush (&attr_tmp);
3622
3623 /* Unintern original. */
3624 aspath_unintern (&attr.aspath);
3625 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3626 bgp_attr_extra_free (&attr);
3627
3628 return;
3629 }
3630 attr_new = bgp_attr_intern (&attr_tmp);
3631 }
3632 else
3633 attr_new = bgp_attr_intern (&attr);
3634
3635 new_attr.extra = &new_extra;
3636 bgp_attr_dup(&new_attr, attr_new);
3637
3638 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3639
3640 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3641 == RMAP_DENY)
3642 {
3643 /* This BGP update is filtered. Log the reason then update BGP entry. */
3644 if (bgp_debug_update(rsclient, p, 1))
3645 zlog_debug ("Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3646 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3647 p->prefixlen, rsclient->host);
3648
3649 bgp->peer_self->rmap_type = 0;
3650
3651 bgp_attr_unintern (&attr_new);
3652 aspath_unintern (&attr.aspath);
3653 bgp_attr_extra_free (&attr);
3654
3655 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3656
3657 return;
3658 }
3659
3660 bgp->peer_self->rmap_type = 0;
3661
3662 bgp_attr_unintern (&attr_new);
3663 attr_new = bgp_attr_intern (&new_attr);
3664
3665 for (ri = rn->info; ri; ri = ri->next)
3666 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3667 && ri->sub_type == BGP_ROUTE_STATIC)
3668 break;
3669
3670 if (ri)
3671 {
3672 if (attrhash_cmp (ri->attr, attr_new) &&
3673 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3674 {
3675 bgp_unlock_node (rn);
3676 bgp_attr_unintern (&attr_new);
3677 aspath_unintern (&attr.aspath);
3678 bgp_attr_extra_free (&attr);
3679 return;
3680 }
3681 else
3682 {
3683 /* The attribute is changed. */
3684 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3685
3686 /* Rewrite BGP route information. */
3687 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3688 bgp_info_restore(rn, ri);
3689 bgp_attr_unintern (&ri->attr);
3690 ri->attr = attr_new;
3691 ri->uptime = bgp_clock ();
3692
3693 /* Nexthop reachability check. */
3694 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3695 {
3696 if (bgp_find_or_add_nexthop (afi, ri, NULL, 0))
3697 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3698 else
3699 {
3700 if (BGP_DEBUG(nht, NHT))
3701 {
3702 char buf1[INET6_ADDRSTRLEN];
3703 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
3704 buf1, INET6_ADDRSTRLEN);
3705 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3706 }
3707 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3708 }
3709 }
3710 /* Process change. */
3711 bgp_process (bgp, rn, afi, safi);
3712 bgp_unlock_node (rn);
3713 aspath_unintern (&attr.aspath);
3714 bgp_attr_extra_free (&attr);
3715 return;
3716 }
3717 }
3718
3719 /* Make new BGP info. */
3720 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
3721 attr_new, rn);
3722 /* Nexthop reachability check. */
3723 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3724 {
3725 if (bgp_find_or_add_nexthop (afi, new, NULL, 0))
3726 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3727 else
3728 {
3729 if (BGP_DEBUG(nht, NHT))
3730 {
3731 char buf1[INET6_ADDRSTRLEN];
3732 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
3733 buf1, INET6_ADDRSTRLEN);
3734 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3735 }
3736 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3737 }
3738 }
3739 else
3740 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3741
3742 /* Register new BGP information. */
3743 bgp_info_add (rn, new);
3744
3745 /* route_node_get lock */
3746 bgp_unlock_node (rn);
3747
3748 /* Process change. */
3749 bgp_process (bgp, rn, afi, safi);
3750
3751 /* Unintern original. */
3752 aspath_unintern (&attr.aspath);
3753 bgp_attr_extra_free (&attr);
3754 }
3755
3756 static void
3757 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3758 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3759 {
3760 struct bgp_node *rn;
3761 struct bgp_info *ri;
3762 struct bgp_info *new;
3763 struct bgp_info info;
3764 struct attr attr;
3765 struct attr *attr_new;
3766 int ret;
3767
3768 assert (bgp_static);
3769 if (!bgp_static)
3770 return;
3771
3772 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3773
3774 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3775
3776 attr.nexthop = bgp_static->igpnexthop;
3777 attr.med = bgp_static->igpmetric;
3778 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3779
3780 if (bgp_static->atomic)
3781 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3782
3783 /* Apply route-map. */
3784 if (bgp_static->rmap.name)
3785 {
3786 struct attr attr_tmp = attr;
3787 info.peer = bgp->peer_self;
3788 info.attr = &attr_tmp;
3789
3790 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3791
3792 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3793
3794 bgp->peer_self->rmap_type = 0;
3795
3796 if (ret == RMAP_DENYMATCH)
3797 {
3798 /* Free uninterned attribute. */
3799 bgp_attr_flush (&attr_tmp);
3800
3801 /* Unintern original. */
3802 aspath_unintern (&attr.aspath);
3803 bgp_attr_extra_free (&attr);
3804 bgp_static_withdraw (bgp, p, afi, safi);
3805 return;
3806 }
3807 attr_new = bgp_attr_intern (&attr_tmp);
3808 }
3809 else
3810 attr_new = bgp_attr_intern (&attr);
3811
3812 for (ri = rn->info; ri; ri = ri->next)
3813 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3814 && ri->sub_type == BGP_ROUTE_STATIC)
3815 break;
3816
3817 if (ri)
3818 {
3819 if (attrhash_cmp (ri->attr, attr_new) &&
3820 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3821 {
3822 bgp_unlock_node (rn);
3823 bgp_attr_unintern (&attr_new);
3824 aspath_unintern (&attr.aspath);
3825 bgp_attr_extra_free (&attr);
3826 return;
3827 }
3828 else
3829 {
3830 /* The attribute is changed. */
3831 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3832
3833 /* Rewrite BGP route information. */
3834 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3835 bgp_info_restore(rn, ri);
3836 else
3837 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3838 bgp_attr_unintern (&ri->attr);
3839 ri->attr = attr_new;
3840 ri->uptime = bgp_clock ();
3841
3842 /* Nexthop reachability check. */
3843 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3844 {
3845 if (bgp_find_or_add_nexthop (afi, ri, NULL, 0))
3846 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3847 else
3848 {
3849 if (BGP_DEBUG(nht, NHT))
3850 {
3851 char buf1[INET6_ADDRSTRLEN];
3852 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
3853 buf1, INET6_ADDRSTRLEN);
3854 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3855 }
3856 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3857 }
3858 }
3859 /* Process change. */
3860 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3861 bgp_process (bgp, rn, afi, safi);
3862 bgp_unlock_node (rn);
3863 aspath_unintern (&attr.aspath);
3864 bgp_attr_extra_free (&attr);
3865 return;
3866 }
3867 }
3868
3869 /* Make new BGP info. */
3870 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3871 rn);
3872 /* Nexthop reachability check. */
3873 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3874 {
3875 if (bgp_find_or_add_nexthop (afi, new, NULL, 0))
3876 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3877 else
3878 {
3879 if (BGP_DEBUG(nht, NHT))
3880 {
3881 char buf1[INET6_ADDRSTRLEN];
3882 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1,
3883 INET6_ADDRSTRLEN);
3884 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3885 }
3886 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3887 }
3888 }
3889 else
3890 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3891
3892 /* Aggregate address increment. */
3893 bgp_aggregate_increment (bgp, p, new, afi, safi);
3894
3895 /* Register new BGP information. */
3896 bgp_info_add (rn, new);
3897
3898 /* route_node_get lock */
3899 bgp_unlock_node (rn);
3900
3901 /* Process change. */
3902 bgp_process (bgp, rn, afi, safi);
3903
3904 /* Unintern original. */
3905 aspath_unintern (&attr.aspath);
3906 bgp_attr_extra_free (&attr);
3907 }
3908
3909 void
3910 bgp_static_update (struct bgp *bgp, struct prefix *p,
3911 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3912 {
3913 struct peer *rsclient;
3914 struct listnode *node, *nnode;
3915
3916 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3917
3918 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
3919 {
3920 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3921 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3922 }
3923 }
3924
3925 static void
3926 bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3927 safi_t safi, struct prefix_rd *prd, u_char *tag)
3928 {
3929 struct bgp_node *rn;
3930 struct bgp_info *new;
3931
3932 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3933
3934 /* Make new BGP info. */
3935 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
3936 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3937
3938 SET_FLAG (new->flags, BGP_INFO_VALID);
3939 new->extra = bgp_info_extra_new();
3940 memcpy (new->extra->tag, tag, 3);
3941
3942 /* Aggregate address increment. */
3943 bgp_aggregate_increment (bgp, p, new, afi, safi);
3944
3945 /* Register new BGP information. */
3946 bgp_info_add (rn, new);
3947
3948 /* route_node_get lock */
3949 bgp_unlock_node (rn);
3950
3951 /* Process change. */
3952 bgp_process (bgp, rn, afi, safi);
3953 }
3954
3955 void
3956 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3957 safi_t safi)
3958 {
3959 struct bgp_node *rn;
3960 struct bgp_info *ri;
3961
3962 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3963
3964 /* Check selected route and self inserted route. */
3965 for (ri = rn->info; ri; ri = ri->next)
3966 if (ri->peer == bgp->peer_self
3967 && ri->type == ZEBRA_ROUTE_BGP
3968 && ri->sub_type == BGP_ROUTE_STATIC)
3969 break;
3970
3971 /* Withdraw static BGP route from routing table. */
3972 if (ri)
3973 {
3974 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3975 bgp_unlink_nexthop(ri);
3976 bgp_info_delete (rn, ri);
3977 bgp_process (bgp, rn, afi, safi);
3978 }
3979
3980 /* Unlock bgp_node_lookup. */
3981 bgp_unlock_node (rn);
3982 }
3983
3984 void
3985 bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3986 {
3987 struct bgp_static *bgp_static;
3988 struct bgp *bgp;
3989 struct bgp_node *rn;
3990 struct prefix *p;
3991
3992 bgp = rsclient->bgp;
3993
3994 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3995 if ((bgp_static = rn->info) != NULL)
3996 {
3997 p = &rn->p;
3998
3999 bgp_static_update_rsclient (rsclient, p, bgp_static,
4000 afi, safi);
4001 }
4002 }
4003
4004 static void
4005 bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
4006 safi_t safi, struct prefix_rd *prd, u_char *tag)
4007 {
4008 struct bgp_node *rn;
4009 struct bgp_info *ri;
4010
4011 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
4012
4013 /* Check selected route and self inserted route. */
4014 for (ri = rn->info; ri; ri = ri->next)
4015 if (ri->peer == bgp->peer_self
4016 && ri->type == ZEBRA_ROUTE_BGP
4017 && ri->sub_type == BGP_ROUTE_STATIC)
4018 break;
4019
4020 /* Withdraw static BGP route from routing table. */
4021 if (ri)
4022 {
4023 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
4024 bgp_info_delete (rn, ri);
4025 bgp_process (bgp, rn, afi, safi);
4026 }
4027
4028 /* Unlock bgp_node_lookup. */
4029 bgp_unlock_node (rn);
4030 }
4031
4032 /* Configure static BGP network. When user don't run zebra, static
4033 route should be installed as valid. */
4034 static int
4035 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
4036 afi_t afi, safi_t safi, const char *rmap, int backdoor)
4037 {
4038 int ret;
4039 struct prefix p;
4040 struct bgp_static *bgp_static;
4041 struct bgp_node *rn;
4042 u_char need_update = 0;
4043
4044 /* Convert IP prefix string to struct prefix. */
4045 ret = str2prefix (ip_str, &p);
4046 if (! ret)
4047 {
4048 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4049 return CMD_WARNING;
4050 }
4051 #ifdef HAVE_IPV6
4052 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4053 {
4054 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4055 VTY_NEWLINE);
4056 return CMD_WARNING;
4057 }
4058 #endif /* HAVE_IPV6 */
4059
4060 apply_mask (&p);
4061
4062 /* Set BGP static route configuration. */
4063 rn = bgp_node_get (bgp->route[afi][safi], &p);
4064
4065 if (rn->info)
4066 {
4067 /* Configuration change. */
4068 bgp_static = rn->info;
4069
4070 /* Check previous routes are installed into BGP. */
4071 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4072 need_update = 1;
4073
4074 bgp_static->backdoor = backdoor;
4075
4076 if (rmap)
4077 {
4078 if (bgp_static->rmap.name)
4079 free (bgp_static->rmap.name);
4080 bgp_static->rmap.name = strdup (rmap);
4081 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4082 }
4083 else
4084 {
4085 if (bgp_static->rmap.name)
4086 free (bgp_static->rmap.name);
4087 bgp_static->rmap.name = NULL;
4088 bgp_static->rmap.map = NULL;
4089 bgp_static->valid = 0;
4090 }
4091 bgp_unlock_node (rn);
4092 }
4093 else
4094 {
4095 /* New configuration. */
4096 bgp_static = bgp_static_new ();
4097 bgp_static->backdoor = backdoor;
4098 bgp_static->valid = 0;
4099 bgp_static->igpmetric = 0;
4100 bgp_static->igpnexthop.s_addr = 0;
4101
4102 if (rmap)
4103 {
4104 if (bgp_static->rmap.name)
4105 free (bgp_static->rmap.name);
4106 bgp_static->rmap.name = strdup (rmap);
4107 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4108 }
4109 rn->info = bgp_static;
4110 }
4111
4112 bgp_static->valid = 1;
4113 if (need_update)
4114 bgp_static_withdraw (bgp, &p, afi, safi);
4115
4116 if (! bgp_static->backdoor)
4117 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4118
4119 return CMD_SUCCESS;
4120 }
4121
4122 /* Configure static BGP network. */
4123 static int
4124 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4125 afi_t afi, safi_t safi)
4126 {
4127 int ret;
4128 struct prefix p;
4129 struct bgp_static *bgp_static;
4130 struct bgp_node *rn;
4131
4132 /* Convert IP prefix string to struct prefix. */
4133 ret = str2prefix (ip_str, &p);
4134 if (! ret)
4135 {
4136 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4137 return CMD_WARNING;
4138 }
4139 #ifdef HAVE_IPV6
4140 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4141 {
4142 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4143 VTY_NEWLINE);
4144 return CMD_WARNING;
4145 }
4146 #endif /* HAVE_IPV6 */
4147
4148 apply_mask (&p);
4149
4150 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4151 if (! rn)
4152 {
4153 vty_out (vty, "%% Can't find specified static route configuration.%s",
4154 VTY_NEWLINE);
4155 return CMD_WARNING;
4156 }
4157
4158 bgp_static = rn->info;
4159
4160 /* Update BGP RIB. */
4161 if (! bgp_static->backdoor)
4162 bgp_static_withdraw (bgp, &p, afi, safi);
4163
4164 /* Clear configuration. */
4165 bgp_unlink_nexthop(bgp_static);
4166 bgp_static_free (bgp_static);
4167 rn->info = NULL;
4168 bgp_unlock_node (rn);
4169 bgp_unlock_node (rn);
4170
4171 return CMD_SUCCESS;
4172 }
4173
4174 /* Called from bgp_delete(). Delete all static routes from the BGP
4175 instance. */
4176 void
4177 bgp_static_delete (struct bgp *bgp)
4178 {
4179 afi_t afi;
4180 safi_t safi;
4181 struct bgp_node *rn;
4182 struct bgp_node *rm;
4183 struct bgp_table *table;
4184 struct bgp_static *bgp_static;
4185
4186 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4187 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4188 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4189 if (rn->info != NULL)
4190 {
4191 if (safi == SAFI_MPLS_VPN)
4192 {
4193 table = rn->info;
4194
4195 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4196 {
4197 bgp_static = rn->info;
4198 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
4199 AFI_IP, SAFI_MPLS_VPN,
4200 (struct prefix_rd *)&rn->p,
4201 bgp_static->tag);
4202 bgp_static_free (bgp_static);
4203 rn->info = NULL;
4204 bgp_unlock_node (rn);
4205 }
4206 }
4207 else
4208 {
4209 bgp_static = rn->info;
4210 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4211 bgp_static_free (bgp_static);
4212 rn->info = NULL;
4213 bgp_unlock_node (rn);
4214 }
4215 }
4216 }
4217
4218 int
4219 bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
4220 const char *tag_str)
4221 {
4222 int ret;
4223 struct prefix p;
4224 struct prefix_rd prd;
4225 struct bgp *bgp;
4226 struct bgp_node *prn;
4227 struct bgp_node *rn;
4228 struct bgp_table *table;
4229 struct bgp_static *bgp_static;
4230 u_char tag[3];
4231
4232 bgp = vty->index;
4233
4234 ret = str2prefix (ip_str, &p);
4235 if (! ret)
4236 {
4237 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4238 return CMD_WARNING;
4239 }
4240 apply_mask (&p);
4241
4242 ret = str2prefix_rd (rd_str, &prd);
4243 if (! ret)
4244 {
4245 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4246 return CMD_WARNING;
4247 }
4248
4249 ret = str2tag (tag_str, tag);
4250 if (! ret)
4251 {
4252 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4253 return CMD_WARNING;
4254 }
4255
4256 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4257 (struct prefix *)&prd);
4258 if (prn->info == NULL)
4259 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
4260 else
4261 bgp_unlock_node (prn);
4262 table = prn->info;
4263
4264 rn = bgp_node_get (table, &p);
4265
4266 if (rn->info)
4267 {
4268 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4269 bgp_unlock_node (rn);
4270 }
4271 else
4272 {
4273 /* New configuration. */
4274 bgp_static = bgp_static_new ();
4275 bgp_static->valid = 1;
4276 memcpy (bgp_static->tag, tag, 3);
4277 rn->info = bgp_static;
4278
4279 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4280 }
4281
4282 return CMD_SUCCESS;
4283 }
4284
4285 /* Configure static BGP network. */
4286 int
4287 bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
4288 const char *rd_str, const char *tag_str)
4289 {
4290 int ret;
4291 struct bgp *bgp;
4292 struct prefix p;
4293 struct prefix_rd prd;
4294 struct bgp_node *prn;
4295 struct bgp_node *rn;
4296 struct bgp_table *table;
4297 struct bgp_static *bgp_static;
4298 u_char tag[3];
4299
4300 bgp = vty->index;
4301
4302 /* Convert IP prefix string to struct prefix. */
4303 ret = str2prefix (ip_str, &p);
4304 if (! ret)
4305 {
4306 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4307 return CMD_WARNING;
4308 }
4309 apply_mask (&p);
4310
4311 ret = str2prefix_rd (rd_str, &prd);
4312 if (! ret)
4313 {
4314 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4315 return CMD_WARNING;
4316 }
4317
4318 ret = str2tag (tag_str, tag);
4319 if (! ret)
4320 {
4321 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4322 return CMD_WARNING;
4323 }
4324
4325 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4326 (struct prefix *)&prd);
4327 if (prn->info == NULL)
4328 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
4329 else
4330 bgp_unlock_node (prn);
4331 table = prn->info;
4332
4333 rn = bgp_node_lookup (table, &p);
4334
4335 if (rn)
4336 {
4337 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4338
4339 bgp_static = rn->info;
4340 bgp_static_free (bgp_static);
4341 rn->info = NULL;
4342 bgp_unlock_node (rn);
4343 bgp_unlock_node (rn);
4344 }
4345 else
4346 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4347
4348 return CMD_SUCCESS;
4349 }
4350
4351 static int
4352 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4353 const char *rmap_name)
4354 {
4355 struct bgp_rmap *rmap;
4356
4357 rmap = &bgp->table_map[afi][safi];
4358 if (rmap_name)
4359 {
4360 if (rmap->name)
4361 free (rmap->name);
4362 rmap->name = strdup (rmap_name);
4363 rmap->map = route_map_lookup_by_name (rmap_name);
4364 }
4365 else
4366 {
4367 if (rmap->name)
4368 free (rmap->name);
4369 rmap->name = NULL;
4370 rmap->map = NULL;
4371 }
4372
4373 bgp_zebra_announce_table(bgp, afi, safi);
4374
4375 return CMD_SUCCESS;
4376 }
4377
4378 static int
4379 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4380 const char *rmap_name)
4381 {
4382 struct bgp_rmap *rmap;
4383
4384 rmap = &bgp->table_map[afi][safi];
4385 if (rmap->name)
4386 free (rmap->name);
4387 rmap->name = NULL;
4388 rmap->map = NULL;
4389
4390 bgp_zebra_announce_table(bgp, afi, safi);
4391
4392 return CMD_SUCCESS;
4393 }
4394
4395 int
4396 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4397 safi_t safi, int *write)
4398 {
4399 if (bgp->table_map[afi][safi].name)
4400 {
4401 bgp_config_write_family_header (vty, afi, safi, write);
4402 vty_out (vty, " table-map %s%s",
4403 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4404 }
4405
4406 return 0;
4407 }
4408
4409
4410 DEFUN (bgp_table_map,
4411 bgp_table_map_cmd,
4412 "table-map WORD",
4413 "BGP table to RIB route download filter\n"
4414 "Name of the route map\n")
4415 {
4416 return bgp_table_map_set (vty, vty->index,
4417 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4418 }
4419 DEFUN (no_bgp_table_map,
4420 no_bgp_table_map_cmd,
4421 "no table-map WORD",
4422 "BGP table to RIB route download filter\n"
4423 "Name of the route map\n")
4424 {
4425 return bgp_table_map_unset (vty, vty->index,
4426 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4427 }
4428
4429 DEFUN (bgp_network,
4430 bgp_network_cmd,
4431 "network A.B.C.D/M",
4432 "Specify a network to announce via BGP\n"
4433 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4434 {
4435 return bgp_static_set (vty, vty->index, argv[0],
4436 AFI_IP, bgp_node_safi (vty), NULL, 0);
4437 }
4438
4439 DEFUN (bgp_network_route_map,
4440 bgp_network_route_map_cmd,
4441 "network A.B.C.D/M route-map WORD",
4442 "Specify a network to announce via BGP\n"
4443 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4444 "Route-map to modify the attributes\n"
4445 "Name of the route map\n")
4446 {
4447 return bgp_static_set (vty, vty->index, argv[0],
4448 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4449 }
4450
4451 DEFUN (bgp_network_backdoor,
4452 bgp_network_backdoor_cmd,
4453 "network A.B.C.D/M backdoor",
4454 "Specify a network to announce via BGP\n"
4455 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4456 "Specify a BGP backdoor route\n")
4457 {
4458 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4459 NULL, 1);
4460 }
4461
4462 DEFUN (bgp_network_mask,
4463 bgp_network_mask_cmd,
4464 "network A.B.C.D mask A.B.C.D",
4465 "Specify a network to announce via BGP\n"
4466 "Network number\n"
4467 "Network mask\n"
4468 "Network mask\n")
4469 {
4470 int ret;
4471 char prefix_str[BUFSIZ];
4472
4473 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4474 if (! ret)
4475 {
4476 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4477 return CMD_WARNING;
4478 }
4479
4480 return bgp_static_set (vty, vty->index, prefix_str,
4481 AFI_IP, bgp_node_safi (vty), NULL, 0);
4482 }
4483
4484 DEFUN (bgp_network_mask_route_map,
4485 bgp_network_mask_route_map_cmd,
4486 "network A.B.C.D mask A.B.C.D route-map WORD",
4487 "Specify a network to announce via BGP\n"
4488 "Network number\n"
4489 "Network mask\n"
4490 "Network mask\n"
4491 "Route-map to modify the attributes\n"
4492 "Name of the route map\n")
4493 {
4494 int ret;
4495 char prefix_str[BUFSIZ];
4496
4497 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4498 if (! ret)
4499 {
4500 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4501 return CMD_WARNING;
4502 }
4503
4504 return bgp_static_set (vty, vty->index, prefix_str,
4505 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4506 }
4507
4508 DEFUN (bgp_network_mask_backdoor,
4509 bgp_network_mask_backdoor_cmd,
4510 "network A.B.C.D mask A.B.C.D backdoor",
4511 "Specify a network to announce via BGP\n"
4512 "Network number\n"
4513 "Network mask\n"
4514 "Network mask\n"
4515 "Specify a BGP backdoor route\n")
4516 {
4517 int ret;
4518 char prefix_str[BUFSIZ];
4519
4520 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4521 if (! ret)
4522 {
4523 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4524 return CMD_WARNING;
4525 }
4526
4527 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4528 NULL, 1);
4529 }
4530
4531 DEFUN (bgp_network_mask_natural,
4532 bgp_network_mask_natural_cmd,
4533 "network A.B.C.D",
4534 "Specify a network to announce via BGP\n"
4535 "Network number\n")
4536 {
4537 int ret;
4538 char prefix_str[BUFSIZ];
4539
4540 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4541 if (! ret)
4542 {
4543 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4544 return CMD_WARNING;
4545 }
4546
4547 return bgp_static_set (vty, vty->index, prefix_str,
4548 AFI_IP, bgp_node_safi (vty), NULL, 0);
4549 }
4550
4551 DEFUN (bgp_network_mask_natural_route_map,
4552 bgp_network_mask_natural_route_map_cmd,
4553 "network A.B.C.D route-map WORD",
4554 "Specify a network to announce via BGP\n"
4555 "Network number\n"
4556 "Route-map to modify the attributes\n"
4557 "Name of the route map\n")
4558 {
4559 int ret;
4560 char prefix_str[BUFSIZ];
4561
4562 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4563 if (! ret)
4564 {
4565 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4566 return CMD_WARNING;
4567 }
4568
4569 return bgp_static_set (vty, vty->index, prefix_str,
4570 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4571 }
4572
4573 DEFUN (bgp_network_mask_natural_backdoor,
4574 bgp_network_mask_natural_backdoor_cmd,
4575 "network A.B.C.D backdoor",
4576 "Specify a network to announce via BGP\n"
4577 "Network number\n"
4578 "Specify a BGP backdoor route\n")
4579 {
4580 int ret;
4581 char prefix_str[BUFSIZ];
4582
4583 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4584 if (! ret)
4585 {
4586 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4587 return CMD_WARNING;
4588 }
4589
4590 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4591 NULL, 1);
4592 }
4593
4594 DEFUN (no_bgp_network,
4595 no_bgp_network_cmd,
4596 "no network A.B.C.D/M",
4597 NO_STR
4598 "Specify a network to announce via BGP\n"
4599 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4600 {
4601 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4602 bgp_node_safi (vty));
4603 }
4604
4605 ALIAS (no_bgp_network,
4606 no_bgp_network_route_map_cmd,
4607 "no network A.B.C.D/M route-map WORD",
4608 NO_STR
4609 "Specify a network to announce via BGP\n"
4610 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4611 "Route-map to modify the attributes\n"
4612 "Name of the route map\n")
4613
4614 ALIAS (no_bgp_network,
4615 no_bgp_network_backdoor_cmd,
4616 "no network A.B.C.D/M backdoor",
4617 NO_STR
4618 "Specify a network to announce via BGP\n"
4619 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4620 "Specify a BGP backdoor route\n")
4621
4622 DEFUN (no_bgp_network_mask,
4623 no_bgp_network_mask_cmd,
4624 "no network A.B.C.D mask A.B.C.D",
4625 NO_STR
4626 "Specify a network to announce via BGP\n"
4627 "Network number\n"
4628 "Network mask\n"
4629 "Network mask\n")
4630 {
4631 int ret;
4632 char prefix_str[BUFSIZ];
4633
4634 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4635 if (! ret)
4636 {
4637 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4638 return CMD_WARNING;
4639 }
4640
4641 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4642 bgp_node_safi (vty));
4643 }
4644
4645 ALIAS (no_bgp_network_mask,
4646 no_bgp_network_mask_route_map_cmd,
4647 "no network A.B.C.D mask A.B.C.D route-map WORD",
4648 NO_STR
4649 "Specify a network to announce via BGP\n"
4650 "Network number\n"
4651 "Network mask\n"
4652 "Network mask\n"
4653 "Route-map to modify the attributes\n"
4654 "Name of the route map\n")
4655
4656 ALIAS (no_bgp_network_mask,
4657 no_bgp_network_mask_backdoor_cmd,
4658 "no network A.B.C.D mask A.B.C.D backdoor",
4659 NO_STR
4660 "Specify a network to announce via BGP\n"
4661 "Network number\n"
4662 "Network mask\n"
4663 "Network mask\n"
4664 "Specify a BGP backdoor route\n")
4665
4666 DEFUN (no_bgp_network_mask_natural,
4667 no_bgp_network_mask_natural_cmd,
4668 "no network A.B.C.D",
4669 NO_STR
4670 "Specify a network to announce via BGP\n"
4671 "Network number\n")
4672 {
4673 int ret;
4674 char prefix_str[BUFSIZ];
4675
4676 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4677 if (! ret)
4678 {
4679 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4680 return CMD_WARNING;
4681 }
4682
4683 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4684 bgp_node_safi (vty));
4685 }
4686
4687 ALIAS (no_bgp_network_mask_natural,
4688 no_bgp_network_mask_natural_route_map_cmd,
4689 "no network A.B.C.D route-map WORD",
4690 NO_STR
4691 "Specify a network to announce via BGP\n"
4692 "Network number\n"
4693 "Route-map to modify the attributes\n"
4694 "Name of the route map\n")
4695
4696 ALIAS (no_bgp_network_mask_natural,
4697 no_bgp_network_mask_natural_backdoor_cmd,
4698 "no network A.B.C.D backdoor",
4699 NO_STR
4700 "Specify a network to announce via BGP\n"
4701 "Network number\n"
4702 "Specify a BGP backdoor route\n")
4703
4704 #ifdef HAVE_IPV6
4705 DEFUN (ipv6_bgp_network,
4706 ipv6_bgp_network_cmd,
4707 "network X:X::X:X/M",
4708 "Specify a network to announce via BGP\n"
4709 "IPv6 prefix <network>/<length>\n")
4710 {
4711 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4712 NULL, 0);
4713 }
4714
4715 DEFUN (ipv6_bgp_network_route_map,
4716 ipv6_bgp_network_route_map_cmd,
4717 "network X:X::X:X/M route-map WORD",
4718 "Specify a network to announce via BGP\n"
4719 "IPv6 prefix <network>/<length>\n"
4720 "Route-map to modify the attributes\n"
4721 "Name of the route map\n")
4722 {
4723 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4724 bgp_node_safi (vty), argv[1], 0);
4725 }
4726
4727 DEFUN (no_ipv6_bgp_network,
4728 no_ipv6_bgp_network_cmd,
4729 "no network X:X::X:X/M",
4730 NO_STR
4731 "Specify a network to announce via BGP\n"
4732 "IPv6 prefix <network>/<length>\n")
4733 {
4734 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4735 }
4736
4737 ALIAS (no_ipv6_bgp_network,
4738 no_ipv6_bgp_network_route_map_cmd,
4739 "no network X:X::X:X/M route-map WORD",
4740 NO_STR
4741 "Specify a network to announce via BGP\n"
4742 "IPv6 prefix <network>/<length>\n"
4743 "Route-map to modify the attributes\n"
4744 "Name of the route map\n")
4745
4746 ALIAS (ipv6_bgp_network,
4747 old_ipv6_bgp_network_cmd,
4748 "ipv6 bgp network X:X::X:X/M",
4749 IPV6_STR
4750 BGP_STR
4751 "Specify a network to announce via BGP\n"
4752 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4753
4754 ALIAS (no_ipv6_bgp_network,
4755 old_no_ipv6_bgp_network_cmd,
4756 "no ipv6 bgp network X:X::X:X/M",
4757 NO_STR
4758 IPV6_STR
4759 BGP_STR
4760 "Specify a network to announce via BGP\n"
4761 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4762 #endif /* HAVE_IPV6 */
4763
4764 /* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4765 ALIAS_DEPRECATED (bgp_network,
4766 bgp_network_ttl_cmd,
4767 "network A.B.C.D/M pathlimit <0-255>",
4768 "Specify a network to announce via BGP\n"
4769 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4770 "AS-Path hopcount limit attribute\n"
4771 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4772 ALIAS_DEPRECATED (bgp_network_backdoor,
4773 bgp_network_backdoor_ttl_cmd,
4774 "network A.B.C.D/M backdoor pathlimit <0-255>",
4775 "Specify a network to announce via BGP\n"
4776 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4777 "Specify a BGP backdoor route\n"
4778 "AS-Path hopcount limit attribute\n"
4779 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4780 ALIAS_DEPRECATED (bgp_network_mask,
4781 bgp_network_mask_ttl_cmd,
4782 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4783 "Specify a network to announce via BGP\n"
4784 "Network number\n"
4785 "Network mask\n"
4786 "Network mask\n"
4787 "AS-Path hopcount limit attribute\n"
4788 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4789 ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4790 bgp_network_mask_backdoor_ttl_cmd,
4791 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4792 "Specify a network to announce via BGP\n"
4793 "Network number\n"
4794 "Network mask\n"
4795 "Network mask\n"
4796 "Specify a BGP backdoor route\n"
4797 "AS-Path hopcount limit attribute\n"
4798 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4799 ALIAS_DEPRECATED (bgp_network_mask_natural,
4800 bgp_network_mask_natural_ttl_cmd,
4801 "network A.B.C.D pathlimit <0-255>",
4802 "Specify a network to announce via BGP\n"
4803 "Network number\n"
4804 "AS-Path hopcount limit attribute\n"
4805 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4806 ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4807 bgp_network_mask_natural_backdoor_ttl_cmd,
4808 "network A.B.C.D backdoor pathlimit <1-255>",
4809 "Specify a network to announce via BGP\n"
4810 "Network number\n"
4811 "Specify a BGP backdoor route\n"
4812 "AS-Path hopcount limit attribute\n"
4813 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4814 ALIAS_DEPRECATED (no_bgp_network,
4815 no_bgp_network_ttl_cmd,
4816 "no network A.B.C.D/M pathlimit <0-255>",
4817 NO_STR
4818 "Specify a network to announce via BGP\n"
4819 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4820 "AS-Path hopcount limit attribute\n"
4821 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4822 ALIAS_DEPRECATED (no_bgp_network,
4823 no_bgp_network_backdoor_ttl_cmd,
4824 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4825 NO_STR
4826 "Specify a network to announce via BGP\n"
4827 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4828 "Specify a BGP backdoor route\n"
4829 "AS-Path hopcount limit attribute\n"
4830 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4831 ALIAS_DEPRECATED (no_bgp_network,
4832 no_bgp_network_mask_ttl_cmd,
4833 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4834 NO_STR
4835 "Specify a network to announce via BGP\n"
4836 "Network number\n"
4837 "Network mask\n"
4838 "Network mask\n"
4839 "AS-Path hopcount limit attribute\n"
4840 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4841 ALIAS_DEPRECATED (no_bgp_network_mask,
4842 no_bgp_network_mask_backdoor_ttl_cmd,
4843 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4844 NO_STR
4845 "Specify a network to announce via BGP\n"
4846 "Network number\n"
4847 "Network mask\n"
4848 "Network mask\n"
4849 "Specify a BGP backdoor route\n"
4850 "AS-Path hopcount limit attribute\n"
4851 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4852 ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4853 no_bgp_network_mask_natural_ttl_cmd,
4854 "no network A.B.C.D pathlimit <0-255>",
4855 NO_STR
4856 "Specify a network to announce via BGP\n"
4857 "Network number\n"
4858 "AS-Path hopcount limit attribute\n"
4859 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4860 ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4861 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4862 "no network A.B.C.D backdoor pathlimit <0-255>",
4863 NO_STR
4864 "Specify a network to announce via BGP\n"
4865 "Network number\n"
4866 "Specify a BGP backdoor route\n"
4867 "AS-Path hopcount limit attribute\n"
4868 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4869 #ifdef HAVE_IPV6
4870 ALIAS_DEPRECATED (ipv6_bgp_network,
4871 ipv6_bgp_network_ttl_cmd,
4872 "network X:X::X:X/M pathlimit <0-255>",
4873 "Specify a network to announce via BGP\n"
4874 "IPv6 prefix <network>/<length>\n"
4875 "AS-Path hopcount limit attribute\n"
4876 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4877 ALIAS_DEPRECATED (no_ipv6_bgp_network,
4878 no_ipv6_bgp_network_ttl_cmd,
4879 "no network X:X::X:X/M pathlimit <0-255>",
4880 NO_STR
4881 "Specify a network to announce via BGP\n"
4882 "IPv6 prefix <network>/<length>\n"
4883 "AS-Path hopcount limit attribute\n"
4884 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4885 #endif /* HAVE_IPV6 */
4886
4887 /* Aggreagete address:
4888
4889 advertise-map Set condition to advertise attribute
4890 as-set Generate AS set path information
4891 attribute-map Set attributes of aggregate
4892 route-map Set parameters of aggregate
4893 summary-only Filter more specific routes from updates
4894 suppress-map Conditionally filter more specific routes from updates
4895 <cr>
4896 */
4897 struct bgp_aggregate
4898 {
4899 /* Summary-only flag. */
4900 u_char summary_only;
4901
4902 /* AS set generation. */
4903 u_char as_set;
4904
4905 /* Route-map for aggregated route. */
4906 struct route_map *map;
4907
4908 /* Suppress-count. */
4909 unsigned long count;
4910
4911 /* SAFI configuration. */
4912 safi_t safi;
4913 };
4914
4915 static struct bgp_aggregate *
4916 bgp_aggregate_new (void)
4917 {
4918 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4919 }
4920
4921 static void
4922 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4923 {
4924 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4925 }
4926
4927 /* Update an aggregate as routes are added/removed from the BGP table */
4928 static void
4929 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4930 afi_t afi, safi_t safi, struct bgp_info *del,
4931 struct bgp_aggregate *aggregate)
4932 {
4933 struct bgp_table *table;
4934 struct bgp_node *top;
4935 struct bgp_node *rn;
4936 u_char origin;
4937 struct aspath *aspath = NULL;
4938 struct aspath *asmerge = NULL;
4939 struct community *community = NULL;
4940 struct community *commerge = NULL;
4941 struct in_addr nexthop;
4942 u_int32_t med = 0;
4943 struct bgp_info *ri;
4944 struct bgp_info *new;
4945 int first = 1;
4946 unsigned long match = 0;
4947 u_char atomic_aggregate = 0;
4948
4949 /* Record adding route's nexthop and med. */
4950 if (rinew)
4951 {
4952 nexthop = rinew->attr->nexthop;
4953 med = rinew->attr->med;
4954 }
4955
4956 /* ORIGIN attribute: If at least one route among routes that are
4957 aggregated has ORIGIN with the value INCOMPLETE, then the
4958 aggregated route must have the ORIGIN attribute with the value
4959 INCOMPLETE. Otherwise, if at least one route among routes that
4960 are aggregated has ORIGIN with the value EGP, then the aggregated
4961 route must have the origin attribute with the value EGP. In all
4962 other case the value of the ORIGIN attribute of the aggregated
4963 route is INTERNAL. */
4964 origin = BGP_ORIGIN_IGP;
4965
4966 table = bgp->rib[afi][safi];
4967
4968 top = bgp_node_get (table, p);
4969 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4970 if (rn->p.prefixlen > p->prefixlen)
4971 {
4972 match = 0;
4973
4974 for (ri = rn->info; ri; ri = ri->next)
4975 {
4976 if (BGP_INFO_HOLDDOWN (ri))
4977 continue;
4978
4979 if (del && ri == del)
4980 continue;
4981
4982 if (! rinew && first)
4983 {
4984 nexthop = ri->attr->nexthop;
4985 med = ri->attr->med;
4986 first = 0;
4987 }
4988
4989 #ifdef AGGREGATE_NEXTHOP_CHECK
4990 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4991 || ri->attr->med != med)
4992 {
4993 if (aspath)
4994 aspath_free (aspath);
4995 if (community)
4996 community_free (community);
4997 bgp_unlock_node (rn);
4998 bgp_unlock_node (top);
4999 return;
5000 }
5001 #endif /* AGGREGATE_NEXTHOP_CHECK */
5002
5003 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5004 atomic_aggregate = 1;
5005
5006 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5007 {
5008 if (aggregate->summary_only)
5009 {
5010 (bgp_info_extra_get (ri))->suppress++;
5011 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5012 match++;
5013 }
5014
5015 aggregate->count++;
5016
5017 if (origin < ri->attr->origin)
5018 origin = ri->attr->origin;
5019
5020 if (aggregate->as_set)
5021 {
5022 if (aspath)
5023 {
5024 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5025 aspath_free (aspath);
5026 aspath = asmerge;
5027 }
5028 else
5029 aspath = aspath_dup (ri->attr->aspath);
5030
5031 if (ri->attr->community)
5032 {
5033 if (community)
5034 {
5035 commerge = community_merge (community,
5036 ri->attr->community);
5037 community = community_uniq_sort (commerge);
5038 community_free (commerge);
5039 }
5040 else
5041 community = community_dup (ri->attr->community);
5042 }
5043 }
5044 }
5045 }
5046 if (match)
5047 bgp_process (bgp, rn, afi, safi);
5048 }
5049 bgp_unlock_node (top);
5050
5051 if (rinew)
5052 {
5053 aggregate->count++;
5054
5055 if (aggregate->summary_only)
5056 (bgp_info_extra_get (rinew))->suppress++;
5057
5058 if (origin < rinew->attr->origin)
5059 origin = rinew->attr->origin;
5060
5061 if (aggregate->as_set)
5062 {
5063 if (aspath)
5064 {
5065 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5066 aspath_free (aspath);
5067 aspath = asmerge;
5068 }
5069 else
5070 aspath = aspath_dup (rinew->attr->aspath);
5071
5072 if (rinew->attr->community)
5073 {
5074 if (community)
5075 {
5076 commerge = community_merge (community,
5077 rinew->attr->community);
5078 community = community_uniq_sort (commerge);
5079 community_free (commerge);
5080 }
5081 else
5082 community = community_dup (rinew->attr->community);
5083 }
5084 }
5085 }
5086
5087 if (aggregate->count > 0)
5088 {
5089 rn = bgp_node_get (table, p);
5090 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5091 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5092 aggregate->as_set,
5093 atomic_aggregate), rn);
5094 SET_FLAG (new->flags, BGP_INFO_VALID);
5095
5096 bgp_info_add (rn, new);
5097 bgp_unlock_node (rn);
5098 bgp_process (bgp, rn, afi, safi);
5099 }
5100 else
5101 {
5102 if (aspath)
5103 aspath_free (aspath);
5104 if (community)
5105 community_free (community);
5106 }
5107 }
5108
5109 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5110 struct bgp_aggregate *);
5111
5112 void
5113 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5114 struct bgp_info *ri, afi_t afi, safi_t safi)
5115 {
5116 struct bgp_node *child;
5117 struct bgp_node *rn;
5118 struct bgp_aggregate *aggregate;
5119 struct bgp_table *table;
5120
5121 /* MPLS-VPN aggregation is not yet supported. */
5122 if (safi == SAFI_MPLS_VPN)
5123 return;
5124
5125 table = bgp->aggregate[afi][safi];
5126
5127 /* No aggregates configured. */
5128 if (bgp_table_top_nolock (table) == NULL)
5129 return;
5130
5131 if (p->prefixlen == 0)
5132 return;
5133
5134 if (BGP_INFO_HOLDDOWN (ri))
5135 return;
5136
5137 child = bgp_node_get (table, p);
5138
5139 /* Aggregate address configuration check. */
5140 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5141 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5142 {
5143 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5144 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
5145 }
5146 bgp_unlock_node (child);
5147 }
5148
5149 void
5150 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5151 struct bgp_info *del, afi_t afi, safi_t safi)
5152 {
5153 struct bgp_node *child;
5154 struct bgp_node *rn;
5155 struct bgp_aggregate *aggregate;
5156 struct bgp_table *table;
5157
5158 /* MPLS-VPN aggregation is not yet supported. */
5159 if (safi == SAFI_MPLS_VPN)
5160 return;
5161
5162 table = bgp->aggregate[afi][safi];
5163
5164 /* No aggregates configured. */
5165 if (bgp_table_top_nolock (table) == NULL)
5166 return;
5167
5168 if (p->prefixlen == 0)
5169 return;
5170
5171 child = bgp_node_get (table, p);
5172
5173 /* Aggregate address configuration check. */
5174 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5175 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5176 {
5177 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5178 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
5179 }
5180 bgp_unlock_node (child);
5181 }
5182
5183 /* Called via bgp_aggregate_set when the user configures aggregate-address */
5184 static void
5185 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5186 struct bgp_aggregate *aggregate)
5187 {
5188 struct bgp_table *table;
5189 struct bgp_node *top;
5190 struct bgp_node *rn;
5191 struct bgp_info *new;
5192 struct bgp_info *ri;
5193 unsigned long match;
5194 u_char origin = BGP_ORIGIN_IGP;
5195 struct aspath *aspath = NULL;
5196 struct aspath *asmerge = NULL;
5197 struct community *community = NULL;
5198 struct community *commerge = NULL;
5199 u_char atomic_aggregate = 0;
5200
5201 table = bgp->rib[afi][safi];
5202
5203 /* Sanity check. */
5204 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5205 return;
5206 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5207 return;
5208
5209 /* If routes exists below this node, generate aggregate routes. */
5210 top = bgp_node_get (table, p);
5211 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5212 if (rn->p.prefixlen > p->prefixlen)
5213 {
5214 match = 0;
5215
5216 for (ri = rn->info; ri; ri = ri->next)
5217 {
5218 if (BGP_INFO_HOLDDOWN (ri))
5219 continue;
5220
5221 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5222 atomic_aggregate = 1;
5223
5224 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5225 {
5226 /* summary-only aggregate route suppress aggregated
5227 route announcement. */
5228 if (aggregate->summary_only)
5229 {
5230 (bgp_info_extra_get (ri))->suppress++;
5231 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5232 match++;
5233 }
5234
5235 /* If at least one route among routes that are aggregated has
5236 * ORIGIN with the value INCOMPLETE, then the aggregated route
5237 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5238 * Otherwise, if at least one route among routes that are
5239 * aggregated has ORIGIN with the value EGP, then the aggregated
5240 * route MUST have the ORIGIN attribute with the value EGP.
5241 */
5242 if (origin < ri->attr->origin)
5243 origin = ri->attr->origin;
5244
5245 /* as-set aggregate route generate origin, as path,
5246 community aggregation. */
5247 if (aggregate->as_set)
5248 {
5249 if (aspath)
5250 {
5251 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5252 aspath_free (aspath);
5253 aspath = asmerge;
5254 }
5255 else
5256 aspath = aspath_dup (ri->attr->aspath);
5257
5258 if (ri->attr->community)
5259 {
5260 if (community)
5261 {
5262 commerge = community_merge (community,
5263 ri->attr->community);
5264 community = community_uniq_sort (commerge);
5265 community_free (commerge);
5266 }
5267 else
5268 community = community_dup (ri->attr->community);
5269 }
5270 }
5271 aggregate->count++;
5272 }
5273 }
5274
5275 /* If this node is suppressed, process the change. */
5276 if (match)
5277 bgp_process (bgp, rn, afi, safi);
5278 }
5279 bgp_unlock_node (top);
5280
5281 /* Add aggregate route to BGP table. */
5282 if (aggregate->count)
5283 {
5284 rn = bgp_node_get (table, p);
5285 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5286 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5287 aggregate->as_set,
5288 atomic_aggregate), rn);
5289 SET_FLAG (new->flags, BGP_INFO_VALID);
5290
5291 bgp_info_add (rn, new);
5292 bgp_unlock_node (rn);
5293
5294 /* Process change. */
5295 bgp_process (bgp, rn, afi, safi);
5296 }
5297 }
5298
5299 void
5300 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5301 safi_t safi, struct bgp_aggregate *aggregate)
5302 {
5303 struct bgp_table *table;
5304 struct bgp_node *top;
5305 struct bgp_node *rn;
5306 struct bgp_info *ri;
5307 unsigned long match;
5308
5309 table = bgp->rib[afi][safi];
5310
5311 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5312 return;
5313 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5314 return;
5315
5316 /* If routes exists below this node, generate aggregate routes. */
5317 top = bgp_node_get (table, p);
5318 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5319 if (rn->p.prefixlen > p->prefixlen)
5320 {
5321 match = 0;
5322
5323 for (ri = rn->info; ri; ri = ri->next)
5324 {
5325 if (BGP_INFO_HOLDDOWN (ri))
5326 continue;
5327
5328 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5329 {
5330 if (aggregate->summary_only && ri->extra)
5331 {
5332 ri->extra->suppress--;
5333
5334 if (ri->extra->suppress == 0)
5335 {
5336 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5337 match++;
5338 }
5339 }
5340 aggregate->count--;
5341 }
5342 }
5343
5344 /* If this node was suppressed, process the change. */
5345 if (match)
5346 bgp_process (bgp, rn, afi, safi);
5347 }
5348 bgp_unlock_node (top);
5349
5350 /* Delete aggregate route from BGP table. */
5351 rn = bgp_node_get (table, p);
5352
5353 for (ri = rn->info; ri; ri = ri->next)
5354 if (ri->peer == bgp->peer_self
5355 && ri->type == ZEBRA_ROUTE_BGP
5356 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5357 break;
5358
5359 /* Withdraw static BGP route from routing table. */
5360 if (ri)
5361 {
5362 bgp_info_delete (rn, ri);
5363 bgp_process (bgp, rn, afi, safi);
5364 }
5365
5366 /* Unlock bgp_node_lookup. */
5367 bgp_unlock_node (rn);
5368 }
5369
5370 /* Aggregate route attribute. */
5371 #define AGGREGATE_SUMMARY_ONLY 1
5372 #define AGGREGATE_AS_SET 1
5373
5374 static int
5375 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5376 afi_t afi, safi_t safi)
5377 {
5378 int ret;
5379 struct prefix p;
5380 struct bgp_node *rn;
5381 struct bgp *bgp;
5382 struct bgp_aggregate *aggregate;
5383
5384 /* Convert string to prefix structure. */
5385 ret = str2prefix (prefix_str, &p);
5386 if (!ret)
5387 {
5388 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5389 return CMD_WARNING;
5390 }
5391 apply_mask (&p);
5392
5393 /* Get BGP structure. */
5394 bgp = vty->index;
5395
5396 /* Old configuration check. */
5397 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5398 if (! rn)
5399 {
5400 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5401 VTY_NEWLINE);
5402 return CMD_WARNING;
5403 }
5404
5405 aggregate = rn->info;
5406 if (aggregate->safi & SAFI_UNICAST)
5407 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5408 if (aggregate->safi & SAFI_MULTICAST)
5409 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5410
5411 /* Unlock aggregate address configuration. */
5412 rn->info = NULL;
5413 bgp_aggregate_free (aggregate);
5414 bgp_unlock_node (rn);
5415 bgp_unlock_node (rn);
5416
5417 return CMD_SUCCESS;
5418 }
5419
5420 static int
5421 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5422 afi_t afi, safi_t safi,
5423 u_char summary_only, u_char as_set)
5424 {
5425 int ret;
5426 struct prefix p;
5427 struct bgp_node *rn;
5428 struct bgp *bgp;
5429 struct bgp_aggregate *aggregate;
5430
5431 /* Convert string to prefix structure. */
5432 ret = str2prefix (prefix_str, &p);
5433 if (!ret)
5434 {
5435 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5436 return CMD_WARNING;
5437 }
5438 apply_mask (&p);
5439
5440 /* Get BGP structure. */
5441 bgp = vty->index;
5442
5443 /* Old configuration check. */
5444 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5445
5446 if (rn->info)
5447 {
5448 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5449 /* try to remove the old entry */
5450 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5451 if (ret)
5452 {
5453 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5454 bgp_unlock_node (rn);
5455 return CMD_WARNING;
5456 }
5457 }
5458
5459 /* Make aggregate address structure. */
5460 aggregate = bgp_aggregate_new ();
5461 aggregate->summary_only = summary_only;
5462 aggregate->as_set = as_set;
5463 aggregate->safi = safi;
5464 rn->info = aggregate;
5465
5466 /* Aggregate address insert into BGP routing table. */
5467 if (safi & SAFI_UNICAST)
5468 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5469 if (safi & SAFI_MULTICAST)
5470 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5471
5472 return CMD_SUCCESS;
5473 }
5474
5475 DEFUN (aggregate_address,
5476 aggregate_address_cmd,
5477 "aggregate-address A.B.C.D/M",
5478 "Configure BGP aggregate entries\n"
5479 "Aggregate prefix\n")
5480 {
5481 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5482 }
5483
5484 DEFUN (aggregate_address_mask,
5485 aggregate_address_mask_cmd,
5486 "aggregate-address A.B.C.D A.B.C.D",
5487 "Configure BGP aggregate entries\n"
5488 "Aggregate address\n"
5489 "Aggregate mask\n")
5490 {
5491 int ret;
5492 char prefix_str[BUFSIZ];
5493
5494 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5495
5496 if (! ret)
5497 {
5498 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5499 return CMD_WARNING;
5500 }
5501
5502 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5503 0, 0);
5504 }
5505
5506 DEFUN (aggregate_address_summary_only,
5507 aggregate_address_summary_only_cmd,
5508 "aggregate-address A.B.C.D/M summary-only",
5509 "Configure BGP aggregate entries\n"
5510 "Aggregate prefix\n"
5511 "Filter more specific routes from updates\n")
5512 {
5513 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5514 AGGREGATE_SUMMARY_ONLY, 0);
5515 }
5516
5517 DEFUN (aggregate_address_mask_summary_only,
5518 aggregate_address_mask_summary_only_cmd,
5519 "aggregate-address A.B.C.D A.B.C.D summary-only",
5520 "Configure BGP aggregate entries\n"
5521 "Aggregate address\n"
5522 "Aggregate mask\n"
5523 "Filter more specific routes from updates\n")
5524 {
5525 int ret;
5526 char prefix_str[BUFSIZ];
5527
5528 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5529
5530 if (! ret)
5531 {
5532 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5533 return CMD_WARNING;
5534 }
5535
5536 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5537 AGGREGATE_SUMMARY_ONLY, 0);
5538 }
5539
5540 DEFUN (aggregate_address_as_set,
5541 aggregate_address_as_set_cmd,
5542 "aggregate-address A.B.C.D/M as-set",
5543 "Configure BGP aggregate entries\n"
5544 "Aggregate prefix\n"
5545 "Generate AS set path information\n")
5546 {
5547 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5548 0, AGGREGATE_AS_SET);
5549 }
5550
5551 DEFUN (aggregate_address_mask_as_set,
5552 aggregate_address_mask_as_set_cmd,
5553 "aggregate-address A.B.C.D A.B.C.D as-set",
5554 "Configure BGP aggregate entries\n"
5555 "Aggregate address\n"
5556 "Aggregate mask\n"
5557 "Generate AS set path information\n")
5558 {
5559 int ret;
5560 char prefix_str[BUFSIZ];
5561
5562 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5563
5564 if (! ret)
5565 {
5566 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5567 return CMD_WARNING;
5568 }
5569
5570 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5571 0, AGGREGATE_AS_SET);
5572 }
5573
5574
5575 DEFUN (aggregate_address_as_set_summary,
5576 aggregate_address_as_set_summary_cmd,
5577 "aggregate-address A.B.C.D/M as-set summary-only",
5578 "Configure BGP aggregate entries\n"
5579 "Aggregate prefix\n"
5580 "Generate AS set path information\n"
5581 "Filter more specific routes from updates\n")
5582 {
5583 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5584 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5585 }
5586
5587 ALIAS (aggregate_address_as_set_summary,
5588 aggregate_address_summary_as_set_cmd,
5589 "aggregate-address A.B.C.D/M summary-only as-set",
5590 "Configure BGP aggregate entries\n"
5591 "Aggregate prefix\n"
5592 "Filter more specific routes from updates\n"
5593 "Generate AS set path information\n")
5594
5595 DEFUN (aggregate_address_mask_as_set_summary,
5596 aggregate_address_mask_as_set_summary_cmd,
5597 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5598 "Configure BGP aggregate entries\n"
5599 "Aggregate address\n"
5600 "Aggregate mask\n"
5601 "Generate AS set path information\n"
5602 "Filter more specific routes from updates\n")
5603 {
5604 int ret;
5605 char prefix_str[BUFSIZ];
5606
5607 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5608
5609 if (! ret)
5610 {
5611 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5612 return CMD_WARNING;
5613 }
5614
5615 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5616 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5617 }
5618
5619 ALIAS (aggregate_address_mask_as_set_summary,
5620 aggregate_address_mask_summary_as_set_cmd,
5621 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5622 "Configure BGP aggregate entries\n"
5623 "Aggregate address\n"
5624 "Aggregate mask\n"
5625 "Filter more specific routes from updates\n"
5626 "Generate AS set path information\n")
5627
5628 DEFUN (no_aggregate_address,
5629 no_aggregate_address_cmd,
5630 "no aggregate-address A.B.C.D/M",
5631 NO_STR
5632 "Configure BGP aggregate entries\n"
5633 "Aggregate prefix\n")
5634 {
5635 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5636 }
5637
5638 ALIAS (no_aggregate_address,
5639 no_aggregate_address_summary_only_cmd,
5640 "no aggregate-address A.B.C.D/M summary-only",
5641 NO_STR
5642 "Configure BGP aggregate entries\n"
5643 "Aggregate prefix\n"
5644 "Filter more specific routes from updates\n")
5645
5646 ALIAS (no_aggregate_address,
5647 no_aggregate_address_as_set_cmd,
5648 "no aggregate-address A.B.C.D/M as-set",
5649 NO_STR
5650 "Configure BGP aggregate entries\n"
5651 "Aggregate prefix\n"
5652 "Generate AS set path information\n")
5653
5654 ALIAS (no_aggregate_address,
5655 no_aggregate_address_as_set_summary_cmd,
5656 "no aggregate-address A.B.C.D/M as-set summary-only",
5657 NO_STR
5658 "Configure BGP aggregate entries\n"
5659 "Aggregate prefix\n"
5660 "Generate AS set path information\n"
5661 "Filter more specific routes from updates\n")
5662
5663 ALIAS (no_aggregate_address,
5664 no_aggregate_address_summary_as_set_cmd,
5665 "no aggregate-address A.B.C.D/M summary-only as-set",
5666 NO_STR
5667 "Configure BGP aggregate entries\n"
5668 "Aggregate prefix\n"
5669 "Filter more specific routes from updates\n"
5670 "Generate AS set path information\n")
5671
5672 DEFUN (no_aggregate_address_mask,
5673 no_aggregate_address_mask_cmd,
5674 "no aggregate-address A.B.C.D A.B.C.D",
5675 NO_STR
5676 "Configure BGP aggregate entries\n"
5677 "Aggregate address\n"
5678 "Aggregate mask\n")
5679 {
5680 int ret;
5681 char prefix_str[BUFSIZ];
5682
5683 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5684
5685 if (! ret)
5686 {
5687 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5688 return CMD_WARNING;
5689 }
5690
5691 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5692 }
5693
5694 ALIAS (no_aggregate_address_mask,
5695 no_aggregate_address_mask_summary_only_cmd,
5696 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5697 NO_STR
5698 "Configure BGP aggregate entries\n"
5699 "Aggregate address\n"
5700 "Aggregate mask\n"
5701 "Filter more specific routes from updates\n")
5702
5703 ALIAS (no_aggregate_address_mask,
5704 no_aggregate_address_mask_as_set_cmd,
5705 "no aggregate-address A.B.C.D A.B.C.D as-set",
5706 NO_STR
5707 "Configure BGP aggregate entries\n"
5708 "Aggregate address\n"
5709 "Aggregate mask\n"
5710 "Generate AS set path information\n")
5711
5712 ALIAS (no_aggregate_address_mask,
5713 no_aggregate_address_mask_as_set_summary_cmd,
5714 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5715 NO_STR
5716 "Configure BGP aggregate entries\n"
5717 "Aggregate address\n"
5718 "Aggregate mask\n"
5719 "Generate AS set path information\n"
5720 "Filter more specific routes from updates\n")
5721
5722 ALIAS (no_aggregate_address_mask,
5723 no_aggregate_address_mask_summary_as_set_cmd,
5724 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5725 NO_STR
5726 "Configure BGP aggregate entries\n"
5727 "Aggregate address\n"
5728 "Aggregate mask\n"
5729 "Filter more specific routes from updates\n"
5730 "Generate AS set path information\n")
5731
5732 #ifdef HAVE_IPV6
5733 DEFUN (ipv6_aggregate_address,
5734 ipv6_aggregate_address_cmd,
5735 "aggregate-address X:X::X:X/M",
5736 "Configure BGP aggregate entries\n"
5737 "Aggregate prefix\n")
5738 {
5739 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5740 }
5741
5742 DEFUN (ipv6_aggregate_address_summary_only,
5743 ipv6_aggregate_address_summary_only_cmd,
5744 "aggregate-address X:X::X:X/M summary-only",
5745 "Configure BGP aggregate entries\n"
5746 "Aggregate prefix\n"
5747 "Filter more specific routes from updates\n")
5748 {
5749 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5750 AGGREGATE_SUMMARY_ONLY, 0);
5751 }
5752
5753 DEFUN (no_ipv6_aggregate_address,
5754 no_ipv6_aggregate_address_cmd,
5755 "no aggregate-address X:X::X:X/M",
5756 NO_STR
5757 "Configure BGP aggregate entries\n"
5758 "Aggregate prefix\n")
5759 {
5760 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5761 }
5762
5763 DEFUN (no_ipv6_aggregate_address_summary_only,
5764 no_ipv6_aggregate_address_summary_only_cmd,
5765 "no aggregate-address X:X::X:X/M summary-only",
5766 NO_STR
5767 "Configure BGP aggregate entries\n"
5768 "Aggregate prefix\n"
5769 "Filter more specific routes from updates\n")
5770 {
5771 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5772 }
5773
5774 ALIAS (ipv6_aggregate_address,
5775 old_ipv6_aggregate_address_cmd,
5776 "ipv6 bgp aggregate-address X:X::X:X/M",
5777 IPV6_STR
5778 BGP_STR
5779 "Configure BGP aggregate entries\n"
5780 "Aggregate prefix\n")
5781
5782 ALIAS (ipv6_aggregate_address_summary_only,
5783 old_ipv6_aggregate_address_summary_only_cmd,
5784 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5785 IPV6_STR
5786 BGP_STR
5787 "Configure BGP aggregate entries\n"
5788 "Aggregate prefix\n"
5789 "Filter more specific routes from updates\n")
5790
5791 ALIAS (no_ipv6_aggregate_address,
5792 old_no_ipv6_aggregate_address_cmd,
5793 "no ipv6 bgp aggregate-address X:X::X:X/M",
5794 NO_STR
5795 IPV6_STR
5796 BGP_STR
5797 "Configure BGP aggregate entries\n"
5798 "Aggregate prefix\n")
5799
5800 ALIAS (no_ipv6_aggregate_address_summary_only,
5801 old_no_ipv6_aggregate_address_summary_only_cmd,
5802 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5803 NO_STR
5804 IPV6_STR
5805 BGP_STR
5806 "Configure BGP aggregate entries\n"
5807 "Aggregate prefix\n"
5808 "Filter more specific routes from updates\n")
5809 #endif /* HAVE_IPV6 */
5810
5811 /* Redistribute route treatment. */
5812 void
5813 bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5814 const struct in6_addr *nexthop6, unsigned int ifindex,
5815 u_int32_t metric, u_char type, u_short instance, u_short tag)
5816 {
5817 struct bgp *bgp;
5818 struct listnode *node, *nnode;
5819 struct bgp_info *new;
5820 struct bgp_info *bi;
5821 struct bgp_info info;
5822 struct bgp_node *bn;
5823 struct attr attr;
5824 struct attr *new_attr;
5825 afi_t afi;
5826 int ret;
5827 struct bgp_redist *red;
5828
5829 /* Make default attribute. */
5830 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5831 if (nexthop)
5832 attr.nexthop = *nexthop;
5833 attr.nh_ifindex = ifindex;
5834
5835 #ifdef HAVE_IPV6
5836 if (nexthop6)
5837 {
5838 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5839 extra->mp_nexthop_global = *nexthop6;
5840 extra->mp_nexthop_len = 16;
5841 }
5842 #endif
5843
5844 attr.med = metric;
5845 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5846 attr.extra->tag = tag;
5847
5848 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5849 {
5850 afi = family2afi (p->family);
5851
5852 red = bgp_redist_lookup(bgp, afi, type, instance);
5853 if (red)
5854 {
5855 struct attr attr_new;
5856 struct attr_extra extra_new;
5857
5858 /* Copy attribute for modification. */
5859 attr_new.extra = &extra_new;
5860 bgp_attr_dup (&attr_new, &attr);
5861
5862 if (red->redist_metric_flag)
5863 attr_new.med = red->redist_metric;
5864
5865 /* Apply route-map. */
5866 if (red->rmap.map)
5867 {
5868 info.peer = bgp->peer_self;
5869 info.attr = &attr_new;
5870
5871 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5872
5873 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5874
5875 bgp->peer_self->rmap_type = 0;
5876
5877 if (ret == RMAP_DENYMATCH)
5878 {
5879 /* Free uninterned attribute. */
5880 bgp_attr_flush (&attr_new);
5881
5882 /* Unintern original. */
5883 aspath_unintern (&attr.aspath);
5884 bgp_attr_extra_free (&attr);
5885 bgp_redistribute_delete (p, type, instance);
5886 return;
5887 }
5888 }
5889
5890 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5891 afi, SAFI_UNICAST, p, NULL);
5892
5893 new_attr = bgp_attr_intern (&attr_new);
5894
5895 for (bi = bn->info; bi; bi = bi->next)
5896 if (bi->peer == bgp->peer_self
5897 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5898 break;
5899
5900 if (bi)
5901 {
5902 if (attrhash_cmp (bi->attr, new_attr) &&
5903 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5904 {
5905 bgp_attr_unintern (&new_attr);
5906 aspath_unintern (&attr.aspath);
5907 bgp_attr_extra_free (&attr);
5908 bgp_unlock_node (bn);
5909 return;
5910 }
5911 else
5912 {
5913 /* The attribute is changed. */
5914 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5915
5916 /* Rewrite BGP route information. */
5917 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5918 bgp_info_restore(bn, bi);
5919 else
5920 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5921 bgp_attr_unintern (&bi->attr);
5922 bi->attr = new_attr;
5923 bi->uptime = bgp_clock ();
5924
5925 /* Process change. */
5926 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5927 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5928 bgp_unlock_node (bn);
5929 aspath_unintern (&attr.aspath);
5930 bgp_attr_extra_free (&attr);
5931 return;
5932 }
5933 }
5934
5935 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5936 new_attr, bn);
5937 SET_FLAG (new->flags, BGP_INFO_VALID);
5938
5939 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5940 bgp_info_add (bn, new);
5941 bgp_unlock_node (bn);
5942 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5943 }
5944 }
5945
5946 /* Unintern original. */
5947 aspath_unintern (&attr.aspath);
5948 bgp_attr_extra_free (&attr);
5949 }
5950
5951 void
5952 bgp_redistribute_delete (struct prefix *p, u_char type, u_short instance)
5953 {
5954 struct bgp *bgp;
5955 struct listnode *node, *nnode;
5956 afi_t afi;
5957 struct bgp_node *rn;
5958 struct bgp_info *ri;
5959 struct bgp_redist *red;
5960
5961 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5962 {
5963 afi = family2afi (p->family);
5964
5965 red = bgp_redist_lookup(bgp, afi, type, instance);
5966 if (red)
5967 {
5968 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5969
5970 for (ri = rn->info; ri; ri = ri->next)
5971 if (ri->peer == bgp->peer_self
5972 && ri->type == type)
5973 break;
5974
5975 if (ri)
5976 {
5977 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5978 bgp_info_delete (rn, ri);
5979 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5980 }
5981 bgp_unlock_node (rn);
5982 }
5983 }
5984 }
5985
5986 /* Withdraw specified route type's route. */
5987 void
5988 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
5989 {
5990 struct bgp_node *rn;
5991 struct bgp_info *ri;
5992 struct bgp_table *table;
5993
5994 table = bgp->rib[afi][SAFI_UNICAST];
5995
5996 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5997 {
5998 for (ri = rn->info; ri; ri = ri->next)
5999 if (ri->peer == bgp->peer_self
6000 && ri->type == type
6001 && ri->instance == instance)
6002 break;
6003
6004 if (ri)
6005 {
6006 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
6007 bgp_info_delete (rn, ri);
6008 bgp_process (bgp, rn, afi, SAFI_UNICAST);
6009 }
6010 }
6011 }
6012
6013 /* Static function to display route. */
6014 static void
6015 route_vty_out_route (struct prefix *p, struct vty *vty)
6016 {
6017 int len;
6018 u_int32_t destination;
6019 char buf[BUFSIZ];
6020
6021 if (p->family == AF_INET)
6022 {
6023 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6024 destination = ntohl (p->u.prefix4.s_addr);
6025
6026 if ((IN_CLASSC (destination) && p->prefixlen == 24)
6027 || (IN_CLASSB (destination) && p->prefixlen == 16)
6028 || (IN_CLASSA (destination) && p->prefixlen == 8)
6029 || p->u.prefix4.s_addr == 0)
6030 {
6031 /* When mask is natural, mask is not displayed. */
6032 }
6033 else
6034 len += vty_out (vty, "/%d", p->prefixlen);
6035 }
6036 else
6037 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6038 p->prefixlen);
6039
6040 len = 17 - len;
6041 if (len < 1)
6042 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6043 else
6044 vty_out (vty, "%*s", len, " ");
6045 }
6046
6047 enum bgp_display_type
6048 {
6049 normal_list,
6050 };
6051
6052 /* Print the short form route status for a bgp_info */
6053 static void
6054 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
6055 {
6056 /* Route status display. */
6057 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6058 vty_out (vty, "R");
6059 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6060 vty_out (vty, "S");
6061 else if (binfo->extra && binfo->extra->suppress)
6062 vty_out (vty, "s");
6063 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6064 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6065 vty_out (vty, "*");
6066 else
6067 vty_out (vty, " ");
6068
6069 /* Selected */
6070 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6071 vty_out (vty, "h");
6072 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6073 vty_out (vty, "d");
6074 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6075 vty_out (vty, ">");
6076 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6077 vty_out (vty, "=");
6078 else
6079 vty_out (vty, " ");
6080
6081 /* Internal route. */
6082 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6083 vty_out (vty, "i");
6084 else
6085 vty_out (vty, " ");
6086 }
6087
6088 /* called from terminal list command */
6089 void
6090 route_vty_out (struct vty *vty, struct prefix *p,
6091 struct bgp_info *binfo, int display, safi_t safi, char *delim)
6092 {
6093 struct attr *attr;
6094
6095 /* short status lead text */
6096 route_vty_short_status_out (vty, binfo);
6097
6098 if (delim)
6099 vty_out (vty, "%c", *delim);
6100
6101 /* print prefix and mask */
6102 if (! display)
6103 route_vty_out_route (p, vty);
6104 else
6105 vty_out (vty, "%*s", 17, " ");
6106
6107 if (delim)
6108 vty_out (vty, "%c", *delim);
6109
6110 /* Print attribute */
6111 attr = binfo->attr;
6112 if (attr)
6113 {
6114 if (p->family == AF_INET)
6115 {
6116 if (safi == SAFI_MPLS_VPN)
6117 vty_out (vty, "%-16s",
6118 inet_ntoa (attr->extra->mp_nexthop_global_in));
6119 else
6120 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6121 }
6122 #ifdef HAVE_IPV6
6123 else if (p->family == AF_INET6)
6124 {
6125 int len;
6126 char buf[BUFSIZ];
6127
6128 len = vty_out (vty, "%s",
6129 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6130 buf, BUFSIZ));
6131 len = 16 - len;
6132 if (len < 1)
6133 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6134 else
6135 vty_out (vty, "%*s", len, " ");
6136 }
6137 #endif /* HAVE_IPV6 */
6138
6139 if (delim)
6140 vty_out (vty, "%c", *delim);
6141
6142 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6143 vty_out (vty, "%10u", attr->med);
6144 else
6145 vty_out (vty, " ");
6146
6147 if (delim)
6148 vty_out (vty, "%c", *delim);
6149
6150 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6151 vty_out (vty, "%7u", attr->local_pref);
6152 else
6153 vty_out (vty, " ");
6154
6155 if (delim)
6156 vty_out (vty, "%c", *delim);
6157
6158 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6159
6160 if (delim)
6161 vty_out (vty, "%c", *delim);
6162
6163 /* Print aspath */
6164 if (attr->aspath)
6165 aspath_print_vty (vty, "%s", attr->aspath, " ");
6166
6167 if (delim)
6168 vty_out (vty, "%c", *delim);
6169
6170 /* Print origin */
6171 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6172 }
6173 vty_out (vty, "%s", VTY_NEWLINE);
6174 }
6175
6176 /* called from terminal list command */
6177 void
6178 route_vty_out_tmp (struct vty *vty, struct prefix *p,
6179 struct attr *attr, safi_t safi, char *delim)
6180 {
6181 /* Route status display. */
6182 vty_out (vty, "*");
6183 vty_out (vty, ">");
6184 vty_out (vty, " ");
6185
6186 if (delim)
6187 vty_out (vty, "%c", *delim);
6188
6189 /* print prefix and mask */
6190 route_vty_out_route (p, vty);
6191
6192 if (delim)
6193 vty_out (vty, "%c", *delim);
6194
6195 /* Print attribute */
6196 if (attr)
6197 {
6198 if (p->family == AF_INET)
6199 {
6200 if (safi == SAFI_MPLS_VPN)
6201 vty_out (vty, "%-16s",
6202 inet_ntoa (attr->extra->mp_nexthop_global_in));
6203 else
6204 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6205 }
6206 #ifdef HAVE_IPV6
6207 else if (p->family == AF_INET6)
6208 {
6209 int len;
6210 char buf[BUFSIZ];
6211
6212 assert (attr->extra);
6213
6214 len = vty_out (vty, "%s",
6215 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6216 buf, BUFSIZ));
6217 len = 16 - len;
6218 if (len < 1)
6219 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6220 else
6221 vty_out (vty, "%*s", len, " ");
6222 }
6223 #endif /* HAVE_IPV6 */
6224
6225 if (delim)
6226 vty_out (vty, "%c", *delim);
6227
6228 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6229 vty_out (vty, "%10u", attr->med);
6230 else
6231 vty_out (vty, " ");
6232
6233 if (delim)
6234 vty_out (vty, "%c", *delim);
6235
6236 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6237 vty_out (vty, "%7u", attr->local_pref);
6238 else
6239 vty_out (vty, " ");
6240
6241 if (delim)
6242 vty_out (vty, "%c", *delim);
6243
6244 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6245
6246 if (delim)
6247 vty_out (vty, "%c", *delim);
6248
6249 /* Print aspath */
6250 if (attr->aspath)
6251 aspath_print_vty (vty, "%s", attr->aspath, " ");
6252
6253 if (delim)
6254 vty_out (vty, "%c", *delim);
6255
6256 /* Print origin */
6257 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6258 }
6259
6260 vty_out (vty, "%s", VTY_NEWLINE);
6261 }
6262
6263 void
6264 route_vty_out_tag (struct vty *vty, struct prefix *p,
6265 struct bgp_info *binfo, int display, safi_t safi)
6266 {
6267 struct attr *attr;
6268 u_int32_t label = 0;
6269
6270 if (!binfo->extra)
6271 return;
6272
6273 /* short status lead text */
6274 route_vty_short_status_out (vty, binfo);
6275
6276 /* print prefix and mask */
6277 if (! display)
6278 route_vty_out_route (p, vty);
6279 else
6280 vty_out (vty, "%*s", 17, " ");
6281
6282 /* Print attribute */
6283 attr = binfo->attr;
6284 if (attr)
6285 {
6286 if (p->family == AF_INET)
6287 {
6288 if (safi == SAFI_MPLS_VPN)
6289 vty_out (vty, "%-16s",
6290 inet_ntoa (attr->extra->mp_nexthop_global_in));
6291 else
6292 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6293 }
6294 #ifdef HAVE_IPV6
6295 else if (p->family == AF_INET6)
6296 {
6297 assert (attr->extra);
6298 char buf[BUFSIZ];
6299 char buf1[BUFSIZ];
6300 if (attr->extra->mp_nexthop_len == 16)
6301 vty_out (vty, "%s",
6302 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6303 buf, BUFSIZ));
6304 else if (attr->extra->mp_nexthop_len == 32)
6305 vty_out (vty, "%s(%s)",
6306 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6307 buf, BUFSIZ),
6308 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6309 buf1, BUFSIZ));
6310
6311 }
6312 #endif /* HAVE_IPV6 */
6313 }
6314
6315 label = decode_label (binfo->extra->tag);
6316
6317 vty_out (vty, "notag/%d", label);
6318
6319 vty_out (vty, "%s", VTY_NEWLINE);
6320 }
6321
6322 /* dampening route */
6323 static void
6324 damp_route_vty_out (struct vty *vty, struct prefix *p,
6325 struct bgp_info *binfo, int display, safi_t safi)
6326 {
6327 struct attr *attr;
6328 int len;
6329 char timebuf[BGP_UPTIME_LEN];
6330
6331 /* short status lead text */
6332 route_vty_short_status_out (vty, binfo);
6333
6334 /* print prefix and mask */
6335 if (! display)
6336 route_vty_out_route (p, vty);
6337 else
6338 vty_out (vty, "%*s", 17, " ");
6339
6340 len = vty_out (vty, "%s", binfo->peer->host);
6341 len = 17 - len;
6342 if (len < 1)
6343 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6344 else
6345 vty_out (vty, "%*s", len, " ");
6346
6347 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
6348
6349 /* Print attribute */
6350 attr = binfo->attr;
6351 if (attr)
6352 {
6353 /* Print aspath */
6354 if (attr->aspath)
6355 aspath_print_vty (vty, "%s", attr->aspath, " ");
6356
6357 /* Print origin */
6358 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6359 }
6360 vty_out (vty, "%s", VTY_NEWLINE);
6361 }
6362
6363 /* flap route */
6364 static void
6365 flap_route_vty_out (struct vty *vty, struct prefix *p,
6366 struct bgp_info *binfo, int display, safi_t safi)
6367 {
6368 struct attr *attr;
6369 struct bgp_damp_info *bdi;
6370 char timebuf[BGP_UPTIME_LEN];
6371 int len;
6372
6373 if (!binfo->extra)
6374 return;
6375
6376 bdi = binfo->extra->damp_info;
6377
6378 /* short status lead text */
6379 route_vty_short_status_out (vty, binfo);
6380
6381 /* print prefix and mask */
6382 if (! display)
6383 route_vty_out_route (p, vty);
6384 else
6385 vty_out (vty, "%*s", 17, " ");
6386
6387 len = vty_out (vty, "%s", binfo->peer->host);
6388 len = 16 - len;
6389 if (len < 1)
6390 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6391 else
6392 vty_out (vty, "%*s", len, " ");
6393
6394 len = vty_out (vty, "%d", bdi->flap);
6395 len = 5 - len;
6396 if (len < 1)
6397 vty_out (vty, " ");
6398 else
6399 vty_out (vty, "%*s ", len, " ");
6400
6401 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6402 timebuf, BGP_UPTIME_LEN));
6403
6404 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6405 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6406 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
6407 else
6408 vty_out (vty, "%*s ", 8, " ");
6409
6410 /* Print attribute */
6411 attr = binfo->attr;
6412 if (attr)
6413 {
6414 /* Print aspath */
6415 if (attr->aspath)
6416 aspath_print_vty (vty, "%s", attr->aspath, " ");
6417
6418 /* Print origin */
6419 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6420 }
6421 vty_out (vty, "%s", VTY_NEWLINE);
6422 }
6423
6424 static void
6425 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6426 struct bgp_info *binfo, afi_t afi, safi_t safi)
6427 {
6428 char buf[INET6_ADDRSTRLEN];
6429 char buf1[BUFSIZ];
6430 struct attr *attr;
6431 int sockunion_vty_out (struct vty *, union sockunion *);
6432 #ifdef HAVE_CLOCK_MONOTONIC
6433 time_t tbuf;
6434 #endif
6435
6436 attr = binfo->attr;
6437
6438 if (attr)
6439 {
6440 /* Line1 display AS-path, Aggregator */
6441 if (attr->aspath)
6442 {
6443 vty_out (vty, " ");
6444 if (aspath_count_hops (attr->aspath) == 0)
6445 vty_out (vty, "Local");
6446 else
6447 aspath_print_vty (vty, "%s", attr->aspath, "");
6448 }
6449
6450 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6451 vty_out (vty, ", (removed)");
6452 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6453 vty_out (vty, ", (stale)");
6454 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6455 vty_out (vty, ", (aggregated by %u %s)",
6456 attr->extra->aggregator_as,
6457 inet_ntoa (attr->extra->aggregator_addr));
6458 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6459 vty_out (vty, ", (Received from a RR-client)");
6460 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6461 vty_out (vty, ", (Received from a RS-client)");
6462 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6463 vty_out (vty, ", (history entry)");
6464 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6465 vty_out (vty, ", (suppressed due to dampening)");
6466 vty_out (vty, "%s", VTY_NEWLINE);
6467
6468 /* Line2 display Next-hop, Neighbor, Router-id */
6469 if (p->family == AF_INET)
6470 {
6471 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
6472 inet_ntoa (attr->extra->mp_nexthop_global_in) :
6473 inet_ntoa (attr->nexthop));
6474 }
6475 #ifdef HAVE_IPV6
6476 else
6477 {
6478 assert (attr->extra);
6479 vty_out (vty, " %s",
6480 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6481 buf, INET6_ADDRSTRLEN));
6482 }
6483 #endif /* HAVE_IPV6 */
6484
6485 if (binfo->peer == bgp->peer_self)
6486 {
6487 vty_out (vty, " from %s ",
6488 p->family == AF_INET ? "0.0.0.0" : "::");
6489 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6490 }
6491 else
6492 {
6493 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6494 vty_out (vty, " (inaccessible)");
6495 else if (binfo->extra && binfo->extra->igpmetric)
6496 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
6497 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6498 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6499 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6500 else
6501 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6502 }
6503 vty_out (vty, "%s", VTY_NEWLINE);
6504
6505 #ifdef HAVE_IPV6
6506 /* display nexthop local */
6507 if (attr->extra && attr->extra->mp_nexthop_len == 32)
6508 {
6509 vty_out (vty, " (%s)%s",
6510 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6511 buf, INET6_ADDRSTRLEN),
6512 VTY_NEWLINE);
6513 }
6514 #endif /* HAVE_IPV6 */
6515
6516 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
6517 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6518
6519 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6520 vty_out (vty, ", metric %u", attr->med);
6521
6522 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6523 vty_out (vty, ", localpref %u", attr->local_pref);
6524 else
6525 vty_out (vty, ", localpref %u", bgp->default_local_pref);
6526
6527 if (attr->extra && attr->extra->weight != 0)
6528 vty_out (vty, ", weight %u", attr->extra->weight);
6529
6530 if (attr->extra && attr->extra->tag != 0)
6531 vty_out (vty, ", tag %d", attr->extra->tag);
6532
6533 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6534 vty_out (vty, ", invalid");
6535 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6536 vty_out (vty, ", valid");
6537
6538 if (binfo->peer != bgp->peer_self)
6539 {
6540 if (binfo->peer->as == binfo->peer->local_as)
6541 vty_out (vty, ", internal");
6542 else
6543 vty_out (vty, ", %s",
6544 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6545 }
6546 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6547 vty_out (vty, ", aggregated, local");
6548 else if (binfo->type != ZEBRA_ROUTE_BGP)
6549 vty_out (vty, ", sourced");
6550 else
6551 vty_out (vty, ", sourced, local");
6552
6553 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6554 vty_out (vty, ", atomic-aggregate");
6555
6556 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6557 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6558 bgp_info_mpath_count (binfo)))
6559 vty_out (vty, ", multipath");
6560
6561 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6562 vty_out (vty, ", best");
6563
6564 vty_out (vty, "%s", VTY_NEWLINE);
6565
6566 /* Line 4 display Community */
6567 if (attr->community)
6568 vty_out (vty, " Community: %s%s", attr->community->str,
6569 VTY_NEWLINE);
6570
6571 /* Line 5 display Extended-community */
6572 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
6573 vty_out (vty, " Extended Community: %s%s",
6574 attr->extra->ecommunity->str, VTY_NEWLINE);
6575
6576 /* Line 6 display Originator, Cluster-id */
6577 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6578 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6579 {
6580 assert (attr->extra);
6581 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6582 vty_out (vty, " Originator: %s",
6583 inet_ntoa (attr->extra->originator_id));
6584
6585 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6586 {
6587 int i;
6588 vty_out (vty, ", Cluster list: ");
6589 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6590 vty_out (vty, "%s ",
6591 inet_ntoa (attr->extra->cluster->list[i]));
6592 }
6593 vty_out (vty, "%s", VTY_NEWLINE);
6594 }
6595
6596 if (binfo->extra && binfo->extra->damp_info)
6597 bgp_damp_info_vty (vty, binfo);
6598
6599 /* Line 7 display Addpath IDs */
6600 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
6601 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
6602 binfo->addpath_rx_id, binfo->addpath_tx_id,
6603 VTY_NEWLINE);
6604
6605 /* Line 8 display Uptime */
6606 #ifdef HAVE_CLOCK_MONOTONIC
6607 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
6608 vty_out (vty, " Last update: %s", ctime(&tbuf));
6609 #else
6610 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6611 #endif /* HAVE_CLOCK_MONOTONIC */
6612 }
6613 vty_out (vty, "%s", VTY_NEWLINE);
6614 }
6615
6616 #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6617 "h history, * valid, > best, = multipath,%s"\
6618 " i internal, r RIB-failure, S Stale, R Removed%s"
6619 #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
6620 #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6621 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
6622 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6623 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6624
6625 enum bgp_show_type
6626 {
6627 bgp_show_type_normal,
6628 bgp_show_type_regexp,
6629 bgp_show_type_prefix_list,
6630 bgp_show_type_filter_list,
6631 bgp_show_type_route_map,
6632 bgp_show_type_neighbor,
6633 bgp_show_type_cidr_only,
6634 bgp_show_type_prefix_longer,
6635 bgp_show_type_community_all,
6636 bgp_show_type_community,
6637 bgp_show_type_community_exact,
6638 bgp_show_type_community_list,
6639 bgp_show_type_community_list_exact,
6640 bgp_show_type_flap_statistics,
6641 bgp_show_type_flap_address,
6642 bgp_show_type_flap_prefix,
6643 bgp_show_type_flap_cidr_only,
6644 bgp_show_type_flap_regexp,
6645 bgp_show_type_flap_filter_list,
6646 bgp_show_type_flap_prefix_list,
6647 bgp_show_type_flap_prefix_longer,
6648 bgp_show_type_flap_route_map,
6649 bgp_show_type_flap_neighbor,
6650 bgp_show_type_dampend_paths,
6651 bgp_show_type_damp_neighbor
6652 };
6653
6654 static int
6655 bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
6656 enum bgp_show_type type, void *output_arg, char *delim)
6657 {
6658 struct bgp_info *ri;
6659 struct bgp_node *rn;
6660 int header = 1;
6661 int display;
6662 unsigned long output_count;
6663
6664 /* This is first entry point, so reset total line. */
6665 output_count = 0;
6666
6667 /* Start processing of routes. */
6668 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6669 if (rn->info != NULL)
6670 {
6671 display = 0;
6672
6673 for (ri = rn->info; ri; ri = ri->next)
6674 {
6675 if (type == bgp_show_type_flap_statistics
6676 || type == bgp_show_type_flap_address
6677 || type == bgp_show_type_flap_prefix
6678 || type == bgp_show_type_flap_cidr_only
6679 || type == bgp_show_type_flap_regexp
6680 || type == bgp_show_type_flap_filter_list
6681 || type == bgp_show_type_flap_prefix_list
6682 || type == bgp_show_type_flap_prefix_longer
6683 || type == bgp_show_type_flap_route_map
6684 || type == bgp_show_type_flap_neighbor
6685 || type == bgp_show_type_dampend_paths
6686 || type == bgp_show_type_damp_neighbor)
6687 {
6688 if (!(ri->extra && ri->extra->damp_info))
6689 continue;
6690 }
6691 if (type == bgp_show_type_regexp
6692 || type == bgp_show_type_flap_regexp)
6693 {
6694 regex_t *regex = output_arg;
6695
6696 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6697 continue;
6698 }
6699 if (type == bgp_show_type_prefix_list
6700 || type == bgp_show_type_flap_prefix_list)
6701 {
6702 struct prefix_list *plist = output_arg;
6703
6704 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6705 continue;
6706 }
6707 if (type == bgp_show_type_filter_list
6708 || type == bgp_show_type_flap_filter_list)
6709 {
6710 struct as_list *as_list = output_arg;
6711
6712 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6713 continue;
6714 }
6715 if (type == bgp_show_type_route_map
6716 || type == bgp_show_type_flap_route_map)
6717 {
6718 struct route_map *rmap = output_arg;
6719 struct bgp_info binfo;
6720 struct attr dummy_attr;
6721 struct attr_extra dummy_extra;
6722 int ret;
6723
6724 dummy_attr.extra = &dummy_extra;
6725 bgp_attr_dup (&dummy_attr, ri->attr);
6726
6727 binfo.peer = ri->peer;
6728 binfo.attr = &dummy_attr;
6729
6730 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
6731 if (ret == RMAP_DENYMATCH)
6732 continue;
6733 }
6734 if (type == bgp_show_type_neighbor
6735 || type == bgp_show_type_flap_neighbor
6736 || type == bgp_show_type_damp_neighbor)
6737 {
6738 union sockunion *su = output_arg;
6739
6740 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6741 continue;
6742 }
6743 if (type == bgp_show_type_cidr_only
6744 || type == bgp_show_type_flap_cidr_only)
6745 {
6746 u_int32_t destination;
6747
6748 destination = ntohl (rn->p.u.prefix4.s_addr);
6749 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6750 continue;
6751 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6752 continue;
6753 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6754 continue;
6755 }
6756 if (type == bgp_show_type_prefix_longer
6757 || type == bgp_show_type_flap_prefix_longer)
6758 {
6759 struct prefix *p = output_arg;
6760
6761 if (! prefix_match (p, &rn->p))
6762 continue;
6763 }
6764 if (type == bgp_show_type_community_all)
6765 {
6766 if (! ri->attr->community)
6767 continue;
6768 }
6769 if (type == bgp_show_type_community)
6770 {
6771 struct community *com = output_arg;
6772
6773 if (! ri->attr->community ||
6774 ! community_match (ri->attr->community, com))
6775 continue;
6776 }
6777 if (type == bgp_show_type_community_exact)
6778 {
6779 struct community *com = output_arg;
6780
6781 if (! ri->attr->community ||
6782 ! community_cmp (ri->attr->community, com))
6783 continue;
6784 }
6785 if (type == bgp_show_type_community_list)
6786 {
6787 struct community_list *list = output_arg;
6788
6789 if (! community_list_match (ri->attr->community, list))
6790 continue;
6791 }
6792 if (type == bgp_show_type_community_list_exact)
6793 {
6794 struct community_list *list = output_arg;
6795
6796 if (! community_list_exact_match (ri->attr->community, list))
6797 continue;
6798 }
6799 if (type == bgp_show_type_flap_address
6800 || type == bgp_show_type_flap_prefix)
6801 {
6802 struct prefix *p = output_arg;
6803
6804 if (! prefix_match (&rn->p, p))
6805 continue;
6806
6807 if (type == bgp_show_type_flap_prefix)
6808 if (p->prefixlen != rn->p.prefixlen)
6809 continue;
6810 }
6811 if (type == bgp_show_type_dampend_paths
6812 || type == bgp_show_type_damp_neighbor)
6813 {
6814 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6815 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6816 continue;
6817 }
6818
6819 if (delim)
6820 {
6821 if (header)
6822 {
6823 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
6824 header = 0;
6825 }
6826 }
6827 else if (header)
6828 {
6829 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6830 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6831 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6832 if (type == bgp_show_type_dampend_paths
6833 || type == bgp_show_type_damp_neighbor)
6834 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6835 else if (type == bgp_show_type_flap_statistics
6836 || type == bgp_show_type_flap_address
6837 || type == bgp_show_type_flap_prefix
6838 || type == bgp_show_type_flap_cidr_only
6839 || type == bgp_show_type_flap_regexp
6840 || type == bgp_show_type_flap_filter_list
6841 || type == bgp_show_type_flap_prefix_list
6842 || type == bgp_show_type_flap_prefix_longer
6843 || type == bgp_show_type_flap_route_map
6844 || type == bgp_show_type_flap_neighbor)
6845 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6846 else
6847 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
6848 header = 0;
6849 }
6850
6851 if (type == bgp_show_type_dampend_paths
6852 || type == bgp_show_type_damp_neighbor)
6853 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6854 else if (type == bgp_show_type_flap_statistics
6855 || type == bgp_show_type_flap_address
6856 || type == bgp_show_type_flap_prefix
6857 || type == bgp_show_type_flap_cidr_only
6858 || type == bgp_show_type_flap_regexp
6859 || type == bgp_show_type_flap_filter_list
6860 || type == bgp_show_type_flap_prefix_list
6861 || type == bgp_show_type_flap_prefix_longer
6862 || type == bgp_show_type_flap_route_map
6863 || type == bgp_show_type_flap_neighbor)
6864 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6865 else
6866 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, delim);
6867 display++;
6868 }
6869 if (display)
6870 output_count++;
6871 }
6872
6873 /* No route is displayed */
6874 if (output_count == 0)
6875 {
6876 if (type == bgp_show_type_normal)
6877 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6878 }
6879 else
6880 vty_out (vty, "%sTotal number of prefixes %ld%s",
6881 VTY_NEWLINE, output_count, VTY_NEWLINE);
6882
6883 return CMD_SUCCESS;
6884 }
6885
6886 static int
6887 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
6888 enum bgp_show_type type, void *output_arg, char *delim)
6889 {
6890 struct bgp_table *table;
6891
6892 if (bgp == NULL) {
6893 bgp = bgp_get_default ();
6894 }
6895
6896 if (bgp == NULL)
6897 {
6898 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6899 return CMD_WARNING;
6900 }
6901
6902
6903 table = bgp->rib[afi][safi];
6904
6905 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, delim);
6906 }
6907
6908 /* Header of detailed BGP route information */
6909 static void
6910 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6911 struct bgp_node *rn,
6912 struct prefix_rd *prd, afi_t afi, safi_t safi)
6913 {
6914 struct bgp_info *ri;
6915 struct prefix *p;
6916 struct peer *peer;
6917 struct listnode *node, *nnode;
6918 char buf1[INET6_ADDRSTRLEN];
6919 char buf2[INET6_ADDRSTRLEN];
6920 int count = 0;
6921 int best = 0;
6922 int suppress = 0;
6923 int no_export = 0;
6924 int no_advertise = 0;
6925 int local_as = 0;
6926 int first = 0;
6927
6928 p = &rn->p;
6929 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6930 (safi == SAFI_MPLS_VPN ?
6931 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6932 safi == SAFI_MPLS_VPN ? ":" : "",
6933 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6934 p->prefixlen, VTY_NEWLINE);
6935
6936 for (ri = rn->info; ri; ri = ri->next)
6937 {
6938 count++;
6939 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6940 {
6941 best = count;
6942 if (ri->extra && ri->extra->suppress)
6943 suppress = 1;
6944 if (ri->attr->community != NULL)
6945 {
6946 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6947 no_advertise = 1;
6948 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6949 no_export = 1;
6950 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6951 local_as = 1;
6952 }
6953 }
6954 }
6955
6956 vty_out (vty, "Paths: (%d available", count);
6957 if (best)
6958 {
6959 vty_out (vty, ", best #%d", best);
6960 if (safi == SAFI_UNICAST)
6961 vty_out (vty, ", table Default-IP-Routing-Table");
6962 }
6963 else
6964 vty_out (vty, ", no best path");
6965 if (no_advertise)
6966 vty_out (vty, ", not advertised to any peer");
6967 else if (no_export)
6968 vty_out (vty, ", not advertised to EBGP peer");
6969 else if (local_as)
6970 vty_out (vty, ", not advertised outside local AS");
6971 if (suppress)
6972 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6973 vty_out (vty, ")%s", VTY_NEWLINE);
6974
6975 /* advertised peer */
6976 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6977 {
6978 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6979 {
6980 if (! first)
6981 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6982 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6983 first = 1;
6984 }
6985 }
6986 if (! first)
6987 vty_out (vty, " Not advertised to any peer");
6988 vty_out (vty, "%s", VTY_NEWLINE);
6989 }
6990
6991 /* Display specified route of BGP table. */
6992 static int
6993 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
6994 struct bgp_table *rib, const char *ip_str,
6995 afi_t afi, safi_t safi, struct prefix_rd *prd,
6996 int prefix_check, enum bgp_path_type pathtype)
6997 {
6998 int ret;
6999 int header;
7000 int display = 0;
7001 struct prefix match;
7002 struct bgp_node *rn;
7003 struct bgp_node *rm;
7004 struct bgp_info *ri;
7005 struct bgp_table *table;
7006
7007 /* Check IP address argument. */
7008 ret = str2prefix (ip_str, &match);
7009 if (! ret)
7010 {
7011 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
7012 return CMD_WARNING;
7013 }
7014
7015 match.family = afi2family (afi);
7016
7017 if (safi == SAFI_MPLS_VPN)
7018 {
7019 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
7020 {
7021 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
7022 continue;
7023
7024 if ((table = rn->info) != NULL)
7025 {
7026 header = 1;
7027
7028 if ((rm = bgp_node_match (table, &match)) != NULL)
7029 {
7030 if (prefix_check && rm->p.prefixlen != match.prefixlen)
7031 {
7032 bgp_unlock_node (rm);
7033 continue;
7034 }
7035
7036 for (ri = rm->info; ri; ri = ri->next)
7037 {
7038 if (header)
7039 {
7040 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
7041 AFI_IP, SAFI_MPLS_VPN);
7042
7043 header = 0;
7044 }
7045 display++;
7046
7047 if (pathtype == BGP_PATH_ALL ||
7048 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7049 (pathtype == BGP_PATH_MULTIPATH &&
7050 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7051 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
7052 }
7053
7054 bgp_unlock_node (rm);
7055 }
7056 }
7057 }
7058 }
7059 else
7060 {
7061 header = 1;
7062
7063 if ((rn = bgp_node_match (rib, &match)) != NULL)
7064 {
7065 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
7066 {
7067 for (ri = rn->info; ri; ri = ri->next)
7068 {
7069 if (header)
7070 {
7071 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
7072 header = 0;
7073 }
7074 display++;
7075
7076 if (pathtype == BGP_PATH_ALL ||
7077 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7078 (pathtype == BGP_PATH_MULTIPATH &&
7079 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7080 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
7081 }
7082 }
7083
7084 bgp_unlock_node (rn);
7085 }
7086 }
7087
7088 if (! display)
7089 {
7090 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7091 return CMD_WARNING;
7092 }
7093
7094 return CMD_SUCCESS;
7095 }
7096
7097 /* Display specified route of Main RIB */
7098 static int
7099 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
7100 afi_t afi, safi_t safi, struct prefix_rd *prd,
7101 int prefix_check, enum bgp_path_type pathtype)
7102 {
7103 struct bgp *bgp;
7104
7105 /* BGP structure lookup. */
7106 if (view_name)
7107 {
7108 bgp = bgp_lookup_by_name (view_name);
7109 if (bgp == NULL)
7110 {
7111 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7112 return CMD_WARNING;
7113 }
7114 }
7115 else
7116 {
7117 bgp = bgp_get_default ();
7118 if (bgp == NULL)
7119 {
7120 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7121 return CMD_WARNING;
7122 }
7123 }
7124
7125 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
7126 afi, safi, prd, prefix_check, pathtype);
7127 }
7128
7129 /* BGP route print out function. */
7130 DEFUN (show_ip_bgp,
7131 show_ip_bgp_cmd,
7132 "show ip bgp",
7133 SHOW_STR
7134 IP_STR
7135 BGP_STR)
7136 {
7137 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7138 }
7139
7140 DEFUN (show_ip_bgp_csv,
7141 show_ip_bgp_csv_cmd,
7142 "show ip bgp csv",
7143 SHOW_STR
7144 IP_STR
7145 BGP_STR)
7146 {
7147 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
7148 }
7149
7150 DEFUN (show_ip_bgp_ipv4,
7151 show_ip_bgp_ipv4_cmd,
7152 "show ip bgp ipv4 (unicast|multicast)",
7153 SHOW_STR
7154 IP_STR
7155 BGP_STR
7156 "Address family\n"
7157 "Address Family modifier\n"
7158 "Address Family modifier\n")
7159 {
7160 if (strncmp (argv[0], "m", 1) == 0)
7161 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7162 NULL, NULL);
7163
7164 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7165 }
7166
7167 ALIAS (show_ip_bgp_ipv4,
7168 show_bgp_ipv4_safi_cmd,
7169 "show bgp ipv4 (unicast|multicast)",
7170 SHOW_STR
7171 BGP_STR
7172 "Address family\n"
7173 "Address Family modifier\n"
7174 "Address Family modifier\n")
7175
7176 DEFUN (show_ip_bgp_ipv4_csv,
7177 show_bgp_ipv4_safi_csv_cmd,
7178 "show bgp ipv4 (unicast|multicast) csv",
7179 SHOW_STR
7180 BGP_STR
7181 "Address family\n"
7182 "Address Family modifier\n"
7183 "Address Family modifier\n")
7184 {
7185 if (strncmp (argv[0], "m", 1) == 0)
7186 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7187 NULL, &csv);
7188
7189 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
7190 }
7191
7192 DEFUN (show_ip_bgp_route,
7193 show_ip_bgp_route_cmd,
7194 "show ip bgp A.B.C.D",
7195 SHOW_STR
7196 IP_STR
7197 BGP_STR
7198 "Network in the BGP routing table to display\n")
7199 {
7200 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7201 }
7202
7203 DEFUN (show_ip_bgp_route_pathtype,
7204 show_ip_bgp_route_pathtype_cmd,
7205 "show ip bgp A.B.C.D (bestpath|multipath)",
7206 SHOW_STR
7207 IP_STR
7208 BGP_STR
7209 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7210 "Display only the bestpath\n"
7211 "Display only multipaths\n")
7212 {
7213 if (strncmp (argv[1], "b", 1) == 0)
7214 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7215 else
7216 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7217 }
7218
7219 DEFUN (show_bgp_ipv4_safi_route_pathtype,
7220 show_bgp_ipv4_safi_route_pathtype_cmd,
7221 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath)",
7222 SHOW_STR
7223 BGP_STR
7224 "Address family\n"
7225 "Address Family modifier\n"
7226 "Address Family modifier\n"
7227 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7228 "Display only the bestpath\n"
7229 "Display only multipaths\n")
7230 {
7231 if (strncmp (argv[0], "m", 1) == 0)
7232 if (strncmp (argv[2], "b", 1) == 0)
7233 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7234 else
7235 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7236 else
7237 if (strncmp (argv[2], "b", 1) == 0)
7238 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7239 else
7240 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7241 }
7242
7243 DEFUN (show_ip_bgp_ipv4_route,
7244 show_ip_bgp_ipv4_route_cmd,
7245 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
7246 SHOW_STR
7247 IP_STR
7248 BGP_STR
7249 "Address family\n"
7250 "Address Family modifier\n"
7251 "Address Family modifier\n"
7252 "Network in the BGP routing table to display\n")
7253 {
7254 if (strncmp (argv[0], "m", 1) == 0)
7255 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
7256
7257 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7258 }
7259
7260 ALIAS (show_ip_bgp_ipv4_route,
7261 show_bgp_ipv4_safi_route_cmd,
7262 "show bgp ipv4 (unicast|multicast) A.B.C.D",
7263 SHOW_STR
7264 BGP_STR
7265 "Address family\n"
7266 "Address Family modifier\n"
7267 "Address Family modifier\n"
7268 "Network in the BGP routing table to display\n")
7269
7270 DEFUN (show_ip_bgp_vpnv4_all_route,
7271 show_ip_bgp_vpnv4_all_route_cmd,
7272 "show ip bgp vpnv4 all A.B.C.D",
7273 SHOW_STR
7274 IP_STR
7275 BGP_STR
7276 "Display VPNv4 NLRI specific information\n"
7277 "Display information about all VPNv4 NLRIs\n"
7278 "Network in the BGP routing table to display\n")
7279 {
7280 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
7281 }
7282
7283
7284 DEFUN (show_ip_bgp_vpnv4_rd_route,
7285 show_ip_bgp_vpnv4_rd_route_cmd,
7286 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
7287 SHOW_STR
7288 IP_STR
7289 BGP_STR
7290 "Display VPNv4 NLRI specific information\n"
7291 "Display information for a route distinguisher\n"
7292 "VPN Route Distinguisher\n"
7293 "Network in the BGP routing table to display\n")
7294 {
7295 int ret;
7296 struct prefix_rd prd;
7297
7298 ret = str2prefix_rd (argv[0], &prd);
7299 if (! ret)
7300 {
7301 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7302 return CMD_WARNING;
7303 }
7304 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
7305 }
7306
7307 DEFUN (show_ip_bgp_prefix,
7308 show_ip_bgp_prefix_cmd,
7309 "show ip bgp A.B.C.D/M",
7310 SHOW_STR
7311 IP_STR
7312 BGP_STR
7313 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7314 {
7315 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7316 }
7317
7318 DEFUN (show_ip_bgp_prefix_pathtype,
7319 show_ip_bgp_prefix_pathtype_cmd,
7320 "show ip bgp A.B.C.D/M (bestpath|multipath)",
7321 SHOW_STR
7322 IP_STR
7323 BGP_STR
7324 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7325 "Display only the bestpath\n"
7326 "Display only multipaths\n")
7327 {
7328 if (strncmp (argv[1], "b", 1) == 0)
7329 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7330 else
7331 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7332 }
7333
7334 DEFUN (show_ip_bgp_ipv4_prefix,
7335 show_ip_bgp_ipv4_prefix_cmd,
7336 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7337 SHOW_STR
7338 IP_STR
7339 BGP_STR
7340 "Address family\n"
7341 "Address Family modifier\n"
7342 "Address Family modifier\n"
7343 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7344 {
7345 if (strncmp (argv[0], "m", 1) == 0)
7346 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
7347
7348 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7349 }
7350
7351 ALIAS (show_ip_bgp_ipv4_prefix,
7352 show_bgp_ipv4_safi_prefix_cmd,
7353 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
7354 SHOW_STR
7355 BGP_STR
7356 "Address family\n"
7357 "Address Family modifier\n"
7358 "Address Family modifier\n"
7359 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7360
7361 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7362 show_ip_bgp_ipv4_prefix_pathtype_cmd,
7363 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7364 SHOW_STR
7365 IP_STR
7366 BGP_STR
7367 "Address family\n"
7368 "Address Family modifier\n"
7369 "Address Family modifier\n"
7370 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7371 "Display only the bestpath\n"
7372 "Display only multipaths\n")
7373 {
7374 if (strncmp (argv[0], "m", 1) == 0)
7375 if (strncmp (argv[2], "b", 1) == 0)
7376 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7377 else
7378 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7379 else
7380 if (strncmp (argv[2], "b", 1) == 0)
7381 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7382 else
7383 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7384 }
7385
7386 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7387 show_bgp_ipv4_safi_prefix_pathtype_cmd,
7388 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7389 SHOW_STR
7390 BGP_STR
7391 "Address family\n"
7392 "Address Family modifier\n"
7393 "Address Family modifier\n"
7394 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7395 "Display only the bestpath\n"
7396 "Display only multipaths\n")
7397
7398 DEFUN (show_ip_bgp_vpnv4_all_prefix,
7399 show_ip_bgp_vpnv4_all_prefix_cmd,
7400 "show ip bgp vpnv4 all A.B.C.D/M",
7401 SHOW_STR
7402 IP_STR
7403 BGP_STR
7404 "Display VPNv4 NLRI specific information\n"
7405 "Display information about all VPNv4 NLRIs\n"
7406 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7407 {
7408 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
7409 }
7410
7411 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7412 show_ip_bgp_vpnv4_rd_prefix_cmd,
7413 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7414 SHOW_STR
7415 IP_STR
7416 BGP_STR
7417 "Display VPNv4 NLRI specific information\n"
7418 "Display information for a route distinguisher\n"
7419 "VPN Route Distinguisher\n"
7420 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7421 {
7422 int ret;
7423 struct prefix_rd prd;
7424
7425 ret = str2prefix_rd (argv[0], &prd);
7426 if (! ret)
7427 {
7428 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7429 return CMD_WARNING;
7430 }
7431 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1, BGP_PATH_ALL);
7432 }
7433
7434 DEFUN (show_ip_bgp_view,
7435 show_ip_bgp_view_cmd,
7436 "show ip bgp view WORD",
7437 SHOW_STR
7438 IP_STR
7439 BGP_STR
7440 "BGP view\n"
7441 "View name\n")
7442 {
7443 struct bgp *bgp;
7444
7445 /* BGP structure lookup. */
7446 bgp = bgp_lookup_by_name (argv[0]);
7447 if (bgp == NULL)
7448 {
7449 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7450 return CMD_WARNING;
7451 }
7452
7453 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7454 }
7455
7456 DEFUN (show_ip_bgp_view_route,
7457 show_ip_bgp_view_route_cmd,
7458 "show ip bgp view WORD A.B.C.D",
7459 SHOW_STR
7460 IP_STR
7461 BGP_STR
7462 "BGP view\n"
7463 "View name\n"
7464 "Network in the BGP routing table to display\n")
7465 {
7466 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7467 }
7468
7469 DEFUN (show_ip_bgp_view_prefix,
7470 show_ip_bgp_view_prefix_cmd,
7471 "show ip bgp view WORD A.B.C.D/M",
7472 SHOW_STR
7473 IP_STR
7474 BGP_STR
7475 "BGP view\n"
7476 "View name\n"
7477 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7478 {
7479 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7480 }
7481
7482 #ifdef HAVE_IPV6
7483 DEFUN (show_bgp,
7484 show_bgp_cmd,
7485 "show bgp",
7486 SHOW_STR
7487 BGP_STR)
7488 {
7489 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7490 NULL, NULL);
7491 }
7492
7493 ALIAS (show_bgp,
7494 show_bgp_ipv6_cmd,
7495 "show bgp ipv6",
7496 SHOW_STR
7497 BGP_STR
7498 "Address family\n")
7499
7500 DEFUN (show_bgp_ipv6_safi,
7501 show_bgp_ipv6_safi_cmd,
7502 "show bgp ipv6 (unicast|multicast)",
7503 SHOW_STR
7504 BGP_STR
7505 "Address family\n"
7506 "Address Family modifier\n"
7507 "Address Family modifier\n")
7508 {
7509 if (strncmp (argv[0], "m", 1) == 0)
7510 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7511 NULL, NULL);
7512
7513 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7514 }
7515
7516 DEFUN (show_bgp_ipv6_safi_csv,
7517 show_bgp_ipv6_safi_csv_cmd,
7518 "show bgp ipv6 (unicast|multicast) csv",
7519 SHOW_STR
7520 BGP_STR
7521 "Address family\n"
7522 "Address Family modifier\n"
7523 "Address Family modifier\n")
7524 {
7525 if (strncmp (argv[0], "m", 1) == 0)
7526 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7527 NULL, &csv);
7528
7529 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
7530 }
7531
7532 /* old command */
7533 DEFUN (show_ipv6_bgp,
7534 show_ipv6_bgp_cmd,
7535 "show ipv6 bgp",
7536 SHOW_STR
7537 IP_STR
7538 BGP_STR)
7539 {
7540 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7541 NULL, NULL);
7542 }
7543
7544 DEFUN (show_bgp_route,
7545 show_bgp_route_cmd,
7546 "show bgp X:X::X:X",
7547 SHOW_STR
7548 BGP_STR
7549 "Network in the BGP routing table to display\n")
7550 {
7551 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7552 }
7553
7554 ALIAS (show_bgp_route,
7555 show_bgp_ipv6_route_cmd,
7556 "show bgp ipv6 X:X::X:X",
7557 SHOW_STR
7558 BGP_STR
7559 "Address family\n"
7560 "Network in the BGP routing table to display\n")
7561
7562 DEFUN (show_bgp_ipv6_safi_route,
7563 show_bgp_ipv6_safi_route_cmd,
7564 "show bgp ipv6 (unicast|multicast) X:X::X:X",
7565 SHOW_STR
7566 BGP_STR
7567 "Address family\n"
7568 "Address Family modifier\n"
7569 "Address Family modifier\n"
7570 "Network in the BGP routing table to display\n")
7571 {
7572 if (strncmp (argv[0], "m", 1) == 0)
7573 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
7574
7575 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7576 }
7577
7578 DEFUN (show_bgp_route_pathtype,
7579 show_bgp_route_pathtype_cmd,
7580 "show bgp X:X::X:X (bestpath|multipath)",
7581 SHOW_STR
7582 BGP_STR
7583 "Network in the BGP routing table to display\n"
7584 "Display only the bestpath\n"
7585 "Display only multipaths\n")
7586 {
7587 if (strncmp (argv[1], "b", 1) == 0)
7588 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7589 else
7590 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7591 }
7592
7593 ALIAS (show_bgp_route_pathtype,
7594 show_bgp_ipv6_route_pathtype_cmd,
7595 "show bgp ipv6 X:X::X:X (bestpath|multipath)",
7596 SHOW_STR
7597 BGP_STR
7598 "Address family\n"
7599 "Network in the BGP routing table to display\n"
7600 "Display only the bestpath\n"
7601 "Display only multipaths\n")
7602
7603 DEFUN (show_bgp_ipv6_safi_route_pathtype,
7604 show_bgp_ipv6_safi_route_pathtype_cmd,
7605 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath)",
7606 SHOW_STR
7607 BGP_STR
7608 "Address family\n"
7609 "Address Family modifier\n"
7610 "Address Family modifier\n"
7611 "Network in the BGP routing table to display\n"
7612 "Display only the bestpath\n"
7613 "Display only multipaths\n")
7614 {
7615 if (strncmp (argv[0], "m", 1) == 0)
7616 if (strncmp (argv[2], "b", 1) == 0)
7617 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7618 else
7619 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7620 else
7621 if (strncmp (argv[2], "b", 1) == 0)
7622 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7623 else
7624 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7625 }
7626
7627 /* old command */
7628 DEFUN (show_ipv6_bgp_route,
7629 show_ipv6_bgp_route_cmd,
7630 "show ipv6 bgp X:X::X:X",
7631 SHOW_STR
7632 IP_STR
7633 BGP_STR
7634 "Network in the BGP routing table to display\n")
7635 {
7636 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7637 }
7638
7639 DEFUN (show_bgp_prefix,
7640 show_bgp_prefix_cmd,
7641 "show bgp X:X::X:X/M",
7642 SHOW_STR
7643 BGP_STR
7644 "IPv6 prefix <network>/<length>\n")
7645 {
7646 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7647 }
7648
7649 ALIAS (show_bgp_prefix,
7650 show_bgp_ipv6_prefix_cmd,
7651 "show bgp ipv6 X:X::X:X/M",
7652 SHOW_STR
7653 BGP_STR
7654 "Address family\n"
7655 "IPv6 prefix <network>/<length>\n")
7656
7657 DEFUN (show_bgp_ipv6_safi_prefix,
7658 show_bgp_ipv6_safi_prefix_cmd,
7659 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7660 SHOW_STR
7661 BGP_STR
7662 "Address family\n"
7663 "Address Family modifier\n"
7664 "Address Family modifier\n"
7665 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7666 {
7667 if (strncmp (argv[0], "m", 1) == 0)
7668 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
7669
7670 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7671 }
7672
7673 DEFUN (show_bgp_prefix_pathtype,
7674 show_bgp_prefix_pathtype_cmd,
7675 "show bgp X:X::X:X/M (bestpath|multipath)",
7676 SHOW_STR
7677 BGP_STR
7678 "IPv6 prefix <network>/<length>\n"
7679 "Display only the bestpath\n"
7680 "Display only multipaths\n")
7681 {
7682 if (strncmp (argv[1], "b", 1) == 0)
7683 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7684 else
7685 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7686 }
7687
7688 ALIAS (show_bgp_prefix_pathtype,
7689 show_bgp_ipv6_prefix_pathtype_cmd,
7690 "show bgp ipv6 X:X::X:X/M (bestpath|multipath)",
7691 SHOW_STR
7692 BGP_STR
7693 "Address family\n"
7694 "IPv6 prefix <network>/<length>\n"
7695 "Display only the bestpath\n"
7696 "Display only multipaths\n")
7697
7698 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
7699 show_bgp_ipv6_safi_prefix_pathtype_cmd,
7700 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath)",
7701 SHOW_STR
7702 BGP_STR
7703 "Address family\n"
7704 "Address Family modifier\n"
7705 "Address Family modifier\n"
7706 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7707 "Display only the bestpath\n"
7708 "Display only multipaths\n")
7709 {
7710 if (strncmp (argv[0], "m", 1) == 0)
7711 if (strncmp (argv[2], "b", 1) == 0)
7712 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7713 else
7714 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7715 else
7716 if (strncmp (argv[2], "b", 1) == 0)
7717 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7718 else
7719 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7720 }
7721
7722 /* old command */
7723 DEFUN (show_ipv6_bgp_prefix,
7724 show_ipv6_bgp_prefix_cmd,
7725 "show ipv6 bgp X:X::X:X/M",
7726 SHOW_STR
7727 IP_STR
7728 BGP_STR
7729 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7730 {
7731 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7732 }
7733
7734 DEFUN (show_bgp_view,
7735 show_bgp_view_cmd,
7736 "show bgp view WORD",
7737 SHOW_STR
7738 BGP_STR
7739 "BGP view\n"
7740 "View name\n")
7741 {
7742 struct bgp *bgp;
7743
7744 /* BGP structure lookup. */
7745 bgp = bgp_lookup_by_name (argv[0]);
7746 if (bgp == NULL)
7747 {
7748 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7749 return CMD_WARNING;
7750 }
7751
7752 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7753 }
7754
7755 ALIAS (show_bgp_view,
7756 show_bgp_view_ipv6_cmd,
7757 "show bgp view WORD ipv6",
7758 SHOW_STR
7759 BGP_STR
7760 "BGP view\n"
7761 "View name\n"
7762 "Address family\n")
7763
7764 DEFUN (show_bgp_view_route,
7765 show_bgp_view_route_cmd,
7766 "show bgp view WORD X:X::X:X",
7767 SHOW_STR
7768 BGP_STR
7769 "BGP view\n"
7770 "View name\n"
7771 "Network in the BGP routing table to display\n")
7772 {
7773 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7774 }
7775
7776 ALIAS (show_bgp_view_route,
7777 show_bgp_view_ipv6_route_cmd,
7778 "show bgp view WORD ipv6 X:X::X:X",
7779 SHOW_STR
7780 BGP_STR
7781 "BGP view\n"
7782 "View name\n"
7783 "Address family\n"
7784 "Network in the BGP routing table to display\n")
7785
7786 DEFUN (show_bgp_view_prefix,
7787 show_bgp_view_prefix_cmd,
7788 "show bgp view WORD X:X::X:X/M",
7789 SHOW_STR
7790 BGP_STR
7791 "BGP view\n"
7792 "View name\n"
7793 "IPv6 prefix <network>/<length>\n")
7794 {
7795 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7796 }
7797
7798 ALIAS (show_bgp_view_prefix,
7799 show_bgp_view_ipv6_prefix_cmd,
7800 "show bgp view WORD ipv6 X:X::X:X/M",
7801 SHOW_STR
7802 BGP_STR
7803 "BGP view\n"
7804 "View name\n"
7805 "Address family\n"
7806 "IPv6 prefix <network>/<length>\n")
7807
7808 /* old command */
7809 DEFUN (show_ipv6_mbgp,
7810 show_ipv6_mbgp_cmd,
7811 "show ipv6 mbgp",
7812 SHOW_STR
7813 IP_STR
7814 MBGP_STR)
7815 {
7816 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7817 NULL, NULL);
7818 }
7819
7820 /* old command */
7821 DEFUN (show_ipv6_mbgp_route,
7822 show_ipv6_mbgp_route_cmd,
7823 "show ipv6 mbgp X:X::X:X",
7824 SHOW_STR
7825 IP_STR
7826 MBGP_STR
7827 "Network in the MBGP routing table to display\n")
7828 {
7829 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
7830 }
7831
7832 /* old command */
7833 DEFUN (show_ipv6_mbgp_prefix,
7834 show_ipv6_mbgp_prefix_cmd,
7835 "show ipv6 mbgp X:X::X:X/M",
7836 SHOW_STR
7837 IP_STR
7838 MBGP_STR
7839 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7840 {
7841 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
7842 }
7843 #endif
7844
7845
7846 static int
7847 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
7848 safi_t safi, enum bgp_show_type type)
7849 {
7850 int i;
7851 struct buffer *b;
7852 char *regstr;
7853 int first;
7854 regex_t *regex;
7855 int rc;
7856
7857 first = 0;
7858 b = buffer_new (1024);
7859 for (i = 0; i < argc; i++)
7860 {
7861 if (first)
7862 buffer_putc (b, ' ');
7863 else
7864 {
7865 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7866 continue;
7867 first = 1;
7868 }
7869
7870 buffer_putstr (b, argv[i]);
7871 }
7872 buffer_putc (b, '\0');
7873
7874 regstr = buffer_getstr (b);
7875 buffer_free (b);
7876
7877 regex = bgp_regcomp (regstr);
7878 XFREE(MTYPE_TMP, regstr);
7879 if (! regex)
7880 {
7881 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7882 VTY_NEWLINE);
7883 return CMD_WARNING;
7884 }
7885
7886 rc = bgp_show (vty, NULL, afi, safi, type, regex, NULL);
7887 bgp_regex_free (regex);
7888 return rc;
7889 }
7890
7891 DEFUN (show_ip_bgp_regexp,
7892 show_ip_bgp_regexp_cmd,
7893 "show ip bgp regexp .LINE",
7894 SHOW_STR
7895 IP_STR
7896 BGP_STR
7897 "Display routes matching the AS path regular expression\n"
7898 "A regular-expression to match the BGP AS paths\n")
7899 {
7900 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7901 bgp_show_type_regexp);
7902 }
7903
7904 DEFUN (show_ip_bgp_flap_regexp,
7905 show_ip_bgp_flap_regexp_cmd,
7906 "show ip bgp flap-statistics regexp .LINE",
7907 SHOW_STR
7908 IP_STR
7909 BGP_STR
7910 "Display flap statistics of routes\n"
7911 "Display routes matching the AS path regular expression\n"
7912 "A regular-expression to match the BGP AS paths\n")
7913 {
7914 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7915 bgp_show_type_flap_regexp);
7916 }
7917
7918 DEFUN (show_ip_bgp_ipv4_regexp,
7919 show_ip_bgp_ipv4_regexp_cmd,
7920 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7921 SHOW_STR
7922 IP_STR
7923 BGP_STR
7924 "Address family\n"
7925 "Address Family modifier\n"
7926 "Address Family modifier\n"
7927 "Display routes matching the AS path regular expression\n"
7928 "A regular-expression to match the BGP AS paths\n")
7929 {
7930 if (strncmp (argv[0], "m", 1) == 0)
7931 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7932 bgp_show_type_regexp);
7933
7934 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7935 bgp_show_type_regexp);
7936 }
7937
7938 #ifdef HAVE_IPV6
7939 DEFUN (show_bgp_regexp,
7940 show_bgp_regexp_cmd,
7941 "show bgp regexp .LINE",
7942 SHOW_STR
7943 BGP_STR
7944 "Display routes matching the AS path regular expression\n"
7945 "A regular-expression to match the BGP AS paths\n")
7946 {
7947 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7948 bgp_show_type_regexp);
7949 }
7950
7951 ALIAS (show_bgp_regexp,
7952 show_bgp_ipv6_regexp_cmd,
7953 "show bgp ipv6 regexp .LINE",
7954 SHOW_STR
7955 BGP_STR
7956 "Address family\n"
7957 "Display routes matching the AS path regular expression\n"
7958 "A regular-expression to match the BGP AS paths\n")
7959
7960 /* old command */
7961 DEFUN (show_ipv6_bgp_regexp,
7962 show_ipv6_bgp_regexp_cmd,
7963 "show ipv6 bgp regexp .LINE",
7964 SHOW_STR
7965 IP_STR
7966 BGP_STR
7967 "Display routes matching the AS path regular expression\n"
7968 "A regular-expression to match the BGP AS paths\n")
7969 {
7970 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7971 bgp_show_type_regexp);
7972 }
7973
7974 /* old command */
7975 DEFUN (show_ipv6_mbgp_regexp,
7976 show_ipv6_mbgp_regexp_cmd,
7977 "show ipv6 mbgp regexp .LINE",
7978 SHOW_STR
7979 IP_STR
7980 BGP_STR
7981 "Display routes matching the AS path regular expression\n"
7982 "A regular-expression to match the MBGP AS paths\n")
7983 {
7984 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7985 bgp_show_type_regexp);
7986 }
7987 #endif /* HAVE_IPV6 */
7988
7989 static int
7990 bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
7991 safi_t safi, enum bgp_show_type type)
7992 {
7993 struct prefix_list *plist;
7994
7995 plist = prefix_list_lookup (afi, prefix_list_str);
7996 if (plist == NULL)
7997 {
7998 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7999 prefix_list_str, VTY_NEWLINE);
8000 return CMD_WARNING;
8001 }
8002
8003 return bgp_show (vty, NULL, afi, safi, type, plist, NULL);
8004 }
8005
8006 DEFUN (show_ip_bgp_prefix_list,
8007 show_ip_bgp_prefix_list_cmd,
8008 "show ip bgp prefix-list WORD",
8009 SHOW_STR
8010 IP_STR
8011 BGP_STR
8012 "Display routes conforming to the prefix-list\n"
8013 "IP prefix-list name\n")
8014 {
8015 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8016 bgp_show_type_prefix_list);
8017 }
8018
8019 DEFUN (show_ip_bgp_flap_prefix_list,
8020 show_ip_bgp_flap_prefix_list_cmd,
8021 "show ip bgp flap-statistics prefix-list WORD",
8022 SHOW_STR
8023 IP_STR
8024 BGP_STR
8025 "Display flap statistics of routes\n"
8026 "Display routes conforming to the prefix-list\n"
8027 "IP prefix-list name\n")
8028 {
8029 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8030 bgp_show_type_flap_prefix_list);
8031 }
8032
8033 DEFUN (show_ip_bgp_ipv4_prefix_list,
8034 show_ip_bgp_ipv4_prefix_list_cmd,
8035 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8036 SHOW_STR
8037 IP_STR
8038 BGP_STR
8039 "Address family\n"
8040 "Address Family modifier\n"
8041 "Address Family modifier\n"
8042 "Display routes conforming to the prefix-list\n"
8043 "IP prefix-list name\n")
8044 {
8045 if (strncmp (argv[0], "m", 1) == 0)
8046 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8047 bgp_show_type_prefix_list);
8048
8049 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8050 bgp_show_type_prefix_list);
8051 }
8052
8053 #ifdef HAVE_IPV6
8054 DEFUN (show_bgp_prefix_list,
8055 show_bgp_prefix_list_cmd,
8056 "show bgp prefix-list WORD",
8057 SHOW_STR
8058 BGP_STR
8059 "Display routes conforming to the prefix-list\n"
8060 "IPv6 prefix-list name\n")
8061 {
8062 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8063 bgp_show_type_prefix_list);
8064 }
8065
8066 ALIAS (show_bgp_prefix_list,
8067 show_bgp_ipv6_prefix_list_cmd,
8068 "show bgp ipv6 prefix-list WORD",
8069 SHOW_STR
8070 BGP_STR
8071 "Address family\n"
8072 "Display routes conforming to the prefix-list\n"
8073 "IPv6 prefix-list name\n")
8074
8075 /* old command */
8076 DEFUN (show_ipv6_bgp_prefix_list,
8077 show_ipv6_bgp_prefix_list_cmd,
8078 "show ipv6 bgp prefix-list WORD",
8079 SHOW_STR
8080 IPV6_STR
8081 BGP_STR
8082 "Display routes matching the prefix-list\n"
8083 "IPv6 prefix-list name\n")
8084 {
8085 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8086 bgp_show_type_prefix_list);
8087 }
8088
8089 /* old command */
8090 DEFUN (show_ipv6_mbgp_prefix_list,
8091 show_ipv6_mbgp_prefix_list_cmd,
8092 "show ipv6 mbgp prefix-list WORD",
8093 SHOW_STR
8094 IPV6_STR
8095 MBGP_STR
8096 "Display routes matching the prefix-list\n"
8097 "IPv6 prefix-list name\n")
8098 {
8099 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8100 bgp_show_type_prefix_list);
8101 }
8102 #endif /* HAVE_IPV6 */
8103
8104 static int
8105 bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
8106 safi_t safi, enum bgp_show_type type)
8107 {
8108 struct as_list *as_list;
8109
8110 as_list = as_list_lookup (filter);
8111 if (as_list == NULL)
8112 {
8113 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8114 return CMD_WARNING;
8115 }
8116
8117 return bgp_show (vty, NULL, afi, safi, type, as_list, NULL);
8118 }
8119
8120 DEFUN (show_ip_bgp_filter_list,
8121 show_ip_bgp_filter_list_cmd,
8122 "show ip bgp filter-list WORD",
8123 SHOW_STR
8124 IP_STR
8125 BGP_STR
8126 "Display routes conforming to the filter-list\n"
8127 "Regular expression access list name\n")
8128 {
8129 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8130 bgp_show_type_filter_list);
8131 }
8132
8133 DEFUN (show_ip_bgp_flap_filter_list,
8134 show_ip_bgp_flap_filter_list_cmd,
8135 "show ip bgp flap-statistics filter-list WORD",
8136 SHOW_STR
8137 IP_STR
8138 BGP_STR
8139 "Display flap statistics of routes\n"
8140 "Display routes conforming to the filter-list\n"
8141 "Regular expression access list name\n")
8142 {
8143 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8144 bgp_show_type_flap_filter_list);
8145 }
8146
8147 DEFUN (show_ip_bgp_ipv4_filter_list,
8148 show_ip_bgp_ipv4_filter_list_cmd,
8149 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8150 SHOW_STR
8151 IP_STR
8152 BGP_STR
8153 "Address family\n"
8154 "Address Family modifier\n"
8155 "Address Family modifier\n"
8156 "Display routes conforming to the filter-list\n"
8157 "Regular expression access list name\n")
8158 {
8159 if (strncmp (argv[0], "m", 1) == 0)
8160 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8161 bgp_show_type_filter_list);
8162
8163 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8164 bgp_show_type_filter_list);
8165 }
8166
8167 #ifdef HAVE_IPV6
8168 DEFUN (show_bgp_filter_list,
8169 show_bgp_filter_list_cmd,
8170 "show bgp filter-list WORD",
8171 SHOW_STR
8172 BGP_STR
8173 "Display routes conforming to the filter-list\n"
8174 "Regular expression access list name\n")
8175 {
8176 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8177 bgp_show_type_filter_list);
8178 }
8179
8180 ALIAS (show_bgp_filter_list,
8181 show_bgp_ipv6_filter_list_cmd,
8182 "show bgp ipv6 filter-list WORD",
8183 SHOW_STR
8184 BGP_STR
8185 "Address family\n"
8186 "Display routes conforming to the filter-list\n"
8187 "Regular expression access list name\n")
8188
8189 /* old command */
8190 DEFUN (show_ipv6_bgp_filter_list,
8191 show_ipv6_bgp_filter_list_cmd,
8192 "show ipv6 bgp filter-list WORD",
8193 SHOW_STR
8194 IPV6_STR
8195 BGP_STR
8196 "Display routes conforming to the filter-list\n"
8197 "Regular expression access list name\n")
8198 {
8199 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8200 bgp_show_type_filter_list);
8201 }
8202
8203 /* old command */
8204 DEFUN (show_ipv6_mbgp_filter_list,
8205 show_ipv6_mbgp_filter_list_cmd,
8206 "show ipv6 mbgp filter-list WORD",
8207 SHOW_STR
8208 IPV6_STR
8209 MBGP_STR
8210 "Display routes conforming to the filter-list\n"
8211 "Regular expression access list name\n")
8212 {
8213 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8214 bgp_show_type_filter_list);
8215 }
8216 #endif /* HAVE_IPV6 */
8217
8218 static int
8219 bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
8220 safi_t safi, enum bgp_show_type type)
8221 {
8222 struct route_map *rmap;
8223
8224 rmap = route_map_lookup_by_name (rmap_str);
8225 if (! rmap)
8226 {
8227 vty_out (vty, "%% %s is not a valid route-map name%s",
8228 rmap_str, VTY_NEWLINE);
8229 return CMD_WARNING;
8230 }
8231
8232 return bgp_show (vty, NULL, afi, safi, type, rmap, NULL);
8233 }
8234
8235 DEFUN (show_ip_bgp_route_map,
8236 show_ip_bgp_route_map_cmd,
8237 "show ip bgp route-map WORD",
8238 SHOW_STR
8239 IP_STR
8240 BGP_STR
8241 "Display routes matching the route-map\n"
8242 "A route-map to match on\n")
8243 {
8244 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8245 bgp_show_type_route_map);
8246 }
8247
8248 DEFUN (show_ip_bgp_flap_route_map,
8249 show_ip_bgp_flap_route_map_cmd,
8250 "show ip bgp flap-statistics route-map WORD",
8251 SHOW_STR
8252 IP_STR
8253 BGP_STR
8254 "Display flap statistics of routes\n"
8255 "Display routes matching the route-map\n"
8256 "A route-map to match on\n")
8257 {
8258 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8259 bgp_show_type_flap_route_map);
8260 }
8261
8262 DEFUN (show_ip_bgp_ipv4_route_map,
8263 show_ip_bgp_ipv4_route_map_cmd,
8264 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8265 SHOW_STR
8266 IP_STR
8267 BGP_STR
8268 "Address family\n"
8269 "Address Family modifier\n"
8270 "Address Family modifier\n"
8271 "Display routes matching the route-map\n"
8272 "A route-map to match on\n")
8273 {
8274 if (strncmp (argv[0], "m", 1) == 0)
8275 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8276 bgp_show_type_route_map);
8277
8278 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8279 bgp_show_type_route_map);
8280 }
8281
8282 DEFUN (show_bgp_route_map,
8283 show_bgp_route_map_cmd,
8284 "show bgp route-map WORD",
8285 SHOW_STR
8286 BGP_STR
8287 "Display routes matching the route-map\n"
8288 "A route-map to match on\n")
8289 {
8290 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8291 bgp_show_type_route_map);
8292 }
8293
8294 ALIAS (show_bgp_route_map,
8295 show_bgp_ipv6_route_map_cmd,
8296 "show bgp ipv6 route-map WORD",
8297 SHOW_STR
8298 BGP_STR
8299 "Address family\n"
8300 "Display routes matching the route-map\n"
8301 "A route-map to match on\n")
8302
8303 DEFUN (show_ip_bgp_cidr_only,
8304 show_ip_bgp_cidr_only_cmd,
8305 "show ip bgp cidr-only",
8306 SHOW_STR
8307 IP_STR
8308 BGP_STR
8309 "Display only routes with non-natural netmasks\n")
8310 {
8311 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8312 bgp_show_type_cidr_only, NULL, NULL);
8313 }
8314
8315 DEFUN (show_ip_bgp_flap_cidr_only,
8316 show_ip_bgp_flap_cidr_only_cmd,
8317 "show ip bgp flap-statistics cidr-only",
8318 SHOW_STR
8319 IP_STR
8320 BGP_STR
8321 "Display flap statistics of routes\n"
8322 "Display only routes with non-natural netmasks\n")
8323 {
8324 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8325 bgp_show_type_flap_cidr_only, NULL, NULL);
8326 }
8327
8328 DEFUN (show_ip_bgp_ipv4_cidr_only,
8329 show_ip_bgp_ipv4_cidr_only_cmd,
8330 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8331 SHOW_STR
8332 IP_STR
8333 BGP_STR
8334 "Address family\n"
8335 "Address Family modifier\n"
8336 "Address Family modifier\n"
8337 "Display only routes with non-natural netmasks\n")
8338 {
8339 if (strncmp (argv[0], "m", 1) == 0)
8340 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8341 bgp_show_type_cidr_only, NULL, NULL);
8342
8343 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8344 bgp_show_type_cidr_only, NULL, NULL);
8345 }
8346
8347 DEFUN (show_ip_bgp_community_all,
8348 show_ip_bgp_community_all_cmd,
8349 "show ip bgp community",
8350 SHOW_STR
8351 IP_STR
8352 BGP_STR
8353 "Display routes matching the communities\n")
8354 {
8355 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8356 bgp_show_type_community_all, NULL, NULL);
8357 }
8358
8359 DEFUN (show_ip_bgp_ipv4_community_all,
8360 show_ip_bgp_ipv4_community_all_cmd,
8361 "show ip bgp ipv4 (unicast|multicast) community",
8362 SHOW_STR
8363 IP_STR
8364 BGP_STR
8365 "Address family\n"
8366 "Address Family modifier\n"
8367 "Address Family modifier\n"
8368 "Display routes matching the communities\n")
8369 {
8370 if (strncmp (argv[0], "m", 1) == 0)
8371 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8372 bgp_show_type_community_all, NULL, NULL);
8373
8374 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8375 bgp_show_type_community_all, NULL, NULL);
8376 }
8377
8378 #ifdef HAVE_IPV6
8379 DEFUN (show_bgp_community_all,
8380 show_bgp_community_all_cmd,
8381 "show bgp community",
8382 SHOW_STR
8383 BGP_STR
8384 "Display routes matching the communities\n")
8385 {
8386 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8387 bgp_show_type_community_all, NULL, NULL);
8388 }
8389
8390 ALIAS (show_bgp_community_all,
8391 show_bgp_ipv6_community_all_cmd,
8392 "show bgp ipv6 community",
8393 SHOW_STR
8394 BGP_STR
8395 "Address family\n"
8396 "Display routes matching the communities\n")
8397
8398 /* old command */
8399 DEFUN (show_ipv6_bgp_community_all,
8400 show_ipv6_bgp_community_all_cmd,
8401 "show ipv6 bgp community",
8402 SHOW_STR
8403 IPV6_STR
8404 BGP_STR
8405 "Display routes matching the communities\n")
8406 {
8407 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8408 bgp_show_type_community_all, NULL, NULL);
8409 }
8410
8411 /* old command */
8412 DEFUN (show_ipv6_mbgp_community_all,
8413 show_ipv6_mbgp_community_all_cmd,
8414 "show ipv6 mbgp community",
8415 SHOW_STR
8416 IPV6_STR
8417 MBGP_STR
8418 "Display routes matching the communities\n")
8419 {
8420 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
8421 bgp_show_type_community_all, NULL, NULL);
8422 }
8423 #endif /* HAVE_IPV6 */
8424
8425 static int
8426 bgp_show_community (struct vty *vty, const char *view_name, int argc,
8427 const char **argv, int exact, afi_t afi, safi_t safi)
8428 {
8429 struct community *com;
8430 struct buffer *b;
8431 struct bgp *bgp;
8432 int i;
8433 char *str;
8434 int first = 0;
8435
8436 /* BGP structure lookup */
8437 if (view_name)
8438 {
8439 bgp = bgp_lookup_by_name (view_name);
8440 if (bgp == NULL)
8441 {
8442 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8443 return CMD_WARNING;
8444 }
8445 }
8446 else
8447 {
8448 bgp = bgp_get_default ();
8449 if (bgp == NULL)
8450 {
8451 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8452 return CMD_WARNING;
8453 }
8454 }
8455
8456 b = buffer_new (1024);
8457 for (i = 0; i < argc; i++)
8458 {
8459 if (first)
8460 buffer_putc (b, ' ');
8461 else
8462 {
8463 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8464 continue;
8465 first = 1;
8466 }
8467
8468 buffer_putstr (b, argv[i]);
8469 }
8470 buffer_putc (b, '\0');
8471
8472 str = buffer_getstr (b);
8473 buffer_free (b);
8474
8475 com = community_str2com (str);
8476 XFREE (MTYPE_TMP, str);
8477 if (! com)
8478 {
8479 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
8480 return CMD_WARNING;
8481 }
8482
8483 return bgp_show (vty, bgp, afi, safi,
8484 (exact ? bgp_show_type_community_exact :
8485 bgp_show_type_community), com, NULL);
8486 }
8487
8488 DEFUN (show_ip_bgp_community,
8489 show_ip_bgp_community_cmd,
8490 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
8491 SHOW_STR
8492 IP_STR
8493 BGP_STR
8494 "Display routes matching the communities\n"
8495 "community number\n"
8496 "Do not send outside local AS (well-known community)\n"
8497 "Do not advertise to any peer (well-known community)\n"
8498 "Do not export to next AS (well-known community)\n")
8499 {
8500 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
8501 }
8502
8503 ALIAS (show_ip_bgp_community,
8504 show_ip_bgp_community2_cmd,
8505 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8506 SHOW_STR
8507 IP_STR
8508 BGP_STR
8509 "Display routes matching the communities\n"
8510 "community number\n"
8511 "Do not send outside local AS (well-known community)\n"
8512 "Do not advertise to any peer (well-known community)\n"
8513 "Do not export to next AS (well-known community)\n"
8514 "community number\n"
8515 "Do not send outside local AS (well-known community)\n"
8516 "Do not advertise to any peer (well-known community)\n"
8517 "Do not export to next AS (well-known community)\n")
8518
8519 ALIAS (show_ip_bgp_community,
8520 show_ip_bgp_community3_cmd,
8521 "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)",
8522 SHOW_STR
8523 IP_STR
8524 BGP_STR
8525 "Display routes matching the communities\n"
8526 "community number\n"
8527 "Do not send outside local AS (well-known community)\n"
8528 "Do not advertise to any peer (well-known community)\n"
8529 "Do not export to next AS (well-known community)\n"
8530 "community number\n"
8531 "Do not send outside local AS (well-known community)\n"
8532 "Do not advertise to any peer (well-known community)\n"
8533 "Do not export to next AS (well-known community)\n"
8534 "community number\n"
8535 "Do not send outside local AS (well-known community)\n"
8536 "Do not advertise to any peer (well-known community)\n"
8537 "Do not export to next AS (well-known community)\n")
8538
8539 ALIAS (show_ip_bgp_community,
8540 show_ip_bgp_community4_cmd,
8541 "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)",
8542 SHOW_STR
8543 IP_STR
8544 BGP_STR
8545 "Display routes matching the communities\n"
8546 "community number\n"
8547 "Do not send outside local AS (well-known community)\n"
8548 "Do not advertise to any peer (well-known community)\n"
8549 "Do not export to next AS (well-known community)\n"
8550 "community number\n"
8551 "Do not send outside local AS (well-known community)\n"
8552 "Do not advertise to any peer (well-known community)\n"
8553 "Do not export to next AS (well-known community)\n"
8554 "community number\n"
8555 "Do not send outside local AS (well-known community)\n"
8556 "Do not advertise to any peer (well-known community)\n"
8557 "Do not export to next AS (well-known community)\n"
8558 "community number\n"
8559 "Do not send outside local AS (well-known community)\n"
8560 "Do not advertise to any peer (well-known community)\n"
8561 "Do not export to next AS (well-known community)\n")
8562
8563 DEFUN (show_ip_bgp_ipv4_community,
8564 show_ip_bgp_ipv4_community_cmd,
8565 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8566 SHOW_STR
8567 IP_STR
8568 BGP_STR
8569 "Address family\n"
8570 "Address Family modifier\n"
8571 "Address Family modifier\n"
8572 "Display routes matching the communities\n"
8573 "community number\n"
8574 "Do not send outside local AS (well-known community)\n"
8575 "Do not advertise to any peer (well-known community)\n"
8576 "Do not export to next AS (well-known community)\n")
8577 {
8578 if (strncmp (argv[0], "m", 1) == 0)
8579 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
8580
8581 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
8582 }
8583
8584 ALIAS (show_ip_bgp_ipv4_community,
8585 show_ip_bgp_ipv4_community2_cmd,
8586 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8587 SHOW_STR
8588 IP_STR
8589 BGP_STR
8590 "Address family\n"
8591 "Address Family modifier\n"
8592 "Address Family modifier\n"
8593 "Display routes matching the communities\n"
8594 "community number\n"
8595 "Do not send outside local AS (well-known community)\n"
8596 "Do not advertise to any peer (well-known community)\n"
8597 "Do not export to next AS (well-known community)\n"
8598 "community number\n"
8599 "Do not send outside local AS (well-known community)\n"
8600 "Do not advertise to any peer (well-known community)\n"
8601 "Do not export to next AS (well-known community)\n")
8602
8603 ALIAS (show_ip_bgp_ipv4_community,
8604 show_ip_bgp_ipv4_community3_cmd,
8605 "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)",
8606 SHOW_STR
8607 IP_STR
8608 BGP_STR
8609 "Address family\n"
8610 "Address Family modifier\n"
8611 "Address Family modifier\n"
8612 "Display routes matching the communities\n"
8613 "community number\n"
8614 "Do not send outside local AS (well-known community)\n"
8615 "Do not advertise to any peer (well-known community)\n"
8616 "Do not export to next AS (well-known community)\n"
8617 "community number\n"
8618 "Do not send outside local AS (well-known community)\n"
8619 "Do not advertise to any peer (well-known community)\n"
8620 "Do not export to next AS (well-known community)\n"
8621 "community number\n"
8622 "Do not send outside local AS (well-known community)\n"
8623 "Do not advertise to any peer (well-known community)\n"
8624 "Do not export to next AS (well-known community)\n")
8625
8626 ALIAS (show_ip_bgp_ipv4_community,
8627 show_ip_bgp_ipv4_community4_cmd,
8628 "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)",
8629 SHOW_STR
8630 IP_STR
8631 BGP_STR
8632 "Address family\n"
8633 "Address Family modifier\n"
8634 "Address Family modifier\n"
8635 "Display routes matching the communities\n"
8636 "community number\n"
8637 "Do not send outside local AS (well-known community)\n"
8638 "Do not advertise to any peer (well-known community)\n"
8639 "Do not export to next AS (well-known community)\n"
8640 "community number\n"
8641 "Do not send outside local AS (well-known community)\n"
8642 "Do not advertise to any peer (well-known community)\n"
8643 "Do not export to next AS (well-known community)\n"
8644 "community number\n"
8645 "Do not send outside local AS (well-known community)\n"
8646 "Do not advertise to any peer (well-known community)\n"
8647 "Do not export to next AS (well-known community)\n"
8648 "community number\n"
8649 "Do not send outside local AS (well-known community)\n"
8650 "Do not advertise to any peer (well-known community)\n"
8651 "Do not export to next AS (well-known community)\n")
8652
8653 DEFUN (show_bgp_view_afi_safi_community_all,
8654 show_bgp_view_afi_safi_community_all_cmd,
8655 #ifdef HAVE_IPV6
8656 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
8657 #else
8658 "show bgp view WORD ipv4 (unicast|multicast) community",
8659 #endif
8660 SHOW_STR
8661 BGP_STR
8662 "BGP view\n"
8663 "View name\n"
8664 "Address family\n"
8665 #ifdef HAVE_IPV6
8666 "Address family\n"
8667 #endif
8668 "Address Family modifier\n"
8669 "Address Family modifier\n"
8670 "Display routes matching the communities\n")
8671 {
8672 int afi;
8673 int safi;
8674 struct bgp *bgp;
8675
8676 /* BGP structure lookup. */
8677 bgp = bgp_lookup_by_name (argv[0]);
8678 if (bgp == NULL)
8679 {
8680 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8681 return CMD_WARNING;
8682 }
8683
8684 #ifdef HAVE_IPV6
8685 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8686 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8687 #else
8688 afi = AFI_IP;
8689 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8690 #endif
8691 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, NULL);
8692 }
8693
8694 DEFUN (show_bgp_view_afi_safi_community,
8695 show_bgp_view_afi_safi_community_cmd,
8696 #ifdef HAVE_IPV6
8697 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8698 #else
8699 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8700 #endif
8701 SHOW_STR
8702 BGP_STR
8703 "BGP view\n"
8704 "View name\n"
8705 "Address family\n"
8706 #ifdef HAVE_IPV6
8707 "Address family\n"
8708 #endif
8709 "Address family modifier\n"
8710 "Address family modifier\n"
8711 "Display routes matching the communities\n"
8712 "community number\n"
8713 "Do not send outside local AS (well-known community)\n"
8714 "Do not advertise to any peer (well-known community)\n"
8715 "Do not export to next AS (well-known community)\n")
8716 {
8717 int afi;
8718 int safi;
8719
8720 #ifdef HAVE_IPV6
8721 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8722 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8723 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
8724 #else
8725 afi = AFI_IP;
8726 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8727 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
8728 #endif
8729 }
8730
8731 ALIAS (show_bgp_view_afi_safi_community,
8732 show_bgp_view_afi_safi_community2_cmd,
8733 #ifdef HAVE_IPV6
8734 "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)",
8735 #else
8736 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8737 #endif
8738 SHOW_STR
8739 BGP_STR
8740 "BGP view\n"
8741 "View name\n"
8742 "Address family\n"
8743 #ifdef HAVE_IPV6
8744 "Address family\n"
8745 #endif
8746 "Address family modifier\n"
8747 "Address family modifier\n"
8748 "Display routes matching the communities\n"
8749 "community number\n"
8750 "Do not send outside local AS (well-known community)\n"
8751 "Do not advertise to any peer (well-known community)\n"
8752 "Do not export to next AS (well-known community)\n"
8753 "community number\n"
8754 "Do not send outside local AS (well-known community)\n"
8755 "Do not advertise to any peer (well-known community)\n"
8756 "Do not export to next AS (well-known community)\n")
8757
8758 ALIAS (show_bgp_view_afi_safi_community,
8759 show_bgp_view_afi_safi_community3_cmd,
8760 #ifdef HAVE_IPV6
8761 "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)",
8762 #else
8763 "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)",
8764 #endif
8765 SHOW_STR
8766 BGP_STR
8767 "BGP view\n"
8768 "View name\n"
8769 "Address family\n"
8770 #ifdef HAVE_IPV6
8771 "Address family\n"
8772 #endif
8773 "Address family modifier\n"
8774 "Address family modifier\n"
8775 "Display routes matching the communities\n"
8776 "community number\n"
8777 "Do not send outside local AS (well-known community)\n"
8778 "Do not advertise to any peer (well-known community)\n"
8779 "Do not export to next AS (well-known community)\n"
8780 "community number\n"
8781 "Do not send outside local AS (well-known community)\n"
8782 "Do not advertise to any peer (well-known community)\n"
8783 "Do not export to next AS (well-known community)\n"
8784 "community number\n"
8785 "Do not send outside local AS (well-known community)\n"
8786 "Do not advertise to any peer (well-known community)\n"
8787 "Do not export to next AS (well-known community)\n")
8788
8789 ALIAS (show_bgp_view_afi_safi_community,
8790 show_bgp_view_afi_safi_community4_cmd,
8791 #ifdef HAVE_IPV6
8792 "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)",
8793 #else
8794 "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)",
8795 #endif
8796 SHOW_STR
8797 BGP_STR
8798 "BGP view\n"
8799 "View name\n"
8800 "Address family\n"
8801 #ifdef HAVE_IPV6
8802 "Address family\n"
8803 #endif
8804 "Address family modifier\n"
8805 "Address family modifier\n"
8806 "Display routes matching the communities\n"
8807 "community number\n"
8808 "Do not send outside local AS (well-known community)\n"
8809 "Do not advertise to any peer (well-known community)\n"
8810 "Do not export to next AS (well-known community)\n"
8811 "community number\n"
8812 "Do not send outside local AS (well-known community)\n"
8813 "Do not advertise to any peer (well-known community)\n"
8814 "Do not export to next AS (well-known community)\n"
8815 "community number\n"
8816 "Do not send outside local AS (well-known community)\n"
8817 "Do not advertise to any peer (well-known community)\n"
8818 "Do not export to next AS (well-known community)\n"
8819 "community number\n"
8820 "Do not send outside local AS (well-known community)\n"
8821 "Do not advertise to any peer (well-known community)\n"
8822 "Do not export to next AS (well-known community)\n")
8823
8824 DEFUN (show_ip_bgp_community_exact,
8825 show_ip_bgp_community_exact_cmd,
8826 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8827 SHOW_STR
8828 IP_STR
8829 BGP_STR
8830 "Display routes matching the communities\n"
8831 "community number\n"
8832 "Do not send outside local AS (well-known community)\n"
8833 "Do not advertise to any peer (well-known community)\n"
8834 "Do not export to next AS (well-known community)\n"
8835 "Exact match of the communities")
8836 {
8837 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
8838 }
8839
8840 ALIAS (show_ip_bgp_community_exact,
8841 show_ip_bgp_community2_exact_cmd,
8842 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8843 SHOW_STR
8844 IP_STR
8845 BGP_STR
8846 "Display routes matching the communities\n"
8847 "community number\n"
8848 "Do not send outside local AS (well-known community)\n"
8849 "Do not advertise to any peer (well-known community)\n"
8850 "Do not export to next AS (well-known community)\n"
8851 "community number\n"
8852 "Do not send outside local AS (well-known community)\n"
8853 "Do not advertise to any peer (well-known community)\n"
8854 "Do not export to next AS (well-known community)\n"
8855 "Exact match of the communities")
8856
8857 ALIAS (show_ip_bgp_community_exact,
8858 show_ip_bgp_community3_exact_cmd,
8859 "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",
8860 SHOW_STR
8861 IP_STR
8862 BGP_STR
8863 "Display routes matching the communities\n"
8864 "community number\n"
8865 "Do not send outside local AS (well-known community)\n"
8866 "Do not advertise to any peer (well-known community)\n"
8867 "Do not export to next AS (well-known community)\n"
8868 "community number\n"
8869 "Do not send outside local AS (well-known community)\n"
8870 "Do not advertise to any peer (well-known community)\n"
8871 "Do not export to next AS (well-known community)\n"
8872 "community number\n"
8873 "Do not send outside local AS (well-known community)\n"
8874 "Do not advertise to any peer (well-known community)\n"
8875 "Do not export to next AS (well-known community)\n"
8876 "Exact match of the communities")
8877
8878 ALIAS (show_ip_bgp_community_exact,
8879 show_ip_bgp_community4_exact_cmd,
8880 "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",
8881 SHOW_STR
8882 IP_STR
8883 BGP_STR
8884 "Display routes matching the communities\n"
8885 "community number\n"
8886 "Do not send outside local AS (well-known community)\n"
8887 "Do not advertise to any peer (well-known community)\n"
8888 "Do not export to next AS (well-known community)\n"
8889 "community number\n"
8890 "Do not send outside local AS (well-known community)\n"
8891 "Do not advertise to any peer (well-known community)\n"
8892 "Do not export to next AS (well-known community)\n"
8893 "community number\n"
8894 "Do not send outside local AS (well-known community)\n"
8895 "Do not advertise to any peer (well-known community)\n"
8896 "Do not export to next AS (well-known community)\n"
8897 "community number\n"
8898 "Do not send outside local AS (well-known community)\n"
8899 "Do not advertise to any peer (well-known community)\n"
8900 "Do not export to next AS (well-known community)\n"
8901 "Exact match of the communities")
8902
8903 DEFUN (show_ip_bgp_ipv4_community_exact,
8904 show_ip_bgp_ipv4_community_exact_cmd,
8905 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8906 SHOW_STR
8907 IP_STR
8908 BGP_STR
8909 "Address family\n"
8910 "Address Family modifier\n"
8911 "Address Family modifier\n"
8912 "Display routes matching the communities\n"
8913 "community number\n"
8914 "Do not send outside local AS (well-known community)\n"
8915 "Do not advertise to any peer (well-known community)\n"
8916 "Do not export to next AS (well-known community)\n"
8917 "Exact match of the communities")
8918 {
8919 if (strncmp (argv[0], "m", 1) == 0)
8920 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
8921
8922 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
8923 }
8924
8925 ALIAS (show_ip_bgp_ipv4_community_exact,
8926 show_ip_bgp_ipv4_community2_exact_cmd,
8927 "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",
8928 SHOW_STR
8929 IP_STR
8930 BGP_STR
8931 "Address family\n"
8932 "Address Family modifier\n"
8933 "Address Family modifier\n"
8934 "Display routes matching the communities\n"
8935 "community number\n"
8936 "Do not send outside local AS (well-known community)\n"
8937 "Do not advertise to any peer (well-known community)\n"
8938 "Do not export to next AS (well-known community)\n"
8939 "community number\n"
8940 "Do not send outside local AS (well-known community)\n"
8941 "Do not advertise to any peer (well-known community)\n"
8942 "Do not export to next AS (well-known community)\n"
8943 "Exact match of the communities")
8944
8945 ALIAS (show_ip_bgp_ipv4_community_exact,
8946 show_ip_bgp_ipv4_community3_exact_cmd,
8947 "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",
8948 SHOW_STR
8949 IP_STR
8950 BGP_STR
8951 "Address family\n"
8952 "Address Family modifier\n"
8953 "Address Family modifier\n"
8954 "Display routes matching the communities\n"
8955 "community number\n"
8956 "Do not send outside local AS (well-known community)\n"
8957 "Do not advertise to any peer (well-known community)\n"
8958 "Do not export to next AS (well-known community)\n"
8959 "community number\n"
8960 "Do not send outside local AS (well-known community)\n"
8961 "Do not advertise to any peer (well-known community)\n"
8962 "Do not export to next AS (well-known community)\n"
8963 "community number\n"
8964 "Do not send outside local AS (well-known community)\n"
8965 "Do not advertise to any peer (well-known community)\n"
8966 "Do not export to next AS (well-known community)\n"
8967 "Exact match of the communities")
8968
8969 ALIAS (show_ip_bgp_ipv4_community_exact,
8970 show_ip_bgp_ipv4_community4_exact_cmd,
8971 "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",
8972 SHOW_STR
8973 IP_STR
8974 BGP_STR
8975 "Address family\n"
8976 "Address Family modifier\n"
8977 "Address Family modifier\n"
8978 "Display routes matching the communities\n"
8979 "community number\n"
8980 "Do not send outside local AS (well-known community)\n"
8981 "Do not advertise to any peer (well-known community)\n"
8982 "Do not export to next AS (well-known community)\n"
8983 "community number\n"
8984 "Do not send outside local AS (well-known community)\n"
8985 "Do not advertise to any peer (well-known community)\n"
8986 "Do not export to next AS (well-known community)\n"
8987 "community number\n"
8988 "Do not send outside local AS (well-known community)\n"
8989 "Do not advertise to any peer (well-known community)\n"
8990 "Do not export to next AS (well-known community)\n"
8991 "community number\n"
8992 "Do not send outside local AS (well-known community)\n"
8993 "Do not advertise to any peer (well-known community)\n"
8994 "Do not export to next AS (well-known community)\n"
8995 "Exact match of the communities")
8996
8997 #ifdef HAVE_IPV6
8998 DEFUN (show_bgp_community,
8999 show_bgp_community_cmd,
9000 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9001 SHOW_STR
9002 BGP_STR
9003 "Display routes matching the communities\n"
9004 "community number\n"
9005 "Do not send outside local AS (well-known community)\n"
9006 "Do not advertise to any peer (well-known community)\n"
9007 "Do not export to next AS (well-known community)\n")
9008 {
9009 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9010 }
9011
9012 ALIAS (show_bgp_community,
9013 show_bgp_ipv6_community_cmd,
9014 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9015 SHOW_STR
9016 BGP_STR
9017 "Address family\n"
9018 "Display routes matching the communities\n"
9019 "community number\n"
9020 "Do not send outside local AS (well-known community)\n"
9021 "Do not advertise to any peer (well-known community)\n"
9022 "Do not export to next AS (well-known community)\n")
9023
9024 ALIAS (show_bgp_community,
9025 show_bgp_community2_cmd,
9026 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9027 SHOW_STR
9028 BGP_STR
9029 "Display routes matching the communities\n"
9030 "community number\n"
9031 "Do not send outside local AS (well-known community)\n"
9032 "Do not advertise to any peer (well-known community)\n"
9033 "Do not export to next AS (well-known community)\n"
9034 "community number\n"
9035 "Do not send outside local AS (well-known community)\n"
9036 "Do not advertise to any peer (well-known community)\n"
9037 "Do not export to next AS (well-known community)\n")
9038
9039 ALIAS (show_bgp_community,
9040 show_bgp_ipv6_community2_cmd,
9041 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9042 SHOW_STR
9043 BGP_STR
9044 "Address family\n"
9045 "Display routes matching the communities\n"
9046 "community number\n"
9047 "Do not send outside local AS (well-known community)\n"
9048 "Do not advertise to any peer (well-known community)\n"
9049 "Do not export to next AS (well-known community)\n"
9050 "community number\n"
9051 "Do not send outside local AS (well-known community)\n"
9052 "Do not advertise to any peer (well-known community)\n"
9053 "Do not export to next AS (well-known community)\n")
9054
9055 ALIAS (show_bgp_community,
9056 show_bgp_community3_cmd,
9057 "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)",
9058 SHOW_STR
9059 BGP_STR
9060 "Display routes matching the communities\n"
9061 "community number\n"
9062 "Do not send outside local AS (well-known community)\n"
9063 "Do not advertise to any peer (well-known community)\n"
9064 "Do not export to next AS (well-known community)\n"
9065 "community number\n"
9066 "Do not send outside local AS (well-known community)\n"
9067 "Do not advertise to any peer (well-known community)\n"
9068 "Do not export to next AS (well-known community)\n"
9069 "community number\n"
9070 "Do not send outside local AS (well-known community)\n"
9071 "Do not advertise to any peer (well-known community)\n"
9072 "Do not export to next AS (well-known community)\n")
9073
9074 ALIAS (show_bgp_community,
9075 show_bgp_ipv6_community3_cmd,
9076 "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)",
9077 SHOW_STR
9078 BGP_STR
9079 "Address family\n"
9080 "Display routes matching the communities\n"
9081 "community number\n"
9082 "Do not send outside local AS (well-known community)\n"
9083 "Do not advertise to any peer (well-known community)\n"
9084 "Do not export to next AS (well-known community)\n"
9085 "community number\n"
9086 "Do not send outside local AS (well-known community)\n"
9087 "Do not advertise to any peer (well-known community)\n"
9088 "Do not export to next AS (well-known community)\n"
9089 "community number\n"
9090 "Do not send outside local AS (well-known community)\n"
9091 "Do not advertise to any peer (well-known community)\n"
9092 "Do not export to next AS (well-known community)\n")
9093
9094 ALIAS (show_bgp_community,
9095 show_bgp_community4_cmd,
9096 "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)",
9097 SHOW_STR
9098 BGP_STR
9099 "Display routes matching the communities\n"
9100 "community number\n"
9101 "Do not send outside local AS (well-known community)\n"
9102 "Do not advertise to any peer (well-known community)\n"
9103 "Do not export to next AS (well-known community)\n"
9104 "community number\n"
9105 "Do not send outside local AS (well-known community)\n"
9106 "Do not advertise to any peer (well-known community)\n"
9107 "Do not export to next AS (well-known community)\n"
9108 "community number\n"
9109 "Do not send outside local AS (well-known community)\n"
9110 "Do not advertise to any peer (well-known community)\n"
9111 "Do not export to next AS (well-known community)\n"
9112 "community number\n"
9113 "Do not send outside local AS (well-known community)\n"
9114 "Do not advertise to any peer (well-known community)\n"
9115 "Do not export to next AS (well-known community)\n")
9116
9117 ALIAS (show_bgp_community,
9118 show_bgp_ipv6_community4_cmd,
9119 "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)",
9120 SHOW_STR
9121 BGP_STR
9122 "Address family\n"
9123 "Display routes matching the communities\n"
9124 "community number\n"
9125 "Do not send outside local AS (well-known community)\n"
9126 "Do not advertise to any peer (well-known community)\n"
9127 "Do not export to next AS (well-known community)\n"
9128 "community number\n"
9129 "Do not send outside local AS (well-known community)\n"
9130 "Do not advertise to any peer (well-known community)\n"
9131 "Do not export to next AS (well-known community)\n"
9132 "community number\n"
9133 "Do not send outside local AS (well-known community)\n"
9134 "Do not advertise to any peer (well-known community)\n"
9135 "Do not export to next AS (well-known community)\n"
9136 "community number\n"
9137 "Do not send outside local AS (well-known community)\n"
9138 "Do not advertise to any peer (well-known community)\n"
9139 "Do not export to next AS (well-known community)\n")
9140
9141 /* old command */
9142 DEFUN (show_ipv6_bgp_community,
9143 show_ipv6_bgp_community_cmd,
9144 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9145 SHOW_STR
9146 IPV6_STR
9147 BGP_STR
9148 "Display routes matching the communities\n"
9149 "community number\n"
9150 "Do not send outside local AS (well-known community)\n"
9151 "Do not advertise to any peer (well-known community)\n"
9152 "Do not export to next AS (well-known community)\n")
9153 {
9154 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9155 }
9156
9157 /* old command */
9158 ALIAS (show_ipv6_bgp_community,
9159 show_ipv6_bgp_community2_cmd,
9160 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9161 SHOW_STR
9162 IPV6_STR
9163 BGP_STR
9164 "Display routes matching the communities\n"
9165 "community number\n"
9166 "Do not send outside local AS (well-known community)\n"
9167 "Do not advertise to any peer (well-known community)\n"
9168 "Do not export to next AS (well-known community)\n"
9169 "community number\n"
9170 "Do not send outside local AS (well-known community)\n"
9171 "Do not advertise to any peer (well-known community)\n"
9172 "Do not export to next AS (well-known community)\n")
9173
9174 /* old command */
9175 ALIAS (show_ipv6_bgp_community,
9176 show_ipv6_bgp_community3_cmd,
9177 "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)",
9178 SHOW_STR
9179 IPV6_STR
9180 BGP_STR
9181 "Display routes matching the communities\n"
9182 "community number\n"
9183 "Do not send outside local AS (well-known community)\n"
9184 "Do not advertise to any peer (well-known community)\n"
9185 "Do not export to next AS (well-known community)\n"
9186 "community number\n"
9187 "Do not send outside local AS (well-known community)\n"
9188 "Do not advertise to any peer (well-known community)\n"
9189 "Do not export to next AS (well-known community)\n"
9190 "community number\n"
9191 "Do not send outside local AS (well-known community)\n"
9192 "Do not advertise to any peer (well-known community)\n"
9193 "Do not export to next AS (well-known community)\n")
9194
9195 /* old command */
9196 ALIAS (show_ipv6_bgp_community,
9197 show_ipv6_bgp_community4_cmd,
9198 "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)",
9199 SHOW_STR
9200 IPV6_STR
9201 BGP_STR
9202 "Display routes matching the communities\n"
9203 "community number\n"
9204 "Do not send outside local AS (well-known community)\n"
9205 "Do not advertise to any peer (well-known community)\n"
9206 "Do not export to next AS (well-known community)\n"
9207 "community number\n"
9208 "Do not send outside local AS (well-known community)\n"
9209 "Do not advertise to any peer (well-known community)\n"
9210 "Do not export to next AS (well-known community)\n"
9211 "community number\n"
9212 "Do not send outside local AS (well-known community)\n"
9213 "Do not advertise to any peer (well-known community)\n"
9214 "Do not export to next AS (well-known community)\n"
9215 "community number\n"
9216 "Do not send outside local AS (well-known community)\n"
9217 "Do not advertise to any peer (well-known community)\n"
9218 "Do not export to next AS (well-known community)\n")
9219
9220 DEFUN (show_bgp_community_exact,
9221 show_bgp_community_exact_cmd,
9222 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9223 SHOW_STR
9224 BGP_STR
9225 "Display routes matching the communities\n"
9226 "community number\n"
9227 "Do not send outside local AS (well-known community)\n"
9228 "Do not advertise to any peer (well-known community)\n"
9229 "Do not export to next AS (well-known community)\n"
9230 "Exact match of the communities")
9231 {
9232 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9233 }
9234
9235 ALIAS (show_bgp_community_exact,
9236 show_bgp_ipv6_community_exact_cmd,
9237 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9238 SHOW_STR
9239 BGP_STR
9240 "Address family\n"
9241 "Display routes matching the communities\n"
9242 "community number\n"
9243 "Do not send outside local AS (well-known community)\n"
9244 "Do not advertise to any peer (well-known community)\n"
9245 "Do not export to next AS (well-known community)\n"
9246 "Exact match of the communities")
9247
9248 ALIAS (show_bgp_community_exact,
9249 show_bgp_community2_exact_cmd,
9250 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9251 SHOW_STR
9252 BGP_STR
9253 "Display routes matching the communities\n"
9254 "community number\n"
9255 "Do not send outside local AS (well-known community)\n"
9256 "Do not advertise to any peer (well-known community)\n"
9257 "Do not export to next AS (well-known community)\n"
9258 "community number\n"
9259 "Do not send outside local AS (well-known community)\n"
9260 "Do not advertise to any peer (well-known community)\n"
9261 "Do not export to next AS (well-known community)\n"
9262 "Exact match of the communities")
9263
9264 ALIAS (show_bgp_community_exact,
9265 show_bgp_ipv6_community2_exact_cmd,
9266 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9267 SHOW_STR
9268 BGP_STR
9269 "Address family\n"
9270 "Display routes matching the communities\n"
9271 "community number\n"
9272 "Do not send outside local AS (well-known community)\n"
9273 "Do not advertise to any peer (well-known community)\n"
9274 "Do not export to next AS (well-known community)\n"
9275 "community number\n"
9276 "Do not send outside local AS (well-known community)\n"
9277 "Do not advertise to any peer (well-known community)\n"
9278 "Do not export to next AS (well-known community)\n"
9279 "Exact match of the communities")
9280
9281 ALIAS (show_bgp_community_exact,
9282 show_bgp_community3_exact_cmd,
9283 "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",
9284 SHOW_STR
9285 BGP_STR
9286 "Display routes matching the communities\n"
9287 "community number\n"
9288 "Do not send outside local AS (well-known community)\n"
9289 "Do not advertise to any peer (well-known community)\n"
9290 "Do not export to next AS (well-known community)\n"
9291 "community number\n"
9292 "Do not send outside local AS (well-known community)\n"
9293 "Do not advertise to any peer (well-known community)\n"
9294 "Do not export to next AS (well-known community)\n"
9295 "community number\n"
9296 "Do not send outside local AS (well-known community)\n"
9297 "Do not advertise to any peer (well-known community)\n"
9298 "Do not export to next AS (well-known community)\n"
9299 "Exact match of the communities")
9300
9301 ALIAS (show_bgp_community_exact,
9302 show_bgp_ipv6_community3_exact_cmd,
9303 "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",
9304 SHOW_STR
9305 BGP_STR
9306 "Address family\n"
9307 "Display routes matching the communities\n"
9308 "community number\n"
9309 "Do not send outside local AS (well-known community)\n"
9310 "Do not advertise to any peer (well-known community)\n"
9311 "Do not export to next AS (well-known community)\n"
9312 "community number\n"
9313 "Do not send outside local AS (well-known community)\n"
9314 "Do not advertise to any peer (well-known community)\n"
9315 "Do not export to next AS (well-known community)\n"
9316 "community number\n"
9317 "Do not send outside local AS (well-known community)\n"
9318 "Do not advertise to any peer (well-known community)\n"
9319 "Do not export to next AS (well-known community)\n"
9320 "Exact match of the communities")
9321
9322 ALIAS (show_bgp_community_exact,
9323 show_bgp_community4_exact_cmd,
9324 "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",
9325 SHOW_STR
9326 BGP_STR
9327 "Display routes matching the communities\n"
9328 "community number\n"
9329 "Do not send outside local AS (well-known community)\n"
9330 "Do not advertise to any peer (well-known community)\n"
9331 "Do not export to next AS (well-known community)\n"
9332 "community number\n"
9333 "Do not send outside local AS (well-known community)\n"
9334 "Do not advertise to any peer (well-known community)\n"
9335 "Do not export to next AS (well-known community)\n"
9336 "community number\n"
9337 "Do not send outside local AS (well-known community)\n"
9338 "Do not advertise to any peer (well-known community)\n"
9339 "Do not export to next AS (well-known community)\n"
9340 "community number\n"
9341 "Do not send outside local AS (well-known community)\n"
9342 "Do not advertise to any peer (well-known community)\n"
9343 "Do not export to next AS (well-known community)\n"
9344 "Exact match of the communities")
9345
9346 ALIAS (show_bgp_community_exact,
9347 show_bgp_ipv6_community4_exact_cmd,
9348 "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",
9349 SHOW_STR
9350 BGP_STR
9351 "Address family\n"
9352 "Display routes matching the communities\n"
9353 "community number\n"
9354 "Do not send outside local AS (well-known community)\n"
9355 "Do not advertise to any peer (well-known community)\n"
9356 "Do not export to next AS (well-known community)\n"
9357 "community number\n"
9358 "Do not send outside local AS (well-known community)\n"
9359 "Do not advertise to any peer (well-known community)\n"
9360 "Do not export to next AS (well-known community)\n"
9361 "community number\n"
9362 "Do not send outside local AS (well-known community)\n"
9363 "Do not advertise to any peer (well-known community)\n"
9364 "Do not export to next AS (well-known community)\n"
9365 "community number\n"
9366 "Do not send outside local AS (well-known community)\n"
9367 "Do not advertise to any peer (well-known community)\n"
9368 "Do not export to next AS (well-known community)\n"
9369 "Exact match of the communities")
9370
9371 /* old command */
9372 DEFUN (show_ipv6_bgp_community_exact,
9373 show_ipv6_bgp_community_exact_cmd,
9374 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9375 SHOW_STR
9376 IPV6_STR
9377 BGP_STR
9378 "Display routes matching the communities\n"
9379 "community number\n"
9380 "Do not send outside local AS (well-known community)\n"
9381 "Do not advertise to any peer (well-known community)\n"
9382 "Do not export to next AS (well-known community)\n"
9383 "Exact match of the communities")
9384 {
9385 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9386 }
9387
9388 /* old command */
9389 ALIAS (show_ipv6_bgp_community_exact,
9390 show_ipv6_bgp_community2_exact_cmd,
9391 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9392 SHOW_STR
9393 IPV6_STR
9394 BGP_STR
9395 "Display routes matching the communities\n"
9396 "community number\n"
9397 "Do not send outside local AS (well-known community)\n"
9398 "Do not advertise to any peer (well-known community)\n"
9399 "Do not export to next AS (well-known community)\n"
9400 "community number\n"
9401 "Do not send outside local AS (well-known community)\n"
9402 "Do not advertise to any peer (well-known community)\n"
9403 "Do not export to next AS (well-known community)\n"
9404 "Exact match of the communities")
9405
9406 /* old command */
9407 ALIAS (show_ipv6_bgp_community_exact,
9408 show_ipv6_bgp_community3_exact_cmd,
9409 "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",
9410 SHOW_STR
9411 IPV6_STR
9412 BGP_STR
9413 "Display routes matching the communities\n"
9414 "community number\n"
9415 "Do not send outside local AS (well-known community)\n"
9416 "Do not advertise to any peer (well-known community)\n"
9417 "Do not export to next AS (well-known community)\n"
9418 "community number\n"
9419 "Do not send outside local AS (well-known community)\n"
9420 "Do not advertise to any peer (well-known community)\n"
9421 "Do not export to next AS (well-known community)\n"
9422 "community number\n"
9423 "Do not send outside local AS (well-known community)\n"
9424 "Do not advertise to any peer (well-known community)\n"
9425 "Do not export to next AS (well-known community)\n"
9426 "Exact match of the communities")
9427
9428 /* old command */
9429 ALIAS (show_ipv6_bgp_community_exact,
9430 show_ipv6_bgp_community4_exact_cmd,
9431 "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",
9432 SHOW_STR
9433 IPV6_STR
9434 BGP_STR
9435 "Display routes matching the communities\n"
9436 "community number\n"
9437 "Do not send outside local AS (well-known community)\n"
9438 "Do not advertise to any peer (well-known community)\n"
9439 "Do not export to next AS (well-known community)\n"
9440 "community number\n"
9441 "Do not send outside local AS (well-known community)\n"
9442 "Do not advertise to any peer (well-known community)\n"
9443 "Do not export to next AS (well-known community)\n"
9444 "community number\n"
9445 "Do not send outside local AS (well-known community)\n"
9446 "Do not advertise to any peer (well-known community)\n"
9447 "Do not export to next AS (well-known community)\n"
9448 "community number\n"
9449 "Do not send outside local AS (well-known community)\n"
9450 "Do not advertise to any peer (well-known community)\n"
9451 "Do not export to next AS (well-known community)\n"
9452 "Exact match of the communities")
9453
9454 /* old command */
9455 DEFUN (show_ipv6_mbgp_community,
9456 show_ipv6_mbgp_community_cmd,
9457 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
9458 SHOW_STR
9459 IPV6_STR
9460 MBGP_STR
9461 "Display routes matching the communities\n"
9462 "community number\n"
9463 "Do not send outside local AS (well-known community)\n"
9464 "Do not advertise to any peer (well-known community)\n"
9465 "Do not export to next AS (well-known community)\n")
9466 {
9467 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
9468 }
9469
9470 /* old command */
9471 ALIAS (show_ipv6_mbgp_community,
9472 show_ipv6_mbgp_community2_cmd,
9473 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9474 SHOW_STR
9475 IPV6_STR
9476 MBGP_STR
9477 "Display routes matching the communities\n"
9478 "community number\n"
9479 "Do not send outside local AS (well-known community)\n"
9480 "Do not advertise to any peer (well-known community)\n"
9481 "Do not export to next AS (well-known community)\n"
9482 "community number\n"
9483 "Do not send outside local AS (well-known community)\n"
9484 "Do not advertise to any peer (well-known community)\n"
9485 "Do not export to next AS (well-known community)\n")
9486
9487 /* old command */
9488 ALIAS (show_ipv6_mbgp_community,
9489 show_ipv6_mbgp_community3_cmd,
9490 "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)",
9491 SHOW_STR
9492 IPV6_STR
9493 MBGP_STR
9494 "Display routes matching the communities\n"
9495 "community number\n"
9496 "Do not send outside local AS (well-known community)\n"
9497 "Do not advertise to any peer (well-known community)\n"
9498 "Do not export to next AS (well-known community)\n"
9499 "community number\n"
9500 "Do not send outside local AS (well-known community)\n"
9501 "Do not advertise to any peer (well-known community)\n"
9502 "Do not export to next AS (well-known community)\n"
9503 "community number\n"
9504 "Do not send outside local AS (well-known community)\n"
9505 "Do not advertise to any peer (well-known community)\n"
9506 "Do not export to next AS (well-known community)\n")
9507
9508 /* old command */
9509 ALIAS (show_ipv6_mbgp_community,
9510 show_ipv6_mbgp_community4_cmd,
9511 "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)",
9512 SHOW_STR
9513 IPV6_STR
9514 MBGP_STR
9515 "Display routes matching the communities\n"
9516 "community number\n"
9517 "Do not send outside local AS (well-known community)\n"
9518 "Do not advertise to any peer (well-known community)\n"
9519 "Do not export to next AS (well-known community)\n"
9520 "community number\n"
9521 "Do not send outside local AS (well-known community)\n"
9522 "Do not advertise to any peer (well-known community)\n"
9523 "Do not export to next AS (well-known community)\n"
9524 "community number\n"
9525 "Do not send outside local AS (well-known community)\n"
9526 "Do not advertise to any peer (well-known community)\n"
9527 "Do not export to next AS (well-known community)\n"
9528 "community number\n"
9529 "Do not send outside local AS (well-known community)\n"
9530 "Do not advertise to any peer (well-known community)\n"
9531 "Do not export to next AS (well-known community)\n")
9532
9533 /* old command */
9534 DEFUN (show_ipv6_mbgp_community_exact,
9535 show_ipv6_mbgp_community_exact_cmd,
9536 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9537 SHOW_STR
9538 IPV6_STR
9539 MBGP_STR
9540 "Display routes matching the communities\n"
9541 "community number\n"
9542 "Do not send outside local AS (well-known community)\n"
9543 "Do not advertise to any peer (well-known community)\n"
9544 "Do not export to next AS (well-known community)\n"
9545 "Exact match of the communities")
9546 {
9547 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
9548 }
9549
9550 /* old command */
9551 ALIAS (show_ipv6_mbgp_community_exact,
9552 show_ipv6_mbgp_community2_exact_cmd,
9553 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9554 SHOW_STR
9555 IPV6_STR
9556 MBGP_STR
9557 "Display routes matching the communities\n"
9558 "community number\n"
9559 "Do not send outside local AS (well-known community)\n"
9560 "Do not advertise to any peer (well-known community)\n"
9561 "Do not export to next AS (well-known community)\n"
9562 "community number\n"
9563 "Do not send outside local AS (well-known community)\n"
9564 "Do not advertise to any peer (well-known community)\n"
9565 "Do not export to next AS (well-known community)\n"
9566 "Exact match of the communities")
9567
9568 /* old command */
9569 ALIAS (show_ipv6_mbgp_community_exact,
9570 show_ipv6_mbgp_community3_exact_cmd,
9571 "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",
9572 SHOW_STR
9573 IPV6_STR
9574 MBGP_STR
9575 "Display routes matching the communities\n"
9576 "community number\n"
9577 "Do not send outside local AS (well-known community)\n"
9578 "Do not advertise to any peer (well-known community)\n"
9579 "Do not export to next AS (well-known community)\n"
9580 "community number\n"
9581 "Do not send outside local AS (well-known community)\n"
9582 "Do not advertise to any peer (well-known community)\n"
9583 "Do not export to next AS (well-known community)\n"
9584 "community number\n"
9585 "Do not send outside local AS (well-known community)\n"
9586 "Do not advertise to any peer (well-known community)\n"
9587 "Do not export to next AS (well-known community)\n"
9588 "Exact match of the communities")
9589
9590 /* old command */
9591 ALIAS (show_ipv6_mbgp_community_exact,
9592 show_ipv6_mbgp_community4_exact_cmd,
9593 "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",
9594 SHOW_STR
9595 IPV6_STR
9596 MBGP_STR
9597 "Display routes matching the communities\n"
9598 "community number\n"
9599 "Do not send outside local AS (well-known community)\n"
9600 "Do not advertise to any peer (well-known community)\n"
9601 "Do not export to next AS (well-known community)\n"
9602 "community number\n"
9603 "Do not send outside local AS (well-known community)\n"
9604 "Do not advertise to any peer (well-known community)\n"
9605 "Do not export to next AS (well-known community)\n"
9606 "community number\n"
9607 "Do not send outside local AS (well-known community)\n"
9608 "Do not advertise to any peer (well-known community)\n"
9609 "Do not export to next AS (well-known community)\n"
9610 "community number\n"
9611 "Do not send outside local AS (well-known community)\n"
9612 "Do not advertise to any peer (well-known community)\n"
9613 "Do not export to next AS (well-known community)\n"
9614 "Exact match of the communities")
9615 #endif /* HAVE_IPV6 */
9616
9617 static int
9618 bgp_show_community_list (struct vty *vty, const char *com, int exact,
9619 afi_t afi, safi_t safi)
9620 {
9621 struct community_list *list;
9622
9623 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
9624 if (list == NULL)
9625 {
9626 vty_out (vty, "%% %s is not a valid community-list name%s", com,
9627 VTY_NEWLINE);
9628 return CMD_WARNING;
9629 }
9630
9631 return bgp_show (vty, NULL, afi, safi,
9632 (exact ? bgp_show_type_community_list_exact :
9633 bgp_show_type_community_list), list, NULL);
9634 }
9635
9636 DEFUN (show_ip_bgp_community_list,
9637 show_ip_bgp_community_list_cmd,
9638 "show ip bgp community-list (<1-500>|WORD)",
9639 SHOW_STR
9640 IP_STR
9641 BGP_STR
9642 "Display routes matching the community-list\n"
9643 "community-list number\n"
9644 "community-list name\n")
9645 {
9646 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
9647 }
9648
9649 DEFUN (show_ip_bgp_ipv4_community_list,
9650 show_ip_bgp_ipv4_community_list_cmd,
9651 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
9652 SHOW_STR
9653 IP_STR
9654 BGP_STR
9655 "Address family\n"
9656 "Address Family modifier\n"
9657 "Address Family modifier\n"
9658 "Display routes matching the community-list\n"
9659 "community-list number\n"
9660 "community-list name\n")
9661 {
9662 if (strncmp (argv[0], "m", 1) == 0)
9663 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
9664
9665 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
9666 }
9667
9668 DEFUN (show_ip_bgp_community_list_exact,
9669 show_ip_bgp_community_list_exact_cmd,
9670 "show ip bgp community-list (<1-500>|WORD) exact-match",
9671 SHOW_STR
9672 IP_STR
9673 BGP_STR
9674 "Display routes matching the community-list\n"
9675 "community-list number\n"
9676 "community-list name\n"
9677 "Exact match of the communities\n")
9678 {
9679 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9680 }
9681
9682 DEFUN (show_ip_bgp_ipv4_community_list_exact,
9683 show_ip_bgp_ipv4_community_list_exact_cmd,
9684 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
9685 SHOW_STR
9686 IP_STR
9687 BGP_STR
9688 "Address family\n"
9689 "Address Family modifier\n"
9690 "Address Family modifier\n"
9691 "Display routes matching the community-list\n"
9692 "community-list number\n"
9693 "community-list name\n"
9694 "Exact match of the communities\n")
9695 {
9696 if (strncmp (argv[0], "m", 1) == 0)
9697 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9698
9699 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9700 }
9701
9702 #ifdef HAVE_IPV6
9703 DEFUN (show_bgp_community_list,
9704 show_bgp_community_list_cmd,
9705 "show bgp community-list (<1-500>|WORD)",
9706 SHOW_STR
9707 BGP_STR
9708 "Display routes matching the community-list\n"
9709 "community-list number\n"
9710 "community-list name\n")
9711 {
9712 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9713 }
9714
9715 ALIAS (show_bgp_community_list,
9716 show_bgp_ipv6_community_list_cmd,
9717 "show bgp ipv6 community-list (<1-500>|WORD)",
9718 SHOW_STR
9719 BGP_STR
9720 "Address family\n"
9721 "Display routes matching the community-list\n"
9722 "community-list number\n"
9723 "community-list name\n")
9724
9725 /* old command */
9726 DEFUN (show_ipv6_bgp_community_list,
9727 show_ipv6_bgp_community_list_cmd,
9728 "show ipv6 bgp community-list WORD",
9729 SHOW_STR
9730 IPV6_STR
9731 BGP_STR
9732 "Display routes matching the community-list\n"
9733 "community-list name\n")
9734 {
9735 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9736 }
9737
9738 /* old command */
9739 DEFUN (show_ipv6_mbgp_community_list,
9740 show_ipv6_mbgp_community_list_cmd,
9741 "show ipv6 mbgp community-list WORD",
9742 SHOW_STR
9743 IPV6_STR
9744 MBGP_STR
9745 "Display routes matching the community-list\n"
9746 "community-list name\n")
9747 {
9748 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9749 }
9750
9751 DEFUN (show_bgp_community_list_exact,
9752 show_bgp_community_list_exact_cmd,
9753 "show bgp community-list (<1-500>|WORD) exact-match",
9754 SHOW_STR
9755 BGP_STR
9756 "Display routes matching the community-list\n"
9757 "community-list number\n"
9758 "community-list name\n"
9759 "Exact match of the communities\n")
9760 {
9761 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9762 }
9763
9764 ALIAS (show_bgp_community_list_exact,
9765 show_bgp_ipv6_community_list_exact_cmd,
9766 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
9767 SHOW_STR
9768 BGP_STR
9769 "Address family\n"
9770 "Display routes matching the community-list\n"
9771 "community-list number\n"
9772 "community-list name\n"
9773 "Exact match of the communities\n")
9774
9775 /* old command */
9776 DEFUN (show_ipv6_bgp_community_list_exact,
9777 show_ipv6_bgp_community_list_exact_cmd,
9778 "show ipv6 bgp community-list WORD exact-match",
9779 SHOW_STR
9780 IPV6_STR
9781 BGP_STR
9782 "Display routes matching the community-list\n"
9783 "community-list name\n"
9784 "Exact match of the communities\n")
9785 {
9786 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9787 }
9788
9789 /* old command */
9790 DEFUN (show_ipv6_mbgp_community_list_exact,
9791 show_ipv6_mbgp_community_list_exact_cmd,
9792 "show ipv6 mbgp community-list WORD exact-match",
9793 SHOW_STR
9794 IPV6_STR
9795 MBGP_STR
9796 "Display routes matching the community-list\n"
9797 "community-list name\n"
9798 "Exact match of the communities\n")
9799 {
9800 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9801 }
9802 #endif /* HAVE_IPV6 */
9803
9804 static int
9805 bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
9806 safi_t safi, enum bgp_show_type type)
9807 {
9808 int ret;
9809 struct prefix *p;
9810
9811 p = prefix_new();
9812
9813 ret = str2prefix (prefix, p);
9814 if (! ret)
9815 {
9816 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9817 return CMD_WARNING;
9818 }
9819
9820 ret = bgp_show (vty, NULL, afi, safi, type, p, NULL);
9821 prefix_free(p);
9822 return ret;
9823 }
9824
9825 DEFUN (show_ip_bgp_prefix_longer,
9826 show_ip_bgp_prefix_longer_cmd,
9827 "show ip bgp A.B.C.D/M longer-prefixes",
9828 SHOW_STR
9829 IP_STR
9830 BGP_STR
9831 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9832 "Display route and more specific routes\n")
9833 {
9834 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9835 bgp_show_type_prefix_longer);
9836 }
9837
9838 DEFUN (show_ip_bgp_flap_prefix_longer,
9839 show_ip_bgp_flap_prefix_longer_cmd,
9840 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9841 SHOW_STR
9842 IP_STR
9843 BGP_STR
9844 "Display flap statistics of routes\n"
9845 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9846 "Display route and more specific routes\n")
9847 {
9848 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9849 bgp_show_type_flap_prefix_longer);
9850 }
9851
9852 DEFUN (show_ip_bgp_ipv4_prefix_longer,
9853 show_ip_bgp_ipv4_prefix_longer_cmd,
9854 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9855 SHOW_STR
9856 IP_STR
9857 BGP_STR
9858 "Address family\n"
9859 "Address Family modifier\n"
9860 "Address Family modifier\n"
9861 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9862 "Display route and more specific routes\n")
9863 {
9864 if (strncmp (argv[0], "m", 1) == 0)
9865 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9866 bgp_show_type_prefix_longer);
9867
9868 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9869 bgp_show_type_prefix_longer);
9870 }
9871
9872 DEFUN (show_ip_bgp_flap_address,
9873 show_ip_bgp_flap_address_cmd,
9874 "show ip bgp flap-statistics A.B.C.D",
9875 SHOW_STR
9876 IP_STR
9877 BGP_STR
9878 "Display flap statistics of routes\n"
9879 "Network in the BGP routing table to display\n")
9880 {
9881 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9882 bgp_show_type_flap_address);
9883 }
9884
9885 DEFUN (show_ip_bgp_flap_prefix,
9886 show_ip_bgp_flap_prefix_cmd,
9887 "show ip bgp flap-statistics A.B.C.D/M",
9888 SHOW_STR
9889 IP_STR
9890 BGP_STR
9891 "Display flap statistics of routes\n"
9892 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9893 {
9894 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9895 bgp_show_type_flap_prefix);
9896 }
9897 #ifdef HAVE_IPV6
9898 DEFUN (show_bgp_prefix_longer,
9899 show_bgp_prefix_longer_cmd,
9900 "show bgp X:X::X:X/M longer-prefixes",
9901 SHOW_STR
9902 BGP_STR
9903 "IPv6 prefix <network>/<length>\n"
9904 "Display route and more specific routes\n")
9905 {
9906 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9907 bgp_show_type_prefix_longer);
9908 }
9909
9910 ALIAS (show_bgp_prefix_longer,
9911 show_bgp_ipv6_prefix_longer_cmd,
9912 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9913 SHOW_STR
9914 BGP_STR
9915 "Address family\n"
9916 "IPv6 prefix <network>/<length>\n"
9917 "Display route and more specific routes\n")
9918
9919 /* old command */
9920 DEFUN (show_ipv6_bgp_prefix_longer,
9921 show_ipv6_bgp_prefix_longer_cmd,
9922 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9923 SHOW_STR
9924 IPV6_STR
9925 BGP_STR
9926 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9927 "Display route and more specific routes\n")
9928 {
9929 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9930 bgp_show_type_prefix_longer);
9931 }
9932
9933 /* old command */
9934 DEFUN (show_ipv6_mbgp_prefix_longer,
9935 show_ipv6_mbgp_prefix_longer_cmd,
9936 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9937 SHOW_STR
9938 IPV6_STR
9939 MBGP_STR
9940 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9941 "Display route and more specific routes\n")
9942 {
9943 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9944 bgp_show_type_prefix_longer);
9945 }
9946 #endif /* HAVE_IPV6 */
9947
9948 static struct peer *
9949 peer_lookup_in_view (struct vty *vty, const char *view_name,
9950 const char *ip_str)
9951 {
9952 int ret;
9953 struct bgp *bgp;
9954 struct peer *peer;
9955 union sockunion su;
9956
9957 /* BGP structure lookup. */
9958 if (view_name)
9959 {
9960 bgp = bgp_lookup_by_name (view_name);
9961 if (! bgp)
9962 {
9963 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9964 return NULL;
9965 }
9966 }
9967 else
9968 {
9969 bgp = bgp_get_default ();
9970 if (! bgp)
9971 {
9972 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9973 return NULL;
9974 }
9975 }
9976
9977 /* Get peer sockunion. */
9978 ret = str2sockunion (ip_str, &su);
9979 if (ret < 0)
9980 {
9981 peer = peer_lookup_by_conf_if (bgp, ip_str);
9982 if (!peer)
9983 {
9984 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
9985 return NULL;
9986 }
9987 return peer;
9988 }
9989
9990 /* Peer structure lookup. */
9991 peer = peer_lookup (bgp, &su);
9992 if (! peer)
9993 {
9994 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9995 return NULL;
9996 }
9997
9998 return peer;
9999 }
10000
10001 enum bgp_stats
10002 {
10003 BGP_STATS_MAXBITLEN = 0,
10004 BGP_STATS_RIB,
10005 BGP_STATS_PREFIXES,
10006 BGP_STATS_TOTPLEN,
10007 BGP_STATS_UNAGGREGATEABLE,
10008 BGP_STATS_MAX_AGGREGATEABLE,
10009 BGP_STATS_AGGREGATES,
10010 BGP_STATS_SPACE,
10011 BGP_STATS_ASPATH_COUNT,
10012 BGP_STATS_ASPATH_MAXHOPS,
10013 BGP_STATS_ASPATH_TOTHOPS,
10014 BGP_STATS_ASPATH_MAXSIZE,
10015 BGP_STATS_ASPATH_TOTSIZE,
10016 BGP_STATS_ASN_HIGHEST,
10017 BGP_STATS_MAX,
10018 };
10019
10020 static const char *table_stats_strs[] =
10021 {
10022 [BGP_STATS_PREFIXES] = "Total Prefixes",
10023 [BGP_STATS_TOTPLEN] = "Average prefix length",
10024 [BGP_STATS_RIB] = "Total Advertisements",
10025 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
10026 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
10027 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
10028 [BGP_STATS_SPACE] = "Address space advertised",
10029 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
10030 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
10031 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
10032 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
10033 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
10034 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
10035 [BGP_STATS_MAX] = NULL,
10036 };
10037
10038 struct bgp_table_stats
10039 {
10040 struct bgp_table *table;
10041 unsigned long long counts[BGP_STATS_MAX];
10042 };
10043
10044 #if 0
10045 #define TALLY_SIGFIG 100000
10046 static unsigned long
10047 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
10048 {
10049 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
10050 unsigned long res = (newtot * TALLY_SIGFIG) / count;
10051 unsigned long ret = newtot / count;
10052
10053 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
10054 return ret + 1;
10055 else
10056 return ret;
10057 }
10058 #endif
10059
10060 static int
10061 bgp_table_stats_walker (struct thread *t)
10062 {
10063 struct bgp_node *rn;
10064 struct bgp_node *top;
10065 struct bgp_table_stats *ts = THREAD_ARG (t);
10066 unsigned int space = 0;
10067
10068 if (!(top = bgp_table_top (ts->table)))
10069 return 0;
10070
10071 switch (top->p.family)
10072 {
10073 case AF_INET:
10074 space = IPV4_MAX_BITLEN;
10075 break;
10076 case AF_INET6:
10077 space = IPV6_MAX_BITLEN;
10078 break;
10079 }
10080
10081 ts->counts[BGP_STATS_MAXBITLEN] = space;
10082
10083 for (rn = top; rn; rn = bgp_route_next (rn))
10084 {
10085 struct bgp_info *ri;
10086 struct bgp_node *prn = bgp_node_parent_nolock (rn);
10087 unsigned int rinum = 0;
10088
10089 if (rn == top)
10090 continue;
10091
10092 if (!rn->info)
10093 continue;
10094
10095 ts->counts[BGP_STATS_PREFIXES]++;
10096 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
10097
10098 #if 0
10099 ts->counts[BGP_STATS_AVGPLEN]
10100 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
10101 ts->counts[BGP_STATS_AVGPLEN],
10102 rn->p.prefixlen);
10103 #endif
10104
10105 /* check if the prefix is included by any other announcements */
10106 while (prn && !prn->info)
10107 prn = bgp_node_parent_nolock (prn);
10108
10109 if (prn == NULL || prn == top)
10110 {
10111 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
10112 /* announced address space */
10113 if (space)
10114 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
10115 }
10116 else if (prn->info)
10117 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
10118
10119 for (ri = rn->info; ri; ri = ri->next)
10120 {
10121 rinum++;
10122 ts->counts[BGP_STATS_RIB]++;
10123
10124 if (ri->attr &&
10125 (CHECK_FLAG (ri->attr->flag,
10126 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
10127 ts->counts[BGP_STATS_AGGREGATES]++;
10128
10129 /* as-path stats */
10130 if (ri->attr && ri->attr->aspath)
10131 {
10132 unsigned int hops = aspath_count_hops (ri->attr->aspath);
10133 unsigned int size = aspath_size (ri->attr->aspath);
10134 as_t highest = aspath_highest (ri->attr->aspath);
10135
10136 ts->counts[BGP_STATS_ASPATH_COUNT]++;
10137
10138 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
10139 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
10140
10141 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
10142 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
10143
10144 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
10145 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
10146 #if 0
10147 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
10148 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
10149 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
10150 hops);
10151 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
10152 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
10153 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
10154 size);
10155 #endif
10156 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
10157 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
10158 }
10159 }
10160 }
10161 return 0;
10162 }
10163
10164 static int
10165 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
10166 {
10167 struct bgp_table_stats ts;
10168 unsigned int i;
10169
10170 if (!bgp->rib[afi][safi])
10171 {
10172 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
10173 return CMD_WARNING;
10174 }
10175
10176 memset (&ts, 0, sizeof (ts));
10177 ts.table = bgp->rib[afi][safi];
10178 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
10179
10180 vty_out (vty, "BGP %s RIB statistics%s%s",
10181 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
10182
10183 for (i = 0; i < BGP_STATS_MAX; i++)
10184 {
10185 if (!table_stats_strs[i])
10186 continue;
10187
10188 switch (i)
10189 {
10190 #if 0
10191 case BGP_STATS_ASPATH_AVGHOPS:
10192 case BGP_STATS_ASPATH_AVGSIZE:
10193 case BGP_STATS_AVGPLEN:
10194 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10195 vty_out (vty, "%12.2f",
10196 (float)ts.counts[i] / (float)TALLY_SIGFIG);
10197 break;
10198 #endif
10199 case BGP_STATS_ASPATH_TOTHOPS:
10200 case BGP_STATS_ASPATH_TOTSIZE:
10201 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10202 vty_out (vty, "%12.2f",
10203 ts.counts[i] ?
10204 (float)ts.counts[i] /
10205 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
10206 : 0);
10207 break;
10208 case BGP_STATS_TOTPLEN:
10209 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10210 vty_out (vty, "%12.2f",
10211 ts.counts[i] ?
10212 (float)ts.counts[i] /
10213 (float)ts.counts[BGP_STATS_PREFIXES]
10214 : 0);
10215 break;
10216 case BGP_STATS_SPACE:
10217 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10218 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
10219 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
10220 break;
10221 vty_out (vty, "%30s: ", "%% announced ");
10222 vty_out (vty, "%12.2f%s",
10223 100 * (float)ts.counts[BGP_STATS_SPACE] /
10224 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
10225 VTY_NEWLINE);
10226 vty_out (vty, "%30s: ", "/8 equivalent ");
10227 vty_out (vty, "%12.2f%s",
10228 (float)ts.counts[BGP_STATS_SPACE] /
10229 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
10230 VTY_NEWLINE);
10231 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
10232 break;
10233 vty_out (vty, "%30s: ", "/24 equivalent ");
10234 vty_out (vty, "%12.2f",
10235 (float)ts.counts[BGP_STATS_SPACE] /
10236 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
10237 break;
10238 default:
10239 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10240 vty_out (vty, "%12llu", ts.counts[i]);
10241 }
10242
10243 vty_out (vty, "%s", VTY_NEWLINE);
10244 }
10245 return CMD_SUCCESS;
10246 }
10247
10248 static int
10249 bgp_table_stats_vty (struct vty *vty, const char *name,
10250 const char *afi_str, const char *safi_str)
10251 {
10252 struct bgp *bgp;
10253 afi_t afi;
10254 safi_t safi;
10255
10256 if (name)
10257 bgp = bgp_lookup_by_name (name);
10258 else
10259 bgp = bgp_get_default ();
10260
10261 if (!bgp)
10262 {
10263 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
10264 return CMD_WARNING;
10265 }
10266 if (strncmp (afi_str, "ipv", 3) == 0)
10267 {
10268 if (strncmp (afi_str, "ipv4", 4) == 0)
10269 afi = AFI_IP;
10270 else if (strncmp (afi_str, "ipv6", 4) == 0)
10271 afi = AFI_IP6;
10272 else
10273 {
10274 vty_out (vty, "%% Invalid address family %s%s",
10275 afi_str, VTY_NEWLINE);
10276 return CMD_WARNING;
10277 }
10278 if (strncmp (safi_str, "m", 1) == 0)
10279 safi = SAFI_MULTICAST;
10280 else if (strncmp (safi_str, "u", 1) == 0)
10281 safi = SAFI_UNICAST;
10282 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
10283 safi = SAFI_MPLS_LABELED_VPN;
10284 else
10285 {
10286 vty_out (vty, "%% Invalid subsequent address family %s%s",
10287 safi_str, VTY_NEWLINE);
10288 return CMD_WARNING;
10289 }
10290 }
10291 else
10292 {
10293 vty_out (vty, "%% Invalid address family %s%s",
10294 afi_str, VTY_NEWLINE);
10295 return CMD_WARNING;
10296 }
10297
10298 return bgp_table_stats (vty, bgp, afi, safi);
10299 }
10300
10301 DEFUN (show_bgp_statistics,
10302 show_bgp_statistics_cmd,
10303 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
10304 SHOW_STR
10305 BGP_STR
10306 "Address family\n"
10307 "Address family\n"
10308 "Address Family modifier\n"
10309 "Address Family modifier\n"
10310 "BGP RIB advertisement statistics\n")
10311 {
10312 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
10313 }
10314
10315 ALIAS (show_bgp_statistics,
10316 show_bgp_statistics_vpnv4_cmd,
10317 "show bgp (ipv4) (vpnv4) statistics",
10318 SHOW_STR
10319 BGP_STR
10320 "Address family\n"
10321 "Address Family modifier\n"
10322 "BGP RIB advertisement statistics\n")
10323
10324 DEFUN (show_bgp_statistics_view,
10325 show_bgp_statistics_view_cmd,
10326 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
10327 SHOW_STR
10328 BGP_STR
10329 "BGP view\n"
10330 "Address family\n"
10331 "Address family\n"
10332 "Address Family modifier\n"
10333 "Address Family modifier\n"
10334 "BGP RIB advertisement statistics\n")
10335 {
10336 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
10337 }
10338
10339 ALIAS (show_bgp_statistics_view,
10340 show_bgp_statistics_view_vpnv4_cmd,
10341 "show bgp view WORD (ipv4) (vpnv4) statistics",
10342 SHOW_STR
10343 BGP_STR
10344 "BGP view\n"
10345 "Address family\n"
10346 "Address Family modifier\n"
10347 "BGP RIB advertisement statistics\n")
10348
10349 enum bgp_pcounts
10350 {
10351 PCOUNT_ADJ_IN = 0,
10352 PCOUNT_DAMPED,
10353 PCOUNT_REMOVED,
10354 PCOUNT_HISTORY,
10355 PCOUNT_STALE,
10356 PCOUNT_VALID,
10357 PCOUNT_ALL,
10358 PCOUNT_COUNTED,
10359 PCOUNT_PFCNT, /* the figure we display to users */
10360 PCOUNT_MAX,
10361 };
10362
10363 static const char *pcount_strs[] =
10364 {
10365 [PCOUNT_ADJ_IN] = "Adj-in",
10366 [PCOUNT_DAMPED] = "Damped",
10367 [PCOUNT_REMOVED] = "Removed",
10368 [PCOUNT_HISTORY] = "History",
10369 [PCOUNT_STALE] = "Stale",
10370 [PCOUNT_VALID] = "Valid",
10371 [PCOUNT_ALL] = "All RIB",
10372 [PCOUNT_COUNTED] = "PfxCt counted",
10373 [PCOUNT_PFCNT] = "Useable",
10374 [PCOUNT_MAX] = NULL,
10375 };
10376
10377 struct peer_pcounts
10378 {
10379 unsigned int count[PCOUNT_MAX];
10380 const struct peer *peer;
10381 const struct bgp_table *table;
10382 };
10383
10384 static int
10385 bgp_peer_count_walker (struct thread *t)
10386 {
10387 struct bgp_node *rn;
10388 struct peer_pcounts *pc = THREAD_ARG (t);
10389 const struct peer *peer = pc->peer;
10390
10391 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
10392 {
10393 struct bgp_adj_in *ain;
10394 struct bgp_info *ri;
10395
10396 for (ain = rn->adj_in; ain; ain = ain->next)
10397 if (ain->peer == peer)
10398 pc->count[PCOUNT_ADJ_IN]++;
10399
10400 for (ri = rn->info; ri; ri = ri->next)
10401 {
10402 char buf[SU_ADDRSTRLEN];
10403
10404 if (ri->peer != peer)
10405 continue;
10406
10407 pc->count[PCOUNT_ALL]++;
10408
10409 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
10410 pc->count[PCOUNT_DAMPED]++;
10411 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
10412 pc->count[PCOUNT_HISTORY]++;
10413 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
10414 pc->count[PCOUNT_REMOVED]++;
10415 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
10416 pc->count[PCOUNT_STALE]++;
10417 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
10418 pc->count[PCOUNT_VALID]++;
10419 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
10420 pc->count[PCOUNT_PFCNT]++;
10421
10422 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
10423 {
10424 pc->count[PCOUNT_COUNTED]++;
10425 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
10426 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
10427 peer->host,
10428 inet_ntop(rn->p.family, &rn->p.u.prefix,
10429 buf, SU_ADDRSTRLEN),
10430 rn->p.prefixlen,
10431 ri->flags);
10432 }
10433 else
10434 {
10435 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
10436 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
10437 peer->host,
10438 inet_ntop(rn->p.family, &rn->p.u.prefix,
10439 buf, SU_ADDRSTRLEN),
10440 rn->p.prefixlen,
10441 ri->flags);
10442 }
10443 }
10444 }
10445 return 0;
10446 }
10447
10448 static int
10449 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
10450 {
10451 struct peer_pcounts pcounts = { .peer = peer };
10452 unsigned int i;
10453
10454 if (!peer || !peer->bgp || !peer->afc[afi][safi]
10455 || !peer->bgp->rib[afi][safi])
10456 {
10457 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10458 return CMD_WARNING;
10459 }
10460
10461 memset (&pcounts, 0, sizeof(pcounts));
10462 pcounts.peer = peer;
10463 pcounts.table = peer->bgp->rib[afi][safi];
10464
10465 /* in-place call via thread subsystem so as to record execution time
10466 * stats for the thread-walk (i.e. ensure this can't be blamed on
10467 * on just vty_read()).
10468 */
10469 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
10470
10471 vty_out (vty, "Prefix counts for %s, %s%s",
10472 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
10473 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
10474 vty_out (vty, "%sCounts from RIB table walk:%s%s",
10475 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
10476
10477 for (i = 0; i < PCOUNT_MAX; i++)
10478 vty_out (vty, "%20s: %-10d%s",
10479 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
10480
10481 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
10482 {
10483 vty_out (vty, "%s [pcount] PfxCt drift!%s",
10484 peer->host, VTY_NEWLINE);
10485 vty_out (vty, "Please report this bug, with the above command output%s",
10486 VTY_NEWLINE);
10487 }
10488
10489 return CMD_SUCCESS;
10490 }
10491
10492 DEFUN (show_ip_bgp_neighbor_prefix_counts,
10493 show_ip_bgp_neighbor_prefix_counts_cmd,
10494 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
10495 SHOW_STR
10496 IP_STR
10497 BGP_STR
10498 "Detailed information on TCP and BGP neighbor connections\n"
10499 "Neighbor to display information about\n"
10500 "Neighbor to display information about\n"
10501 "Neighbor on bgp configured interface\n"
10502 "Display detailed prefix count information\n")
10503 {
10504 struct peer *peer;
10505
10506 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10507 if (! peer)
10508 return CMD_WARNING;
10509
10510 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10511 }
10512
10513 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
10514 show_bgp_ipv6_neighbor_prefix_counts_cmd,
10515 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
10516 SHOW_STR
10517 BGP_STR
10518 "Address family\n"
10519 "Detailed information on TCP and BGP neighbor connections\n"
10520 "Neighbor to display information about\n"
10521 "Neighbor to display information about\n"
10522 "Neighbor on bgp configured interface\n"
10523 "Display detailed prefix count information\n")
10524 {
10525 struct peer *peer;
10526
10527 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10528 if (! peer)
10529 return CMD_WARNING;
10530
10531 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
10532 }
10533
10534 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
10535 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
10536 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
10537 SHOW_STR
10538 IP_STR
10539 BGP_STR
10540 "Address family\n"
10541 "Address Family modifier\n"
10542 "Address Family modifier\n"
10543 "Detailed information on TCP and BGP neighbor connections\n"
10544 "Neighbor to display information about\n"
10545 "Neighbor to display information about\n"
10546 "Neighbor on bgp configured interface\n"
10547 "Display detailed prefix count information\n")
10548 {
10549 struct peer *peer;
10550
10551 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10552 if (! peer)
10553 return CMD_WARNING;
10554
10555 if (strncmp (argv[0], "m", 1) == 0)
10556 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
10557
10558 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10559 }
10560
10561 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
10562 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
10563 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
10564 SHOW_STR
10565 IP_STR
10566 BGP_STR
10567 "Address family\n"
10568 "Address Family modifier\n"
10569 "Address Family modifier\n"
10570 "Detailed information on TCP and BGP neighbor connections\n"
10571 "Neighbor to display information about\n"
10572 "Neighbor to display information about\n"
10573 "Neighbor on bgp configured interface\n"
10574 "Display detailed prefix count information\n")
10575 {
10576 struct peer *peer;
10577
10578 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10579 if (! peer)
10580 return CMD_WARNING;
10581
10582 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
10583 }
10584
10585 static void
10586 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10587 int in, char *delim, char *rmap_name)
10588 {
10589 struct bgp_table *table;
10590 struct bgp_adj_in *ain;
10591 struct bgp_adj_out *adj;
10592 unsigned long output_count;
10593 unsigned long filtered_count;
10594 struct bgp_node *rn;
10595 int header1 = 1;
10596 struct bgp *bgp;
10597 int header2 = 1;
10598 struct attr attr;
10599 struct attr_extra extra;
10600 int ret;
10601
10602 bgp = peer->bgp;
10603
10604 if (! bgp)
10605 return;
10606
10607 if (delim)
10608 header1 = 0;
10609
10610 table = bgp->rib[afi][safi];
10611
10612 output_count = filtered_count = 0;
10613
10614 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
10615 PEER_STATUS_DEFAULT_ORIGINATE))
10616 {
10617 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
10618 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10619 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10620
10621 vty_out (vty, "Originating default network 0.0.0.0%s%s",
10622 VTY_NEWLINE, VTY_NEWLINE);
10623 header1 = 0;
10624 }
10625
10626 attr.extra = &extra;
10627 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10628 if (in)
10629 {
10630 for (ain = rn->adj_in; ain; ain = ain->next)
10631 if (ain->peer == peer)
10632 {
10633 if (header1)
10634 {
10635 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
10636 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10637 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10638 header1 = 0;
10639 }
10640 if (header2)
10641 {
10642 if (delim)
10643 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
10644 else
10645 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10646 header2 = 0;
10647 }
10648 if (ain->attr)
10649 {
10650 bgp_attr_dup(&attr, ain->attr);
10651 if (bgp_input_modifier(peer, &rn->p, &attr, afi,
10652 safi, rmap_name) != RMAP_DENY)
10653 {
10654 route_vty_out_tmp (vty, &rn->p, &attr, safi, delim);
10655 output_count++;
10656 }
10657 else
10658 filtered_count++;
10659 }
10660 }
10661 }
10662 else
10663 {
10664 for (adj = rn->adj_out; adj; adj = adj->next)
10665 if (adj->peer == peer)
10666 {
10667 if (header1)
10668 {
10669 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
10670 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10671 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10672 header1 = 0;
10673 }
10674 if (header2)
10675 {
10676 if (delim)
10677 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
10678 else
10679 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10680 header2 = 0;
10681 }
10682 if (adj->attr)
10683 {
10684 if (!CHECK_FLAG(peer->af_flags[afi][safi],
10685 PEER_FLAG_REFLECTOR_CLIENT)
10686 || bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
10687 {
10688
10689 bgp_attr_dup(&attr, adj->attr);
10690 ret = bgp_output_modifier(peer, &rn->p, &attr, afi,
10691 safi, rmap_name);
10692 }
10693 else
10694 ret = RMAP_PERMIT;
10695
10696 if (ret != RMAP_DENY)
10697 {
10698 route_vty_out_tmp (vty, &rn->p, &attr, safi, delim);
10699 output_count++;
10700 }
10701 else
10702 filtered_count++;
10703 }
10704 }
10705 }
10706
10707 if (output_count != 0)
10708 vty_out (vty, "%sTotal number of prefixes %ld%s",
10709 VTY_NEWLINE, output_count, VTY_NEWLINE);
10710 }
10711
10712 static int
10713 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10714 int in, char *delim, char *rmap_name)
10715 {
10716 if (! peer || ! peer->afc[afi][safi])
10717 {
10718 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10719 return CMD_WARNING;
10720 }
10721
10722 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10723 {
10724 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10725 VTY_NEWLINE);
10726 return CMD_WARNING;
10727 }
10728
10729 if (!in && (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)
10730 && !bgp_flag_check(peer->bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)))
10731 {
10732 vty_out (vty, "%% Cannot apply outgoing route-map on route-reflector clients%s",
10733 VTY_NEWLINE);
10734 vty_out (vty, "%% Enable bgp route-reflector allow-outbound-policy flag%s",
10735 VTY_NEWLINE);
10736 return CMD_WARNING;
10737 }
10738
10739 show_adj_route (vty, peer, afi, safi, in, delim, rmap_name);
10740
10741 return CMD_SUCCESS;
10742 }
10743
10744 DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10745 show_ip_bgp_view_neighbor_advertised_route_cmd,
10746 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10747 SHOW_STR
10748 IP_STR
10749 BGP_STR
10750 "BGP view\n"
10751 "View name\n"
10752 "Detailed information on TCP and BGP neighbor connections\n"
10753 "Neighbor to display information about\n"
10754 "Neighbor to display information about\n"
10755 "Display the routes advertised to a BGP neighbor\n")
10756 {
10757 struct peer *peer;
10758
10759 if (argc == 2)
10760 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10761 else
10762 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10763
10764 if (! peer)
10765 return CMD_WARNING;
10766
10767 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, NULL);
10768 }
10769
10770 DEFUN (show_ip_bgp_neighbor_advertised_route,
10771 show_ip_bgp_neighbor_advertised_route_cmd,
10772 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10773 SHOW_STR
10774 IP_STR
10775 BGP_STR
10776 "Detailed information on TCP and BGP neighbor connections\n"
10777 "Neighbor to display information about\n"
10778 "Neighbor to display information about\n"
10779 "Neighbor on bgp configured interface\n"
10780 "Display the routes advertised to a BGP neighbor\n")
10781
10782 {
10783 struct peer *peer;
10784 char *rmap_name = NULL;
10785
10786 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10787
10788 if (! peer)
10789 return CMD_WARNING;
10790
10791 if (argc == 2)
10792 rmap_name = argv[1];
10793
10794 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, rmap_name);
10795 }
10796
10797 ALIAS (show_ip_bgp_neighbor_advertised_route,
10798 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
10799 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
10800 SHOW_STR
10801 IP_STR
10802 BGP_STR
10803 "Detailed information on TCP and BGP neighbor connections\n"
10804 "Neighbor to display information about\n"
10805 "Neighbor to display information about\n"
10806 "Neighbor on bgp configured interface\n"
10807 "Display the routes advertised to a BGP neighbor\n")
10808
10809 DEFUN (show_ip_bgp_neighbor_advertised_route_csv,
10810 show_ip_bgp_neighbor_advertised_route_csv_cmd,
10811 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
10812 SHOW_STR
10813 IP_STR
10814 BGP_STR
10815 "BGP view\n"
10816 "View name\n"
10817 "Detailed information on TCP and BGP neighbor connections\n"
10818 "Neighbor to display information about\n"
10819 "Neighbor to display information about\n"
10820 "Neighbor on bgp configured interface\n"
10821 "Display the routes advertised to a BGP neighbor\n")
10822 {
10823 struct peer *peer;
10824 char *rmap_name = NULL;
10825
10826 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10827
10828 if (! peer)
10829 return CMD_WARNING;
10830
10831 if (argc == 2)
10832 rmap_name = argv[1];
10833
10834 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, &csv, rmap_name);
10835 }
10836
10837 ALIAS (show_ip_bgp_neighbor_advertised_route_csv,
10838 show_ip_bgp_neighbor_advertised_route_csv_rmap_cmd,
10839 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv route-map WORD",
10840 SHOW_STR
10841 IP_STR
10842 BGP_STR
10843 "BGP view\n"
10844 "View name\n"
10845 "Detailed information on TCP and BGP neighbor connections\n"
10846 "Neighbor to display information about\n"
10847 "Neighbor to display information about\n"
10848 "Neighbor on bgp configured interface\n"
10849 "Display the routes advertised to a BGP neighbor\n"
10850 "Apply this route-map to display what would've been advertised\n")
10851
10852 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10853 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10854 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10855 SHOW_STR
10856 IP_STR
10857 BGP_STR
10858 "Address family\n"
10859 "Address Family modifier\n"
10860 "Address Family modifier\n"
10861 "Detailed information on TCP and BGP neighbor connections\n"
10862 "Neighbor to display information about\n"
10863 "Neighbor to display information about\n"
10864 "Neighbor on bgp configured interface\n"
10865 "Display the routes advertised to a BGP neighbor\n")
10866 {
10867 struct peer *peer;
10868 char *rmap_name = NULL;
10869
10870 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10871 if (! peer)
10872 return CMD_WARNING;
10873
10874 if (argc == 3)
10875 rmap_name = argv[2];
10876
10877 if (strncmp (argv[0], "m", 1) == 0)
10878 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, NULL, rmap_name);
10879
10880 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, rmap_name);
10881 }
10882
10883 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
10884 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
10885 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
10886 SHOW_STR
10887 IP_STR
10888 BGP_STR
10889 "Address family\n"
10890 "Address Family modifier\n"
10891 "Address Family modifier\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 "Neighbor on bgp configured interface\n"
10896 "Display the routes advertised to a BGP neighbor\n"
10897 "Route-map to control what is displayed\n")
10898
10899 #ifdef HAVE_IPV6
10900 DEFUN (show_bgp_view_neighbor_advertised_route,
10901 show_bgp_view_neighbor_advertised_route_cmd,
10902 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10903 SHOW_STR
10904 BGP_STR
10905 "BGP view\n"
10906 "View name\n"
10907 "Detailed information on TCP and BGP neighbor connections\n"
10908 "Neighbor to display information about\n"
10909 "Neighbor to display information about\n"
10910 "Neighbor on bgp configured interface\n"
10911 "Display the routes advertised to a BGP neighbor\n")
10912 {
10913 struct peer *peer;
10914
10915 if (argc == 2)
10916 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10917 else
10918 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10919
10920 if (! peer)
10921 return CMD_WARNING;
10922
10923 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, NULL);
10924 }
10925
10926 ALIAS (show_bgp_view_neighbor_advertised_route,
10927 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10928 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10929 SHOW_STR
10930 BGP_STR
10931 "BGP view\n"
10932 "View name\n"
10933 "Address family\n"
10934 "Detailed information on TCP and BGP neighbor connections\n"
10935 "Neighbor to display information about\n"
10936 "Neighbor to display information about\n"
10937 "Neighbor on bgp configured interface\n"
10938 "Display the routes advertised to a BGP neighbor\n")
10939
10940 DEFUN (show_bgp_view_neighbor_advertised_route_csv,
10941 show_bgp_view_neighbor_advertised_route_csv_cmd,
10942 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
10943 SHOW_STR
10944 BGP_STR
10945 "BGP view\n"
10946 "View name\n"
10947 "Detailed information on TCP and BGP neighbor connections\n"
10948 "Neighbor to display information about\n"
10949 "Neighbor to display information about\n"
10950 "Neighbor on bgp configured interface\n"
10951 "Display the routes advertised to a BGP neighbor\n")
10952 {
10953 struct peer *peer;
10954
10955 if (argc == 2)
10956 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10957 else
10958 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10959
10960 if (! peer)
10961 return CMD_WARNING;
10962
10963 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, &csv, NULL);
10964 }
10965
10966 ALIAS (show_bgp_view_neighbor_advertised_route_csv,
10967 show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd,
10968 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
10969 SHOW_STR
10970 BGP_STR
10971 "BGP view\n"
10972 "View name\n"
10973 "Address family\n"
10974 "Detailed information on TCP and BGP neighbor connections\n"
10975 "Neighbor to display information about\n"
10976 "Neighbor to display information about\n"
10977 "Neighbor on bgp configured interface\n"
10978 "Display the routes advertised to a BGP neighbor\n")
10979
10980 DEFUN (show_bgp_neighbor_advertised_route,
10981 show_bgp_neighbor_advertised_route_cmd,
10982 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10983 SHOW_STR
10984 BGP_STR
10985 "Detailed information on TCP and BGP neighbor connections\n"
10986 "Neighbor to display information about\n"
10987 "Neighbor to display information about\n"
10988 "Neighbor on bgp configured interface\n"
10989 "Display the routes advertised to a BGP neighbor\n")
10990
10991 {
10992 struct peer *peer;
10993 char *rmap_name = NULL;
10994
10995 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10996
10997 if (! peer)
10998 return CMD_WARNING;
10999
11000 if (argc == 2)
11001 rmap_name = argv[1];
11002
11003 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, rmap_name);
11004 }
11005
11006 ALIAS (show_bgp_neighbor_advertised_route,
11007 show_bgp_neighbor_advertised_route_rmap_cmd,
11008 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
11009 SHOW_STR
11010 BGP_STR
11011 "Detailed information on TCP and BGP neighbor connections\n"
11012 "Neighbor to display information about\n"
11013 "Neighbor to display information about\n"
11014 "Neighbor on bgp configured interface\n"
11015 "Display the routes advertised to a BGP neighbor\n")
11016
11017 ALIAS (show_bgp_neighbor_advertised_route,
11018 show_bgp_ipv6_neighbor_advertised_route_cmd,
11019 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
11020 SHOW_STR
11021 BGP_STR
11022 "Address family\n"
11023 "Detailed information on TCP and BGP neighbor connections\n"
11024 "Neighbor to display information about\n"
11025 "Neighbor to display information about\n"
11026 "Neighbor on bgp configured interface\n"
11027 "Display the routes advertised to a BGP neighbor\n")
11028
11029 ALIAS (show_bgp_neighbor_advertised_route,
11030 show_bgp_ipv6_neighbor_advertised_route_rmap_cmd,
11031 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
11032 SHOW_STR
11033 BGP_STR
11034 "Address family\n"
11035 "Detailed information on TCP and BGP neighbor connections\n"
11036 "Neighbor to display information about\n"
11037 "Neighbor to display information about\n"
11038 "Neighbor on bgp configured interface\n"
11039 "Display the routes advertised to a BGP neighbor\n")
11040
11041 DEFUN (show_bgp_neighbor_advertised_route_csv,
11042 show_bgp_neighbor_advertised_route_csv_cmd,
11043 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
11044 SHOW_STR
11045 BGP_STR
11046 "Detailed information on TCP and BGP neighbor connections\n"
11047 "Neighbor to display information about\n"
11048 "Neighbor to display information about\n"
11049 "Neighbor on bgp configured interface\n"
11050 "Display the routes advertised to a BGP neighbor\n")
11051 {
11052 struct peer *peer;
11053 char *rmap_name = NULL;
11054
11055 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11056
11057 if (! peer)
11058 return CMD_WARNING;
11059
11060 if (argc == 2)
11061 rmap_name = argv[1];
11062
11063 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, &csv, rmap_name);
11064 }
11065
11066 ALIAS (show_bgp_neighbor_advertised_route_csv,
11067 show_bgp_neighbor_advertised_route_csv_rmap_cmd,
11068 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv route-map WORD",
11069 SHOW_STR
11070 BGP_STR
11071 "Detailed information on TCP and BGP neighbor connections\n"
11072 "Neighbor to display information about\n"
11073 "Neighbor to display information about\n"
11074 "Neighbor on bgp configured interface\n"
11075 "Display the routes advertised to a BGP neighbor\n")
11076
11077 ALIAS (show_bgp_neighbor_advertised_route_csv,
11078 show_bgp_ipv6_neighbor_advertised_route_csv_cmd,
11079 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
11080 SHOW_STR
11081 BGP_STR
11082 "Address family\n"
11083 "Detailed information on TCP and BGP neighbor connections\n"
11084 "Neighbor to display information about\n"
11085 "Neighbor to display information about\n"
11086 "Neighbor on bgp configured interface\n"
11087 "Display the routes advertised to a BGP neighbor\n")
11088
11089 ALIAS (show_bgp_neighbor_advertised_route_csv,
11090 show_bgp_ipv6_neighbor_advertised_route_csv_rmap_cmd,
11091 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv route-map WORD",
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 "Neighbor on bgp configured interface\n"
11099 "Display the routes advertised to a BGP neighbor\n")
11100
11101 /* old command */
11102 ALIAS (show_bgp_neighbor_advertised_route,
11103 ipv6_bgp_neighbor_advertised_route_cmd,
11104 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
11105 SHOW_STR
11106 IPV6_STR
11107 BGP_STR
11108 "Detailed information on TCP and BGP neighbor connections\n"
11109 "Neighbor to display information about\n"
11110 "Neighbor to display information about\n"
11111 "Neighbor on bgp configured interface\n"
11112 "Display the routes advertised to a BGP neighbor\n")
11113
11114 /* old command */
11115 DEFUN (ipv6_mbgp_neighbor_advertised_route,
11116 ipv6_mbgp_neighbor_advertised_route_cmd,
11117 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
11118 SHOW_STR
11119 IPV6_STR
11120 MBGP_STR
11121 "Detailed information on TCP and BGP neighbor connections\n"
11122 "Neighbor to display information about\n"
11123 "Neighbor to display information about\n"
11124 "Neighbor on bgp configured interface\n"
11125 "Neighbor on bgp configured interface\n"
11126 "Display the routes advertised to a BGP neighbor\n")
11127 {
11128 struct peer *peer;
11129
11130 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11131 if (! peer)
11132 return CMD_WARNING;
11133
11134 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, NULL);
11135 }
11136 #endif /* HAVE_IPV6 */
11137
11138 DEFUN (show_bgp_view_neighbor_received_routes,
11139 show_bgp_view_neighbor_received_routes_cmd,
11140 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11141 SHOW_STR
11142 BGP_STR
11143 "BGP view\n"
11144 "View name\n"
11145 "Detailed information on TCP and BGP neighbor connections\n"
11146 "Neighbor to display information about\n"
11147 "Neighbor to display information about\n"
11148 "Neighbor on bgp configured interface\n"
11149 "Display the received routes from neighbor\n")
11150 {
11151 struct peer *peer;
11152
11153 if (argc == 2)
11154 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11155 else
11156 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11157
11158 if (! peer)
11159 return CMD_WARNING;
11160
11161 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, NULL);
11162 }
11163
11164 DEFUN (show_ip_bgp_view_neighbor_received_routes,
11165 show_ip_bgp_view_neighbor_received_routes_cmd,
11166 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11167 SHOW_STR
11168 IP_STR
11169 BGP_STR
11170 "BGP view\n"
11171 "View name\n"
11172 "Detailed information on TCP and BGP neighbor connections\n"
11173 "Neighbor to display information about\n"
11174 "Neighbor to display information about\n"
11175 "Neighbor on bgp configured interface\n"
11176 "Display the received routes from neighbor\n")
11177 {
11178 struct peer *peer;
11179
11180 if (argc == 2)
11181 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11182 else
11183 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11184
11185 if (! peer)
11186 return CMD_WARNING;
11187
11188 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, NULL);
11189 }
11190
11191 ALIAS (show_bgp_view_neighbor_received_routes,
11192 show_bgp_view_ipv6_neighbor_received_routes_cmd,
11193 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11194 SHOW_STR
11195 BGP_STR
11196 "BGP view\n"
11197 "View name\n"
11198 "Address family\n"
11199 "Detailed information on TCP and BGP neighbor connections\n"
11200 "Neighbor to display information about\n"
11201 "Neighbor to display information about\n"
11202 "Neighbor on bgp configured interface\n"
11203 "Display the received routes from neighbor\n")
11204
11205 DEFUN (show_ip_bgp_neighbor_received_routes,
11206 show_ip_bgp_neighbor_received_routes_cmd,
11207 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11208 SHOW_STR
11209 IP_STR
11210 BGP_STR
11211 "Detailed information on TCP and BGP neighbor connections\n"
11212 "Neighbor to display information about\n"
11213 "Neighbor to display information about\n"
11214 "Neighbor on bgp configured interface\n"
11215 "Display the received routes from neighbor\n")
11216
11217 {
11218 struct peer *peer;
11219 char *rmap_name = NULL;
11220
11221 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11222
11223 if (! peer)
11224 return CMD_WARNING;
11225
11226 if (argc == 2)
11227 rmap_name = argv[1];
11228
11229 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, rmap_name);
11230 }
11231
11232 ALIAS (show_ip_bgp_neighbor_received_routes,
11233 show_ip_bgp_neighbor_received_routes_rmap_cmd,
11234 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11235 SHOW_STR
11236 IP_STR
11237 BGP_STR
11238 "Detailed information on TCP and BGP neighbor connections\n"
11239 "Neighbor to display information about\n"
11240 "Neighbor to display information about\n"
11241 "Neighbor on bgp configured interface\n"
11242 "Display the received routes from neighbor\n")
11243
11244 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
11245 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
11246 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11247 SHOW_STR
11248 IP_STR
11249 BGP_STR
11250 "Address family\n"
11251 "Address Family modifier\n"
11252 "Address Family modifier\n"
11253 "Detailed information on TCP and BGP neighbor connections\n"
11254 "Neighbor to display information about\n"
11255 "Neighbor to display information about\n"
11256 "Neighbor on bgp configured interface\n"
11257 "Display the received routes from neighbor\n")
11258 {
11259 struct peer *peer;
11260 char *rmap_name = NULL;
11261
11262 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11263 if (! peer)
11264 return CMD_WARNING;
11265
11266 if (argc == 3)
11267 rmap_name = argv[2];
11268
11269 if (strncmp (argv[0], "m", 1) == 0)
11270 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, NULL, rmap_name);
11271
11272 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, rmap_name);
11273 }
11274
11275 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
11276 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
11277 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11278 SHOW_STR
11279 IP_STR
11280 BGP_STR
11281 "Address family\n"
11282 "Address Family modifier\n"
11283 "Address Family modifier\n"
11284 "Detailed information on TCP and BGP neighbor connections\n"
11285 "Neighbor to display information about\n"
11286 "Neighbor to display information about\n"
11287 "Neighbor on bgp configured interface\n"
11288 "Display the received routes from neighbor\n")
11289
11290 DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
11291 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
11292 #ifdef HAVE_IPV6
11293 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
11294 #else
11295 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
11296 #endif
11297 SHOW_STR
11298 BGP_STR
11299 "BGP view\n"
11300 "View name\n"
11301 "Address family\n"
11302 #ifdef HAVE_IPV6
11303 "Address family\n"
11304 #endif
11305 "Address family modifier\n"
11306 "Address family modifier\n"
11307 "Detailed information on TCP and BGP neighbor connections\n"
11308 "Neighbor to display information about\n"
11309 "Neighbor to display information about\n"
11310 "Neighbor on bgp configured interface\n"
11311 "Display the advertised routes to neighbor\n"
11312 "Display the received routes from neighbor\n")
11313 {
11314 int afi;
11315 int safi;
11316 int in;
11317 struct peer *peer;
11318
11319 #ifdef HAVE_IPV6
11320 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
11321 #else
11322 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11323 #endif
11324
11325 if (! peer)
11326 return CMD_WARNING;
11327
11328 #ifdef HAVE_IPV6
11329 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
11330 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11331 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
11332 #else
11333 afi = AFI_IP;
11334 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11335 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
11336 #endif
11337
11338 return peer_adj_routes (vty, peer, afi, safi, in, NULL, NULL);
11339 }
11340
11341 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
11342 show_ip_bgp_neighbor_received_prefix_filter_cmd,
11343 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11344 SHOW_STR
11345 IP_STR
11346 BGP_STR
11347 "Detailed information on TCP and BGP neighbor connections\n"
11348 "Neighbor to display information about\n"
11349 "Neighbor to display information about\n"
11350 "Neighbor on bgp configured interface\n"
11351 "Display information received from a BGP neighbor\n"
11352 "Display the prefixlist filter\n")
11353 {
11354 char name[BUFSIZ];
11355 union sockunion su;
11356 struct peer *peer;
11357 int count, ret;
11358
11359 ret = str2sockunion (argv[0], &su);
11360 if (ret < 0)
11361 {
11362 peer = peer_lookup_by_conf_if (NULL, argv[0]);
11363 if (!peer)
11364 {
11365 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
11366 return CMD_WARNING;
11367 }
11368 }
11369 else
11370 {
11371 peer = peer_lookup (NULL, &su);
11372 if (! peer)
11373 return CMD_WARNING;
11374 }
11375
11376 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
11377 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
11378 if (count)
11379 {
11380 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
11381 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
11382 }
11383
11384 return CMD_SUCCESS;
11385 }
11386
11387 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
11388 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
11389 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11390 SHOW_STR
11391 IP_STR
11392 BGP_STR
11393 "Address family\n"
11394 "Address Family modifier\n"
11395 "Address Family modifier\n"
11396 "Detailed information on TCP and BGP neighbor connections\n"
11397 "Neighbor to display information about\n"
11398 "Neighbor to display information about\n"
11399 "Neighbor on bgp configured interface\n"
11400 "Display information received from a BGP neighbor\n"
11401 "Display the prefixlist filter\n")
11402 {
11403 char name[BUFSIZ];
11404 union sockunion su;
11405 struct peer *peer;
11406 int count, ret;
11407
11408 ret = str2sockunion (argv[1], &su);
11409 if (ret < 0)
11410 {
11411 peer = peer_lookup_by_conf_if (NULL, argv[1]);
11412 if (!peer)
11413 {
11414 vty_out (vty, "Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
11415 return CMD_WARNING;
11416 }
11417 }
11418 else
11419 {
11420 peer = peer_lookup (NULL, &su);
11421 if (! peer)
11422 return CMD_WARNING;
11423 }
11424
11425 if (strncmp (argv[0], "m", 1) == 0)
11426 {
11427 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
11428 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
11429 if (count)
11430 {
11431 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
11432 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
11433 }
11434 }
11435 else
11436 {
11437 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
11438 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
11439 if (count)
11440 {
11441 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
11442 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
11443 }
11444 }
11445
11446 return CMD_SUCCESS;
11447 }
11448
11449
11450 #ifdef HAVE_IPV6
11451 ALIAS (show_bgp_view_neighbor_received_routes,
11452 show_bgp_neighbor_received_routes_cmd,
11453 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11454 SHOW_STR
11455 BGP_STR
11456 "Detailed information on TCP and BGP neighbor connections\n"
11457 "Neighbor to display information about\n"
11458 "Neighbor to display information about\n"
11459 "Neighbor on bgp configured interface\n"
11460 "Display the received routes from neighbor\n")
11461
11462 ALIAS (show_bgp_view_neighbor_received_routes,
11463 show_bgp_ipv6_neighbor_received_routes_cmd,
11464 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11465 SHOW_STR
11466 BGP_STR
11467 "Address family\n"
11468 "Detailed information on TCP and BGP neighbor connections\n"
11469 "Neighbor to display information about\n"
11470 "Neighbor to display information about\n"
11471 "Neighbor on bgp configured interface\n"
11472 "Display the received routes from neighbor\n")
11473
11474 ALIAS (show_bgp_view_neighbor_received_routes,
11475 show_bgp_neighbor_received_routes_rmap_cmd,
11476 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11477 SHOW_STR
11478 BGP_STR
11479 "Detailed information on TCP and BGP neighbor connections\n"
11480 "Neighbor to display information about\n"
11481 "Neighbor to display information about\n"
11482 "Neighbor on bgp configured interface\n"
11483 "Display the received routes from neighbor\n")
11484
11485 ALIAS (show_bgp_view_neighbor_received_routes,
11486 show_bgp_ipv6_neighbor_received_routes_rmap_cmd,
11487 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11488 SHOW_STR
11489 BGP_STR
11490 "Address family\n"
11491 "Detailed information on TCP and BGP neighbor connections\n"
11492 "Neighbor to display information about\n"
11493 "Neighbor to display information about\n"
11494 "Neighbor on bgp configured interface\n"
11495 "Display the received routes from neighbor\n")
11496
11497 DEFUN (show_bgp_neighbor_received_prefix_filter,
11498 show_bgp_neighbor_received_prefix_filter_cmd,
11499 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11500 SHOW_STR
11501 BGP_STR
11502 "Detailed information on TCP and BGP neighbor connections\n"
11503 "Neighbor to display information about\n"
11504 "Neighbor to display information about\n"
11505 "Neighbor on bgp configured interface\n"
11506 "Display information received from a BGP neighbor\n"
11507 "Display the prefixlist filter\n")
11508 {
11509 char name[BUFSIZ];
11510 union sockunion su;
11511 struct peer *peer;
11512 int count, ret;
11513
11514 ret = str2sockunion (argv[0], &su);
11515 if (ret < 0)
11516 {
11517 peer = peer_lookup_by_conf_if (NULL, argv[0]);
11518 if (!peer)
11519 {
11520 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
11521 return CMD_WARNING;
11522 }
11523 }
11524 else
11525 {
11526 peer = peer_lookup (NULL, &su);
11527 if (! peer)
11528 return CMD_WARNING;
11529 }
11530
11531 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
11532 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
11533 if (count)
11534 {
11535 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
11536 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
11537 }
11538
11539 return CMD_SUCCESS;
11540 }
11541
11542 ALIAS (show_bgp_neighbor_received_prefix_filter,
11543 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
11544 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11545 SHOW_STR
11546 BGP_STR
11547 "Address family\n"
11548 "Detailed information on TCP and BGP neighbor connections\n"
11549 "Neighbor to display information about\n"
11550 "Neighbor to display information about\n"
11551 "Neighbor on bgp configured interface\n"
11552 "Display information received from a BGP neighbor\n"
11553 "Display the prefixlist filter\n")
11554
11555 /* old command */
11556 ALIAS (show_bgp_view_neighbor_received_routes,
11557 ipv6_bgp_neighbor_received_routes_cmd,
11558 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11559 SHOW_STR
11560 IPV6_STR
11561 BGP_STR
11562 "Detailed information on TCP and BGP neighbor connections\n"
11563 "Neighbor to display information about\n"
11564 "Neighbor to display information about\n"
11565 "Neighbor on bgp configured interface\n"
11566 "Display the received routes from neighbor\n")
11567
11568 /* old command */
11569 DEFUN (ipv6_mbgp_neighbor_received_routes,
11570 ipv6_mbgp_neighbor_received_routes_cmd,
11571 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11572 SHOW_STR
11573 IPV6_STR
11574 MBGP_STR
11575 "Detailed information on TCP and BGP neighbor connections\n"
11576 "Neighbor to display information about\n"
11577 "Neighbor to display information about\n"
11578 "Neighbor on bgp configured interface\n"
11579 "Display the received routes from neighbor\n")
11580 {
11581 struct peer *peer;
11582
11583 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11584 if (! peer)
11585 return CMD_WARNING;
11586
11587 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, NULL);
11588 }
11589
11590 DEFUN (show_bgp_view_neighbor_received_prefix_filter,
11591 show_bgp_view_neighbor_received_prefix_filter_cmd,
11592 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11593 SHOW_STR
11594 BGP_STR
11595 "BGP view\n"
11596 "View name\n"
11597 "Detailed information on TCP and BGP neighbor connections\n"
11598 "Neighbor to display information about\n"
11599 "Neighbor to display information about\n"
11600 "Neighbor on bgp configured interface\n"
11601 "Display information received from a BGP neighbor\n"
11602 "Display the prefixlist filter\n")
11603 {
11604 char name[BUFSIZ];
11605 union sockunion su;
11606 struct peer *peer;
11607 struct bgp *bgp;
11608 int count, ret;
11609
11610 /* BGP structure lookup. */
11611 bgp = bgp_lookup_by_name (argv[0]);
11612 if (bgp == NULL)
11613 {
11614 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11615 return CMD_WARNING;
11616 }
11617
11618 ret = str2sockunion (argv[1], &su);
11619 if (ret < 0)
11620 {
11621 peer = peer_lookup_by_conf_if (bgp, argv[1]);
11622 if (!peer)
11623 {
11624 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
11625 return CMD_WARNING;
11626 }
11627 }
11628 else
11629 {
11630 peer = peer_lookup (bgp, &su);
11631 if (! peer)
11632 return CMD_WARNING;
11633 }
11634
11635 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
11636 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
11637 if (count)
11638 {
11639 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
11640 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
11641 }
11642
11643 return CMD_SUCCESS;
11644 }
11645
11646 ALIAS (show_bgp_view_neighbor_received_prefix_filter,
11647 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
11648 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11649 SHOW_STR
11650 BGP_STR
11651 "BGP view\n"
11652 "View name\n"
11653 "Address family\n"
11654 "Detailed information on TCP and BGP neighbor connections\n"
11655 "Neighbor to display information about\n"
11656 "Neighbor to display information about\n"
11657 "Neighbor on bgp configured interface\n"
11658 "Display information received from a BGP neighbor\n"
11659 "Display the prefixlist filter\n")
11660 #endif /* HAVE_IPV6 */
11661
11662 static int
11663 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
11664 safi_t safi, enum bgp_show_type type, char *delim)
11665 {
11666 if (! peer || ! peer->afc[afi][safi])
11667 {
11668 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11669 return CMD_WARNING;
11670 }
11671
11672 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, delim);
11673 }
11674
11675 DEFUN (show_ip_bgp_neighbor_routes,
11676 show_ip_bgp_neighbor_routes_cmd,
11677 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
11678 SHOW_STR
11679 IP_STR
11680 BGP_STR
11681 "Detailed information on TCP and BGP neighbor connections\n"
11682 "Neighbor to display information about\n"
11683 "Neighbor to display information about\n"
11684 "Neighbor on bgp configured interface\n"
11685 "Display routes learned from neighbor\n")
11686 {
11687 struct peer *peer;
11688
11689 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11690 if (! peer)
11691 return CMD_WARNING;
11692
11693 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
11694 bgp_show_type_neighbor, NULL);
11695 }
11696
11697 DEFUN (show_ip_bgp_neighbor_routes_csv,
11698 show_ip_bgp_neighbor_routes_csv_cmd,
11699 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
11700 SHOW_STR
11701 IP_STR
11702 BGP_STR
11703 "Detailed information on TCP and BGP neighbor connections\n"
11704 "Neighbor to display information about\n"
11705 "Neighbor to display information about\n"
11706 "Neighbor on bgp configured interface\n"
11707 "Display routes learned from neighbor\n")
11708 {
11709 struct peer *peer;
11710
11711 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11712 if (! peer)
11713 return CMD_WARNING;
11714
11715 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
11716 bgp_show_type_neighbor, &csv);
11717 }
11718
11719 DEFUN (show_ip_bgp_neighbor_flap,
11720 show_ip_bgp_neighbor_flap_cmd,
11721 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
11722 SHOW_STR
11723 IP_STR
11724 BGP_STR
11725 "Detailed information on TCP and BGP neighbor connections\n"
11726 "Neighbor to display information about\n"
11727 "Neighbor to display information about\n"
11728 "Neighbor on bgp configured interface\n"
11729 "Display flap statistics of the routes learned from neighbor\n")
11730 {
11731 struct peer *peer;
11732
11733 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11734 if (! peer)
11735 return CMD_WARNING;
11736
11737 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
11738 bgp_show_type_flap_neighbor, NULL);
11739 }
11740
11741 DEFUN (show_ip_bgp_neighbor_damp,
11742 show_ip_bgp_neighbor_damp_cmd,
11743 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
11744 SHOW_STR
11745 IP_STR
11746 BGP_STR
11747 "Detailed information on TCP and BGP neighbor connections\n"
11748 "Neighbor to display information about\n"
11749 "Neighbor to display information about\n"
11750 "Neighbor on bgp configured interface\n"
11751 "Display the dampened routes received from neighbor\n")
11752 {
11753 struct peer *peer;
11754
11755 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11756 if (! peer)
11757 return CMD_WARNING;
11758
11759 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
11760 bgp_show_type_damp_neighbor, NULL);
11761 }
11762
11763 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
11764 show_ip_bgp_ipv4_neighbor_routes_cmd,
11765 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes",
11766 SHOW_STR
11767 IP_STR
11768 BGP_STR
11769 "Address family\n"
11770 "Address Family modifier\n"
11771 "Address Family modifier\n"
11772 "Detailed information on TCP and BGP neighbor connections\n"
11773 "Neighbor to display information about\n"
11774 "Neighbor to display information about\n"
11775 "Neighbor on bgp configured interface\n"
11776 "Display routes learned from neighbor\n")
11777 {
11778 struct peer *peer;
11779
11780 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11781 if (! peer)
11782 return CMD_WARNING;
11783
11784 if (strncmp (argv[0], "m", 1) == 0)
11785 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
11786 bgp_show_type_neighbor, NULL);
11787
11788 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
11789 bgp_show_type_neighbor, NULL);
11790 }
11791
11792 DEFUN (show_ip_bgp_view_rsclient,
11793 show_ip_bgp_view_rsclient_cmd,
11794 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
11795 SHOW_STR
11796 IP_STR
11797 BGP_STR
11798 "BGP view\n"
11799 "View name\n"
11800 "Information about Route Server Client\n"
11801 NEIGHBOR_ADDR_STR3)
11802 {
11803 struct bgp_table *table;
11804 struct peer *peer;
11805
11806 if (argc == 2)
11807 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11808 else
11809 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11810
11811 if (! peer)
11812 return CMD_WARNING;
11813
11814 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11815 {
11816 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11817 VTY_NEWLINE);
11818 return CMD_WARNING;
11819 }
11820
11821 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11822 PEER_FLAG_RSERVER_CLIENT))
11823 {
11824 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11825 VTY_NEWLINE);
11826 return CMD_WARNING;
11827 }
11828
11829 table = peer->rib[AFI_IP][SAFI_UNICAST];
11830
11831 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
11832 NULL, NULL);
11833 }
11834
11835 ALIAS (show_ip_bgp_view_rsclient,
11836 show_ip_bgp_rsclient_cmd,
11837 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
11838 SHOW_STR
11839 IP_STR
11840 BGP_STR
11841 "Information about Route Server Client\n"
11842 NEIGHBOR_ADDR_STR3)
11843
11844 DEFUN (show_bgp_view_ipv4_safi_rsclient,
11845 show_bgp_view_ipv4_safi_rsclient_cmd,
11846 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
11847 SHOW_STR
11848 BGP_STR
11849 "BGP view\n"
11850 "View name\n"
11851 "Address family\n"
11852 "Address Family modifier\n"
11853 "Address Family modifier\n"
11854 "Information about Route Server Client\n"
11855 NEIGHBOR_ADDR_STR3)
11856 {
11857 struct bgp_table *table;
11858 struct peer *peer;
11859 safi_t safi;
11860
11861 if (argc == 3) {
11862 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11863 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11864 } else {
11865 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11866 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11867 }
11868
11869 if (! peer)
11870 return CMD_WARNING;
11871
11872 if (! peer->afc[AFI_IP][safi])
11873 {
11874 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11875 VTY_NEWLINE);
11876 return CMD_WARNING;
11877 }
11878
11879 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11880 PEER_FLAG_RSERVER_CLIENT))
11881 {
11882 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11883 VTY_NEWLINE);
11884 return CMD_WARNING;
11885 }
11886
11887 table = peer->rib[AFI_IP][safi];
11888
11889 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
11890 NULL, NULL);
11891 }
11892
11893 ALIAS (show_bgp_view_ipv4_safi_rsclient,
11894 show_bgp_ipv4_safi_rsclient_cmd,
11895 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
11896 SHOW_STR
11897 BGP_STR
11898 "Address family\n"
11899 "Address Family modifier\n"
11900 "Address Family modifier\n"
11901 "Information about Route Server Client\n"
11902 NEIGHBOR_ADDR_STR3)
11903
11904 DEFUN (show_ip_bgp_view_rsclient_route,
11905 show_ip_bgp_view_rsclient_route_cmd,
11906 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
11907 SHOW_STR
11908 IP_STR
11909 BGP_STR
11910 "BGP view\n"
11911 "View name\n"
11912 "Information about Route Server Client\n"
11913 NEIGHBOR_ADDR_STR3
11914 "Network in the BGP routing table to display\n")
11915 {
11916 struct bgp *bgp;
11917 struct peer *peer;
11918
11919 /* BGP structure lookup. */
11920 if (argc == 3)
11921 {
11922 bgp = bgp_lookup_by_name (argv[0]);
11923 if (bgp == NULL)
11924 {
11925 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11926 return CMD_WARNING;
11927 }
11928 }
11929 else
11930 {
11931 bgp = bgp_get_default ();
11932 if (bgp == NULL)
11933 {
11934 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11935 return CMD_WARNING;
11936 }
11937 }
11938
11939 if (argc == 3)
11940 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11941 else
11942 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11943
11944 if (! peer)
11945 return CMD_WARNING;
11946
11947 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11948 {
11949 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11950 VTY_NEWLINE);
11951 return CMD_WARNING;
11952 }
11953
11954 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11955 PEER_FLAG_RSERVER_CLIENT))
11956 {
11957 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11958 VTY_NEWLINE);
11959 return CMD_WARNING;
11960 }
11961
11962 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11963 (argc == 3) ? argv[2] : argv[1],
11964 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
11965 }
11966
11967 ALIAS (show_ip_bgp_view_rsclient_route,
11968 show_ip_bgp_rsclient_route_cmd,
11969 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
11970 SHOW_STR
11971 IP_STR
11972 BGP_STR
11973 "Information about Route Server Client\n"
11974 NEIGHBOR_ADDR_STR3
11975 "Network in the BGP routing table to display\n")
11976
11977 DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
11978 show_bgp_view_ipv4_safi_rsclient_route_cmd,
11979 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
11980 SHOW_STR
11981 BGP_STR
11982 "BGP view\n"
11983 "View name\n"
11984 "Address family\n"
11985 "Address Family modifier\n"
11986 "Address Family modifier\n"
11987 "Information about Route Server Client\n"
11988 NEIGHBOR_ADDR_STR3
11989 "Network in the BGP routing table to display\n")
11990 {
11991 struct bgp *bgp;
11992 struct peer *peer;
11993 safi_t safi;
11994
11995 /* BGP structure lookup. */
11996 if (argc == 4)
11997 {
11998 bgp = bgp_lookup_by_name (argv[0]);
11999 if (bgp == NULL)
12000 {
12001 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12002 return CMD_WARNING;
12003 }
12004 }
12005 else
12006 {
12007 bgp = bgp_get_default ();
12008 if (bgp == NULL)
12009 {
12010 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12011 return CMD_WARNING;
12012 }
12013 }
12014
12015 if (argc == 4) {
12016 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12017 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12018 } else {
12019 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12020 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12021 }
12022
12023 if (! peer)
12024 return CMD_WARNING;
12025
12026 if (! peer->afc[AFI_IP][safi])
12027 {
12028 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12029 VTY_NEWLINE);
12030 return CMD_WARNING;
12031 }
12032
12033 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
12034 PEER_FLAG_RSERVER_CLIENT))
12035 {
12036 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12037 VTY_NEWLINE);
12038 return CMD_WARNING;
12039 }
12040
12041 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
12042 (argc == 4) ? argv[3] : argv[2],
12043 AFI_IP, safi, NULL, 0, BGP_PATH_ALL);
12044 }
12045
12046 ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
12047 show_bgp_ipv4_safi_rsclient_route_cmd,
12048 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
12049 SHOW_STR
12050 BGP_STR
12051 "Address family\n"
12052 "Address Family modifier\n"
12053 "Address Family modifier\n"
12054 "Information about Route Server Client\n"
12055 NEIGHBOR_ADDR_STR3
12056 "Network in the BGP routing table to display\n")
12057
12058 DEFUN (show_ip_bgp_view_rsclient_prefix,
12059 show_ip_bgp_view_rsclient_prefix_cmd,
12060 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
12061 SHOW_STR
12062 IP_STR
12063 BGP_STR
12064 "BGP view\n"
12065 "View name\n"
12066 "Information about Route Server Client\n"
12067 NEIGHBOR_ADDR_STR3
12068 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12069 {
12070 struct bgp *bgp;
12071 struct peer *peer;
12072
12073 /* BGP structure lookup. */
12074 if (argc == 3)
12075 {
12076 bgp = bgp_lookup_by_name (argv[0]);
12077 if (bgp == NULL)
12078 {
12079 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12080 return CMD_WARNING;
12081 }
12082 }
12083 else
12084 {
12085 bgp = bgp_get_default ();
12086 if (bgp == NULL)
12087 {
12088 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12089 return CMD_WARNING;
12090 }
12091 }
12092
12093 if (argc == 3)
12094 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12095 else
12096 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12097
12098 if (! peer)
12099 return CMD_WARNING;
12100
12101 if (! peer->afc[AFI_IP][SAFI_UNICAST])
12102 {
12103 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12104 VTY_NEWLINE);
12105 return CMD_WARNING;
12106 }
12107
12108 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
12109 PEER_FLAG_RSERVER_CLIENT))
12110 {
12111 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12112 VTY_NEWLINE);
12113 return CMD_WARNING;
12114 }
12115
12116 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
12117 (argc == 3) ? argv[2] : argv[1],
12118 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
12119 }
12120
12121 ALIAS (show_ip_bgp_view_rsclient_prefix,
12122 show_ip_bgp_rsclient_prefix_cmd,
12123 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
12124 SHOW_STR
12125 IP_STR
12126 BGP_STR
12127 "Information about Route Server Client\n"
12128 NEIGHBOR_ADDR_STR3
12129 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12130
12131 DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
12132 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
12133 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
12134 SHOW_STR
12135 BGP_STR
12136 "BGP view\n"
12137 "View name\n"
12138 "Address family\n"
12139 "Address Family modifier\n"
12140 "Address Family modifier\n"
12141 "Information about Route Server Client\n"
12142 NEIGHBOR_ADDR_STR3
12143 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12144 {
12145 struct bgp *bgp;
12146 struct peer *peer;
12147 safi_t safi;
12148
12149 /* BGP structure lookup. */
12150 if (argc == 4)
12151 {
12152 bgp = bgp_lookup_by_name (argv[0]);
12153 if (bgp == NULL)
12154 {
12155 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12156 return CMD_WARNING;
12157 }
12158 }
12159 else
12160 {
12161 bgp = bgp_get_default ();
12162 if (bgp == NULL)
12163 {
12164 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12165 return CMD_WARNING;
12166 }
12167 }
12168
12169 if (argc == 4) {
12170 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12171 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12172 } else {
12173 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12174 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12175 }
12176
12177 if (! peer)
12178 return CMD_WARNING;
12179
12180 if (! peer->afc[AFI_IP][safi])
12181 {
12182 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12183 VTY_NEWLINE);
12184 return CMD_WARNING;
12185 }
12186
12187 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
12188 PEER_FLAG_RSERVER_CLIENT))
12189 {
12190 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12191 VTY_NEWLINE);
12192 return CMD_WARNING;
12193 }
12194
12195 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
12196 (argc == 4) ? argv[3] : argv[2],
12197 AFI_IP, safi, NULL, 1, BGP_PATH_ALL);
12198 }
12199
12200 ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
12201 show_bgp_ipv4_safi_rsclient_prefix_cmd,
12202 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
12203 SHOW_STR
12204 BGP_STR
12205 "Address family\n"
12206 "Address Family modifier\n"
12207 "Address Family modifier\n"
12208 "Information about Route Server Client\n"
12209 NEIGHBOR_ADDR_STR3
12210 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12211
12212 #ifdef HAVE_IPV6
12213 DEFUN (show_bgp_view_neighbor_routes,
12214 show_bgp_view_neighbor_routes_cmd,
12215 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12216 SHOW_STR
12217 BGP_STR
12218 "BGP view\n"
12219 "View name\n"
12220 "Detailed information on TCP and BGP neighbor connections\n"
12221 "Neighbor to display information about\n"
12222 "Neighbor to display information about\n"
12223 "Neighbor on bgp configured interface\n"
12224 "Display routes learned from neighbor\n")
12225 {
12226 struct peer *peer;
12227
12228 if (argc == 2)
12229 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12230 else
12231 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12232
12233 if (! peer)
12234 return CMD_WARNING;
12235
12236 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12237 bgp_show_type_neighbor, NULL);
12238 }
12239
12240 DEFUN (show_bgp_view_neighbor_routes_csv,
12241 show_bgp_view_neighbor_routes_csv_cmd,
12242 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
12243 SHOW_STR
12244 BGP_STR
12245 "BGP view\n"
12246 "BGP view name\n"
12247 "Detailed information on TCP and BGP neighbor connections\n"
12248 "Neighbor to display information about\n"
12249 "Neighbor to display information about\n"
12250 "Neighbor on bgp configured interface\n"
12251 "Display routes learned from neighbor\n")
12252 {
12253 struct peer *peer;
12254
12255 if (argc == 2)
12256 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12257 else
12258 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12259
12260 if (! peer)
12261 return CMD_WARNING;
12262
12263 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12264 bgp_show_type_neighbor, &csv);
12265 }
12266
12267 ALIAS (show_bgp_view_neighbor_routes,
12268 show_bgp_view_ipv6_neighbor_routes_cmd,
12269 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12270 SHOW_STR
12271 BGP_STR
12272 "BGP view\n"
12273 "View name\n"
12274 "Address family\n"
12275 "Detailed information on TCP and BGP neighbor connections\n"
12276 "Neighbor to display information about\n"
12277 "Neighbor to display information about\n"
12278 "Neighbor on bgp configured interface\n"
12279 "Display routes learned from neighbor\n")
12280
12281 DEFUN (show_bgp_view_neighbor_damp,
12282 show_bgp_view_neighbor_damp_cmd,
12283 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
12284 SHOW_STR
12285 BGP_STR
12286 "BGP view\n"
12287 "View name\n"
12288 "Detailed information on TCP and BGP neighbor connections\n"
12289 "Neighbor to display information about\n"
12290 "Neighbor to display information about\n"
12291 "Neighbor on bgp configured interface\n"
12292 "Display the dampened routes received from neighbor\n")
12293 {
12294 struct peer *peer;
12295
12296 if (argc == 2)
12297 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12298 else
12299 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12300
12301 if (! peer)
12302 return CMD_WARNING;
12303
12304 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12305 bgp_show_type_damp_neighbor, NULL);
12306 }
12307
12308 ALIAS (show_bgp_view_neighbor_damp,
12309 show_bgp_view_ipv6_neighbor_damp_cmd,
12310 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
12311 SHOW_STR
12312 BGP_STR
12313 "BGP view\n"
12314 "View name\n"
12315 "Address family\n"
12316 "Detailed information on TCP and BGP neighbor connections\n"
12317 "Neighbor to display information about\n"
12318 "Neighbor to display information about\n"
12319 "Neighbor on bgp configured interface\n"
12320 "Display the dampened routes received from neighbor\n")
12321
12322 DEFUN (show_bgp_view_neighbor_flap,
12323 show_bgp_view_neighbor_flap_cmd,
12324 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
12325 SHOW_STR
12326 BGP_STR
12327 "BGP view\n"
12328 "View name\n"
12329 "Detailed information on TCP and BGP neighbor connections\n"
12330 "Neighbor to display information about\n"
12331 "Neighbor to display information about\n"
12332 "Neighbor on bgp configured interface\n"
12333 "Display flap statistics of the routes learned from neighbor\n")
12334 {
12335 struct peer *peer;
12336
12337 if (argc == 2)
12338 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12339 else
12340 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12341
12342 if (! peer)
12343 return CMD_WARNING;
12344
12345 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12346 bgp_show_type_flap_neighbor, NULL);
12347 }
12348
12349 ALIAS (show_bgp_view_neighbor_flap,
12350 show_bgp_view_ipv6_neighbor_flap_cmd,
12351 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
12352 SHOW_STR
12353 BGP_STR
12354 "BGP view\n"
12355 "View name\n"
12356 "Address family\n"
12357 "Detailed information on TCP and BGP neighbor connections\n"
12358 "Neighbor to display information about\n"
12359 "Neighbor to display information about\n"
12360 "Neighbor on bgp configured interface\n"
12361 "Display flap statistics of the routes learned from neighbor\n")
12362
12363 ALIAS (show_bgp_view_neighbor_routes,
12364 show_bgp_neighbor_routes_cmd,
12365 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12366 SHOW_STR
12367 BGP_STR
12368 "Detailed information on TCP and BGP neighbor connections\n"
12369 "Neighbor to display information about\n"
12370 "Neighbor to display information about\n"
12371 "Neighbor on bgp configured interface\n"
12372 "Display routes learned from neighbor\n")
12373
12374
12375 ALIAS (show_bgp_view_neighbor_routes,
12376 show_bgp_ipv6_neighbor_routes_cmd,
12377 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12378 SHOW_STR
12379 BGP_STR
12380 "Address family\n"
12381 "Detailed information on TCP and BGP neighbor connections\n"
12382 "Neighbor to display information about\n"
12383 "Neighbor to display information about\n"
12384 "Neighbor on bgp configured interface\n"
12385 "Display routes learned from neighbor\n")
12386
12387 /* old command */
12388 ALIAS (show_bgp_view_neighbor_routes,
12389 ipv6_bgp_neighbor_routes_cmd,
12390 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12391 SHOW_STR
12392 IPV6_STR
12393 BGP_STR
12394 "Detailed information on TCP and BGP neighbor connections\n"
12395 "Neighbor to display information about\n"
12396 "Neighbor to display information about\n"
12397 "Neighbor on bgp configured interface\n"
12398 "Display routes learned from neighbor\n")
12399
12400 ALIAS (show_bgp_view_neighbor_routes_csv,
12401 show_bgp_neighbor_routes_csv_cmd,
12402 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
12403 SHOW_STR
12404 BGP_STR
12405 "Detailed information on TCP and BGP neighbor connections\n"
12406 "Neighbor to display information about\n"
12407 "Neighbor to display information about\n"
12408 "Neighbor on bgp configured interface\n"
12409 "Display routes learned from neighbor\n")
12410
12411
12412 ALIAS (show_bgp_view_neighbor_routes_csv,
12413 show_bgp_ipv6_neighbor_routes_csv_cmd,
12414 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
12415 SHOW_STR
12416 BGP_STR
12417 "Address family\n"
12418 "Detailed information on TCP and BGP neighbor connections\n"
12419 "Neighbor to display information about\n"
12420 "Neighbor to display information about\n"
12421 "Neighbor on bgp configured interface\n"
12422 "Display routes learned from neighbor\n")
12423
12424 /* old command */
12425 ALIAS (show_bgp_view_neighbor_routes_csv,
12426 ipv6_bgp_neighbor_routes_csv_cmd,
12427 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
12428 SHOW_STR
12429 IPV6_STR
12430 BGP_STR
12431 "Detailed information on TCP and BGP neighbor connections\n"
12432 "Neighbor to display information about\n"
12433 "Neighbor to display information about\n"
12434 "Neighbor on bgp configured interface\n"
12435 "Display routes learned from neighbor\n")
12436
12437 /* old command */
12438 DEFUN (ipv6_mbgp_neighbor_routes,
12439 ipv6_mbgp_neighbor_routes_cmd,
12440 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12441 SHOW_STR
12442 IPV6_STR
12443 MBGP_STR
12444 "Detailed information on TCP and BGP neighbor connections\n"
12445 "Neighbor to display information about\n"
12446 "Neighbor to display information about\n"
12447 "Neighbor on bgp configured interface\n"
12448 "Display routes learned from neighbor\n")
12449 {
12450 struct peer *peer;
12451
12452 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12453 if (! peer)
12454 return CMD_WARNING;
12455
12456 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
12457 bgp_show_type_neighbor, NULL);
12458 }
12459
12460 ALIAS (show_bgp_view_neighbor_flap,
12461 show_bgp_neighbor_flap_cmd,
12462 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
12463 SHOW_STR
12464 BGP_STR
12465 "Detailed information on TCP and BGP neighbor connections\n"
12466 "Neighbor to display information about\n"
12467 "Neighbor to display information about\n"
12468 "Neighbor on bgp configured interface\n"
12469 "Display flap statistics of the routes learned from neighbor\n")
12470
12471 ALIAS (show_bgp_view_neighbor_flap,
12472 show_bgp_ipv6_neighbor_flap_cmd,
12473 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
12474 SHOW_STR
12475 BGP_STR
12476 "Address family\n"
12477 "Detailed information on TCP and BGP neighbor connections\n"
12478 "Neighbor to display information about\n"
12479 "Neighbor to display information about\n"
12480 "Neighbor on bgp configured interface\n"
12481 "Display flap statistics of the routes learned from neighbor\n")
12482
12483 ALIAS (show_bgp_view_neighbor_damp,
12484 show_bgp_neighbor_damp_cmd,
12485 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
12486 SHOW_STR
12487 BGP_STR
12488 "Detailed information on TCP and BGP neighbor connections\n"
12489 "Neighbor to display information about\n"
12490 "Neighbor to display information about\n"
12491 "Neighbor on bgp configured interface\n"
12492 "Display the dampened routes received from neighbor\n")
12493
12494 ALIAS (show_bgp_view_neighbor_damp,
12495 show_bgp_ipv6_neighbor_damp_cmd,
12496 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
12497 SHOW_STR
12498 BGP_STR
12499 "Address family\n"
12500 "Detailed information on TCP and BGP neighbor connections\n"
12501 "Neighbor to display information about\n"
12502 "Neighbor to display information about\n"
12503 "Neighbor on bgp configured interface\n"
12504 "Display the dampened routes received from neighbor\n")
12505
12506 DEFUN (show_bgp_view_rsclient,
12507 show_bgp_view_rsclient_cmd,
12508 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
12509 SHOW_STR
12510 BGP_STR
12511 "BGP view\n"
12512 "View name\n"
12513 "Information about Route Server Client\n"
12514 NEIGHBOR_ADDR_STR3)
12515 {
12516 struct bgp_table *table;
12517 struct peer *peer;
12518
12519 if (argc == 2)
12520 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12521 else
12522 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12523
12524 if (! peer)
12525 return CMD_WARNING;
12526
12527 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
12528 {
12529 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12530 VTY_NEWLINE);
12531 return CMD_WARNING;
12532 }
12533
12534 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
12535 PEER_FLAG_RSERVER_CLIENT))
12536 {
12537 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12538 VTY_NEWLINE);
12539 return CMD_WARNING;
12540 }
12541
12542 table = peer->rib[AFI_IP6][SAFI_UNICAST];
12543
12544 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
12545 NULL, NULL);
12546 }
12547
12548 ALIAS (show_bgp_view_rsclient,
12549 show_bgp_rsclient_cmd,
12550 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
12551 SHOW_STR
12552 BGP_STR
12553 "Information about Route Server Client\n"
12554 NEIGHBOR_ADDR_STR3)
12555
12556 DEFUN (show_bgp_view_ipv6_safi_rsclient,
12557 show_bgp_view_ipv6_safi_rsclient_cmd,
12558 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
12559 SHOW_STR
12560 BGP_STR
12561 "BGP view\n"
12562 "View name\n"
12563 "Address family\n"
12564 "Address Family modifier\n"
12565 "Address Family modifier\n"
12566 "Information about Route Server Client\n"
12567 NEIGHBOR_ADDR_STR3)
12568 {
12569 struct bgp_table *table;
12570 struct peer *peer;
12571 safi_t safi;
12572
12573 if (argc == 3) {
12574 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12575 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12576 } else {
12577 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12578 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12579 }
12580
12581 if (! peer)
12582 return CMD_WARNING;
12583
12584 if (! peer->afc[AFI_IP6][safi])
12585 {
12586 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12587 VTY_NEWLINE);
12588 return CMD_WARNING;
12589 }
12590
12591 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
12592 PEER_FLAG_RSERVER_CLIENT))
12593 {
12594 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12595 VTY_NEWLINE);
12596 return CMD_WARNING;
12597 }
12598
12599 table = peer->rib[AFI_IP6][safi];
12600
12601 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
12602 NULL, NULL);
12603 }
12604
12605 ALIAS (show_bgp_view_ipv6_safi_rsclient,
12606 show_bgp_ipv6_safi_rsclient_cmd,
12607 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
12608 SHOW_STR
12609 BGP_STR
12610 "Address family\n"
12611 "Address Family modifier\n"
12612 "Address Family modifier\n"
12613 "Information about Route Server Client\n"
12614 NEIGHBOR_ADDR_STR3)
12615
12616 DEFUN (show_bgp_view_rsclient_route,
12617 show_bgp_view_rsclient_route_cmd,
12618 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
12619 SHOW_STR
12620 BGP_STR
12621 "BGP view\n"
12622 "View name\n"
12623 "Information about Route Server Client\n"
12624 NEIGHBOR_ADDR_STR3
12625 "Network in the BGP routing table to display\n")
12626 {
12627 struct bgp *bgp;
12628 struct peer *peer;
12629
12630 /* BGP structure lookup. */
12631 if (argc == 3)
12632 {
12633 bgp = bgp_lookup_by_name (argv[0]);
12634 if (bgp == NULL)
12635 {
12636 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12637 return CMD_WARNING;
12638 }
12639 }
12640 else
12641 {
12642 bgp = bgp_get_default ();
12643 if (bgp == NULL)
12644 {
12645 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12646 return CMD_WARNING;
12647 }
12648 }
12649
12650 if (argc == 3)
12651 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12652 else
12653 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12654
12655 if (! peer)
12656 return CMD_WARNING;
12657
12658 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
12659 {
12660 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12661 VTY_NEWLINE);
12662 return CMD_WARNING;
12663 }
12664
12665 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
12666 PEER_FLAG_RSERVER_CLIENT))
12667 {
12668 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12669 VTY_NEWLINE);
12670 return CMD_WARNING;
12671 }
12672
12673 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
12674 (argc == 3) ? argv[2] : argv[1],
12675 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
12676 }
12677
12678 ALIAS (show_bgp_view_rsclient_route,
12679 show_bgp_rsclient_route_cmd,
12680 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
12681 SHOW_STR
12682 BGP_STR
12683 "Information about Route Server Client\n"
12684 NEIGHBOR_ADDR_STR3
12685 "Network in the BGP routing table to display\n")
12686
12687 DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
12688 show_bgp_view_ipv6_safi_rsclient_route_cmd,
12689 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
12690 SHOW_STR
12691 BGP_STR
12692 "BGP view\n"
12693 "View name\n"
12694 "Address family\n"
12695 "Address Family modifier\n"
12696 "Address Family modifier\n"
12697 "Information about Route Server Client\n"
12698 NEIGHBOR_ADDR_STR3
12699 "Network in the BGP routing table to display\n")
12700 {
12701 struct bgp *bgp;
12702 struct peer *peer;
12703 safi_t safi;
12704
12705 /* BGP structure lookup. */
12706 if (argc == 4)
12707 {
12708 bgp = bgp_lookup_by_name (argv[0]);
12709 if (bgp == NULL)
12710 {
12711 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12712 return CMD_WARNING;
12713 }
12714 }
12715 else
12716 {
12717 bgp = bgp_get_default ();
12718 if (bgp == NULL)
12719 {
12720 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12721 return CMD_WARNING;
12722 }
12723 }
12724
12725 if (argc == 4) {
12726 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12727 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12728 } else {
12729 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12730 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12731 }
12732
12733 if (! peer)
12734 return CMD_WARNING;
12735
12736 if (! peer->afc[AFI_IP6][safi])
12737 {
12738 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12739 VTY_NEWLINE);
12740 return CMD_WARNING;
12741 }
12742
12743 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
12744 PEER_FLAG_RSERVER_CLIENT))
12745 {
12746 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12747 VTY_NEWLINE);
12748 return CMD_WARNING;
12749 }
12750
12751 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
12752 (argc == 4) ? argv[3] : argv[2],
12753 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL);
12754 }
12755
12756 ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
12757 show_bgp_ipv6_safi_rsclient_route_cmd,
12758 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
12759 SHOW_STR
12760 BGP_STR
12761 "Address family\n"
12762 "Address Family modifier\n"
12763 "Address Family modifier\n"
12764 "Information about Route Server Client\n"
12765 NEIGHBOR_ADDR_STR3
12766 "Network in the BGP routing table to display\n")
12767
12768 DEFUN (show_bgp_view_rsclient_prefix,
12769 show_bgp_view_rsclient_prefix_cmd,
12770 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
12771 SHOW_STR
12772 BGP_STR
12773 "BGP view\n"
12774 "View name\n"
12775 "Information about Route Server Client\n"
12776 NEIGHBOR_ADDR_STR3
12777 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
12778 {
12779 struct bgp *bgp;
12780 struct peer *peer;
12781
12782 /* BGP structure lookup. */
12783 if (argc == 3)
12784 {
12785 bgp = bgp_lookup_by_name (argv[0]);
12786 if (bgp == NULL)
12787 {
12788 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12789 return CMD_WARNING;
12790 }
12791 }
12792 else
12793 {
12794 bgp = bgp_get_default ();
12795 if (bgp == NULL)
12796 {
12797 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12798 return CMD_WARNING;
12799 }
12800 }
12801
12802 if (argc == 3)
12803 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12804 else
12805 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12806
12807 if (! peer)
12808 return CMD_WARNING;
12809
12810 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
12811 {
12812 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12813 VTY_NEWLINE);
12814 return CMD_WARNING;
12815 }
12816
12817 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
12818 PEER_FLAG_RSERVER_CLIENT))
12819 {
12820 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12821 VTY_NEWLINE);
12822 return CMD_WARNING;
12823 }
12824
12825 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
12826 (argc == 3) ? argv[2] : argv[1],
12827 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
12828 }
12829
12830 ALIAS (show_bgp_view_rsclient_prefix,
12831 show_bgp_rsclient_prefix_cmd,
12832 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
12833 SHOW_STR
12834 BGP_STR
12835 "Information about Route Server Client\n"
12836 NEIGHBOR_ADDR_STR3
12837 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
12838
12839 DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
12840 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
12841 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
12842 SHOW_STR
12843 BGP_STR
12844 "BGP view\n"
12845 "View name\n"
12846 "Address family\n"
12847 "Address Family modifier\n"
12848 "Address Family modifier\n"
12849 "Information about Route Server Client\n"
12850 NEIGHBOR_ADDR_STR3
12851 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
12852 {
12853 struct bgp *bgp;
12854 struct peer *peer;
12855 safi_t safi;
12856
12857 /* BGP structure lookup. */
12858 if (argc == 4)
12859 {
12860 bgp = bgp_lookup_by_name (argv[0]);
12861 if (bgp == NULL)
12862 {
12863 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12864 return CMD_WARNING;
12865 }
12866 }
12867 else
12868 {
12869 bgp = bgp_get_default ();
12870 if (bgp == NULL)
12871 {
12872 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12873 return CMD_WARNING;
12874 }
12875 }
12876
12877 if (argc == 4) {
12878 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12879 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12880 } else {
12881 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12882 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12883 }
12884
12885 if (! peer)
12886 return CMD_WARNING;
12887
12888 if (! peer->afc[AFI_IP6][safi])
12889 {
12890 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12891 VTY_NEWLINE);
12892 return CMD_WARNING;
12893 }
12894
12895 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
12896 PEER_FLAG_RSERVER_CLIENT))
12897 {
12898 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12899 VTY_NEWLINE);
12900 return CMD_WARNING;
12901 }
12902
12903 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
12904 (argc == 4) ? argv[3] : argv[2],
12905 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL);
12906 }
12907
12908 ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
12909 show_bgp_ipv6_safi_rsclient_prefix_cmd,
12910 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
12911 SHOW_STR
12912 BGP_STR
12913 "Address family\n"
12914 "Address Family modifier\n"
12915 "Address Family modifier\n"
12916 "Information about Route Server Client\n"
12917 NEIGHBOR_ADDR_STR3
12918 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
12919
12920 #endif /* HAVE_IPV6 */
12921
12922 struct bgp_table *bgp_distance_table;
12923
12924 struct bgp_distance
12925 {
12926 /* Distance value for the IP source prefix. */
12927 u_char distance;
12928
12929 /* Name of the access-list to be matched. */
12930 char *access_list;
12931 };
12932
12933 static struct bgp_distance *
12934 bgp_distance_new (void)
12935 {
12936 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
12937 }
12938
12939 static void
12940 bgp_distance_free (struct bgp_distance *bdistance)
12941 {
12942 XFREE (MTYPE_BGP_DISTANCE, bdistance);
12943 }
12944
12945 static int
12946 bgp_distance_set (struct vty *vty, const char *distance_str,
12947 const char *ip_str, const char *access_list_str)
12948 {
12949 int ret;
12950 struct prefix_ipv4 p;
12951 u_char distance;
12952 struct bgp_node *rn;
12953 struct bgp_distance *bdistance;
12954
12955 ret = str2prefix_ipv4 (ip_str, &p);
12956 if (ret == 0)
12957 {
12958 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12959 return CMD_WARNING;
12960 }
12961
12962 distance = atoi (distance_str);
12963
12964 /* Get BGP distance node. */
12965 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
12966 if (rn->info)
12967 {
12968 bdistance = rn->info;
12969 bgp_unlock_node (rn);
12970 }
12971 else
12972 {
12973 bdistance = bgp_distance_new ();
12974 rn->info = bdistance;
12975 }
12976
12977 /* Set distance value. */
12978 bdistance->distance = distance;
12979
12980 /* Reset access-list configuration. */
12981 if (bdistance->access_list)
12982 {
12983 free (bdistance->access_list);
12984 bdistance->access_list = NULL;
12985 }
12986 if (access_list_str)
12987 bdistance->access_list = strdup (access_list_str);
12988
12989 return CMD_SUCCESS;
12990 }
12991
12992 static int
12993 bgp_distance_unset (struct vty *vty, const char *distance_str,
12994 const char *ip_str, const char *access_list_str)
12995 {
12996 int ret;
12997 struct prefix_ipv4 p;
12998 u_char distance;
12999 struct bgp_node *rn;
13000 struct bgp_distance *bdistance;
13001
13002 ret = str2prefix_ipv4 (ip_str, &p);
13003 if (ret == 0)
13004 {
13005 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13006 return CMD_WARNING;
13007 }
13008
13009 distance = atoi (distance_str);
13010
13011 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
13012 if (! rn)
13013 {
13014 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13015 return CMD_WARNING;
13016 }
13017
13018 bdistance = rn->info;
13019
13020 if (bdistance->access_list)
13021 free (bdistance->access_list);
13022 bgp_distance_free (bdistance);
13023
13024 rn->info = NULL;
13025 bgp_unlock_node (rn);
13026 bgp_unlock_node (rn);
13027
13028 return CMD_SUCCESS;
13029 }
13030
13031 /* Apply BGP information to distance method. */
13032 u_char
13033 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
13034 {
13035 struct bgp_node *rn;
13036 struct prefix_ipv4 q;
13037 struct peer *peer;
13038 struct bgp_distance *bdistance;
13039 struct access_list *alist;
13040 struct bgp_static *bgp_static;
13041
13042 if (! bgp)
13043 return 0;
13044
13045 if (p->family != AF_INET)
13046 return 0;
13047
13048 peer = rinfo->peer;
13049
13050 if (peer->su.sa.sa_family != AF_INET)
13051 return 0;
13052
13053 memset (&q, 0, sizeof (struct prefix_ipv4));
13054 q.family = AF_INET;
13055 q.prefix = peer->su.sin.sin_addr;
13056 q.prefixlen = IPV4_MAX_BITLEN;
13057
13058 /* Check source address. */
13059 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
13060 if (rn)
13061 {
13062 bdistance = rn->info;
13063 bgp_unlock_node (rn);
13064
13065 if (bdistance->access_list)
13066 {
13067 alist = access_list_lookup (AFI_IP, bdistance->access_list);
13068 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13069 return bdistance->distance;
13070 }
13071 else
13072 return bdistance->distance;
13073 }
13074
13075 /* Backdoor check. */
13076 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
13077 if (rn)
13078 {
13079 bgp_static = rn->info;
13080 bgp_unlock_node (rn);
13081
13082 if (bgp_static->backdoor)
13083 {
13084 if (bgp->distance_local)
13085 return bgp->distance_local;
13086 else
13087 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13088 }
13089 }
13090
13091 if (peer->sort == BGP_PEER_EBGP)
13092 {
13093 if (bgp->distance_ebgp)
13094 return bgp->distance_ebgp;
13095 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13096 }
13097 else
13098 {
13099 if (bgp->distance_ibgp)
13100 return bgp->distance_ibgp;
13101 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13102 }
13103 }
13104
13105 DEFUN (bgp_distance,
13106 bgp_distance_cmd,
13107 "distance bgp <1-255> <1-255> <1-255>",
13108 "Define an administrative distance\n"
13109 "BGP distance\n"
13110 "Distance for routes external to the AS\n"
13111 "Distance for routes internal to the AS\n"
13112 "Distance for local routes\n")
13113 {
13114 struct bgp *bgp;
13115
13116 bgp = vty->index;
13117
13118 bgp->distance_ebgp = atoi (argv[0]);
13119 bgp->distance_ibgp = atoi (argv[1]);
13120 bgp->distance_local = atoi (argv[2]);
13121 return CMD_SUCCESS;
13122 }
13123
13124 DEFUN (no_bgp_distance,
13125 no_bgp_distance_cmd,
13126 "no distance bgp <1-255> <1-255> <1-255>",
13127 NO_STR
13128 "Define an administrative distance\n"
13129 "BGP distance\n"
13130 "Distance for routes external to the AS\n"
13131 "Distance for routes internal to the AS\n"
13132 "Distance for local routes\n")
13133 {
13134 struct bgp *bgp;
13135
13136 bgp = vty->index;
13137
13138 bgp->distance_ebgp= 0;
13139 bgp->distance_ibgp = 0;
13140 bgp->distance_local = 0;
13141 return CMD_SUCCESS;
13142 }
13143
13144 ALIAS (no_bgp_distance,
13145 no_bgp_distance2_cmd,
13146 "no distance bgp",
13147 NO_STR
13148 "Define an administrative distance\n"
13149 "BGP distance\n")
13150
13151 DEFUN (bgp_distance_source,
13152 bgp_distance_source_cmd,
13153 "distance <1-255> A.B.C.D/M",
13154 "Define an administrative distance\n"
13155 "Administrative distance\n"
13156 "IP source prefix\n")
13157 {
13158 bgp_distance_set (vty, argv[0], argv[1], NULL);
13159 return CMD_SUCCESS;
13160 }
13161
13162 DEFUN (no_bgp_distance_source,
13163 no_bgp_distance_source_cmd,
13164 "no distance <1-255> A.B.C.D/M",
13165 NO_STR
13166 "Define an administrative distance\n"
13167 "Administrative distance\n"
13168 "IP source prefix\n")
13169 {
13170 bgp_distance_unset (vty, argv[0], argv[1], NULL);
13171 return CMD_SUCCESS;
13172 }
13173
13174 DEFUN (bgp_distance_source_access_list,
13175 bgp_distance_source_access_list_cmd,
13176 "distance <1-255> A.B.C.D/M WORD",
13177 "Define an administrative distance\n"
13178 "Administrative distance\n"
13179 "IP source prefix\n"
13180 "Access list name\n")
13181 {
13182 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
13183 return CMD_SUCCESS;
13184 }
13185
13186 DEFUN (no_bgp_distance_source_access_list,
13187 no_bgp_distance_source_access_list_cmd,
13188 "no distance <1-255> A.B.C.D/M WORD",
13189 NO_STR
13190 "Define an administrative distance\n"
13191 "Administrative distance\n"
13192 "IP source prefix\n"
13193 "Access list name\n")
13194 {
13195 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
13196 return CMD_SUCCESS;
13197 }
13198
13199 DEFUN (bgp_damp_set,
13200 bgp_damp_set_cmd,
13201 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13202 "BGP Specific commands\n"
13203 "Enable route-flap dampening\n"
13204 "Half-life time for the penalty\n"
13205 "Value to start reusing a route\n"
13206 "Value to start suppressing a route\n"
13207 "Maximum duration to suppress a stable route\n")
13208 {
13209 struct bgp *bgp;
13210 int half = DEFAULT_HALF_LIFE * 60;
13211 int reuse = DEFAULT_REUSE;
13212 int suppress = DEFAULT_SUPPRESS;
13213 int max = 4 * half;
13214
13215 if (argc == 4)
13216 {
13217 half = atoi (argv[0]) * 60;
13218 reuse = atoi (argv[1]);
13219 suppress = atoi (argv[2]);
13220 max = atoi (argv[3]) * 60;
13221 }
13222 else if (argc == 1)
13223 {
13224 half = atoi (argv[0]) * 60;
13225 max = 4 * half;
13226 }
13227
13228 bgp = vty->index;
13229 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
13230 half, reuse, suppress, max);
13231 }
13232
13233 ALIAS (bgp_damp_set,
13234 bgp_damp_set2_cmd,
13235 "bgp dampening <1-45>",
13236 "BGP Specific commands\n"
13237 "Enable route-flap dampening\n"
13238 "Half-life time for the penalty\n")
13239
13240 ALIAS (bgp_damp_set,
13241 bgp_damp_set3_cmd,
13242 "bgp dampening",
13243 "BGP Specific commands\n"
13244 "Enable route-flap dampening\n")
13245
13246 DEFUN (bgp_damp_unset,
13247 bgp_damp_unset_cmd,
13248 "no bgp dampening",
13249 NO_STR
13250 "BGP Specific commands\n"
13251 "Enable route-flap dampening\n")
13252 {
13253 struct bgp *bgp;
13254
13255 bgp = vty->index;
13256 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
13257 }
13258
13259 ALIAS (bgp_damp_unset,
13260 bgp_damp_unset2_cmd,
13261 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13262 NO_STR
13263 "BGP Specific commands\n"
13264 "Enable route-flap dampening\n"
13265 "Half-life time for the penalty\n"
13266 "Value to start reusing a route\n"
13267 "Value to start suppressing a route\n"
13268 "Maximum duration to suppress a stable route\n")
13269
13270 DEFUN (show_ip_bgp_dampened_paths,
13271 show_ip_bgp_dampened_paths_cmd,
13272 "show ip bgp dampened-paths",
13273 SHOW_STR
13274 IP_STR
13275 BGP_STR
13276 "Display paths suppressed due to dampening\n")
13277 {
13278 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
13279 NULL, NULL);
13280 }
13281
13282 DEFUN (show_ip_bgp_flap_statistics,
13283 show_ip_bgp_flap_statistics_cmd,
13284 "show ip bgp flap-statistics",
13285 SHOW_STR
13286 IP_STR
13287 BGP_STR
13288 "Display flap statistics of routes\n")
13289 {
13290 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
13291 bgp_show_type_flap_statistics, NULL, NULL);
13292 }
13293
13294 /* Display specified route of BGP table. */
13295 static int
13296 bgp_clear_damp_route (struct vty *vty, const char *view_name,
13297 const char *ip_str, afi_t afi, safi_t safi,
13298 struct prefix_rd *prd, int prefix_check)
13299 {
13300 int ret;
13301 struct prefix match;
13302 struct bgp_node *rn;
13303 struct bgp_node *rm;
13304 struct bgp_info *ri;
13305 struct bgp_info *ri_temp;
13306 struct bgp *bgp;
13307 struct bgp_table *table;
13308
13309 /* BGP structure lookup. */
13310 if (view_name)
13311 {
13312 bgp = bgp_lookup_by_name (view_name);
13313 if (bgp == NULL)
13314 {
13315 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
13316 return CMD_WARNING;
13317 }
13318 }
13319 else
13320 {
13321 bgp = bgp_get_default ();
13322 if (bgp == NULL)
13323 {
13324 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
13325 return CMD_WARNING;
13326 }
13327 }
13328
13329 /* Check IP address argument. */
13330 ret = str2prefix (ip_str, &match);
13331 if (! ret)
13332 {
13333 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
13334 return CMD_WARNING;
13335 }
13336
13337 match.family = afi2family (afi);
13338
13339 if (safi == SAFI_MPLS_VPN)
13340 {
13341 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
13342 {
13343 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
13344 continue;
13345
13346 if ((table = rn->info) != NULL)
13347 if ((rm = bgp_node_match (table, &match)) != NULL)
13348 {
13349 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
13350 {
13351 ri = rm->info;
13352 while (ri)
13353 {
13354 if (ri->extra && ri->extra->damp_info)
13355 {
13356 ri_temp = ri->next;
13357 bgp_damp_info_free (ri->extra->damp_info, 1);
13358 ri = ri_temp;
13359 }
13360 else
13361 ri = ri->next;
13362 }
13363 }
13364
13365 bgp_unlock_node (rm);
13366 }
13367 }
13368 }
13369 else
13370 {
13371 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
13372 {
13373 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
13374 {
13375 ri = rn->info;
13376 while (ri)
13377 {
13378 if (ri->extra && ri->extra->damp_info)
13379 {
13380 ri_temp = ri->next;
13381 bgp_damp_info_free (ri->extra->damp_info, 1);
13382 ri = ri_temp;
13383 }
13384 else
13385 ri = ri->next;
13386 }
13387 }
13388
13389 bgp_unlock_node (rn);
13390 }
13391 }
13392
13393 return CMD_SUCCESS;
13394 }
13395
13396 DEFUN (clear_ip_bgp_dampening,
13397 clear_ip_bgp_dampening_cmd,
13398 "clear ip bgp dampening",
13399 CLEAR_STR
13400 IP_STR
13401 BGP_STR
13402 "Clear route flap dampening information\n")
13403 {
13404 bgp_damp_info_clean ();
13405 return CMD_SUCCESS;
13406 }
13407
13408 DEFUN (clear_ip_bgp_dampening_prefix,
13409 clear_ip_bgp_dampening_prefix_cmd,
13410 "clear ip bgp dampening A.B.C.D/M",
13411 CLEAR_STR
13412 IP_STR
13413 BGP_STR
13414 "Clear route flap dampening information\n"
13415 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13416 {
13417 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13418 SAFI_UNICAST, NULL, 1);
13419 }
13420
13421 DEFUN (clear_ip_bgp_dampening_address,
13422 clear_ip_bgp_dampening_address_cmd,
13423 "clear ip bgp dampening A.B.C.D",
13424 CLEAR_STR
13425 IP_STR
13426 BGP_STR
13427 "Clear route flap dampening information\n"
13428 "Network to clear damping information\n")
13429 {
13430 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13431 SAFI_UNICAST, NULL, 0);
13432 }
13433
13434 DEFUN (clear_ip_bgp_dampening_address_mask,
13435 clear_ip_bgp_dampening_address_mask_cmd,
13436 "clear ip bgp dampening A.B.C.D A.B.C.D",
13437 CLEAR_STR
13438 IP_STR
13439 BGP_STR
13440 "Clear route flap dampening information\n"
13441 "Network to clear damping information\n"
13442 "Network mask\n")
13443 {
13444 int ret;
13445 char prefix_str[BUFSIZ];
13446
13447 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
13448 if (! ret)
13449 {
13450 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
13451 return CMD_WARNING;
13452 }
13453
13454 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
13455 SAFI_UNICAST, NULL, 0);
13456 }
13457
13458 static int
13459 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
13460 afi_t afi, safi_t safi, int *write)
13461 {
13462 struct bgp_node *prn;
13463 struct bgp_node *rn;
13464 struct bgp_table *table;
13465 struct prefix *p;
13466 struct prefix_rd *prd;
13467 struct bgp_static *bgp_static;
13468 u_int32_t label;
13469 char buf[SU_ADDRSTRLEN];
13470 char rdbuf[RD_ADDRSTRLEN];
13471
13472 /* Network configuration. */
13473 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
13474 if ((table = prn->info) != NULL)
13475 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
13476 if ((bgp_static = rn->info) != NULL)
13477 {
13478 p = &rn->p;
13479 prd = (struct prefix_rd *) &prn->p;
13480
13481 /* "address-family" display. */
13482 bgp_config_write_family_header (vty, afi, safi, write);
13483
13484 /* "network" configuration display. */
13485 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
13486 label = decode_label (bgp_static->tag);
13487
13488 vty_out (vty, " network %s/%d rd %s tag %d",
13489 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13490 p->prefixlen,
13491 rdbuf, label);
13492 vty_out (vty, "%s", VTY_NEWLINE);
13493 }
13494 return 0;
13495 }
13496
13497 /* Configuration of static route announcement and aggregate
13498 information. */
13499 int
13500 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
13501 afi_t afi, safi_t safi, int *write)
13502 {
13503 struct bgp_node *rn;
13504 struct prefix *p;
13505 struct bgp_static *bgp_static;
13506 struct bgp_aggregate *bgp_aggregate;
13507 char buf[SU_ADDRSTRLEN];
13508
13509 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
13510 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
13511
13512 /* Network configuration. */
13513 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
13514 if ((bgp_static = rn->info) != NULL)
13515 {
13516 p = &rn->p;
13517
13518 /* "address-family" display. */
13519 bgp_config_write_family_header (vty, afi, safi, write);
13520
13521 /* "network" configuration display. */
13522 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13523 {
13524 u_int32_t destination;
13525 struct in_addr netmask;
13526
13527 destination = ntohl (p->u.prefix4.s_addr);
13528 masklen2ip (p->prefixlen, &netmask);
13529 vty_out (vty, " network %s",
13530 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
13531
13532 if ((IN_CLASSC (destination) && p->prefixlen == 24)
13533 || (IN_CLASSB (destination) && p->prefixlen == 16)
13534 || (IN_CLASSA (destination) && p->prefixlen == 8)
13535 || p->u.prefix4.s_addr == 0)
13536 {
13537 /* Natural mask is not display. */
13538 }
13539 else
13540 vty_out (vty, " mask %s", inet_ntoa (netmask));
13541 }
13542 else
13543 {
13544 vty_out (vty, " network %s/%d",
13545 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13546 p->prefixlen);
13547 }
13548
13549 if (bgp_static->rmap.name)
13550 vty_out (vty, " route-map %s", bgp_static->rmap.name);
13551 else
13552 {
13553 if (bgp_static->backdoor)
13554 vty_out (vty, " backdoor");
13555 }
13556
13557 vty_out (vty, "%s", VTY_NEWLINE);
13558 }
13559
13560 /* Aggregate-address configuration. */
13561 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
13562 if ((bgp_aggregate = rn->info) != NULL)
13563 {
13564 p = &rn->p;
13565
13566 /* "address-family" display. */
13567 bgp_config_write_family_header (vty, afi, safi, write);
13568
13569 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13570 {
13571 struct in_addr netmask;
13572
13573 masklen2ip (p->prefixlen, &netmask);
13574 vty_out (vty, " aggregate-address %s %s",
13575 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13576 inet_ntoa (netmask));
13577 }
13578 else
13579 {
13580 vty_out (vty, " aggregate-address %s/%d",
13581 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13582 p->prefixlen);
13583 }
13584
13585 if (bgp_aggregate->as_set)
13586 vty_out (vty, " as-set");
13587
13588 if (bgp_aggregate->summary_only)
13589 vty_out (vty, " summary-only");
13590
13591 vty_out (vty, "%s", VTY_NEWLINE);
13592 }
13593
13594 return 0;
13595 }
13596
13597 int
13598 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
13599 {
13600 struct bgp_node *rn;
13601 struct bgp_distance *bdistance;
13602
13603 /* Distance configuration. */
13604 if (bgp->distance_ebgp
13605 && bgp->distance_ibgp
13606 && bgp->distance_local
13607 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
13608 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
13609 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
13610 vty_out (vty, " distance bgp %d %d %d%s",
13611 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
13612 VTY_NEWLINE);
13613
13614 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
13615 if ((bdistance = rn->info) != NULL)
13616 {
13617 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
13618 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
13619 bdistance->access_list ? bdistance->access_list : "",
13620 VTY_NEWLINE);
13621 }
13622
13623 return 0;
13624 }
13625
13626 /* Allocate routing table structure and install commands. */
13627 void
13628 bgp_route_init (void)
13629 {
13630 /* Init BGP distance table. */
13631 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
13632
13633 /* IPv4 BGP commands. */
13634 install_element (BGP_NODE, &bgp_table_map_cmd);
13635 install_element (BGP_NODE, &bgp_network_cmd);
13636 install_element (BGP_NODE, &bgp_network_mask_cmd);
13637 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
13638 install_element (BGP_NODE, &bgp_network_route_map_cmd);
13639 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
13640 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
13641 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
13642 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
13643 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
13644 install_element (BGP_NODE, &no_bgp_table_map_cmd);
13645 install_element (BGP_NODE, &no_bgp_network_cmd);
13646 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
13647 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
13648 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
13649 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
13650 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13651 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
13652 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
13653 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
13654
13655 install_element (BGP_NODE, &aggregate_address_cmd);
13656 install_element (BGP_NODE, &aggregate_address_mask_cmd);
13657 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
13658 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
13659 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
13660 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
13661 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
13662 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
13663 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
13664 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
13665 install_element (BGP_NODE, &no_aggregate_address_cmd);
13666 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
13667 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
13668 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
13669 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
13670 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
13671 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
13672 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
13673 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13674 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13675
13676 /* IPv4 unicast configuration. */
13677 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
13678 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
13679 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
13680 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
13681 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
13682 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
13683 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
13684 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
13685 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
13686 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
13687 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
13688 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
13689 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
13690 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13691
13692 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
13693 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
13694 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
13695 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
13696 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
13697 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
13698 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
13699 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
13700 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
13701 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
13702 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
13703 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
13704 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
13705 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
13706 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
13707 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
13708 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
13709 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
13710 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13711 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13712
13713 /* IPv4 multicast configuration. */
13714 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
13715 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
13716 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
13717 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
13718 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
13719 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
13720 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
13721 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
13722 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
13723 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
13724 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
13725 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
13726 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
13727 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13728 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
13729 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
13730 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
13731 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
13732 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
13733 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
13734 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
13735 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
13736 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
13737 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
13738 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
13739 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
13740 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
13741 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
13742 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
13743 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
13744 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
13745 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
13746 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13747 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13748
13749 install_element (VIEW_NODE, &show_ip_bgp_cmd);
13750 install_element (VIEW_NODE, &show_ip_bgp_csv_cmd);
13751 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
13752 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
13753 install_element (VIEW_NODE, &show_bgp_ipv4_safi_csv_cmd);
13754 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
13755 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
13756 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
13757 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
13758 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
13759 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
13760 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13761 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
13762 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
13763 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13764 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
13765 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
13766 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
13767 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13768 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13769 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
13770 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
13771 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
13772 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
13773 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
13774 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
13775 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
13776 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
13777 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
13778 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
13779 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
13780 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
13781 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
13782 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
13783 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
13784 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
13785 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
13786 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
13787 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
13788 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
13789 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
13790 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
13791 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
13792 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13793 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
13794 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
13795 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
13796 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
13797 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
13798 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
13799 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
13800 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
13801 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13802 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13803 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13804 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13805 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
13806 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
13807 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
13808 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
13809 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
13810 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
13811 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
13812 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
13813 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_csv_cmd);
13814 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_csv_rmap_cmd);
13815 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
13816 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
13817 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
13818 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
13819 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
13820 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
13821 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
13822 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
13823 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_csv_cmd);
13824 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
13825 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
13826 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
13827 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
13828 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
13829 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
13830 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
13831 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
13832 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
13833 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
13834 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
13835 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
13836 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
13837 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
13838 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
13839 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
13840 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
13841 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
13842 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
13843 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
13844 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
13845 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13846 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
13847 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
13848 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
13849 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
13850 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
13851 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
13852 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
13853
13854 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
13855 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
13856 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
13857 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
13858 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
13859 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
13860 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13861 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
13862 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
13863 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13864 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
13865 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
13866 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
13867 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13868 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13869 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
13870 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
13871 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
13872 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
13873 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
13874 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
13875 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
13876 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
13877 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
13878 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
13879 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13880 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
13881 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
13882 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
13883 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
13884 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
13885 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
13886 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
13887 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
13888 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13889 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13890 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13891 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13892 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
13893 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
13894 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
13895 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
13896 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
13897 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
13898 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
13899 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
13900
13901 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
13902 install_element (ENABLE_NODE, &show_ip_bgp_csv_cmd);
13903 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
13904 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
13905 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_csv_cmd);
13906 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
13907 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
13908 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
13909 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
13910 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
13911 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
13912 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13913 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
13914 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
13915 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13916 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
13917 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
13918 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
13919 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13920 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13921 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
13922 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
13923 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
13924 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
13925 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
13926 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
13927 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
13928 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
13929 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
13930 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
13931 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
13932 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
13933 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
13934 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
13935 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
13936 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
13937 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
13938 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
13939 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
13940 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
13941 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
13942 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
13943 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
13944 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13945 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
13946 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
13947 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
13948 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
13949 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
13950 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
13951 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
13952 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
13953 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13954 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13955 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13956 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13957 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
13958 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
13959 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
13960 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
13961 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
13962 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
13963 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
13964 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_csv_cmd);
13965 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
13966 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_csv_rmap_cmd);
13967 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
13968 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
13969 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
13970 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
13971 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
13972 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
13973 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
13974 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
13975 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_csv_cmd);
13976 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
13977 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
13978 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
13979 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
13980 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
13981 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
13982 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
13983 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
13984 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
13985 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
13986 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
13987 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
13988 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
13989 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
13990 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
13991 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
13992 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
13993 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
13994 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
13995 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
13996 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
13997 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13998 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
13999 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
14000 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
14001 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
14002 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
14003 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
14004 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
14005
14006 /* BGP dampening clear commands */
14007 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14008 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14009 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14010 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14011
14012 /* prefix count */
14013 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14014 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14015 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
14016 #ifdef HAVE_IPV6
14017 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14018
14019 /* New config IPv6 BGP commands. */
14020 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
14021 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14022 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
14023 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
14024 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14025 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14026
14027 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14028 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14029 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14030 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
14031
14032 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14033 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
14034
14035 /* Old config IPv6 BGP commands. */
14036 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14037 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14038
14039 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14040 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14041 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14042 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14043
14044 install_element (VIEW_NODE, &show_bgp_cmd);
14045 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
14046 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
14047 install_element (VIEW_NODE, &show_bgp_ipv6_safi_csv_cmd);
14048 install_element (VIEW_NODE, &show_bgp_route_cmd);
14049 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
14050 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
14051 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14052 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14053 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14054 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14055 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
14056 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14057 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14058 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14059 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14060 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14061 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14062 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14063 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14064 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14065 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14066 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14067 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14068 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14069 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14070 install_element (VIEW_NODE, &show_bgp_community_cmd);
14071 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14072 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14073 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14074 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14075 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14076 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14077 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14078 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14079 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14080 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14081 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14082 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14083 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14084 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14085 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14086 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14087 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14088 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14089 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14090 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14091 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14092 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14093 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14094 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_csv_cmd);
14095 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_csv_cmd);
14096 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14097 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14098 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14099 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14100 install_element (VIEW_NODE, &show_bgp_neighbor_routes_csv_cmd);
14101 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_csv_cmd);
14102 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14103 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14104 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14105 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14106 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14107 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14108 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
14109 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
14110 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
14111 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
14112 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
14113 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
14114 install_element (VIEW_NODE, &show_bgp_view_cmd);
14115 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
14116 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
14117 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
14118 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
14119 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
14120 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
14121 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
14122 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_csv_cmd);
14123 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd);
14124 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
14125 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
14126 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
14127 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_csv_cmd);
14128 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
14129 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
14130 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
14131 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
14132 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
14133 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
14134 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
14135 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
14136 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
14137 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
14138 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
14139 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
14140 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
14141
14142 /* Restricted:
14143 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
14144 */
14145 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
14146 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
14147 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
14148 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
14149 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14150 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14151 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
14152 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
14153 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14154 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
14155 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14156 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14157 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
14158 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
14159 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
14160 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
14161 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
14162 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
14163 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
14164 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
14165 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
14166 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
14167 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
14168 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
14169 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
14170 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
14171 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
14172 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
14173 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
14174 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
14175 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
14176 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
14177 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
14178 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
14179 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
14180 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
14181 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
14182 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
14183 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
14184 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
14185 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
14186 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
14187
14188 install_element (ENABLE_NODE, &show_bgp_cmd);
14189 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
14190 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
14191 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_csv_cmd);
14192 install_element (ENABLE_NODE, &show_bgp_route_cmd);
14193 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
14194 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
14195 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
14196 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14197 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14198 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
14199 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
14200 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14201 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14202 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
14203 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14204 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
14205 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
14206 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
14207 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
14208 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
14209 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
14210 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
14211 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
14212 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
14213 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
14214 install_element (ENABLE_NODE, &show_bgp_community_cmd);
14215 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
14216 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
14217 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
14218 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
14219 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
14220 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
14221 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
14222 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
14223 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
14224 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
14225 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
14226 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
14227 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
14228 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
14229 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
14230 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
14231 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
14232 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
14233 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14234 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
14235 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14236 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
14237 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14238 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_csv_cmd);
14239 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_csv_cmd);
14240 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
14241 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14242 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
14243 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14244 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_csv_cmd);
14245 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_csv_cmd);
14246 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14247 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14248 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
14249 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14250 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
14251 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14252 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
14253 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
14254 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
14255 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
14256 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
14257 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
14258 install_element (ENABLE_NODE, &show_bgp_view_cmd);
14259 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
14260 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
14261 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
14262 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
14263 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
14264 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
14265 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
14266 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_csv_cmd);
14267 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd);
14268 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
14269 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
14270 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
14271 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_csv_cmd);
14272 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
14273 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
14274 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
14275 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
14276 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
14277 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
14278 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
14279 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
14280 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
14281 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
14282 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
14283 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
14284 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
14285
14286 /* Statistics */
14287 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
14288 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
14289 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
14290 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
14291
14292 /* old command */
14293 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14294 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14295 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
14296 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
14297 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
14298 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
14299 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
14300 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
14301 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
14302 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
14303 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
14304 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
14305 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
14306 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
14307 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
14308 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
14309 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14310 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14311 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
14312 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
14313 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
14314 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
14315 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14316 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
14317 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
14318 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
14319 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
14320 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
14321 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
14322 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
14323 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14324 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14325 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14326 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
14327 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14328 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14329
14330 /* old command */
14331 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
14332 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
14333 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
14334 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
14335 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
14336 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
14337 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
14338 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
14339 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
14340 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
14341 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
14342 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
14343 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
14344 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
14345 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
14346 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
14347 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14348 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14349 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
14350 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
14351 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
14352 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
14353 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14354 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
14355 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
14356 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
14357 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
14358 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
14359 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
14360 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
14361 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14362 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14363 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14364 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
14365 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14366 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14367
14368 /* old command */
14369 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14370 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14371 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14372 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14373
14374 /* old command */
14375 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14376 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14377 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14378 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14379
14380 /* old command */
14381 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
14382 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
14383 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14384 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14385 #endif /* HAVE_IPV6 */
14386
14387 install_element (BGP_NODE, &bgp_distance_cmd);
14388 install_element (BGP_NODE, &no_bgp_distance_cmd);
14389 install_element (BGP_NODE, &no_bgp_distance2_cmd);
14390 install_element (BGP_NODE, &bgp_distance_source_cmd);
14391 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
14392 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
14393 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
14394
14395 install_element (BGP_NODE, &bgp_damp_set_cmd);
14396 install_element (BGP_NODE, &bgp_damp_set2_cmd);
14397 install_element (BGP_NODE, &bgp_damp_set3_cmd);
14398 install_element (BGP_NODE, &bgp_damp_unset_cmd);
14399 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
14400 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
14401 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
14402 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
14403 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
14404 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
14405
14406 /* Deprecated AS-Pathlimit commands */
14407 install_element (BGP_NODE, &bgp_network_ttl_cmd);
14408 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
14409 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
14410 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
14411 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
14412 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
14413
14414 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
14415 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
14416 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
14417 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
14418 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
14419 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
14420
14421 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
14422 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
14423 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
14424 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
14425 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
14426 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
14427
14428 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
14429 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
14430 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
14431 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
14432 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
14433 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
14434
14435 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
14436 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
14437 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
14438 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
14439 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
14440 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
14441
14442 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
14443 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
14444 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
14445 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
14446 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
14447 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
14448
14449 #ifdef HAVE_IPV6
14450 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
14451 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
14452 #endif
14453 }
14454
14455 void
14456 bgp_route_finish (void)
14457 {
14458 bgp_table_unlock (bgp_distance_table);
14459 bgp_distance_table = NULL;
14460 }