]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
Changes to improve BGP convergence time:
[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. Rourter-ID comparision. */
544 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
545 new_id.s_addr = newattre->originator_id.s_addr;
546 else
547 new_id.s_addr = new->peer->remote_id.s_addr;
548 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
549 exist_id.s_addr = existattre->originator_id.s_addr;
550 else
551 exist_id.s_addr = exist->peer->remote_id.s_addr;
552
553 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
554 return 1;
555 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
556 return 0;
557
558 /* 12. Cluster length comparision. */
559 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
560 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
561
562 if (new_cluster < exist_cluster)
563 return 1;
564 if (new_cluster > exist_cluster)
565 return 0;
566
567 /* 13. Neighbor address comparision. */
568 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
569
570 if (ret == 1)
571 return 0;
572 if (ret == -1)
573 return 1;
574
575 return 1;
576 }
577
578 static enum filter_type
579 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
580 afi_t afi, safi_t safi)
581 {
582 struct bgp_filter *filter;
583
584 filter = &peer->filter[afi][safi];
585
586 #define FILTER_EXIST_WARN(F,f,filter) \
587 if (BGP_DEBUG (update, UPDATE_IN) \
588 && !(F ## _IN (filter))) \
589 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
590 peer->host, #f, F ## _IN_NAME(filter));
591
592 if (DISTRIBUTE_IN_NAME (filter)) {
593 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
594
595 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
596 return FILTER_DENY;
597 }
598
599 if (PREFIX_LIST_IN_NAME (filter)) {
600 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
601
602 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
603 return FILTER_DENY;
604 }
605
606 if (FILTER_LIST_IN_NAME (filter)) {
607 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
608
609 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
610 return FILTER_DENY;
611 }
612
613 return FILTER_PERMIT;
614 #undef FILTER_EXIST_WARN
615 }
616
617 static enum filter_type
618 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
619 afi_t afi, safi_t safi)
620 {
621 struct bgp_filter *filter;
622
623 filter = &peer->filter[afi][safi];
624
625 #define FILTER_EXIST_WARN(F,f,filter) \
626 if (BGP_DEBUG (update, UPDATE_OUT) \
627 && !(F ## _OUT (filter))) \
628 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
629 peer->host, #f, F ## _OUT_NAME(filter));
630
631 if (DISTRIBUTE_OUT_NAME (filter)) {
632 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
633
634 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
635 return FILTER_DENY;
636 }
637
638 if (PREFIX_LIST_OUT_NAME (filter)) {
639 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
640
641 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
642 return FILTER_DENY;
643 }
644
645 if (FILTER_LIST_OUT_NAME (filter)) {
646 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
647
648 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
649 return FILTER_DENY;
650 }
651
652 return FILTER_PERMIT;
653 #undef FILTER_EXIST_WARN
654 }
655
656 /* If community attribute includes no_export then return 1. */
657 static int
658 bgp_community_filter (struct peer *peer, struct attr *attr)
659 {
660 if (attr->community)
661 {
662 /* NO_ADVERTISE check. */
663 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
664 return 1;
665
666 /* NO_EXPORT check. */
667 if (peer->sort == BGP_PEER_EBGP &&
668 community_include (attr->community, COMMUNITY_NO_EXPORT))
669 return 1;
670
671 /* NO_EXPORT_SUBCONFED check. */
672 if (peer->sort == BGP_PEER_EBGP
673 || peer->sort == BGP_PEER_CONFED)
674 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
675 return 1;
676 }
677 return 0;
678 }
679
680 /* Route reflection loop check. */
681 static int
682 bgp_cluster_filter (struct peer *peer, struct attr *attr)
683 {
684 struct in_addr cluster_id;
685
686 if (attr->extra && attr->extra->cluster)
687 {
688 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
689 cluster_id = peer->bgp->cluster_id;
690 else
691 cluster_id = peer->bgp->router_id;
692
693 if (cluster_loop_check (attr->extra->cluster, cluster_id))
694 return 1;
695 }
696 return 0;
697 }
698
699 static int
700 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
701 afi_t afi, safi_t safi, char *rmap_name)
702 {
703 struct bgp_filter *filter;
704 struct bgp_info info;
705 route_map_result_t ret;
706 struct route_map *rmap = NULL;
707
708 filter = &peer->filter[afi][safi];
709
710 /* Apply default weight value. */
711 if (peer->weight)
712 (bgp_attr_extra_get (attr))->weight = peer->weight;
713
714 if (rmap_name)
715 {
716 rmap = route_map_lookup_by_name(rmap_name);
717 }
718 else
719 {
720 if (ROUTE_MAP_IN_NAME(filter))
721 rmap = ROUTE_MAP_IN (filter);
722 }
723
724 /* Route map apply. */
725 if (rmap)
726 {
727 /* Duplicate current value to new strucutre for modification. */
728 info.peer = peer;
729 info.attr = attr;
730
731 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
732
733 /* Apply BGP route map to the attribute. */
734 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
735
736 peer->rmap_type = 0;
737
738 if (ret == RMAP_DENYMATCH)
739 {
740 /* Free newly generated AS path and community by route-map. */
741 bgp_attr_flush (attr);
742 return RMAP_DENY;
743 }
744 }
745 return RMAP_PERMIT;
746 }
747
748 static int
749 bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
750 afi_t afi, safi_t safi, char *rmap_name)
751 {
752 struct bgp_filter *filter;
753 struct bgp_info info;
754 route_map_result_t ret;
755 struct route_map *rmap = NULL;
756
757 filter = &peer->filter[afi][safi];
758
759 /* Apply default weight value. */
760 if (peer->weight)
761 (bgp_attr_extra_get (attr))->weight = peer->weight;
762
763 if (rmap_name)
764 {
765 rmap = route_map_lookup_by_name(rmap_name);
766 }
767 else
768 {
769 if (ROUTE_MAP_OUT_NAME(filter))
770 rmap = ROUTE_MAP_OUT (filter);
771 }
772
773 /* Route map apply. */
774 if (rmap)
775 {
776 /* Duplicate current value to new strucutre for modification. */
777 info.peer = peer;
778 info.attr = attr;
779
780 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
781
782 /* Apply BGP route map to the attribute. */
783 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
784
785 peer->rmap_type = 0;
786
787 if (ret == RMAP_DENYMATCH)
788 /* caller has multiple error paths with bgp_attr_flush() */
789 return RMAP_DENY;
790 }
791 return RMAP_PERMIT;
792 }
793
794 static int
795 bgp_export_modifier (struct peer *rsclient, struct peer *peer,
796 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
797 {
798 struct bgp_filter *filter;
799 struct bgp_info info;
800 route_map_result_t ret;
801
802 filter = &peer->filter[afi][safi];
803
804 /* Route map apply. */
805 if (ROUTE_MAP_EXPORT_NAME (filter))
806 {
807 /* Duplicate current value to new strucutre for modification. */
808 info.peer = rsclient;
809 info.attr = attr;
810
811 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
812
813 /* Apply BGP route map to the attribute. */
814 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
815
816 rsclient->rmap_type = 0;
817
818 if (ret == RMAP_DENYMATCH)
819 {
820 /* Free newly generated AS path and community by route-map. */
821 bgp_attr_flush (attr);
822 return RMAP_DENY;
823 }
824 }
825 return RMAP_PERMIT;
826 }
827
828 static int
829 bgp_import_modifier (struct peer *rsclient, struct peer *peer,
830 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
831 {
832 struct bgp_filter *filter;
833 struct bgp_info info;
834 route_map_result_t ret;
835
836 filter = &rsclient->filter[afi][safi];
837
838 /* Apply default weight value. */
839 if (peer->weight)
840 (bgp_attr_extra_get (attr))->weight = peer->weight;
841
842 /* Route map apply. */
843 if (ROUTE_MAP_IMPORT_NAME (filter))
844 {
845 /* Duplicate current value to new strucutre for modification. */
846 info.peer = peer;
847 info.attr = attr;
848
849 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
850
851 /* Apply BGP route map to the attribute. */
852 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
853
854 peer->rmap_type = 0;
855
856 if (ret == RMAP_DENYMATCH)
857 {
858 /* Free newly generated AS path and community by route-map. */
859 bgp_attr_flush (attr);
860 return RMAP_DENY;
861 }
862 }
863 return RMAP_PERMIT;
864 }
865
866
867 /* If this is an EBGP peer with remove-private-AS */
868 void
869 bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
870 struct peer *peer, struct attr *attr)
871 {
872 if (peer->sort == BGP_PEER_EBGP &&
873 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS))
874 {
875 // Take action on the entire aspath
876 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
877 {
878 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
879 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
880
881 // The entire aspath consists of private ASNs so create an empty aspath
882 else if (aspath_private_as_check (attr->aspath))
883 attr->aspath = aspath_empty_get ();
884
885 // There are some public and some private ASNs, remove the private ASNs
886 else
887 attr->aspath = aspath_remove_private_asns (attr->aspath);
888 }
889
890 // 'all' was not specified so the entire aspath must be private ASNs
891 // for us to do anything
892 else if (aspath_private_as_check (attr->aspath))
893 {
894 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
895 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
896 else
897 attr->aspath = aspath_empty_get ();
898 }
899 }
900 }
901
902 static int
903 bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
904 struct attr *attr, afi_t afi, safi_t safi)
905 {
906 int ret;
907 char buf[SU_ADDRSTRLEN];
908 struct bgp_filter *filter;
909 struct peer *from;
910 struct bgp *bgp;
911 int transparent;
912 int reflect;
913 struct attr *riattr;
914
915 from = ri->peer;
916 filter = &peer->filter[afi][safi];
917 bgp = peer->bgp;
918 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
919
920 if (DISABLE_BGP_ANNOUNCE)
921 return 0;
922
923 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
924 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
925 return 0;
926
927 /* Do not send back route to sender. */
928 if (from == peer)
929 return 0;
930
931 /* Aggregate-address suppress check. */
932 if (ri->extra && ri->extra->suppress)
933 if (! UNSUPPRESS_MAP_NAME (filter))
934 return 0;
935
936 /* Default route check. */
937 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
938 {
939 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
940 return 0;
941 #ifdef HAVE_IPV6
942 else if (p->family == AF_INET6 && p->prefixlen == 0)
943 return 0;
944 #endif /* HAVE_IPV6 */
945 }
946
947 /* Transparency check. */
948 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
949 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
950 transparent = 1;
951 else
952 transparent = 0;
953
954 /* If community is not disabled check the no-export and local. */
955 if (! transparent && bgp_community_filter (peer, riattr))
956 return 0;
957
958 /* If the attribute has originator-id and it is same as remote
959 peer's id. */
960 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
961 {
962 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
963 {
964 if (BGP_DEBUG (filter, FILTER))
965 zlog (peer->log, LOG_DEBUG,
966 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
967 peer->host,
968 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
969 p->prefixlen);
970 return 0;
971 }
972 }
973
974 /* ORF prefix-list filter check */
975 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
976 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
977 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
978 if (peer->orf_plist[afi][safi])
979 {
980 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
981 return 0;
982 }
983
984 /* Output filter check. */
985 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
986 {
987 if (BGP_DEBUG (filter, FILTER))
988 zlog (peer->log, LOG_DEBUG,
989 "%s [Update:SEND] %s/%d is filtered",
990 peer->host,
991 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
992 p->prefixlen);
993 return 0;
994 }
995
996 #ifdef BGP_SEND_ASPATH_CHECK
997 /* AS path loop check. */
998 if (aspath_loop_check (riattr->aspath, peer->as))
999 {
1000 if (BGP_DEBUG (filter, FILTER))
1001 zlog (peer->log, LOG_DEBUG,
1002 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1003 peer->host, peer->as);
1004 return 0;
1005 }
1006 #endif /* BGP_SEND_ASPATH_CHECK */
1007
1008 /* If we're a CONFED we need to loop check the CONFED ID too */
1009 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1010 {
1011 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1012 {
1013 if (BGP_DEBUG (filter, FILTER))
1014 zlog (peer->log, LOG_DEBUG,
1015 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1016 peer->host,
1017 bgp->confed_id);
1018 return 0;
1019 }
1020 }
1021
1022 /* Route-Reflect check. */
1023 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1024 reflect = 1;
1025 else
1026 reflect = 0;
1027
1028 /* IBGP reflection check. */
1029 if (reflect)
1030 {
1031 /* A route from a Client peer. */
1032 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1033 {
1034 /* Reflect to all the Non-Client peers and also to the
1035 Client peers other than the originator. Originator check
1036 is already done. So there is noting to do. */
1037 /* no bgp client-to-client reflection check. */
1038 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1039 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1040 return 0;
1041 }
1042 else
1043 {
1044 /* A route from a Non-client peer. Reflect to all other
1045 clients. */
1046 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1047 return 0;
1048 }
1049 }
1050
1051 /* For modify attribute, copy it to temporary structure. */
1052 bgp_attr_dup (attr, riattr);
1053
1054 /* If local-preference is not set. */
1055 if ((peer->sort == BGP_PEER_IBGP
1056 || peer->sort == BGP_PEER_CONFED)
1057 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1058 {
1059 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1060 attr->local_pref = bgp->default_local_pref;
1061 }
1062
1063 /* If originator-id is not set and the route is to be reflected,
1064 set the originator id */
1065 if (peer && from && peer->sort == BGP_PEER_IBGP &&
1066 from->sort == BGP_PEER_IBGP &&
1067 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1068 {
1069 attr->extra = bgp_attr_extra_get(attr);
1070 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1071 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1072 }
1073
1074 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1075 if (peer->sort == BGP_PEER_EBGP
1076 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1077 {
1078 if (ri->peer != bgp->peer_self && ! transparent
1079 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1080 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1081 }
1082
1083 /* next-hop-set */
1084 if (transparent
1085 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
1086 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
1087 && ((p->family == AF_INET && attr->nexthop.s_addr)
1088 #ifdef HAVE_IPV6
1089 || (p->family == AF_INET6 &&
1090 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1091 #endif /* HAVE_IPV6 */
1092 )))
1093 {
1094 /* NEXT-HOP Unchanged. */
1095 }
1096 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
1097 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
1098 #ifdef HAVE_IPV6
1099 || (p->family == AF_INET6 &&
1100 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1101 #endif /* HAVE_IPV6 */
1102 || (peer->sort == BGP_PEER_EBGP
1103 && (bgp_multiaccess_check_v4 (attr->nexthop, peer) == 0)))
1104 {
1105 /* Set IPv4 nexthop. */
1106 if (p->family == AF_INET)
1107 {
1108 if (safi == SAFI_MPLS_VPN)
1109 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1110 IPV4_MAX_BYTELEN);
1111 else
1112 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1113 }
1114 #ifdef HAVE_IPV6
1115 /* Set IPv6 nexthop. */
1116 if (p->family == AF_INET6)
1117 {
1118 /* IPv6 global nexthop must be included. */
1119 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
1120 IPV6_MAX_BYTELEN);
1121 attr->extra->mp_nexthop_len = 16;
1122 }
1123 #endif /* HAVE_IPV6 */
1124 }
1125
1126 #ifdef HAVE_IPV6
1127 if (p->family == AF_INET6)
1128 {
1129 /* Left nexthop_local unchanged if so configured. */
1130 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1131 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1132 {
1133 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1134 attr->extra->mp_nexthop_len=32;
1135 else
1136 attr->extra->mp_nexthop_len=16;
1137 }
1138
1139 /* Default nexthop_local treatment for non-RS-Clients */
1140 else
1141 {
1142 /* Link-local address should not be transit to different peer. */
1143 attr->extra->mp_nexthop_len = 16;
1144
1145 /* Set link-local address for shared network peer. */
1146 if (peer->shared_network
1147 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1148 {
1149 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
1150 IPV6_MAX_BYTELEN);
1151 attr->extra->mp_nexthop_len = 32;
1152 }
1153
1154 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1155 address.*/
1156 if (reflect)
1157 attr->extra->mp_nexthop_len = 16;
1158
1159 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1160 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
1161 attr->extra->mp_nexthop_len = 16;
1162 }
1163
1164 }
1165 #endif /* HAVE_IPV6 */
1166
1167 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1168
1169 /* Route map & unsuppress-map apply. */
1170 if (ROUTE_MAP_OUT_NAME (filter)
1171 || (ri->extra && ri->extra->suppress) )
1172 {
1173 struct bgp_info info;
1174 struct attr dummy_attr;
1175 struct attr_extra dummy_extra;
1176
1177 dummy_attr.extra = &dummy_extra;
1178
1179 info.peer = peer;
1180 info.attr = attr;
1181
1182 /* The route reflector is not allowed to modify the attributes
1183 of the reflected IBGP routes. */
1184 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) &&
1185 !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1186 {
1187 bgp_attr_dup (&dummy_attr, attr);
1188 info.attr = &dummy_attr;
1189 }
1190
1191 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1192
1193 if (ri->extra && ri->extra->suppress)
1194 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1195 else
1196 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1197
1198 peer->rmap_type = 0;
1199
1200 if (ret == RMAP_DENYMATCH)
1201 {
1202 bgp_attr_flush (attr);
1203 return 0;
1204 }
1205 }
1206 return 1;
1207 }
1208
1209 static int
1210 bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1211 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1212 {
1213 int ret;
1214 char buf[SU_ADDRSTRLEN];
1215 struct bgp_filter *filter;
1216 struct bgp_info info;
1217 struct peer *from;
1218 struct attr *riattr;
1219 struct bgp *bgp;
1220
1221 from = ri->peer;
1222 filter = &rsclient->filter[afi][safi];
1223 bgp = rsclient->bgp;
1224 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1225
1226 if (DISABLE_BGP_ANNOUNCE)
1227 return 0;
1228
1229 /* Do not send back route to sender. */
1230 if (from == rsclient)
1231 return 0;
1232
1233 /* Aggregate-address suppress check. */
1234 if (ri->extra && ri->extra->suppress)
1235 if (! UNSUPPRESS_MAP_NAME (filter))
1236 return 0;
1237
1238 /* Default route check. */
1239 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1240 PEER_STATUS_DEFAULT_ORIGINATE))
1241 {
1242 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1243 return 0;
1244 #ifdef HAVE_IPV6
1245 else if (p->family == AF_INET6 && p->prefixlen == 0)
1246 return 0;
1247 #endif /* HAVE_IPV6 */
1248 }
1249
1250 /* If the attribute has originator-id and it is same as remote
1251 peer's id. */
1252 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1253 {
1254 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1255 &riattr->extra->originator_id))
1256 {
1257 if (BGP_DEBUG (filter, FILTER))
1258 zlog (rsclient->log, LOG_DEBUG,
1259 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1260 rsclient->host,
1261 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1262 p->prefixlen);
1263 return 0;
1264 }
1265 }
1266
1267 /* ORF prefix-list filter check */
1268 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1269 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1270 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1271 if (rsclient->orf_plist[afi][safi])
1272 {
1273 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1274 return 0;
1275 }
1276
1277 /* Output filter check. */
1278 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
1279 {
1280 if (BGP_DEBUG (filter, FILTER))
1281 zlog (rsclient->log, LOG_DEBUG,
1282 "%s [Update:SEND] %s/%d is filtered",
1283 rsclient->host,
1284 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1285 p->prefixlen);
1286 return 0;
1287 }
1288
1289 #ifdef BGP_SEND_ASPATH_CHECK
1290 /* AS path loop check. */
1291 if (aspath_loop_check (riattr->aspath, rsclient->as))
1292 {
1293 if (BGP_DEBUG (filter, FILTER))
1294 zlog (rsclient->log, LOG_DEBUG,
1295 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1296 rsclient->host, rsclient->as);
1297 return 0;
1298 }
1299 #endif /* BGP_SEND_ASPATH_CHECK */
1300
1301 /* For modify attribute, copy it to temporary structure. */
1302 bgp_attr_dup (attr, riattr);
1303
1304 /* next-hop-set */
1305 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1306 #ifdef HAVE_IPV6
1307 || (p->family == AF_INET6 &&
1308 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1309 #endif /* HAVE_IPV6 */
1310 )
1311 {
1312 /* Set IPv4 nexthop. */
1313 if (p->family == AF_INET)
1314 {
1315 if (safi == SAFI_MPLS_VPN)
1316 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
1317 IPV4_MAX_BYTELEN);
1318 else
1319 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1320 }
1321 #ifdef HAVE_IPV6
1322 /* Set IPv6 nexthop. */
1323 if (p->family == AF_INET6)
1324 {
1325 /* IPv6 global nexthop must be included. */
1326 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
1327 IPV6_MAX_BYTELEN);
1328 attr->extra->mp_nexthop_len = 16;
1329 }
1330 #endif /* HAVE_IPV6 */
1331 }
1332
1333 #ifdef HAVE_IPV6
1334 if (p->family == AF_INET6)
1335 {
1336 struct attr_extra *attre = attr->extra;
1337
1338 /* Left nexthop_local unchanged if so configured. */
1339 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1340 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1341 {
1342 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1343 attre->mp_nexthop_len=32;
1344 else
1345 attre->mp_nexthop_len=16;
1346 }
1347
1348 /* Default nexthop_local treatment for RS-Clients */
1349 else
1350 {
1351 /* Announcer and RS-Client are both in the same network */
1352 if (rsclient->shared_network && from->shared_network &&
1353 (rsclient->ifindex == from->ifindex))
1354 {
1355 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1356 attre->mp_nexthop_len=32;
1357 else
1358 attre->mp_nexthop_len=16;
1359 }
1360
1361 /* Set link-local address for shared network peer. */
1362 else if (rsclient->shared_network
1363 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1364 {
1365 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
1366 IPV6_MAX_BYTELEN);
1367 attre->mp_nexthop_len = 32;
1368 }
1369
1370 else
1371 attre->mp_nexthop_len = 16;
1372 }
1373
1374 }
1375 #endif /* HAVE_IPV6 */
1376
1377 bgp_peer_remove_private_as(bgp, afi, safi, rsclient, attr);
1378
1379 /* Route map & unsuppress-map apply. */
1380 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
1381 {
1382 info.peer = rsclient;
1383 info.attr = attr;
1384
1385 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1386
1387 if (ri->extra && ri->extra->suppress)
1388 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1389 else
1390 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1391
1392 rsclient->rmap_type = 0;
1393
1394 if (ret == RMAP_DENYMATCH)
1395 {
1396 bgp_attr_flush (attr);
1397 return 0;
1398 }
1399 }
1400
1401 return 1;
1402 }
1403
1404 struct bgp_info_pair
1405 {
1406 struct bgp_info *old;
1407 struct bgp_info *new;
1408 };
1409
1410 static void
1411 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1412 struct bgp_maxpaths_cfg *mpath_cfg,
1413 struct bgp_info_pair *result)
1414 {
1415 struct bgp_info *new_select;
1416 struct bgp_info *old_select;
1417 struct bgp_info *ri;
1418 struct bgp_info *ri1;
1419 struct bgp_info *ri2;
1420 struct bgp_info *nextri = NULL;
1421 int paths_eq, do_mpath;
1422 struct list mp_list;
1423 char buf[INET6_BUFSIZ];
1424
1425 bgp_mp_list_init (&mp_list);
1426 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1427 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1428
1429 /* bgp deterministic-med */
1430 new_select = NULL;
1431 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1432 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1433 {
1434 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1435 continue;
1436 if (BGP_INFO_HOLDDOWN (ri1))
1437 continue;
1438
1439 new_select = ri1;
1440 if (do_mpath)
1441 bgp_mp_list_add (&mp_list, ri1);
1442 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
1443 if (ri1->next)
1444 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1445 {
1446 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1447 continue;
1448 if (BGP_INFO_HOLDDOWN (ri2))
1449 continue;
1450
1451 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1452 || aspath_cmp_left_confed (ri1->attr->aspath,
1453 ri2->attr->aspath))
1454 {
1455 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1456 old_select = ri2;
1457 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1458 mpath_cfg))
1459 {
1460 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1461 new_select = ri2;
1462 if (do_mpath && !paths_eq)
1463 {
1464 bgp_mp_list_clear (&mp_list);
1465 bgp_mp_list_add (&mp_list, ri2);
1466 }
1467 }
1468
1469 if (do_mpath && paths_eq)
1470 bgp_mp_list_add (&mp_list, ri2);
1471
1472 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1473 }
1474 }
1475 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1476 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1477
1478 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1479 bgp_mp_list_clear (&mp_list);
1480 }
1481
1482 /* Check old selected route and new selected route. */
1483 old_select = NULL;
1484 new_select = NULL;
1485 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1486 {
1487 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1488 old_select = ri;
1489
1490 if (BGP_INFO_HOLDDOWN (ri))
1491 {
1492 /* reap REMOVED routes, if needs be
1493 * selected route must stay for a while longer though
1494 */
1495 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1496 && (ri != old_select))
1497 bgp_info_reap (rn, ri);
1498
1499 continue;
1500 }
1501
1502 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1503 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1504 {
1505 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1506 continue;
1507 }
1508 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1509 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
1510
1511 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg))
1512 {
1513 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1514 bgp_mp_dmed_deselect (new_select);
1515
1516 new_select = ri;
1517
1518 if (do_mpath && !paths_eq)
1519 {
1520 bgp_mp_list_clear (&mp_list);
1521 bgp_mp_list_add (&mp_list, ri);
1522 }
1523 }
1524 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1525 bgp_mp_dmed_deselect (ri);
1526
1527 if (do_mpath && paths_eq)
1528 bgp_mp_list_add (&mp_list, ri);
1529 }
1530
1531
1532 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1533 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1534
1535 bgp_info_mpath_aggregate_update (new_select, old_select);
1536 bgp_mp_list_clear (&mp_list);
1537
1538 result->old = old_select;
1539 result->new = new_select;
1540
1541 return;
1542 }
1543
1544 static int
1545 bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1546 struct bgp_node *rn, afi_t afi, safi_t safi)
1547 {
1548 struct prefix *p;
1549 struct attr attr;
1550 struct attr_extra extra;
1551
1552 p = &rn->p;
1553
1554 /* Announce route to Established peer. */
1555 if (peer->status != Established)
1556 return 0;
1557
1558 /* Address family configuration check. */
1559 if (! peer->afc_nego[afi][safi])
1560 return 0;
1561
1562 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1563 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1564 PEER_STATUS_ORF_WAIT_REFRESH))
1565 return 0;
1566
1567 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1568 attr.extra = &extra;
1569
1570 switch (bgp_node_table (rn)->type)
1571 {
1572 case BGP_TABLE_MAIN:
1573 /* Announcement to peer->conf. If the route is filtered,
1574 withdraw it. */
1575 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1576 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1577 else
1578 bgp_adj_out_unset (rn, peer, p, afi, safi);
1579 break;
1580 case BGP_TABLE_RSCLIENT:
1581 /* Announcement to peer->conf. If the route is filtered,
1582 withdraw it. */
1583 if (selected &&
1584 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1585 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1586 else
1587 bgp_adj_out_unset (rn, peer, p, afi, safi);
1588 break;
1589 }
1590
1591 return 0;
1592 }
1593
1594 struct bgp_process_queue
1595 {
1596 struct bgp *bgp;
1597 struct bgp_node *rn;
1598 afi_t afi;
1599 safi_t safi;
1600 };
1601
1602 static wq_item_status
1603 bgp_process_rsclient (struct work_queue *wq, void *data)
1604 {
1605 struct bgp_process_queue *pq = data;
1606 struct bgp *bgp = pq->bgp;
1607 struct bgp_node *rn = pq->rn;
1608 afi_t afi = pq->afi;
1609 safi_t safi = pq->safi;
1610 struct bgp_info *new_select;
1611 struct bgp_info *old_select;
1612 struct bgp_info_pair old_and_new;
1613 struct listnode *node, *nnode;
1614 struct peer *rsclient;
1615
1616 /* Is it end of initial update? (after startup) */
1617 if (!rn)
1618 {
1619 /* This is just to keep the display sane in case all the peers are
1620 rsclients only */
1621 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1622 sizeof(bgp->update_delay_zebra_resume_time));
1623
1624 bgp->rsclient_peers_update_hold = 0;
1625 bgp_start_routeadv(bgp);
1626 return WQ_SUCCESS;
1627 }
1628
1629 rsclient = bgp_node_table (rn)->owner;
1630
1631 /* Best path selection. */
1632 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1633 new_select = old_and_new.new;
1634 old_select = old_and_new.old;
1635
1636 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1637 {
1638 if (rsclient->group)
1639 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1640 {
1641 /* Nothing to do. */
1642 if (old_select && old_select == new_select)
1643 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1644 continue;
1645
1646 if (old_select)
1647 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1648 if (new_select)
1649 {
1650 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1651 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1652 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1653 }
1654
1655 bgp_process_announce_selected (rsclient, new_select, rn,
1656 afi, safi);
1657 }
1658 }
1659 else
1660 {
1661 if (old_select)
1662 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1663 if (new_select)
1664 {
1665 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1666 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1667 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1668 }
1669 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
1670 }
1671
1672 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1673 bgp_info_reap (rn, old_select);
1674
1675 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1676 return WQ_SUCCESS;
1677 }
1678
1679 static wq_item_status
1680 bgp_process_main (struct work_queue *wq, void *data)
1681 {
1682 struct bgp_process_queue *pq = data;
1683 struct bgp *bgp = pq->bgp;
1684 struct bgp_node *rn = pq->rn;
1685 afi_t afi = pq->afi;
1686 safi_t safi = pq->safi;
1687 struct prefix *p = &rn->p;
1688 struct bgp_info *new_select;
1689 struct bgp_info *old_select;
1690 struct bgp_info_pair old_and_new;
1691 struct listnode *node, *nnode;
1692 struct peer *peer;
1693
1694 /* Is it end of initial update? (after startup) */
1695 if (!rn)
1696 {
1697 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1698 sizeof(bgp->update_delay_zebra_resume_time));
1699
1700 bgp->main_zebra_update_hold = 0;
1701 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1702 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1703 {
1704 bgp_zebra_announce_table(bgp, afi, safi);
1705 }
1706 bgp->main_peers_update_hold = 0;
1707
1708 bgp_start_routeadv(bgp);
1709 return WQ_SUCCESS;
1710 }
1711
1712 /* Best path selection. */
1713 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1714 old_select = old_and_new.old;
1715 new_select = old_and_new.new;
1716
1717 /* Nothing to do. */
1718 if (old_select && old_select == new_select && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
1719 {
1720 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1721 {
1722 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1723 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
1724 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1725
1726 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1727 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1728 return WQ_SUCCESS;
1729 }
1730 }
1731
1732 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1733 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1734
1735 if (old_select)
1736 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1737 if (new_select)
1738 {
1739 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1740 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1741 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1742 }
1743
1744
1745 /* Check each BGP peer. */
1746 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
1747 {
1748 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
1749 }
1750
1751 /* FIB update. */
1752 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1753 ! bgp_option_check (BGP_OPT_NO_FIB)))
1754 {
1755 if (new_select
1756 && new_select->type == ZEBRA_ROUTE_BGP
1757 && new_select->sub_type == BGP_ROUTE_NORMAL)
1758 bgp_zebra_announce (p, new_select, bgp, afi, safi);
1759 else
1760 {
1761 /* Withdraw the route from the kernel. */
1762 if (old_select
1763 && old_select->type == ZEBRA_ROUTE_BGP
1764 && old_select->sub_type == BGP_ROUTE_NORMAL)
1765 bgp_zebra_withdraw (p, old_select, safi);
1766 }
1767 }
1768
1769 /* Reap old select bgp_info, it it has been removed */
1770 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1771 bgp_info_reap (rn, old_select);
1772
1773 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1774 return WQ_SUCCESS;
1775 }
1776
1777 static void
1778 bgp_processq_del (struct work_queue *wq, void *data)
1779 {
1780 struct bgp_process_queue *pq = data;
1781 struct bgp_table *table;
1782
1783 bgp_unlock (pq->bgp);
1784 if (pq->rn)
1785 {
1786 table = bgp_node_table (pq->rn);
1787 bgp_unlock_node (pq->rn);
1788 bgp_table_unlock (table);
1789 }
1790 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1791 }
1792
1793 static void
1794 bgp_process_queue_complete (struct work_queue *wq)
1795 {
1796 struct bgp *bgp;
1797 struct peer *peer;
1798 struct listnode *node, *nnode;
1799
1800 /* Schedule write thread either directly or through the MRAI timer
1801 * if needed.
1802 */
1803 bgp = bgp_get_default ();
1804 if (!bgp)
1805 return;
1806
1807 if (BGP_ROUTE_ADV_HOLD(bgp))
1808 return;
1809
1810 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
1811 bgp_peer_schedule_updates(peer);
1812 }
1813
1814 void
1815 bgp_process_queue_init (void)
1816 {
1817 bm->process_main_queue
1818 = work_queue_new (bm->master, "process_main_queue");
1819 bm->process_rsclient_queue
1820 = work_queue_new (bm->master, "process_rsclient_queue");
1821
1822 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1823 {
1824 zlog_err ("%s: Failed to allocate work queue", __func__);
1825 exit (1);
1826 }
1827
1828 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1829 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1830 bm->process_main_queue->spec.completion_func = &bgp_process_queue_complete;
1831 bm->process_main_queue->spec.max_retries = 0;
1832 bm->process_main_queue->spec.hold = 50;
1833 /* Use a higher yield value of 50ms for main queue processing */
1834 bm->process_main_queue->spec.yield = 50 * 1000L;
1835
1836 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1837 sizeof (struct work_queue *));
1838 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1839 }
1840
1841 void
1842 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1843 {
1844 struct bgp_process_queue *pqnode;
1845
1846 /* already scheduled for processing? */
1847 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1848 return;
1849
1850 if ( (bm->process_main_queue == NULL) ||
1851 (bm->process_rsclient_queue == NULL) )
1852 bgp_process_queue_init ();
1853
1854 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1855 sizeof (struct bgp_process_queue));
1856 if (!pqnode)
1857 return;
1858
1859 /* all unlocked in bgp_processq_del */
1860 bgp_table_lock (bgp_node_table (rn));
1861 pqnode->rn = bgp_lock_node (rn);
1862 pqnode->bgp = bgp;
1863 bgp_lock (bgp);
1864 pqnode->afi = afi;
1865 pqnode->safi = safi;
1866
1867 switch (bgp_node_table (rn)->type)
1868 {
1869 case BGP_TABLE_MAIN:
1870 work_queue_add (bm->process_main_queue, pqnode);
1871 break;
1872 case BGP_TABLE_RSCLIENT:
1873 work_queue_add (bm->process_rsclient_queue, pqnode);
1874 break;
1875 }
1876
1877 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1878 return;
1879 }
1880
1881 void
1882 bgp_add_eoiu_mark (struct bgp *bgp, bgp_table_t type)
1883 {
1884 struct bgp_process_queue *pqnode;
1885
1886 if ( (bm->process_main_queue == NULL) ||
1887 (bm->process_rsclient_queue == NULL) )
1888 bgp_process_queue_init ();
1889
1890 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1891 sizeof (struct bgp_process_queue));
1892 if (!pqnode)
1893 return;
1894
1895 pqnode->rn = NULL;
1896 pqnode->bgp = bgp;
1897 bgp_lock (bgp);
1898 switch (type)
1899 {
1900 case BGP_TABLE_MAIN:
1901 work_queue_add (bm->process_main_queue, pqnode);
1902 break;
1903 case BGP_TABLE_RSCLIENT:
1904 work_queue_add (bm->process_rsclient_queue, pqnode);
1905 break;
1906 }
1907
1908 return;
1909 }
1910
1911 static int
1912 bgp_maximum_prefix_restart_timer (struct thread *thread)
1913 {
1914 struct peer *peer;
1915
1916 peer = THREAD_ARG (thread);
1917 peer->t_pmax_restart = NULL;
1918
1919 if (BGP_DEBUG (events, EVENTS))
1920 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1921 peer->host);
1922
1923 peer_clear (peer, NULL);
1924
1925 return 0;
1926 }
1927
1928 int
1929 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1930 safi_t safi, int always)
1931 {
1932 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1933 return 0;
1934
1935 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
1936 {
1937 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1938 && ! always)
1939 return 0;
1940
1941 zlog (peer->log, LOG_INFO,
1942 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1943 "limit %ld", afi_safi_print (afi, safi), peer->host,
1944 peer->pcount[afi][safi], peer->pmax[afi][safi]);
1945 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1946
1947 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1948 return 0;
1949
1950 {
1951 u_int8_t ndata[7];
1952
1953 if (safi == SAFI_MPLS_VPN)
1954 safi = SAFI_MPLS_LABELED_VPN;
1955
1956 ndata[0] = (afi >> 8);
1957 ndata[1] = afi;
1958 ndata[2] = safi;
1959 ndata[3] = (peer->pmax[afi][safi] >> 24);
1960 ndata[4] = (peer->pmax[afi][safi] >> 16);
1961 ndata[5] = (peer->pmax[afi][safi] >> 8);
1962 ndata[6] = (peer->pmax[afi][safi]);
1963
1964 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1965 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1966 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1967 }
1968
1969 /* restart timer start */
1970 if (peer->pmax_restart[afi][safi])
1971 {
1972 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1973
1974 if (BGP_DEBUG (events, EVENTS))
1975 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1976 peer->host, peer->v_pmax_restart);
1977
1978 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1979 peer->v_pmax_restart);
1980 }
1981
1982 return 1;
1983 }
1984 else
1985 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1986
1987 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1988 {
1989 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1990 && ! always)
1991 return 0;
1992
1993 zlog (peer->log, LOG_INFO,
1994 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1995 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1996 peer->pmax[afi][safi]);
1997 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1998 }
1999 else
2000 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2001 return 0;
2002 }
2003
2004 /* Unconditionally remove the route from the RIB, without taking
2005 * damping into consideration (eg, because the session went down)
2006 */
2007 static void
2008 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2009 afi_t afi, safi_t safi)
2010 {
2011 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2012
2013 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2014 bgp_info_delete (rn, ri); /* keep historical info */
2015
2016 bgp_process (peer->bgp, rn, afi, safi);
2017 }
2018
2019 static void
2020 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2021 afi_t afi, safi_t safi)
2022 {
2023 int status = BGP_DAMP_NONE;
2024
2025 /* apply dampening, if result is suppressed, we'll be retaining
2026 * the bgp_info in the RIB for historical reference.
2027 */
2028 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2029 && peer->sort == BGP_PEER_EBGP)
2030 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2031 == BGP_DAMP_SUPPRESSED)
2032 {
2033 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2034 return;
2035 }
2036
2037 bgp_rib_remove (rn, ri, peer, afi, safi);
2038 }
2039
2040 static struct bgp_info *
2041 info_make (int type, int sub_type, struct peer *peer, struct attr *attr,
2042 struct bgp_node *rn)
2043 {
2044 struct bgp_info *new;
2045
2046 /* Make new BGP info. */
2047 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2048 new->type = type;
2049 new->sub_type = sub_type;
2050 new->peer = peer;
2051 new->attr = attr;
2052 new->uptime = bgp_clock ();
2053 new->net = rn;
2054 return new;
2055 }
2056
2057 static void
2058 bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2059 struct attr *attr, struct peer *peer, struct prefix *p, int type,
2060 int sub_type, struct prefix_rd *prd, u_char *tag)
2061 {
2062 struct bgp_node *rn;
2063 struct bgp *bgp;
2064 struct attr new_attr;
2065 struct attr_extra new_extra;
2066 struct attr *attr_new;
2067 struct attr *attr_new2;
2068 struct bgp_info *ri;
2069 struct bgp_info *new;
2070 const char *reason;
2071 char buf[SU_ADDRSTRLEN];
2072
2073 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
2074 if (peer == rsclient)
2075 return;
2076
2077 bgp = peer->bgp;
2078 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2079
2080 /* Check previously received route. */
2081 for (ri = rn->info; ri; ri = ri->next)
2082 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2083 break;
2084
2085 /* AS path loop check. */
2086 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
2087 {
2088 reason = "as-path contains our own AS;";
2089 goto filtered;
2090 }
2091
2092 /* Route reflector originator ID check. */
2093 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2094 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
2095 {
2096 reason = "originator is us;";
2097 goto filtered;
2098 }
2099
2100 new_attr.extra = &new_extra;
2101 bgp_attr_dup (&new_attr, attr);
2102
2103 /* Apply export policy. */
2104 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
2105 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2106 {
2107 reason = "export-policy;";
2108 goto filtered;
2109 }
2110
2111 attr_new2 = bgp_attr_intern (&new_attr);
2112
2113 /* Apply import policy. */
2114 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
2115 {
2116 bgp_attr_unintern (&attr_new2);
2117
2118 reason = "import-policy;";
2119 goto filtered;
2120 }
2121
2122 attr_new = bgp_attr_intern (&new_attr);
2123 bgp_attr_unintern (&attr_new2);
2124
2125 /* IPv4 unicast next hop check. */
2126 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
2127 {
2128 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
2129 if (new_attr.nexthop.s_addr == 0
2130 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
2131 {
2132 bgp_attr_unintern (&attr_new);
2133
2134 reason = "martian next-hop;";
2135 goto filtered;
2136 }
2137 }
2138
2139 /* If the update is implicit withdraw. */
2140 if (ri)
2141 {
2142 ri->uptime = bgp_clock ();
2143
2144 /* Same attribute comes in. */
2145 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
2146 && attrhash_cmp (ri->attr, attr_new))
2147 {
2148
2149 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2150
2151 if (BGP_DEBUG (update, UPDATE_IN))
2152 zlog (peer->log, LOG_DEBUG,
2153 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
2154 peer->host,
2155 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2156 p->prefixlen, rsclient->host);
2157
2158 bgp_unlock_node (rn);
2159 bgp_attr_unintern (&attr_new);
2160
2161 return;
2162 }
2163
2164 /* Withdraw/Announce before we fully processed the withdraw */
2165 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2166 bgp_info_restore (rn, ri);
2167
2168 /* Received Logging. */
2169 if (BGP_DEBUG (update, UPDATE_IN))
2170 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
2171 peer->host,
2172 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2173 p->prefixlen, rsclient->host);
2174
2175 /* The attribute is changed. */
2176 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2177
2178 /* Update to new attribute. */
2179 bgp_attr_unintern (&ri->attr);
2180 ri->attr = attr_new;
2181
2182 /* Update MPLS tag. */
2183 if (safi == SAFI_MPLS_VPN)
2184 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2185
2186 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2187
2188 /* Process change. */
2189 bgp_process (bgp, rn, afi, safi);
2190 bgp_unlock_node (rn);
2191
2192 return;
2193 }
2194
2195 /* Received Logging. */
2196 if (BGP_DEBUG (update, UPDATE_IN))
2197 {
2198 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
2199 peer->host,
2200 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2201 p->prefixlen, rsclient->host);
2202 }
2203
2204 new = info_make(type, sub_type, peer, attr_new, rn);
2205
2206 /* Update MPLS tag. */
2207 if (safi == SAFI_MPLS_VPN)
2208 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2209
2210 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2211
2212 /* Register new BGP information. */
2213 bgp_info_add (rn, new);
2214
2215 /* route_node_get lock */
2216 bgp_unlock_node (rn);
2217
2218 /* Process change. */
2219 bgp_process (bgp, rn, afi, safi);
2220
2221 return;
2222
2223 filtered:
2224
2225 /* This BGP update is filtered. Log the reason then update BGP entry. */
2226 if (BGP_DEBUG (update, UPDATE_IN))
2227 zlog (peer->log, LOG_DEBUG,
2228 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2229 peer->host,
2230 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2231 p->prefixlen, rsclient->host, reason);
2232
2233 if (ri)
2234 bgp_rib_remove (rn, ri, peer, afi, safi);
2235
2236 bgp_unlock_node (rn);
2237
2238 return;
2239 }
2240
2241 static void
2242 bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2243 struct peer *peer, struct prefix *p, int type, int sub_type,
2244 struct prefix_rd *prd, u_char *tag)
2245 {
2246 struct bgp_node *rn;
2247 struct bgp_info *ri;
2248 char buf[SU_ADDRSTRLEN];
2249
2250 if (rsclient == peer)
2251 return;
2252
2253 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2254
2255 /* Lookup withdrawn route. */
2256 for (ri = rn->info; ri; ri = ri->next)
2257 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2258 break;
2259
2260 /* Withdraw specified route from routing table. */
2261 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2262 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2263 else if (BGP_DEBUG (update, UPDATE_IN))
2264 zlog (peer->log, LOG_DEBUG,
2265 "%s Can't find the route %s/%d", peer->host,
2266 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2267 p->prefixlen);
2268
2269 /* Unlock bgp_node_get() lock. */
2270 bgp_unlock_node (rn);
2271 }
2272
2273 static int
2274 bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
2275 afi_t afi, safi_t safi, int type, int sub_type,
2276 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2277 {
2278 int ret;
2279 int aspath_loop_count = 0;
2280 struct bgp_node *rn;
2281 struct bgp *bgp;
2282 struct attr new_attr;
2283 struct attr_extra new_extra;
2284 struct attr *attr_new;
2285 struct bgp_info *ri;
2286 struct bgp_info *new;
2287 const char *reason;
2288 char buf[SU_ADDRSTRLEN];
2289 int connected = 0;
2290
2291 bgp = peer->bgp;
2292 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2293
2294 /* When peer's soft reconfiguration enabled. Record input packet in
2295 Adj-RIBs-In. */
2296 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2297 && peer != bgp->peer_self)
2298 bgp_adj_in_set (rn, peer, attr);
2299
2300 /* Check previously received route. */
2301 for (ri = rn->info; ri; ri = ri->next)
2302 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2303 break;
2304
2305 /* AS path local-as loop check. */
2306 if (peer->change_local_as)
2307 {
2308 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2309 aspath_loop_count = 1;
2310
2311 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2312 {
2313 reason = "as-path contains our own AS;";
2314 goto filtered;
2315 }
2316 }
2317
2318 /* AS path loop check. */
2319 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2320 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2321 && aspath_loop_check(attr->aspath, bgp->confed_id)
2322 > peer->allowas_in[afi][safi]))
2323 {
2324 reason = "as-path contains our own AS;";
2325 goto filtered;
2326 }
2327
2328 /* Route reflector originator ID check. */
2329 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2330 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2331 {
2332 reason = "originator is us;";
2333 goto filtered;
2334 }
2335
2336 /* Route reflector cluster ID check. */
2337 if (bgp_cluster_filter (peer, attr))
2338 {
2339 reason = "reflected from the same cluster;";
2340 goto filtered;
2341 }
2342
2343 /* Apply incoming filter. */
2344 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2345 {
2346 reason = "filter;";
2347 goto filtered;
2348 }
2349
2350 new_attr.extra = &new_extra;
2351 bgp_attr_dup (&new_attr, attr);
2352
2353 /* Apply incoming route-map.
2354 * NB: new_attr may now contain newly allocated values from route-map "set"
2355 * commands, so we need bgp_attr_flush in the error paths, until we intern
2356 * the attr (which takes over the memory references) */
2357 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2358 {
2359 reason = "route-map;";
2360 bgp_attr_flush (&new_attr);
2361 goto filtered;
2362 }
2363
2364 /* IPv4 unicast next hop check. */
2365 if (afi == AFI_IP && safi == SAFI_UNICAST)
2366 {
2367 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
2368 must not be my own address. */
2369 if (new_attr.nexthop.s_addr == 0
2370 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2371 || bgp_nexthop_self (&new_attr))
2372 {
2373 reason = "martian next-hop;";
2374 bgp_attr_flush (&new_attr);
2375 goto filtered;
2376 }
2377 }
2378
2379 attr_new = bgp_attr_intern (&new_attr);
2380
2381 /* If the update is implicit withdraw. */
2382 if (ri)
2383 {
2384 ri->uptime = bgp_clock ();
2385
2386 /* Same attribute comes in. */
2387 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2388 && attrhash_cmp (ri->attr, attr_new))
2389 {
2390 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2391
2392 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2393 && peer->sort == BGP_PEER_EBGP
2394 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2395 {
2396 if (BGP_DEBUG (update, UPDATE_IN))
2397 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2398 peer->host,
2399 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2400 p->prefixlen);
2401
2402 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2403 {
2404 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2405 bgp_process (bgp, rn, afi, safi);
2406 }
2407 }
2408 else /* Duplicate - odd */
2409 {
2410 if (BGP_DEBUG (update, UPDATE_IN))
2411 zlog (peer->log, LOG_DEBUG,
2412 "%s rcvd %s/%d...duplicate ignored",
2413 peer->host,
2414 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2415 p->prefixlen);
2416
2417 /* graceful restart STALE flag unset. */
2418 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2419 {
2420 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2421 bgp_process (bgp, rn, afi, safi);
2422 }
2423 }
2424
2425 bgp_unlock_node (rn);
2426 bgp_attr_unintern (&attr_new);
2427
2428 return 0;
2429 }
2430
2431 /* Withdraw/Announce before we fully processed the withdraw */
2432 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2433 {
2434 if (BGP_DEBUG (update, UPDATE_IN))
2435 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2436 peer->host,
2437 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2438 p->prefixlen);
2439 bgp_info_restore (rn, ri);
2440 }
2441
2442 /* Received Logging. */
2443 if (BGP_DEBUG (update, UPDATE_IN))
2444 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2445 peer->host,
2446 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2447 p->prefixlen);
2448
2449 /* graceful restart STALE flag unset. */
2450 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2451 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2452
2453 /* The attribute is changed. */
2454 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2455
2456 /* implicit withdraw, decrement aggregate and pcount here.
2457 * only if update is accepted, they'll increment below.
2458 */
2459 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2460
2461 /* Update bgp route dampening information. */
2462 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2463 && peer->sort == BGP_PEER_EBGP)
2464 {
2465 /* This is implicit withdraw so we should update dampening
2466 information. */
2467 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2468 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2469 }
2470
2471 /* Update to new attribute. */
2472 bgp_attr_unintern (&ri->attr);
2473 ri->attr = attr_new;
2474
2475 /* Update MPLS tag. */
2476 if (safi == SAFI_MPLS_VPN)
2477 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2478
2479 /* Update bgp route dampening information. */
2480 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2481 && peer->sort == BGP_PEER_EBGP)
2482 {
2483 /* Now we do normal update dampening. */
2484 ret = bgp_damp_update (ri, rn, afi, safi);
2485 if (ret == BGP_DAMP_SUPPRESSED)
2486 {
2487 bgp_unlock_node (rn);
2488 return 0;
2489 }
2490 }
2491
2492 /* Nexthop reachability check. */
2493 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2494 {
2495 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2496 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
2497 connected = 1;
2498 else
2499 connected = 0;
2500
2501 if (bgp_find_or_add_nexthop (afi, ri, NULL, connected))
2502 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2503 else
2504 {
2505 if (BGP_DEBUG(nht, NHT))
2506 {
2507 char buf1[INET6_ADDRSTRLEN];
2508 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2509 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2510 }
2511 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2512 }
2513 }
2514 else
2515 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2516
2517 /* Process change. */
2518 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2519
2520 bgp_process (bgp, rn, afi, safi);
2521 bgp_unlock_node (rn);
2522
2523 return 0;
2524 }
2525
2526 /* Received Logging. */
2527 if (BGP_DEBUG (update, UPDATE_IN))
2528 {
2529 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2530 peer->host,
2531 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2532 p->prefixlen);
2533 }
2534
2535 /* Make new BGP info. */
2536 new = info_make(type, sub_type, peer, attr_new, rn);
2537
2538 /* Update MPLS tag. */
2539 if (safi == SAFI_MPLS_VPN)
2540 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2541
2542 /* Nexthop reachability check. */
2543 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2544 {
2545 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2546 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
2547 connected = 1;
2548 else
2549 connected = 0;
2550
2551 if (bgp_find_or_add_nexthop (afi, new, NULL, connected))
2552 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2553 else
2554 {
2555 if (BGP_DEBUG(nht, NHT))
2556 {
2557 char buf1[INET6_ADDRSTRLEN];
2558 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2559 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2560 }
2561 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2562 }
2563 }
2564 else
2565 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2566
2567 /* Increment prefix */
2568 bgp_aggregate_increment (bgp, p, new, afi, safi);
2569
2570 /* Register new BGP information. */
2571 bgp_info_add (rn, new);
2572
2573 /* route_node_get lock */
2574 bgp_unlock_node (rn);
2575
2576 /* If maximum prefix count is configured and current prefix
2577 count exeed it. */
2578 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2579 return -1;
2580
2581 /* Process change. */
2582 bgp_process (bgp, rn, afi, safi);
2583
2584 return 0;
2585
2586 /* This BGP update is filtered. Log the reason then update BGP
2587 entry. */
2588 filtered:
2589 if (BGP_DEBUG (update, UPDATE_IN))
2590 zlog (peer->log, LOG_DEBUG,
2591 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2592 peer->host,
2593 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2594 p->prefixlen, reason);
2595
2596 if (ri)
2597 bgp_rib_remove (rn, ri, peer, afi, safi);
2598
2599 bgp_unlock_node (rn);
2600
2601 return 0;
2602 }
2603
2604 int
2605 bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2606 afi_t afi, safi_t safi, int type, int sub_type,
2607 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2608 {
2609 struct peer *rsclient;
2610 struct listnode *node, *nnode;
2611 struct bgp *bgp;
2612 int ret;
2613
2614 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2615 soft_reconfig);
2616
2617 bgp = peer->bgp;
2618
2619 /* Process the update for each RS-client. */
2620 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2621 {
2622 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2623 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2624 sub_type, prd, tag);
2625 }
2626
2627 return ret;
2628 }
2629
2630 int
2631 bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
2632 afi_t afi, safi_t safi, int type, int sub_type,
2633 struct prefix_rd *prd, u_char *tag)
2634 {
2635 struct bgp *bgp;
2636 char buf[SU_ADDRSTRLEN];
2637 struct bgp_node *rn;
2638 struct bgp_info *ri;
2639 struct peer *rsclient;
2640 struct listnode *node, *nnode;
2641
2642 bgp = peer->bgp;
2643
2644 /* Process the withdraw for each RS-client. */
2645 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2646 {
2647 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2648 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2649 }
2650
2651 /* Logging. */
2652 if (BGP_DEBUG (update, UPDATE_IN))
2653 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
2654 peer->host,
2655 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2656 p->prefixlen);
2657
2658 /* Lookup node. */
2659 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2660
2661 /* If peer is soft reconfiguration enabled. Record input packet for
2662 further calculation. */
2663 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2664 && peer != bgp->peer_self)
2665 bgp_adj_in_unset (rn, peer);
2666
2667 /* Lookup withdrawn route. */
2668 for (ri = rn->info; ri; ri = ri->next)
2669 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2670 break;
2671
2672 /* Withdraw specified route from routing table. */
2673 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2674 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2675 else if (BGP_DEBUG (update, UPDATE_IN))
2676 zlog (peer->log, LOG_DEBUG,
2677 "%s Can't find the route %s/%d", peer->host,
2678 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2679 p->prefixlen);
2680
2681 /* Unlock bgp_node_get() lock. */
2682 bgp_unlock_node (rn);
2683
2684 return 0;
2685 }
2686
2687 void
2688 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2689 {
2690 struct bgp *bgp;
2691 struct attr attr;
2692 struct aspath *aspath;
2693 struct prefix p;
2694 struct peer *from;
2695 struct bgp_node *rn;
2696 struct bgp_info *ri;
2697 int ret = RMAP_DENYMATCH;
2698
2699 if (!(afi == AFI_IP || afi == AFI_IP6))
2700 return;
2701
2702 bgp = peer->bgp;
2703 from = bgp->peer_self;
2704
2705 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2706 aspath = attr.aspath;
2707 attr.local_pref = bgp->default_local_pref;
2708 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2709
2710 if (afi == AFI_IP)
2711 str2prefix ("0.0.0.0/0", &p);
2712 #ifdef HAVE_IPV6
2713 else if (afi == AFI_IP6)
2714 {
2715 struct attr_extra *ae = attr.extra;
2716
2717 str2prefix ("::/0", &p);
2718
2719 /* IPv6 global nexthop must be included. */
2720 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
2721 IPV6_MAX_BYTELEN);
2722 ae->mp_nexthop_len = 16;
2723
2724 /* If the peer is on shared nextwork and we have link-local
2725 nexthop set it. */
2726 if (peer->shared_network
2727 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2728 {
2729 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
2730 IPV6_MAX_BYTELEN);
2731 ae->mp_nexthop_len = 32;
2732 }
2733 }
2734 #endif /* HAVE_IPV6 */
2735
2736 if (peer->default_rmap[afi][safi].name)
2737 {
2738 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2739 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2740 {
2741 for (ri = rn->info; ri; ri = ri->next)
2742 {
2743 struct attr dummy_attr;
2744 struct attr_extra dummy_extra;
2745 struct bgp_info info;
2746
2747 /* Provide dummy so the route-map can't modify the attributes */
2748 dummy_attr.extra = &dummy_extra;
2749 bgp_attr_dup(&dummy_attr, ri->attr);
2750 info.peer = ri->peer;
2751 info.attr = &dummy_attr;
2752
2753 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2754 RMAP_BGP, &info);
2755
2756 /* The route map might have set attributes. If we don't flush them
2757 * here, they will be leaked. */
2758 bgp_attr_flush(&dummy_attr);
2759 if (ret != RMAP_DENYMATCH)
2760 break;
2761 }
2762 if (ret != RMAP_DENYMATCH)
2763 break;
2764 }
2765 bgp->peer_self->rmap_type = 0;
2766
2767 if (ret == RMAP_DENYMATCH)
2768 withdraw = 1;
2769 }
2770
2771 if (withdraw)
2772 {
2773 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2774 bgp_default_withdraw_send (peer, afi, safi);
2775 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2776 }
2777 else
2778 {
2779 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2780 {
2781 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2782 bgp_default_update_send (peer, &attr, afi, safi, from);
2783 }
2784 }
2785
2786 bgp_attr_extra_free (&attr);
2787 aspath_unintern (&aspath);
2788 }
2789
2790 static void
2791 bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
2792 struct bgp_table *table, int rsclient)
2793 {
2794 struct bgp_node *rn;
2795 struct bgp_info *ri;
2796 struct attr attr;
2797 struct attr_extra extra;
2798
2799 if (! table)
2800 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
2801
2802 if (safi != SAFI_MPLS_VPN
2803 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2804 bgp_default_originate (peer, afi, safi, 0);
2805
2806 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2807 attr.extra = &extra;
2808
2809 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2810 for (ri = rn->info; ri; ri = ri->next)
2811 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2812 {
2813 if ( (rsclient) ?
2814 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2815 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
2816 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2817 else
2818 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2819 }
2820 }
2821
2822 void
2823 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2824 {
2825 struct bgp_node *rn;
2826 struct bgp_table *table;
2827
2828 if (peer->status != Established)
2829 return;
2830
2831 if (! peer->afc_nego[afi][safi])
2832 return;
2833
2834 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2835 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2836 return;
2837
2838 if (safi != SAFI_MPLS_VPN)
2839 bgp_announce_table (peer, afi, safi, NULL, 0);
2840 else
2841 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2842 rn = bgp_route_next(rn))
2843 if ((table = (rn->info)) != NULL)
2844 bgp_announce_table (peer, afi, safi, table, 0);
2845
2846 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2847 bgp_announce_table (peer, afi, safi, NULL, 1);
2848
2849 /*
2850 * The write thread needs to be scheduled since it may not be done as
2851 * part of building adj_out.
2852 */
2853 bgp_peer_schedule_updates(peer);
2854 }
2855
2856 void
2857 bgp_announce_route_all (struct peer *peer)
2858 {
2859 afi_t afi;
2860 safi_t safi;
2861
2862 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2863 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2864 bgp_announce_route (peer, afi, safi);
2865 }
2866
2867 static void
2868 bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2869 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
2870 {
2871 struct bgp_node *rn;
2872 struct bgp_adj_in *ain;
2873
2874 if (! table)
2875 table = rsclient->bgp->rib[afi][safi];
2876
2877 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2878 for (ain = rn->adj_in; ain; ain = ain->next)
2879 {
2880 struct bgp_info *ri = rn->info;
2881 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2882
2883 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2884 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
2885 }
2886 }
2887
2888 void
2889 bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2890 {
2891 struct bgp_table *table;
2892 struct bgp_node *rn;
2893
2894 if (safi != SAFI_MPLS_VPN)
2895 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
2896
2897 else
2898 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2899 rn = bgp_route_next (rn))
2900 if ((table = rn->info) != NULL)
2901 {
2902 struct prefix_rd prd;
2903 prd.family = AF_UNSPEC;
2904 prd.prefixlen = 64;
2905 memcpy(&prd.val, rn->p.u.val, 8);
2906
2907 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2908 }
2909 }
2910
2911 static void
2912 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2913 struct bgp_table *table, struct prefix_rd *prd)
2914 {
2915 int ret;
2916 struct bgp_node *rn;
2917 struct bgp_adj_in *ain;
2918
2919 if (! table)
2920 table = peer->bgp->rib[afi][safi];
2921
2922 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2923 for (ain = rn->adj_in; ain; ain = ain->next)
2924 {
2925 if (ain->peer == peer)
2926 {
2927 struct bgp_info *ri = rn->info;
2928 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2929
2930 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2931 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2932 prd, tag, 1);
2933
2934 if (ret < 0)
2935 {
2936 bgp_unlock_node (rn);
2937 return;
2938 }
2939 continue;
2940 }
2941 }
2942 }
2943
2944 void
2945 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2946 {
2947 struct bgp_node *rn;
2948 struct bgp_table *table;
2949
2950 if (peer->status != Established)
2951 return;
2952
2953 if (safi != SAFI_MPLS_VPN)
2954 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
2955 else
2956 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2957 rn = bgp_route_next (rn))
2958 if ((table = rn->info) != NULL)
2959 {
2960 struct prefix_rd prd;
2961 prd.family = AF_UNSPEC;
2962 prd.prefixlen = 64;
2963 memcpy(&prd.val, rn->p.u.val, 8);
2964
2965 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2966 }
2967 }
2968
2969
2970 struct bgp_clear_node_queue
2971 {
2972 struct bgp_node *rn;
2973 enum bgp_clear_route_type purpose;
2974 };
2975
2976 static wq_item_status
2977 bgp_clear_route_node (struct work_queue *wq, void *data)
2978 {
2979 struct bgp_clear_node_queue *cnq = data;
2980 struct bgp_node *rn = cnq->rn;
2981 struct peer *peer = wq->spec.data;
2982 struct bgp_info *ri;
2983 afi_t afi = bgp_node_table (rn)->afi;
2984 safi_t safi = bgp_node_table (rn)->safi;
2985
2986 assert (rn && peer);
2987
2988 for (ri = rn->info; ri; ri = ri->next)
2989 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2990 {
2991 /* graceful restart STALE flag set. */
2992 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2993 && peer->nsf[afi][safi]
2994 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2995 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2996 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
2997 else
2998 bgp_rib_remove (rn, ri, peer, afi, safi);
2999 break;
3000 }
3001 return WQ_SUCCESS;
3002 }
3003
3004 static void
3005 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
3006 {
3007 struct bgp_clear_node_queue *cnq = data;
3008 struct bgp_node *rn = cnq->rn;
3009 struct bgp_table *table = bgp_node_table (rn);
3010
3011 bgp_unlock_node (rn);
3012 bgp_table_unlock (table);
3013 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
3014 }
3015
3016 static void
3017 bgp_clear_node_complete (struct work_queue *wq)
3018 {
3019 struct peer *peer = wq->spec.data;
3020
3021 /* Tickle FSM to start moving again */
3022 BGP_EVENT_ADD (peer, Clearing_Completed);
3023
3024 peer_unlock (peer); /* bgp_clear_route */
3025 }
3026
3027 static void
3028 bgp_clear_node_queue_init (struct peer *peer)
3029 {
3030 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
3031
3032 snprintf (wname, sizeof(wname), "clear %s", peer->host);
3033 #undef CLEAR_QUEUE_NAME_LEN
3034
3035 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
3036 {
3037 zlog_err ("%s: Failed to allocate work queue", __func__);
3038 exit (1);
3039 }
3040 peer->clear_node_queue->spec.hold = 10;
3041 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3042 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3043 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3044 peer->clear_node_queue->spec.max_retries = 0;
3045
3046 /* we only 'lock' this peer reference when the queue is actually active */
3047 peer->clear_node_queue->spec.data = peer;
3048 }
3049
3050 static void
3051 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
3052 struct bgp_table *table, struct peer *rsclient,
3053 enum bgp_clear_route_type purpose)
3054 {
3055 struct bgp_node *rn;
3056
3057
3058 if (! table)
3059 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
3060
3061 /* If still no table => afi/safi isn't configured at all or smth. */
3062 if (! table)
3063 return;
3064
3065 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3066 {
3067 struct bgp_info *ri;
3068 struct bgp_adj_in *ain;
3069 struct bgp_adj_out *aout;
3070
3071 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3072 * queued for every clearing peer, regardless of whether it is
3073 * relevant to the peer at hand.
3074 *
3075 * Overview: There are 3 different indices which need to be
3076 * scrubbed, potentially, when a peer is removed:
3077 *
3078 * 1 peer's routes visible via the RIB (ie accepted routes)
3079 * 2 peer's routes visible by the (optional) peer's adj-in index
3080 * 3 other routes visible by the peer's adj-out index
3081 *
3082 * 3 there is no hurry in scrubbing, once the struct peer is
3083 * removed from bgp->peer, we could just GC such deleted peer's
3084 * adj-outs at our leisure.
3085 *
3086 * 1 and 2 must be 'scrubbed' in some way, at least made
3087 * invisible via RIB index before peer session is allowed to be
3088 * brought back up. So one needs to know when such a 'search' is
3089 * complete.
3090 *
3091 * Ideally:
3092 *
3093 * - there'd be a single global queue or a single RIB walker
3094 * - rather than tracking which route_nodes still need to be
3095 * examined on a peer basis, we'd track which peers still
3096 * aren't cleared
3097 *
3098 * Given that our per-peer prefix-counts now should be reliable,
3099 * this may actually be achievable. It doesn't seem to be a huge
3100 * problem at this time,
3101 */
3102 for (ain = rn->adj_in; ain; ain = ain->next)
3103 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3104 {
3105 bgp_adj_in_remove (rn, ain);
3106 bgp_unlock_node (rn);
3107 break;
3108 }
3109 for (aout = rn->adj_out; aout; aout = aout->next)
3110 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3111 {
3112 bgp_adj_out_remove (rn, aout, peer, afi, safi);
3113 bgp_unlock_node (rn);
3114 break;
3115 }
3116
3117 for (ri = rn->info; ri; ri = ri->next)
3118 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
3119 {
3120 struct bgp_clear_node_queue *cnq;
3121
3122 /* both unlocked in bgp_clear_node_queue_del */
3123 bgp_table_lock (bgp_node_table (rn));
3124 bgp_lock_node (rn);
3125 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3126 sizeof (struct bgp_clear_node_queue));
3127 cnq->rn = rn;
3128 cnq->purpose = purpose;
3129 work_queue_add (peer->clear_node_queue, cnq);
3130 break;
3131 }
3132 }
3133 return;
3134 }
3135
3136 void
3137 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
3138 enum bgp_clear_route_type purpose)
3139 {
3140 struct bgp_node *rn;
3141 struct bgp_table *table;
3142 struct peer *rsclient;
3143 struct listnode *node, *nnode;
3144
3145 if (peer->clear_node_queue == NULL)
3146 bgp_clear_node_queue_init (peer);
3147
3148 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3149 * Idle until it receives a Clearing_Completed event. This protects
3150 * against peers which flap faster than we can we clear, which could
3151 * lead to:
3152 *
3153 * a) race with routes from the new session being installed before
3154 * clear_route_node visits the node (to delete the route of that
3155 * peer)
3156 * b) resource exhaustion, clear_route_node likely leads to an entry
3157 * on the process_main queue. Fast-flapping could cause that queue
3158 * to grow and grow.
3159 */
3160 if (!peer->clear_node_queue->thread)
3161 peer_lock (peer); /* bgp_clear_node_complete */
3162
3163 switch (purpose)
3164 {
3165 case BGP_CLEAR_ROUTE_NORMAL:
3166 if (safi != SAFI_MPLS_VPN)
3167 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3168 else
3169 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3170 rn = bgp_route_next (rn))
3171 if ((table = rn->info) != NULL)
3172 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3173
3174 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3175 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3176 PEER_FLAG_RSERVER_CLIENT))
3177 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3178 break;
3179
3180 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3181 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3182 break;
3183
3184 default:
3185 assert (0);
3186 break;
3187 }
3188
3189 /* If no routes were cleared, nothing was added to workqueue, the
3190 * completion function won't be run by workqueue code - call it here.
3191 * XXX: Actually, this assumption doesn't hold, see
3192 * bgp_clear_route_table(), we queue all non-empty nodes.
3193 *
3194 * Additionally, there is a presumption in FSM that clearing is only
3195 * really needed if peer state is Established - peers in
3196 * pre-Established states shouldn't have any route-update state
3197 * associated with them (in or out).
3198 *
3199 * We still can get here in pre-Established though, through
3200 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
3201 * check to ensure the assumption above holds.
3202 *
3203 * At some future point, this check could be move to the top of the
3204 * function, and do a quick early-return when state is
3205 * pre-Established, avoiding above list and table scans. Once we're
3206 * sure it is safe..
3207 */
3208 if (!peer->clear_node_queue->thread)
3209 bgp_clear_node_complete (peer->clear_node_queue);
3210 }
3211
3212 void
3213 bgp_clear_route_all (struct peer *peer)
3214 {
3215 afi_t afi;
3216 safi_t safi;
3217
3218 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3219 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3220 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
3221 }
3222
3223 void
3224 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3225 {
3226 struct bgp_table *table;
3227 struct bgp_node *rn;
3228 struct bgp_adj_in *ain;
3229
3230 table = peer->bgp->rib[afi][safi];
3231
3232 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3233 for (ain = rn->adj_in; ain ; ain = ain->next)
3234 if (ain->peer == peer)
3235 {
3236 bgp_adj_in_remove (rn, ain);
3237 bgp_unlock_node (rn);
3238 break;
3239 }
3240 }
3241
3242 void
3243 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3244 {
3245 struct bgp_node *rn;
3246 struct bgp_info *ri;
3247 struct bgp_table *table;
3248
3249 table = peer->bgp->rib[afi][safi];
3250
3251 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3252 {
3253 for (ri = rn->info; ri; ri = ri->next)
3254 if (ri->peer == peer)
3255 {
3256 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3257 bgp_rib_remove (rn, ri, peer, afi, safi);
3258 break;
3259 }
3260 }
3261 }
3262
3263 /* Delete all kernel routes. */
3264 void
3265 bgp_cleanup_routes (void)
3266 {
3267 struct bgp *bgp;
3268 struct listnode *node, *nnode;
3269 struct bgp_node *rn;
3270 struct bgp_table *table;
3271 struct bgp_info *ri;
3272
3273 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
3274 {
3275 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3276
3277 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3278 for (ri = rn->info; ri; ri = ri->next)
3279 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3280 && ri->type == ZEBRA_ROUTE_BGP
3281 && ri->sub_type == BGP_ROUTE_NORMAL)
3282 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
3283
3284 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3285
3286 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3287 for (ri = rn->info; ri; ri = ri->next)
3288 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3289 && ri->type == ZEBRA_ROUTE_BGP
3290 && ri->sub_type == BGP_ROUTE_NORMAL)
3291 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
3292 }
3293 }
3294
3295 void
3296 bgp_reset (void)
3297 {
3298 vty_reset ();
3299 bgp_zclient_reset ();
3300 access_list_reset ();
3301 prefix_list_reset ();
3302 }
3303
3304 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3305 value. */
3306 int
3307 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3308 {
3309 u_char *pnt;
3310 u_char *lim;
3311 struct prefix p;
3312 int psize;
3313 int ret;
3314
3315 /* Check peer status. */
3316 if (peer->status != Established)
3317 return 0;
3318
3319 pnt = packet->nlri;
3320 lim = pnt + packet->length;
3321
3322 for (; pnt < lim; pnt += psize)
3323 {
3324 /* Clear prefix structure. */
3325 memset (&p, 0, sizeof (struct prefix));
3326
3327 /* Fetch prefix length. */
3328 p.prefixlen = *pnt++;
3329 p.family = afi2family (packet->afi);
3330
3331 /* Already checked in nlri_sanity_check(). We do double check
3332 here. */
3333 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3334 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3335 return -1;
3336
3337 /* Packet size overflow check. */
3338 psize = PSIZE (p.prefixlen);
3339
3340 /* When packet overflow occur return immediately. */
3341 if (pnt + psize > lim)
3342 return -1;
3343
3344 /* Fetch prefix from NLRI packet. */
3345 memcpy (&p.u.prefix, pnt, psize);
3346
3347 /* Check address. */
3348 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3349 {
3350 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3351 {
3352 /*
3353 * From draft-ietf-idr-bgp4-22, Section 6.3:
3354 * If a BGP router receives an UPDATE message with a
3355 * semantically incorrect NLRI field, in which a prefix is
3356 * semantically incorrect (eg. an unexpected multicast IP
3357 * address), it should ignore the prefix.
3358 */
3359 zlog (peer->log, LOG_ERR,
3360 "IPv4 unicast NLRI is multicast address %s",
3361 inet_ntoa (p.u.prefix4));
3362
3363 return -1;
3364 }
3365 }
3366
3367 #ifdef HAVE_IPV6
3368 /* Check address. */
3369 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3370 {
3371 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3372 {
3373 char buf[BUFSIZ];
3374
3375 zlog (peer->log, LOG_WARNING,
3376 "IPv6 link-local NLRI received %s ignore this NLRI",
3377 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3378
3379 continue;
3380 }
3381 }
3382 #endif /* HAVE_IPV6 */
3383
3384 /* Normal process. */
3385 if (attr)
3386 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3387 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3388 else
3389 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3390 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3391
3392 /* Address family configuration mismatch or maximum-prefix count
3393 overflow. */
3394 if (ret < 0)
3395 return -1;
3396 }
3397
3398 /* Packet length consistency check. */
3399 if (pnt != lim)
3400 return -1;
3401
3402 return 0;
3403 }
3404
3405 /* NLRI encode syntax check routine. */
3406 int
3407 bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3408 bgp_size_t length, int *numpfx)
3409 {
3410 u_char *end;
3411 u_char prefixlen;
3412 int psize;
3413
3414 *numpfx = 0;
3415 end = pnt + length;
3416
3417 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3418 syntactic validity. If the field is syntactically incorrect,
3419 then the Error Subcode is set to Invalid Network Field. */
3420
3421 while (pnt < end)
3422 {
3423 prefixlen = *pnt++;
3424
3425 /* Prefix length check. */
3426 if ((afi == AFI_IP && prefixlen > 32)
3427 || (afi == AFI_IP6 && prefixlen > 128))
3428 {
3429 plog_err (peer->log,
3430 "%s [Error] Update packet error (wrong prefix length %d)",
3431 peer->host, prefixlen);
3432 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3433 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3434 return -1;
3435 }
3436
3437 /* Packet size overflow check. */
3438 psize = PSIZE (prefixlen);
3439
3440 if (pnt + psize > end)
3441 {
3442 plog_err (peer->log,
3443 "%s [Error] Update packet error"
3444 " (prefix data overflow prefix size is %d)",
3445 peer->host, psize);
3446 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3447 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3448 return -1;
3449 }
3450
3451 pnt += psize;
3452 (*numpfx)++;
3453 }
3454
3455 /* Packet length consistency check. */
3456 if (pnt != end)
3457 {
3458 plog_err (peer->log,
3459 "%s [Error] Update packet error"
3460 " (prefix length mismatch with total length)",
3461 peer->host);
3462 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3463 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3464 return -1;
3465 }
3466 return 0;
3467 }
3468
3469 static struct bgp_static *
3470 bgp_static_new (void)
3471 {
3472 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3473 }
3474
3475 static void
3476 bgp_static_free (struct bgp_static *bgp_static)
3477 {
3478 if (bgp_static->rmap.name)
3479 free (bgp_static->rmap.name);
3480 XFREE (MTYPE_BGP_STATIC, bgp_static);
3481 }
3482
3483 static void
3484 bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3485 struct prefix *p, afi_t afi, safi_t safi)
3486 {
3487 struct bgp_node *rn;
3488 struct bgp_info *ri;
3489
3490 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3491
3492 /* Check selected route and self inserted route. */
3493 for (ri = rn->info; ri; ri = ri->next)
3494 if (ri->peer == bgp->peer_self
3495 && ri->type == ZEBRA_ROUTE_BGP
3496 && ri->sub_type == BGP_ROUTE_STATIC)
3497 break;
3498
3499 /* Withdraw static BGP route from routing table. */
3500 if (ri)
3501 {
3502 bgp_info_delete (rn, ri);
3503 bgp_process (bgp, rn, afi, safi);
3504 }
3505
3506 /* Unlock bgp_node_lookup. */
3507 bgp_unlock_node (rn);
3508 }
3509
3510 static void
3511 bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
3512 struct bgp_static *bgp_static,
3513 afi_t afi, safi_t safi)
3514 {
3515 struct bgp_node *rn;
3516 struct bgp_info *ri;
3517 struct bgp_info *new;
3518 struct bgp_info info;
3519 struct attr *attr_new;
3520 struct attr attr;
3521 struct attr new_attr;
3522 struct attr_extra new_extra;
3523 struct bgp *bgp;
3524 int ret;
3525 char buf[SU_ADDRSTRLEN];
3526
3527 bgp = rsclient->bgp;
3528
3529 assert (bgp_static);
3530 if (!bgp_static)
3531 return;
3532
3533 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3534
3535 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3536
3537 attr.nexthop = bgp_static->igpnexthop;
3538 attr.med = bgp_static->igpmetric;
3539 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3540
3541 if (bgp_static->atomic)
3542 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3543
3544 /* Apply network route-map for export to this rsclient. */
3545 if (bgp_static->rmap.name)
3546 {
3547 struct attr attr_tmp = attr;
3548 info.peer = rsclient;
3549 info.attr = &attr_tmp;
3550
3551 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3552 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3553
3554 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3555
3556 rsclient->rmap_type = 0;
3557
3558 if (ret == RMAP_DENYMATCH)
3559 {
3560 /* Free uninterned attribute. */
3561 bgp_attr_flush (&attr_tmp);
3562
3563 /* Unintern original. */
3564 aspath_unintern (&attr.aspath);
3565 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3566 bgp_attr_extra_free (&attr);
3567
3568 return;
3569 }
3570 attr_new = bgp_attr_intern (&attr_tmp);
3571 }
3572 else
3573 attr_new = bgp_attr_intern (&attr);
3574
3575 new_attr.extra = &new_extra;
3576 bgp_attr_dup(&new_attr, attr_new);
3577
3578 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3579
3580 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3581 == RMAP_DENY)
3582 {
3583 /* This BGP update is filtered. Log the reason then update BGP entry. */
3584 if (BGP_DEBUG (update, UPDATE_IN))
3585 zlog (rsclient->log, LOG_DEBUG,
3586 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3587 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3588 p->prefixlen, rsclient->host);
3589
3590 bgp->peer_self->rmap_type = 0;
3591
3592 bgp_attr_unintern (&attr_new);
3593 aspath_unintern (&attr.aspath);
3594 bgp_attr_extra_free (&attr);
3595
3596 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3597
3598 return;
3599 }
3600
3601 bgp->peer_self->rmap_type = 0;
3602
3603 bgp_attr_unintern (&attr_new);
3604 attr_new = bgp_attr_intern (&new_attr);
3605
3606 for (ri = rn->info; ri; ri = ri->next)
3607 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3608 && ri->sub_type == BGP_ROUTE_STATIC)
3609 break;
3610
3611 if (ri)
3612 {
3613 if (attrhash_cmp (ri->attr, attr_new) &&
3614 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3615 {
3616 bgp_unlock_node (rn);
3617 bgp_attr_unintern (&attr_new);
3618 aspath_unintern (&attr.aspath);
3619 bgp_attr_extra_free (&attr);
3620 return;
3621 }
3622 else
3623 {
3624 /* The attribute is changed. */
3625 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3626
3627 /* Rewrite BGP route information. */
3628 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3629 bgp_info_restore(rn, ri);
3630 bgp_attr_unintern (&ri->attr);
3631 ri->attr = attr_new;
3632 ri->uptime = bgp_clock ();
3633
3634 /* Nexthop reachability check. */
3635 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3636 {
3637 if (bgp_find_or_add_nexthop (afi, ri, NULL, 0))
3638 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3639 else
3640 {
3641 if (BGP_DEBUG(nht, NHT))
3642 {
3643 char buf1[INET6_ADDRSTRLEN];
3644 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
3645 buf1, INET6_ADDRSTRLEN);
3646 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3647 }
3648 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3649 }
3650 }
3651 /* Process change. */
3652 bgp_process (bgp, rn, afi, safi);
3653 bgp_unlock_node (rn);
3654 aspath_unintern (&attr.aspath);
3655 bgp_attr_extra_free (&attr);
3656 return;
3657 }
3658 }
3659
3660 /* Make new BGP info. */
3661 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3662 attr_new, rn);
3663 /* Nexthop reachability check. */
3664 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3665 {
3666 if (bgp_find_or_add_nexthop (afi, new, NULL, 0))
3667 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3668 else
3669 {
3670 if (BGP_DEBUG(nht, NHT))
3671 {
3672 char buf1[INET6_ADDRSTRLEN];
3673 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
3674 buf1, INET6_ADDRSTRLEN);
3675 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3676 }
3677 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3678 }
3679 }
3680 else
3681 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3682
3683 /* Register new BGP information. */
3684 bgp_info_add (rn, new);
3685
3686 /* route_node_get lock */
3687 bgp_unlock_node (rn);
3688
3689 /* Process change. */
3690 bgp_process (bgp, rn, afi, safi);
3691
3692 /* Unintern original. */
3693 aspath_unintern (&attr.aspath);
3694 bgp_attr_extra_free (&attr);
3695 }
3696
3697 static void
3698 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3699 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3700 {
3701 struct bgp_node *rn;
3702 struct bgp_info *ri;
3703 struct bgp_info *new;
3704 struct bgp_info info;
3705 struct attr attr;
3706 struct attr *attr_new;
3707 int ret;
3708
3709 assert (bgp_static);
3710 if (!bgp_static)
3711 return;
3712
3713 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3714
3715 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3716
3717 attr.nexthop = bgp_static->igpnexthop;
3718 attr.med = bgp_static->igpmetric;
3719 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3720
3721 if (bgp_static->atomic)
3722 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3723
3724 /* Apply route-map. */
3725 if (bgp_static->rmap.name)
3726 {
3727 struct attr attr_tmp = attr;
3728 info.peer = bgp->peer_self;
3729 info.attr = &attr_tmp;
3730
3731 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3732
3733 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3734
3735 bgp->peer_self->rmap_type = 0;
3736
3737 if (ret == RMAP_DENYMATCH)
3738 {
3739 /* Free uninterned attribute. */
3740 bgp_attr_flush (&attr_tmp);
3741
3742 /* Unintern original. */
3743 aspath_unintern (&attr.aspath);
3744 bgp_attr_extra_free (&attr);
3745 bgp_static_withdraw (bgp, p, afi, safi);
3746 return;
3747 }
3748 attr_new = bgp_attr_intern (&attr_tmp);
3749 }
3750 else
3751 attr_new = bgp_attr_intern (&attr);
3752
3753 for (ri = rn->info; ri; ri = ri->next)
3754 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3755 && ri->sub_type == BGP_ROUTE_STATIC)
3756 break;
3757
3758 if (ri)
3759 {
3760 if (attrhash_cmp (ri->attr, attr_new) &&
3761 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3762 {
3763 bgp_unlock_node (rn);
3764 bgp_attr_unintern (&attr_new);
3765 aspath_unintern (&attr.aspath);
3766 bgp_attr_extra_free (&attr);
3767 return;
3768 }
3769 else
3770 {
3771 /* The attribute is changed. */
3772 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3773
3774 /* Rewrite BGP route information. */
3775 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3776 bgp_info_restore(rn, ri);
3777 else
3778 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3779 bgp_attr_unintern (&ri->attr);
3780 ri->attr = attr_new;
3781 ri->uptime = bgp_clock ();
3782
3783 /* Nexthop reachability check. */
3784 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3785 {
3786 if (bgp_find_or_add_nexthop (afi, ri, NULL, 0))
3787 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3788 else
3789 {
3790 if (BGP_DEBUG(nht, NHT))
3791 {
3792 char buf1[INET6_ADDRSTRLEN];
3793 inet_ntop(AF_INET, (const void *)&attr_new->nexthop,
3794 buf1, INET6_ADDRSTRLEN);
3795 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3796 }
3797 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3798 }
3799 }
3800 /* Process change. */
3801 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3802 bgp_process (bgp, rn, afi, safi);
3803 bgp_unlock_node (rn);
3804 aspath_unintern (&attr.aspath);
3805 bgp_attr_extra_free (&attr);
3806 return;
3807 }
3808 }
3809
3810 /* Make new BGP info. */
3811 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self, attr_new,
3812 rn);
3813 /* Nexthop reachability check. */
3814 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3815 {
3816 if (bgp_find_or_add_nexthop (afi, new, NULL, 0))
3817 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3818 else
3819 {
3820 if (BGP_DEBUG(nht, NHT))
3821 {
3822 char buf1[INET6_ADDRSTRLEN];
3823 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1,
3824 INET6_ADDRSTRLEN);
3825 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
3826 }
3827 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3828 }
3829 }
3830 else
3831 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3832
3833 /* Aggregate address increment. */
3834 bgp_aggregate_increment (bgp, p, new, afi, safi);
3835
3836 /* Register new BGP information. */
3837 bgp_info_add (rn, new);
3838
3839 /* route_node_get lock */
3840 bgp_unlock_node (rn);
3841
3842 /* Process change. */
3843 bgp_process (bgp, rn, afi, safi);
3844
3845 /* Unintern original. */
3846 aspath_unintern (&attr.aspath);
3847 bgp_attr_extra_free (&attr);
3848 }
3849
3850 void
3851 bgp_static_update (struct bgp *bgp, struct prefix *p,
3852 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3853 {
3854 struct peer *rsclient;
3855 struct listnode *node, *nnode;
3856
3857 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3858
3859 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
3860 {
3861 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3862 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3863 }
3864 }
3865
3866 static void
3867 bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3868 safi_t safi, struct prefix_rd *prd, u_char *tag)
3869 {
3870 struct bgp_node *rn;
3871 struct bgp_info *new;
3872
3873 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3874
3875 /* Make new BGP info. */
3876 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3877 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3878
3879 SET_FLAG (new->flags, BGP_INFO_VALID);
3880 new->extra = bgp_info_extra_new();
3881 memcpy (new->extra->tag, tag, 3);
3882
3883 /* Aggregate address increment. */
3884 bgp_aggregate_increment (bgp, p, new, afi, safi);
3885
3886 /* Register new BGP information. */
3887 bgp_info_add (rn, new);
3888
3889 /* route_node_get lock */
3890 bgp_unlock_node (rn);
3891
3892 /* Process change. */
3893 bgp_process (bgp, rn, afi, safi);
3894 }
3895
3896 void
3897 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3898 safi_t safi)
3899 {
3900 struct bgp_node *rn;
3901 struct bgp_info *ri;
3902
3903 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3904
3905 /* Check selected route and self inserted route. */
3906 for (ri = rn->info; ri; ri = ri->next)
3907 if (ri->peer == bgp->peer_self
3908 && ri->type == ZEBRA_ROUTE_BGP
3909 && ri->sub_type == BGP_ROUTE_STATIC)
3910 break;
3911
3912 /* Withdraw static BGP route from routing table. */
3913 if (ri)
3914 {
3915 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3916 bgp_unlink_nexthop(ri);
3917 bgp_info_delete (rn, ri);
3918 bgp_process (bgp, rn, afi, safi);
3919 }
3920
3921 /* Unlock bgp_node_lookup. */
3922 bgp_unlock_node (rn);
3923 }
3924
3925 void
3926 bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3927 {
3928 struct bgp_static *bgp_static;
3929 struct bgp *bgp;
3930 struct bgp_node *rn;
3931 struct prefix *p;
3932
3933 bgp = rsclient->bgp;
3934
3935 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3936 if ((bgp_static = rn->info) != NULL)
3937 {
3938 p = &rn->p;
3939
3940 bgp_static_update_rsclient (rsclient, p, bgp_static,
3941 afi, safi);
3942 }
3943 }
3944
3945 static void
3946 bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3947 safi_t safi, struct prefix_rd *prd, u_char *tag)
3948 {
3949 struct bgp_node *rn;
3950 struct bgp_info *ri;
3951
3952 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3953
3954 /* Check selected route and self inserted route. */
3955 for (ri = rn->info; ri; ri = ri->next)
3956 if (ri->peer == bgp->peer_self
3957 && ri->type == ZEBRA_ROUTE_BGP
3958 && ri->sub_type == BGP_ROUTE_STATIC)
3959 break;
3960
3961 /* Withdraw static BGP route from routing table. */
3962 if (ri)
3963 {
3964 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3965 bgp_info_delete (rn, ri);
3966 bgp_process (bgp, rn, afi, safi);
3967 }
3968
3969 /* Unlock bgp_node_lookup. */
3970 bgp_unlock_node (rn);
3971 }
3972
3973 /* Configure static BGP network. When user don't run zebra, static
3974 route should be installed as valid. */
3975 static int
3976 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3977 afi_t afi, safi_t safi, const char *rmap, int backdoor)
3978 {
3979 int ret;
3980 struct prefix p;
3981 struct bgp_static *bgp_static;
3982 struct bgp_node *rn;
3983 u_char need_update = 0;
3984
3985 /* Convert IP prefix string to struct prefix. */
3986 ret = str2prefix (ip_str, &p);
3987 if (! ret)
3988 {
3989 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3990 return CMD_WARNING;
3991 }
3992 #ifdef HAVE_IPV6
3993 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3994 {
3995 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3996 VTY_NEWLINE);
3997 return CMD_WARNING;
3998 }
3999 #endif /* HAVE_IPV6 */
4000
4001 apply_mask (&p);
4002
4003 /* Set BGP static route configuration. */
4004 rn = bgp_node_get (bgp->route[afi][safi], &p);
4005
4006 if (rn->info)
4007 {
4008 /* Configuration change. */
4009 bgp_static = rn->info;
4010
4011 /* Check previous routes are installed into BGP. */
4012 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4013 need_update = 1;
4014
4015 bgp_static->backdoor = backdoor;
4016
4017 if (rmap)
4018 {
4019 if (bgp_static->rmap.name)
4020 free (bgp_static->rmap.name);
4021 bgp_static->rmap.name = strdup (rmap);
4022 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4023 }
4024 else
4025 {
4026 if (bgp_static->rmap.name)
4027 free (bgp_static->rmap.name);
4028 bgp_static->rmap.name = NULL;
4029 bgp_static->rmap.map = NULL;
4030 bgp_static->valid = 0;
4031 }
4032 bgp_unlock_node (rn);
4033 }
4034 else
4035 {
4036 /* New configuration. */
4037 bgp_static = bgp_static_new ();
4038 bgp_static->backdoor = backdoor;
4039 bgp_static->valid = 0;
4040 bgp_static->igpmetric = 0;
4041 bgp_static->igpnexthop.s_addr = 0;
4042
4043 if (rmap)
4044 {
4045 if (bgp_static->rmap.name)
4046 free (bgp_static->rmap.name);
4047 bgp_static->rmap.name = strdup (rmap);
4048 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4049 }
4050 rn->info = bgp_static;
4051 }
4052
4053 bgp_static->valid = 1;
4054 if (need_update)
4055 bgp_static_withdraw (bgp, &p, afi, safi);
4056
4057 if (! bgp_static->backdoor)
4058 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4059
4060 return CMD_SUCCESS;
4061 }
4062
4063 /* Configure static BGP network. */
4064 static int
4065 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4066 afi_t afi, safi_t safi)
4067 {
4068 int ret;
4069 struct prefix p;
4070 struct bgp_static *bgp_static;
4071 struct bgp_node *rn;
4072
4073 /* Convert IP prefix string to struct prefix. */
4074 ret = str2prefix (ip_str, &p);
4075 if (! ret)
4076 {
4077 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4078 return CMD_WARNING;
4079 }
4080 #ifdef HAVE_IPV6
4081 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4082 {
4083 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4084 VTY_NEWLINE);
4085 return CMD_WARNING;
4086 }
4087 #endif /* HAVE_IPV6 */
4088
4089 apply_mask (&p);
4090
4091 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4092 if (! rn)
4093 {
4094 vty_out (vty, "%% Can't find specified static route configuration.%s",
4095 VTY_NEWLINE);
4096 return CMD_WARNING;
4097 }
4098
4099 bgp_static = rn->info;
4100
4101 /* Update BGP RIB. */
4102 if (! bgp_static->backdoor)
4103 bgp_static_withdraw (bgp, &p, afi, safi);
4104
4105 /* Clear configuration. */
4106 bgp_unlink_nexthop(bgp_static);
4107 bgp_static_free (bgp_static);
4108 rn->info = NULL;
4109 bgp_unlock_node (rn);
4110 bgp_unlock_node (rn);
4111
4112 return CMD_SUCCESS;
4113 }
4114
4115 /* Called from bgp_delete(). Delete all static routes from the BGP
4116 instance. */
4117 void
4118 bgp_static_delete (struct bgp *bgp)
4119 {
4120 afi_t afi;
4121 safi_t safi;
4122 struct bgp_node *rn;
4123 struct bgp_node *rm;
4124 struct bgp_table *table;
4125 struct bgp_static *bgp_static;
4126
4127 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4128 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4129 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4130 if (rn->info != NULL)
4131 {
4132 if (safi == SAFI_MPLS_VPN)
4133 {
4134 table = rn->info;
4135
4136 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4137 {
4138 bgp_static = rn->info;
4139 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
4140 AFI_IP, SAFI_MPLS_VPN,
4141 (struct prefix_rd *)&rn->p,
4142 bgp_static->tag);
4143 bgp_static_free (bgp_static);
4144 rn->info = NULL;
4145 bgp_unlock_node (rn);
4146 }
4147 }
4148 else
4149 {
4150 bgp_static = rn->info;
4151 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4152 bgp_static_free (bgp_static);
4153 rn->info = NULL;
4154 bgp_unlock_node (rn);
4155 }
4156 }
4157 }
4158
4159 int
4160 bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
4161 const char *tag_str)
4162 {
4163 int ret;
4164 struct prefix p;
4165 struct prefix_rd prd;
4166 struct bgp *bgp;
4167 struct bgp_node *prn;
4168 struct bgp_node *rn;
4169 struct bgp_table *table;
4170 struct bgp_static *bgp_static;
4171 u_char tag[3];
4172
4173 bgp = vty->index;
4174
4175 ret = str2prefix (ip_str, &p);
4176 if (! ret)
4177 {
4178 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4179 return CMD_WARNING;
4180 }
4181 apply_mask (&p);
4182
4183 ret = str2prefix_rd (rd_str, &prd);
4184 if (! ret)
4185 {
4186 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4187 return CMD_WARNING;
4188 }
4189
4190 ret = str2tag (tag_str, tag);
4191 if (! ret)
4192 {
4193 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4194 return CMD_WARNING;
4195 }
4196
4197 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4198 (struct prefix *)&prd);
4199 if (prn->info == NULL)
4200 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
4201 else
4202 bgp_unlock_node (prn);
4203 table = prn->info;
4204
4205 rn = bgp_node_get (table, &p);
4206
4207 if (rn->info)
4208 {
4209 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4210 bgp_unlock_node (rn);
4211 }
4212 else
4213 {
4214 /* New configuration. */
4215 bgp_static = bgp_static_new ();
4216 bgp_static->valid = 1;
4217 memcpy (bgp_static->tag, tag, 3);
4218 rn->info = bgp_static;
4219
4220 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4221 }
4222
4223 return CMD_SUCCESS;
4224 }
4225
4226 /* Configure static BGP network. */
4227 int
4228 bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
4229 const char *rd_str, const char *tag_str)
4230 {
4231 int ret;
4232 struct bgp *bgp;
4233 struct prefix p;
4234 struct prefix_rd prd;
4235 struct bgp_node *prn;
4236 struct bgp_node *rn;
4237 struct bgp_table *table;
4238 struct bgp_static *bgp_static;
4239 u_char tag[3];
4240
4241 bgp = vty->index;
4242
4243 /* Convert IP prefix string to struct prefix. */
4244 ret = str2prefix (ip_str, &p);
4245 if (! ret)
4246 {
4247 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4248 return CMD_WARNING;
4249 }
4250 apply_mask (&p);
4251
4252 ret = str2prefix_rd (rd_str, &prd);
4253 if (! ret)
4254 {
4255 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4256 return CMD_WARNING;
4257 }
4258
4259 ret = str2tag (tag_str, tag);
4260 if (! ret)
4261 {
4262 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4263 return CMD_WARNING;
4264 }
4265
4266 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4267 (struct prefix *)&prd);
4268 if (prn->info == NULL)
4269 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
4270 else
4271 bgp_unlock_node (prn);
4272 table = prn->info;
4273
4274 rn = bgp_node_lookup (table, &p);
4275
4276 if (rn)
4277 {
4278 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4279
4280 bgp_static = rn->info;
4281 bgp_static_free (bgp_static);
4282 rn->info = NULL;
4283 bgp_unlock_node (rn);
4284 bgp_unlock_node (rn);
4285 }
4286 else
4287 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4288
4289 return CMD_SUCCESS;
4290 }
4291
4292 static int
4293 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4294 const char *rmap_name)
4295 {
4296 struct bgp_rmap *rmap;
4297
4298 rmap = &bgp->table_map[afi][safi];
4299 if (rmap_name)
4300 {
4301 if (rmap->name)
4302 free (rmap->name);
4303 rmap->name = strdup (rmap_name);
4304 rmap->map = route_map_lookup_by_name (rmap_name);
4305 }
4306 else
4307 {
4308 if (rmap->name)
4309 free (rmap->name);
4310 rmap->name = NULL;
4311 rmap->map = NULL;
4312 }
4313
4314 bgp_zebra_announce_table(bgp, afi, safi);
4315
4316 return CMD_SUCCESS;
4317 }
4318
4319 static int
4320 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4321 const char *rmap_name)
4322 {
4323 struct bgp_rmap *rmap;
4324
4325 rmap = &bgp->table_map[afi][safi];
4326 if (rmap->name)
4327 free (rmap->name);
4328 rmap->name = NULL;
4329 rmap->map = NULL;
4330
4331 bgp_zebra_announce_table(bgp, afi, safi);
4332
4333 return CMD_SUCCESS;
4334 }
4335
4336 int
4337 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4338 safi_t safi, int *write)
4339 {
4340 if (bgp->table_map[afi][safi].name)
4341 {
4342 bgp_config_write_family_header (vty, afi, safi, write);
4343 vty_out (vty, " table-map %s%s",
4344 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4345 }
4346
4347 return 0;
4348 }
4349
4350
4351 DEFUN (bgp_table_map,
4352 bgp_table_map_cmd,
4353 "table-map WORD",
4354 "BGP table to RIB route download filter\n"
4355 "Name of the route map\n")
4356 {
4357 return bgp_table_map_set (vty, vty->index,
4358 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4359 }
4360 DEFUN (no_bgp_table_map,
4361 no_bgp_table_map_cmd,
4362 "no table-map WORD",
4363 "BGP table to RIB route download filter\n"
4364 "Name of the route map\n")
4365 {
4366 return bgp_table_map_unset (vty, vty->index,
4367 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4368 }
4369
4370 DEFUN (bgp_network,
4371 bgp_network_cmd,
4372 "network A.B.C.D/M",
4373 "Specify a network to announce via BGP\n"
4374 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4375 {
4376 return bgp_static_set (vty, vty->index, argv[0],
4377 AFI_IP, bgp_node_safi (vty), NULL, 0);
4378 }
4379
4380 DEFUN (bgp_network_route_map,
4381 bgp_network_route_map_cmd,
4382 "network A.B.C.D/M route-map WORD",
4383 "Specify a network to announce via BGP\n"
4384 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4385 "Route-map to modify the attributes\n"
4386 "Name of the route map\n")
4387 {
4388 return bgp_static_set (vty, vty->index, argv[0],
4389 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4390 }
4391
4392 DEFUN (bgp_network_backdoor,
4393 bgp_network_backdoor_cmd,
4394 "network A.B.C.D/M backdoor",
4395 "Specify a network to announce via BGP\n"
4396 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4397 "Specify a BGP backdoor route\n")
4398 {
4399 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4400 NULL, 1);
4401 }
4402
4403 DEFUN (bgp_network_mask,
4404 bgp_network_mask_cmd,
4405 "network A.B.C.D mask A.B.C.D",
4406 "Specify a network to announce via BGP\n"
4407 "Network number\n"
4408 "Network mask\n"
4409 "Network mask\n")
4410 {
4411 int ret;
4412 char prefix_str[BUFSIZ];
4413
4414 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4415 if (! ret)
4416 {
4417 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4418 return CMD_WARNING;
4419 }
4420
4421 return bgp_static_set (vty, vty->index, prefix_str,
4422 AFI_IP, bgp_node_safi (vty), NULL, 0);
4423 }
4424
4425 DEFUN (bgp_network_mask_route_map,
4426 bgp_network_mask_route_map_cmd,
4427 "network A.B.C.D mask A.B.C.D route-map WORD",
4428 "Specify a network to announce via BGP\n"
4429 "Network number\n"
4430 "Network mask\n"
4431 "Network mask\n"
4432 "Route-map to modify the attributes\n"
4433 "Name of the route map\n")
4434 {
4435 int ret;
4436 char prefix_str[BUFSIZ];
4437
4438 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4439 if (! ret)
4440 {
4441 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4442 return CMD_WARNING;
4443 }
4444
4445 return bgp_static_set (vty, vty->index, prefix_str,
4446 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4447 }
4448
4449 DEFUN (bgp_network_mask_backdoor,
4450 bgp_network_mask_backdoor_cmd,
4451 "network A.B.C.D mask A.B.C.D backdoor",
4452 "Specify a network to announce via BGP\n"
4453 "Network number\n"
4454 "Network mask\n"
4455 "Network mask\n"
4456 "Specify a BGP backdoor route\n")
4457 {
4458 int ret;
4459 char prefix_str[BUFSIZ];
4460
4461 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4462 if (! ret)
4463 {
4464 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4465 return CMD_WARNING;
4466 }
4467
4468 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4469 NULL, 1);
4470 }
4471
4472 DEFUN (bgp_network_mask_natural,
4473 bgp_network_mask_natural_cmd,
4474 "network A.B.C.D",
4475 "Specify a network to announce via BGP\n"
4476 "Network number\n")
4477 {
4478 int ret;
4479 char prefix_str[BUFSIZ];
4480
4481 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4482 if (! ret)
4483 {
4484 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4485 return CMD_WARNING;
4486 }
4487
4488 return bgp_static_set (vty, vty->index, prefix_str,
4489 AFI_IP, bgp_node_safi (vty), NULL, 0);
4490 }
4491
4492 DEFUN (bgp_network_mask_natural_route_map,
4493 bgp_network_mask_natural_route_map_cmd,
4494 "network A.B.C.D route-map WORD",
4495 "Specify a network to announce via BGP\n"
4496 "Network number\n"
4497 "Route-map to modify the attributes\n"
4498 "Name of the route map\n")
4499 {
4500 int ret;
4501 char prefix_str[BUFSIZ];
4502
4503 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4504 if (! ret)
4505 {
4506 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4507 return CMD_WARNING;
4508 }
4509
4510 return bgp_static_set (vty, vty->index, prefix_str,
4511 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4512 }
4513
4514 DEFUN (bgp_network_mask_natural_backdoor,
4515 bgp_network_mask_natural_backdoor_cmd,
4516 "network A.B.C.D backdoor",
4517 "Specify a network to announce via BGP\n"
4518 "Network number\n"
4519 "Specify a BGP backdoor route\n")
4520 {
4521 int ret;
4522 char prefix_str[BUFSIZ];
4523
4524 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4525 if (! ret)
4526 {
4527 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4528 return CMD_WARNING;
4529 }
4530
4531 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4532 NULL, 1);
4533 }
4534
4535 DEFUN (no_bgp_network,
4536 no_bgp_network_cmd,
4537 "no network A.B.C.D/M",
4538 NO_STR
4539 "Specify a network to announce via BGP\n"
4540 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4541 {
4542 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4543 bgp_node_safi (vty));
4544 }
4545
4546 ALIAS (no_bgp_network,
4547 no_bgp_network_route_map_cmd,
4548 "no network A.B.C.D/M route-map WORD",
4549 NO_STR
4550 "Specify a network to announce via BGP\n"
4551 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4552 "Route-map to modify the attributes\n"
4553 "Name of the route map\n")
4554
4555 ALIAS (no_bgp_network,
4556 no_bgp_network_backdoor_cmd,
4557 "no network A.B.C.D/M backdoor",
4558 NO_STR
4559 "Specify a network to announce via BGP\n"
4560 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4561 "Specify a BGP backdoor route\n")
4562
4563 DEFUN (no_bgp_network_mask,
4564 no_bgp_network_mask_cmd,
4565 "no network A.B.C.D mask A.B.C.D",
4566 NO_STR
4567 "Specify a network to announce via BGP\n"
4568 "Network number\n"
4569 "Network mask\n"
4570 "Network mask\n")
4571 {
4572 int ret;
4573 char prefix_str[BUFSIZ];
4574
4575 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4576 if (! ret)
4577 {
4578 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4579 return CMD_WARNING;
4580 }
4581
4582 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4583 bgp_node_safi (vty));
4584 }
4585
4586 ALIAS (no_bgp_network_mask,
4587 no_bgp_network_mask_route_map_cmd,
4588 "no network A.B.C.D mask A.B.C.D route-map WORD",
4589 NO_STR
4590 "Specify a network to announce via BGP\n"
4591 "Network number\n"
4592 "Network mask\n"
4593 "Network mask\n"
4594 "Route-map to modify the attributes\n"
4595 "Name of the route map\n")
4596
4597 ALIAS (no_bgp_network_mask,
4598 no_bgp_network_mask_backdoor_cmd,
4599 "no network A.B.C.D mask A.B.C.D backdoor",
4600 NO_STR
4601 "Specify a network to announce via BGP\n"
4602 "Network number\n"
4603 "Network mask\n"
4604 "Network mask\n"
4605 "Specify a BGP backdoor route\n")
4606
4607 DEFUN (no_bgp_network_mask_natural,
4608 no_bgp_network_mask_natural_cmd,
4609 "no network A.B.C.D",
4610 NO_STR
4611 "Specify a network to announce via BGP\n"
4612 "Network number\n")
4613 {
4614 int ret;
4615 char prefix_str[BUFSIZ];
4616
4617 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4618 if (! ret)
4619 {
4620 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4621 return CMD_WARNING;
4622 }
4623
4624 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4625 bgp_node_safi (vty));
4626 }
4627
4628 ALIAS (no_bgp_network_mask_natural,
4629 no_bgp_network_mask_natural_route_map_cmd,
4630 "no network A.B.C.D route-map WORD",
4631 NO_STR
4632 "Specify a network to announce via BGP\n"
4633 "Network number\n"
4634 "Route-map to modify the attributes\n"
4635 "Name of the route map\n")
4636
4637 ALIAS (no_bgp_network_mask_natural,
4638 no_bgp_network_mask_natural_backdoor_cmd,
4639 "no network A.B.C.D backdoor",
4640 NO_STR
4641 "Specify a network to announce via BGP\n"
4642 "Network number\n"
4643 "Specify a BGP backdoor route\n")
4644
4645 #ifdef HAVE_IPV6
4646 DEFUN (ipv6_bgp_network,
4647 ipv6_bgp_network_cmd,
4648 "network X:X::X:X/M",
4649 "Specify a network to announce via BGP\n"
4650 "IPv6 prefix <network>/<length>\n")
4651 {
4652 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4653 NULL, 0);
4654 }
4655
4656 DEFUN (ipv6_bgp_network_route_map,
4657 ipv6_bgp_network_route_map_cmd,
4658 "network X:X::X:X/M route-map WORD",
4659 "Specify a network to announce via BGP\n"
4660 "IPv6 prefix <network>/<length>\n"
4661 "Route-map to modify the attributes\n"
4662 "Name of the route map\n")
4663 {
4664 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4665 bgp_node_safi (vty), argv[1], 0);
4666 }
4667
4668 DEFUN (no_ipv6_bgp_network,
4669 no_ipv6_bgp_network_cmd,
4670 "no network X:X::X:X/M",
4671 NO_STR
4672 "Specify a network to announce via BGP\n"
4673 "IPv6 prefix <network>/<length>\n")
4674 {
4675 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4676 }
4677
4678 ALIAS (no_ipv6_bgp_network,
4679 no_ipv6_bgp_network_route_map_cmd,
4680 "no network X:X::X:X/M route-map WORD",
4681 NO_STR
4682 "Specify a network to announce via BGP\n"
4683 "IPv6 prefix <network>/<length>\n"
4684 "Route-map to modify the attributes\n"
4685 "Name of the route map\n")
4686
4687 ALIAS (ipv6_bgp_network,
4688 old_ipv6_bgp_network_cmd,
4689 "ipv6 bgp network X:X::X:X/M",
4690 IPV6_STR
4691 BGP_STR
4692 "Specify a network to announce via BGP\n"
4693 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4694
4695 ALIAS (no_ipv6_bgp_network,
4696 old_no_ipv6_bgp_network_cmd,
4697 "no ipv6 bgp network X:X::X:X/M",
4698 NO_STR
4699 IPV6_STR
4700 BGP_STR
4701 "Specify a network to announce via BGP\n"
4702 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4703 #endif /* HAVE_IPV6 */
4704
4705 /* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4706 ALIAS_DEPRECATED (bgp_network,
4707 bgp_network_ttl_cmd,
4708 "network A.B.C.D/M pathlimit <0-255>",
4709 "Specify a network to announce via BGP\n"
4710 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4711 "AS-Path hopcount limit attribute\n"
4712 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4713 ALIAS_DEPRECATED (bgp_network_backdoor,
4714 bgp_network_backdoor_ttl_cmd,
4715 "network A.B.C.D/M backdoor pathlimit <0-255>",
4716 "Specify a network to announce via BGP\n"
4717 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4718 "Specify a BGP backdoor route\n"
4719 "AS-Path hopcount limit attribute\n"
4720 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4721 ALIAS_DEPRECATED (bgp_network_mask,
4722 bgp_network_mask_ttl_cmd,
4723 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4724 "Specify a network to announce via BGP\n"
4725 "Network number\n"
4726 "Network mask\n"
4727 "Network mask\n"
4728 "AS-Path hopcount limit attribute\n"
4729 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4730 ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4731 bgp_network_mask_backdoor_ttl_cmd,
4732 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4733 "Specify a network to announce via BGP\n"
4734 "Network number\n"
4735 "Network mask\n"
4736 "Network mask\n"
4737 "Specify a BGP backdoor route\n"
4738 "AS-Path hopcount limit attribute\n"
4739 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4740 ALIAS_DEPRECATED (bgp_network_mask_natural,
4741 bgp_network_mask_natural_ttl_cmd,
4742 "network A.B.C.D pathlimit <0-255>",
4743 "Specify a network to announce via BGP\n"
4744 "Network number\n"
4745 "AS-Path hopcount limit attribute\n"
4746 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4747 ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4748 bgp_network_mask_natural_backdoor_ttl_cmd,
4749 "network A.B.C.D backdoor pathlimit <1-255>",
4750 "Specify a network to announce via BGP\n"
4751 "Network number\n"
4752 "Specify a BGP backdoor route\n"
4753 "AS-Path hopcount limit attribute\n"
4754 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4755 ALIAS_DEPRECATED (no_bgp_network,
4756 no_bgp_network_ttl_cmd,
4757 "no network A.B.C.D/M pathlimit <0-255>",
4758 NO_STR
4759 "Specify a network to announce via BGP\n"
4760 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4761 "AS-Path hopcount limit attribute\n"
4762 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4763 ALIAS_DEPRECATED (no_bgp_network,
4764 no_bgp_network_backdoor_ttl_cmd,
4765 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4766 NO_STR
4767 "Specify a network to announce via BGP\n"
4768 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4769 "Specify a BGP backdoor route\n"
4770 "AS-Path hopcount limit attribute\n"
4771 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4772 ALIAS_DEPRECATED (no_bgp_network,
4773 no_bgp_network_mask_ttl_cmd,
4774 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4775 NO_STR
4776 "Specify a network to announce via BGP\n"
4777 "Network number\n"
4778 "Network mask\n"
4779 "Network mask\n"
4780 "AS-Path hopcount limit attribute\n"
4781 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4782 ALIAS_DEPRECATED (no_bgp_network_mask,
4783 no_bgp_network_mask_backdoor_ttl_cmd,
4784 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4785 NO_STR
4786 "Specify a network to announce via BGP\n"
4787 "Network number\n"
4788 "Network mask\n"
4789 "Network mask\n"
4790 "Specify a BGP backdoor route\n"
4791 "AS-Path hopcount limit attribute\n"
4792 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4793 ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4794 no_bgp_network_mask_natural_ttl_cmd,
4795 "no network A.B.C.D pathlimit <0-255>",
4796 NO_STR
4797 "Specify a network to announce via BGP\n"
4798 "Network number\n"
4799 "AS-Path hopcount limit attribute\n"
4800 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4801 ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4802 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4803 "no network A.B.C.D backdoor pathlimit <0-255>",
4804 NO_STR
4805 "Specify a network to announce via BGP\n"
4806 "Network number\n"
4807 "Specify a BGP backdoor route\n"
4808 "AS-Path hopcount limit attribute\n"
4809 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4810 #ifdef HAVE_IPV6
4811 ALIAS_DEPRECATED (ipv6_bgp_network,
4812 ipv6_bgp_network_ttl_cmd,
4813 "network X:X::X:X/M pathlimit <0-255>",
4814 "Specify a network to announce via BGP\n"
4815 "IPv6 prefix <network>/<length>\n"
4816 "AS-Path hopcount limit attribute\n"
4817 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4818 ALIAS_DEPRECATED (no_ipv6_bgp_network,
4819 no_ipv6_bgp_network_ttl_cmd,
4820 "no network X:X::X:X/M pathlimit <0-255>",
4821 NO_STR
4822 "Specify a network to announce via BGP\n"
4823 "IPv6 prefix <network>/<length>\n"
4824 "AS-Path hopcount limit attribute\n"
4825 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4826 #endif /* HAVE_IPV6 */
4827
4828 /* Aggreagete address:
4829
4830 advertise-map Set condition to advertise attribute
4831 as-set Generate AS set path information
4832 attribute-map Set attributes of aggregate
4833 route-map Set parameters of aggregate
4834 summary-only Filter more specific routes from updates
4835 suppress-map Conditionally filter more specific routes from updates
4836 <cr>
4837 */
4838 struct bgp_aggregate
4839 {
4840 /* Summary-only flag. */
4841 u_char summary_only;
4842
4843 /* AS set generation. */
4844 u_char as_set;
4845
4846 /* Route-map for aggregated route. */
4847 struct route_map *map;
4848
4849 /* Suppress-count. */
4850 unsigned long count;
4851
4852 /* SAFI configuration. */
4853 safi_t safi;
4854 };
4855
4856 static struct bgp_aggregate *
4857 bgp_aggregate_new (void)
4858 {
4859 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4860 }
4861
4862 static void
4863 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4864 {
4865 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4866 }
4867
4868 /* Update an aggregate as routes are added/removed from the BGP table */
4869 static void
4870 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4871 afi_t afi, safi_t safi, struct bgp_info *del,
4872 struct bgp_aggregate *aggregate)
4873 {
4874 struct bgp_table *table;
4875 struct bgp_node *top;
4876 struct bgp_node *rn;
4877 u_char origin;
4878 struct aspath *aspath = NULL;
4879 struct aspath *asmerge = NULL;
4880 struct community *community = NULL;
4881 struct community *commerge = NULL;
4882 struct in_addr nexthop;
4883 u_int32_t med = 0;
4884 struct bgp_info *ri;
4885 struct bgp_info *new;
4886 int first = 1;
4887 unsigned long match = 0;
4888 u_char atomic_aggregate = 0;
4889
4890 /* Record adding route's nexthop and med. */
4891 if (rinew)
4892 {
4893 nexthop = rinew->attr->nexthop;
4894 med = rinew->attr->med;
4895 }
4896
4897 /* ORIGIN attribute: If at least one route among routes that are
4898 aggregated has ORIGIN with the value INCOMPLETE, then the
4899 aggregated route must have the ORIGIN attribute with the value
4900 INCOMPLETE. Otherwise, if at least one route among routes that
4901 are aggregated has ORIGIN with the value EGP, then the aggregated
4902 route must have the origin attribute with the value EGP. In all
4903 other case the value of the ORIGIN attribute of the aggregated
4904 route is INTERNAL. */
4905 origin = BGP_ORIGIN_IGP;
4906
4907 table = bgp->rib[afi][safi];
4908
4909 top = bgp_node_get (table, p);
4910 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4911 if (rn->p.prefixlen > p->prefixlen)
4912 {
4913 match = 0;
4914
4915 for (ri = rn->info; ri; ri = ri->next)
4916 {
4917 if (BGP_INFO_HOLDDOWN (ri))
4918 continue;
4919
4920 if (del && ri == del)
4921 continue;
4922
4923 if (! rinew && first)
4924 {
4925 nexthop = ri->attr->nexthop;
4926 med = ri->attr->med;
4927 first = 0;
4928 }
4929
4930 #ifdef AGGREGATE_NEXTHOP_CHECK
4931 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4932 || ri->attr->med != med)
4933 {
4934 if (aspath)
4935 aspath_free (aspath);
4936 if (community)
4937 community_free (community);
4938 bgp_unlock_node (rn);
4939 bgp_unlock_node (top);
4940 return;
4941 }
4942 #endif /* AGGREGATE_NEXTHOP_CHECK */
4943
4944 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4945 atomic_aggregate = 1;
4946
4947 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4948 {
4949 if (aggregate->summary_only)
4950 {
4951 (bgp_info_extra_get (ri))->suppress++;
4952 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4953 match++;
4954 }
4955
4956 aggregate->count++;
4957
4958 if (origin < ri->attr->origin)
4959 origin = ri->attr->origin;
4960
4961 if (aggregate->as_set)
4962 {
4963 if (aspath)
4964 {
4965 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4966 aspath_free (aspath);
4967 aspath = asmerge;
4968 }
4969 else
4970 aspath = aspath_dup (ri->attr->aspath);
4971
4972 if (ri->attr->community)
4973 {
4974 if (community)
4975 {
4976 commerge = community_merge (community,
4977 ri->attr->community);
4978 community = community_uniq_sort (commerge);
4979 community_free (commerge);
4980 }
4981 else
4982 community = community_dup (ri->attr->community);
4983 }
4984 }
4985 }
4986 }
4987 if (match)
4988 bgp_process (bgp, rn, afi, safi);
4989 }
4990 bgp_unlock_node (top);
4991
4992 if (rinew)
4993 {
4994 aggregate->count++;
4995
4996 if (aggregate->summary_only)
4997 (bgp_info_extra_get (rinew))->suppress++;
4998
4999 if (origin < rinew->attr->origin)
5000 origin = rinew->attr->origin;
5001
5002 if (aggregate->as_set)
5003 {
5004 if (aspath)
5005 {
5006 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5007 aspath_free (aspath);
5008 aspath = asmerge;
5009 }
5010 else
5011 aspath = aspath_dup (rinew->attr->aspath);
5012
5013 if (rinew->attr->community)
5014 {
5015 if (community)
5016 {
5017 commerge = community_merge (community,
5018 rinew->attr->community);
5019 community = community_uniq_sort (commerge);
5020 community_free (commerge);
5021 }
5022 else
5023 community = community_dup (rinew->attr->community);
5024 }
5025 }
5026 }
5027
5028 if (aggregate->count > 0)
5029 {
5030 rn = bgp_node_get (table, p);
5031 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
5032 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5033 aggregate->as_set,
5034 atomic_aggregate), rn);
5035 SET_FLAG (new->flags, BGP_INFO_VALID);
5036
5037 bgp_info_add (rn, new);
5038 bgp_unlock_node (rn);
5039 bgp_process (bgp, rn, afi, safi);
5040 }
5041 else
5042 {
5043 if (aspath)
5044 aspath_free (aspath);
5045 if (community)
5046 community_free (community);
5047 }
5048 }
5049
5050 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5051 struct bgp_aggregate *);
5052
5053 void
5054 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5055 struct bgp_info *ri, afi_t afi, safi_t safi)
5056 {
5057 struct bgp_node *child;
5058 struct bgp_node *rn;
5059 struct bgp_aggregate *aggregate;
5060 struct bgp_table *table;
5061
5062 /* MPLS-VPN aggregation is not yet supported. */
5063 if (safi == SAFI_MPLS_VPN)
5064 return;
5065
5066 table = bgp->aggregate[afi][safi];
5067
5068 /* No aggregates configured. */
5069 if (bgp_table_top_nolock (table) == NULL)
5070 return;
5071
5072 if (p->prefixlen == 0)
5073 return;
5074
5075 if (BGP_INFO_HOLDDOWN (ri))
5076 return;
5077
5078 child = bgp_node_get (table, p);
5079
5080 /* Aggregate address configuration check. */
5081 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5082 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5083 {
5084 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5085 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
5086 }
5087 bgp_unlock_node (child);
5088 }
5089
5090 void
5091 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5092 struct bgp_info *del, afi_t afi, safi_t safi)
5093 {
5094 struct bgp_node *child;
5095 struct bgp_node *rn;
5096 struct bgp_aggregate *aggregate;
5097 struct bgp_table *table;
5098
5099 /* MPLS-VPN aggregation is not yet supported. */
5100 if (safi == SAFI_MPLS_VPN)
5101 return;
5102
5103 table = bgp->aggregate[afi][safi];
5104
5105 /* No aggregates configured. */
5106 if (bgp_table_top_nolock (table) == NULL)
5107 return;
5108
5109 if (p->prefixlen == 0)
5110 return;
5111
5112 child = bgp_node_get (table, p);
5113
5114 /* Aggregate address configuration check. */
5115 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5116 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5117 {
5118 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5119 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
5120 }
5121 bgp_unlock_node (child);
5122 }
5123
5124 /* Called via bgp_aggregate_set when the user configures aggregate-address */
5125 static void
5126 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5127 struct bgp_aggregate *aggregate)
5128 {
5129 struct bgp_table *table;
5130 struct bgp_node *top;
5131 struct bgp_node *rn;
5132 struct bgp_info *new;
5133 struct bgp_info *ri;
5134 unsigned long match;
5135 u_char origin = BGP_ORIGIN_IGP;
5136 struct aspath *aspath = NULL;
5137 struct aspath *asmerge = NULL;
5138 struct community *community = NULL;
5139 struct community *commerge = NULL;
5140 u_char atomic_aggregate = 0;
5141
5142 table = bgp->rib[afi][safi];
5143
5144 /* Sanity check. */
5145 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5146 return;
5147 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5148 return;
5149
5150 /* If routes exists below this node, generate aggregate routes. */
5151 top = bgp_node_get (table, p);
5152 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5153 if (rn->p.prefixlen > p->prefixlen)
5154 {
5155 match = 0;
5156
5157 for (ri = rn->info; ri; ri = ri->next)
5158 {
5159 if (BGP_INFO_HOLDDOWN (ri))
5160 continue;
5161
5162 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5163 atomic_aggregate = 1;
5164
5165 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5166 {
5167 /* summary-only aggregate route suppress aggregated
5168 route announcement. */
5169 if (aggregate->summary_only)
5170 {
5171 (bgp_info_extra_get (ri))->suppress++;
5172 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5173 match++;
5174 }
5175
5176 /* If at least one route among routes that are aggregated has
5177 * ORIGIN with the value INCOMPLETE, then the aggregated route
5178 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5179 * Otherwise, if at least one route among routes that are
5180 * aggregated has ORIGIN with the value EGP, then the aggregated
5181 * route MUST have the ORIGIN attribute with the value EGP.
5182 */
5183 if (origin < ri->attr->origin)
5184 origin = ri->attr->origin;
5185
5186 /* as-set aggregate route generate origin, as path,
5187 community aggregation. */
5188 if (aggregate->as_set)
5189 {
5190 if (aspath)
5191 {
5192 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5193 aspath_free (aspath);
5194 aspath = asmerge;
5195 }
5196 else
5197 aspath = aspath_dup (ri->attr->aspath);
5198
5199 if (ri->attr->community)
5200 {
5201 if (community)
5202 {
5203 commerge = community_merge (community,
5204 ri->attr->community);
5205 community = community_uniq_sort (commerge);
5206 community_free (commerge);
5207 }
5208 else
5209 community = community_dup (ri->attr->community);
5210 }
5211 }
5212 aggregate->count++;
5213 }
5214 }
5215
5216 /* If this node is suppressed, process the change. */
5217 if (match)
5218 bgp_process (bgp, rn, afi, safi);
5219 }
5220 bgp_unlock_node (top);
5221
5222 /* Add aggregate route to BGP table. */
5223 if (aggregate->count)
5224 {
5225 rn = bgp_node_get (table, p);
5226 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
5227 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5228 aggregate->as_set,
5229 atomic_aggregate), rn);
5230 SET_FLAG (new->flags, BGP_INFO_VALID);
5231
5232 bgp_info_add (rn, new);
5233 bgp_unlock_node (rn);
5234
5235 /* Process change. */
5236 bgp_process (bgp, rn, afi, safi);
5237 }
5238 }
5239
5240 void
5241 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5242 safi_t safi, struct bgp_aggregate *aggregate)
5243 {
5244 struct bgp_table *table;
5245 struct bgp_node *top;
5246 struct bgp_node *rn;
5247 struct bgp_info *ri;
5248 unsigned long match;
5249
5250 table = bgp->rib[afi][safi];
5251
5252 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5253 return;
5254 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5255 return;
5256
5257 /* If routes exists below this node, generate aggregate routes. */
5258 top = bgp_node_get (table, p);
5259 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5260 if (rn->p.prefixlen > p->prefixlen)
5261 {
5262 match = 0;
5263
5264 for (ri = rn->info; ri; ri = ri->next)
5265 {
5266 if (BGP_INFO_HOLDDOWN (ri))
5267 continue;
5268
5269 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5270 {
5271 if (aggregate->summary_only && ri->extra)
5272 {
5273 ri->extra->suppress--;
5274
5275 if (ri->extra->suppress == 0)
5276 {
5277 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5278 match++;
5279 }
5280 }
5281 aggregate->count--;
5282 }
5283 }
5284
5285 /* If this node was suppressed, process the change. */
5286 if (match)
5287 bgp_process (bgp, rn, afi, safi);
5288 }
5289 bgp_unlock_node (top);
5290
5291 /* Delete aggregate route from BGP table. */
5292 rn = bgp_node_get (table, p);
5293
5294 for (ri = rn->info; ri; ri = ri->next)
5295 if (ri->peer == bgp->peer_self
5296 && ri->type == ZEBRA_ROUTE_BGP
5297 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5298 break;
5299
5300 /* Withdraw static BGP route from routing table. */
5301 if (ri)
5302 {
5303 bgp_info_delete (rn, ri);
5304 bgp_process (bgp, rn, afi, safi);
5305 }
5306
5307 /* Unlock bgp_node_lookup. */
5308 bgp_unlock_node (rn);
5309 }
5310
5311 /* Aggregate route attribute. */
5312 #define AGGREGATE_SUMMARY_ONLY 1
5313 #define AGGREGATE_AS_SET 1
5314
5315 static int
5316 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5317 afi_t afi, safi_t safi)
5318 {
5319 int ret;
5320 struct prefix p;
5321 struct bgp_node *rn;
5322 struct bgp *bgp;
5323 struct bgp_aggregate *aggregate;
5324
5325 /* Convert string to prefix structure. */
5326 ret = str2prefix (prefix_str, &p);
5327 if (!ret)
5328 {
5329 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5330 return CMD_WARNING;
5331 }
5332 apply_mask (&p);
5333
5334 /* Get BGP structure. */
5335 bgp = vty->index;
5336
5337 /* Old configuration check. */
5338 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5339 if (! rn)
5340 {
5341 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5342 VTY_NEWLINE);
5343 return CMD_WARNING;
5344 }
5345
5346 aggregate = rn->info;
5347 if (aggregate->safi & SAFI_UNICAST)
5348 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5349 if (aggregate->safi & SAFI_MULTICAST)
5350 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5351
5352 /* Unlock aggregate address configuration. */
5353 rn->info = NULL;
5354 bgp_aggregate_free (aggregate);
5355 bgp_unlock_node (rn);
5356 bgp_unlock_node (rn);
5357
5358 return CMD_SUCCESS;
5359 }
5360
5361 static int
5362 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5363 afi_t afi, safi_t safi,
5364 u_char summary_only, u_char as_set)
5365 {
5366 int ret;
5367 struct prefix p;
5368 struct bgp_node *rn;
5369 struct bgp *bgp;
5370 struct bgp_aggregate *aggregate;
5371
5372 /* Convert string to prefix structure. */
5373 ret = str2prefix (prefix_str, &p);
5374 if (!ret)
5375 {
5376 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5377 return CMD_WARNING;
5378 }
5379 apply_mask (&p);
5380
5381 /* Get BGP structure. */
5382 bgp = vty->index;
5383
5384 /* Old configuration check. */
5385 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5386
5387 if (rn->info)
5388 {
5389 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5390 /* try to remove the old entry */
5391 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5392 if (ret)
5393 {
5394 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5395 bgp_unlock_node (rn);
5396 return CMD_WARNING;
5397 }
5398 }
5399
5400 /* Make aggregate address structure. */
5401 aggregate = bgp_aggregate_new ();
5402 aggregate->summary_only = summary_only;
5403 aggregate->as_set = as_set;
5404 aggregate->safi = safi;
5405 rn->info = aggregate;
5406
5407 /* Aggregate address insert into BGP routing table. */
5408 if (safi & SAFI_UNICAST)
5409 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5410 if (safi & SAFI_MULTICAST)
5411 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5412
5413 return CMD_SUCCESS;
5414 }
5415
5416 DEFUN (aggregate_address,
5417 aggregate_address_cmd,
5418 "aggregate-address A.B.C.D/M",
5419 "Configure BGP aggregate entries\n"
5420 "Aggregate prefix\n")
5421 {
5422 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5423 }
5424
5425 DEFUN (aggregate_address_mask,
5426 aggregate_address_mask_cmd,
5427 "aggregate-address A.B.C.D A.B.C.D",
5428 "Configure BGP aggregate entries\n"
5429 "Aggregate address\n"
5430 "Aggregate mask\n")
5431 {
5432 int ret;
5433 char prefix_str[BUFSIZ];
5434
5435 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5436
5437 if (! ret)
5438 {
5439 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5440 return CMD_WARNING;
5441 }
5442
5443 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5444 0, 0);
5445 }
5446
5447 DEFUN (aggregate_address_summary_only,
5448 aggregate_address_summary_only_cmd,
5449 "aggregate-address A.B.C.D/M summary-only",
5450 "Configure BGP aggregate entries\n"
5451 "Aggregate prefix\n"
5452 "Filter more specific routes from updates\n")
5453 {
5454 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5455 AGGREGATE_SUMMARY_ONLY, 0);
5456 }
5457
5458 DEFUN (aggregate_address_mask_summary_only,
5459 aggregate_address_mask_summary_only_cmd,
5460 "aggregate-address A.B.C.D A.B.C.D summary-only",
5461 "Configure BGP aggregate entries\n"
5462 "Aggregate address\n"
5463 "Aggregate mask\n"
5464 "Filter more specific routes from updates\n")
5465 {
5466 int ret;
5467 char prefix_str[BUFSIZ];
5468
5469 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5470
5471 if (! ret)
5472 {
5473 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5474 return CMD_WARNING;
5475 }
5476
5477 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5478 AGGREGATE_SUMMARY_ONLY, 0);
5479 }
5480
5481 DEFUN (aggregate_address_as_set,
5482 aggregate_address_as_set_cmd,
5483 "aggregate-address A.B.C.D/M as-set",
5484 "Configure BGP aggregate entries\n"
5485 "Aggregate prefix\n"
5486 "Generate AS set path information\n")
5487 {
5488 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5489 0, AGGREGATE_AS_SET);
5490 }
5491
5492 DEFUN (aggregate_address_mask_as_set,
5493 aggregate_address_mask_as_set_cmd,
5494 "aggregate-address A.B.C.D A.B.C.D as-set",
5495 "Configure BGP aggregate entries\n"
5496 "Aggregate address\n"
5497 "Aggregate mask\n"
5498 "Generate AS set path information\n")
5499 {
5500 int ret;
5501 char prefix_str[BUFSIZ];
5502
5503 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5504
5505 if (! ret)
5506 {
5507 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5508 return CMD_WARNING;
5509 }
5510
5511 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5512 0, AGGREGATE_AS_SET);
5513 }
5514
5515
5516 DEFUN (aggregate_address_as_set_summary,
5517 aggregate_address_as_set_summary_cmd,
5518 "aggregate-address A.B.C.D/M as-set summary-only",
5519 "Configure BGP aggregate entries\n"
5520 "Aggregate prefix\n"
5521 "Generate AS set path information\n"
5522 "Filter more specific routes from updates\n")
5523 {
5524 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5525 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5526 }
5527
5528 ALIAS (aggregate_address_as_set_summary,
5529 aggregate_address_summary_as_set_cmd,
5530 "aggregate-address A.B.C.D/M summary-only as-set",
5531 "Configure BGP aggregate entries\n"
5532 "Aggregate prefix\n"
5533 "Filter more specific routes from updates\n"
5534 "Generate AS set path information\n")
5535
5536 DEFUN (aggregate_address_mask_as_set_summary,
5537 aggregate_address_mask_as_set_summary_cmd,
5538 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5539 "Configure BGP aggregate entries\n"
5540 "Aggregate address\n"
5541 "Aggregate mask\n"
5542 "Generate AS set path information\n"
5543 "Filter more specific routes from updates\n")
5544 {
5545 int ret;
5546 char prefix_str[BUFSIZ];
5547
5548 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5549
5550 if (! ret)
5551 {
5552 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5553 return CMD_WARNING;
5554 }
5555
5556 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5557 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5558 }
5559
5560 ALIAS (aggregate_address_mask_as_set_summary,
5561 aggregate_address_mask_summary_as_set_cmd,
5562 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5563 "Configure BGP aggregate entries\n"
5564 "Aggregate address\n"
5565 "Aggregate mask\n"
5566 "Filter more specific routes from updates\n"
5567 "Generate AS set path information\n")
5568
5569 DEFUN (no_aggregate_address,
5570 no_aggregate_address_cmd,
5571 "no aggregate-address A.B.C.D/M",
5572 NO_STR
5573 "Configure BGP aggregate entries\n"
5574 "Aggregate prefix\n")
5575 {
5576 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5577 }
5578
5579 ALIAS (no_aggregate_address,
5580 no_aggregate_address_summary_only_cmd,
5581 "no aggregate-address A.B.C.D/M summary-only",
5582 NO_STR
5583 "Configure BGP aggregate entries\n"
5584 "Aggregate prefix\n"
5585 "Filter more specific routes from updates\n")
5586
5587 ALIAS (no_aggregate_address,
5588 no_aggregate_address_as_set_cmd,
5589 "no aggregate-address A.B.C.D/M as-set",
5590 NO_STR
5591 "Configure BGP aggregate entries\n"
5592 "Aggregate prefix\n"
5593 "Generate AS set path information\n")
5594
5595 ALIAS (no_aggregate_address,
5596 no_aggregate_address_as_set_summary_cmd,
5597 "no aggregate-address A.B.C.D/M as-set summary-only",
5598 NO_STR
5599 "Configure BGP aggregate entries\n"
5600 "Aggregate prefix\n"
5601 "Generate AS set path information\n"
5602 "Filter more specific routes from updates\n")
5603
5604 ALIAS (no_aggregate_address,
5605 no_aggregate_address_summary_as_set_cmd,
5606 "no aggregate-address A.B.C.D/M summary-only as-set",
5607 NO_STR
5608 "Configure BGP aggregate entries\n"
5609 "Aggregate prefix\n"
5610 "Filter more specific routes from updates\n"
5611 "Generate AS set path information\n")
5612
5613 DEFUN (no_aggregate_address_mask,
5614 no_aggregate_address_mask_cmd,
5615 "no aggregate-address A.B.C.D A.B.C.D",
5616 NO_STR
5617 "Configure BGP aggregate entries\n"
5618 "Aggregate address\n"
5619 "Aggregate mask\n")
5620 {
5621 int ret;
5622 char prefix_str[BUFSIZ];
5623
5624 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5625
5626 if (! ret)
5627 {
5628 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5629 return CMD_WARNING;
5630 }
5631
5632 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5633 }
5634
5635 ALIAS (no_aggregate_address_mask,
5636 no_aggregate_address_mask_summary_only_cmd,
5637 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5638 NO_STR
5639 "Configure BGP aggregate entries\n"
5640 "Aggregate address\n"
5641 "Aggregate mask\n"
5642 "Filter more specific routes from updates\n")
5643
5644 ALIAS (no_aggregate_address_mask,
5645 no_aggregate_address_mask_as_set_cmd,
5646 "no aggregate-address A.B.C.D A.B.C.D as-set",
5647 NO_STR
5648 "Configure BGP aggregate entries\n"
5649 "Aggregate address\n"
5650 "Aggregate mask\n"
5651 "Generate AS set path information\n")
5652
5653 ALIAS (no_aggregate_address_mask,
5654 no_aggregate_address_mask_as_set_summary_cmd,
5655 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5656 NO_STR
5657 "Configure BGP aggregate entries\n"
5658 "Aggregate address\n"
5659 "Aggregate mask\n"
5660 "Generate AS set path information\n"
5661 "Filter more specific routes from updates\n")
5662
5663 ALIAS (no_aggregate_address_mask,
5664 no_aggregate_address_mask_summary_as_set_cmd,
5665 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5666 NO_STR
5667 "Configure BGP aggregate entries\n"
5668 "Aggregate address\n"
5669 "Aggregate mask\n"
5670 "Filter more specific routes from updates\n"
5671 "Generate AS set path information\n")
5672
5673 #ifdef HAVE_IPV6
5674 DEFUN (ipv6_aggregate_address,
5675 ipv6_aggregate_address_cmd,
5676 "aggregate-address X:X::X:X/M",
5677 "Configure BGP aggregate entries\n"
5678 "Aggregate prefix\n")
5679 {
5680 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5681 }
5682
5683 DEFUN (ipv6_aggregate_address_summary_only,
5684 ipv6_aggregate_address_summary_only_cmd,
5685 "aggregate-address X:X::X:X/M summary-only",
5686 "Configure BGP aggregate entries\n"
5687 "Aggregate prefix\n"
5688 "Filter more specific routes from updates\n")
5689 {
5690 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5691 AGGREGATE_SUMMARY_ONLY, 0);
5692 }
5693
5694 DEFUN (no_ipv6_aggregate_address,
5695 no_ipv6_aggregate_address_cmd,
5696 "no aggregate-address X:X::X:X/M",
5697 NO_STR
5698 "Configure BGP aggregate entries\n"
5699 "Aggregate prefix\n")
5700 {
5701 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5702 }
5703
5704 DEFUN (no_ipv6_aggregate_address_summary_only,
5705 no_ipv6_aggregate_address_summary_only_cmd,
5706 "no aggregate-address X:X::X:X/M summary-only",
5707 NO_STR
5708 "Configure BGP aggregate entries\n"
5709 "Aggregate prefix\n"
5710 "Filter more specific routes from updates\n")
5711 {
5712 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5713 }
5714
5715 ALIAS (ipv6_aggregate_address,
5716 old_ipv6_aggregate_address_cmd,
5717 "ipv6 bgp aggregate-address X:X::X:X/M",
5718 IPV6_STR
5719 BGP_STR
5720 "Configure BGP aggregate entries\n"
5721 "Aggregate prefix\n")
5722
5723 ALIAS (ipv6_aggregate_address_summary_only,
5724 old_ipv6_aggregate_address_summary_only_cmd,
5725 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5726 IPV6_STR
5727 BGP_STR
5728 "Configure BGP aggregate entries\n"
5729 "Aggregate prefix\n"
5730 "Filter more specific routes from updates\n")
5731
5732 ALIAS (no_ipv6_aggregate_address,
5733 old_no_ipv6_aggregate_address_cmd,
5734 "no ipv6 bgp aggregate-address X:X::X:X/M",
5735 NO_STR
5736 IPV6_STR
5737 BGP_STR
5738 "Configure BGP aggregate entries\n"
5739 "Aggregate prefix\n")
5740
5741 ALIAS (no_ipv6_aggregate_address_summary_only,
5742 old_no_ipv6_aggregate_address_summary_only_cmd,
5743 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5744 NO_STR
5745 IPV6_STR
5746 BGP_STR
5747 "Configure BGP aggregate entries\n"
5748 "Aggregate prefix\n"
5749 "Filter more specific routes from updates\n")
5750 #endif /* HAVE_IPV6 */
5751
5752 /* Redistribute route treatment. */
5753 void
5754 bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5755 const struct in6_addr *nexthop6, unsigned int ifindex,
5756 u_int32_t metric, u_char type, u_short tag)
5757 {
5758 struct bgp *bgp;
5759 struct listnode *node, *nnode;
5760 struct bgp_info *new;
5761 struct bgp_info *bi;
5762 struct bgp_info info;
5763 struct bgp_node *bn;
5764 struct attr attr;
5765 struct attr *new_attr;
5766 afi_t afi;
5767 int ret;
5768
5769 /* Make default attribute. */
5770 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5771 if (nexthop)
5772 attr.nexthop = *nexthop;
5773 attr.nh_ifindex = ifindex;
5774
5775 #ifdef HAVE_IPV6
5776 if (nexthop6)
5777 {
5778 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5779 extra->mp_nexthop_global = *nexthop6;
5780 extra->mp_nexthop_len = 16;
5781 }
5782 #endif
5783
5784 attr.med = metric;
5785 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5786 attr.extra->tag = tag;
5787
5788 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5789 {
5790 afi = family2afi (p->family);
5791
5792 if (bgp->redist[afi][type])
5793 {
5794 struct attr attr_new;
5795 struct attr_extra extra_new;
5796
5797 /* Copy attribute for modification. */
5798 attr_new.extra = &extra_new;
5799 bgp_attr_dup (&attr_new, &attr);
5800
5801 if (bgp->redist_metric_flag[afi][type])
5802 attr_new.med = bgp->redist_metric[afi][type];
5803
5804 /* Apply route-map. */
5805 if (bgp->rmap[afi][type].map)
5806 {
5807 info.peer = bgp->peer_self;
5808 info.attr = &attr_new;
5809
5810 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5811
5812 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5813 &info);
5814
5815 bgp->peer_self->rmap_type = 0;
5816
5817 if (ret == RMAP_DENYMATCH)
5818 {
5819 /* Free uninterned attribute. */
5820 bgp_attr_flush (&attr_new);
5821
5822 /* Unintern original. */
5823 aspath_unintern (&attr.aspath);
5824 bgp_attr_extra_free (&attr);
5825 bgp_redistribute_delete (p, type);
5826 return;
5827 }
5828 }
5829
5830 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5831 afi, SAFI_UNICAST, p, NULL);
5832
5833 new_attr = bgp_attr_intern (&attr_new);
5834
5835 for (bi = bn->info; bi; bi = bi->next)
5836 if (bi->peer == bgp->peer_self
5837 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5838 break;
5839
5840 if (bi)
5841 {
5842 if (attrhash_cmp (bi->attr, new_attr) &&
5843 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5844 {
5845 bgp_attr_unintern (&new_attr);
5846 aspath_unintern (&attr.aspath);
5847 bgp_attr_extra_free (&attr);
5848 bgp_unlock_node (bn);
5849 return;
5850 }
5851 else
5852 {
5853 /* The attribute is changed. */
5854 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5855
5856 /* Rewrite BGP route information. */
5857 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5858 bgp_info_restore(bn, bi);
5859 else
5860 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5861 bgp_attr_unintern (&bi->attr);
5862 bi->attr = new_attr;
5863 bi->uptime = bgp_clock ();
5864
5865 /* Process change. */
5866 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5867 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5868 bgp_unlock_node (bn);
5869 aspath_unintern (&attr.aspath);
5870 bgp_attr_extra_free (&attr);
5871 return;
5872 }
5873 }
5874
5875 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, bgp->peer_self,
5876 new_attr, bn);
5877 SET_FLAG (new->flags, BGP_INFO_VALID);
5878
5879 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5880 bgp_info_add (bn, new);
5881 bgp_unlock_node (bn);
5882 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5883 }
5884 }
5885
5886 /* Unintern original. */
5887 aspath_unintern (&attr.aspath);
5888 bgp_attr_extra_free (&attr);
5889 }
5890
5891 void
5892 bgp_redistribute_delete (struct prefix *p, u_char type)
5893 {
5894 struct bgp *bgp;
5895 struct listnode *node, *nnode;
5896 afi_t afi;
5897 struct bgp_node *rn;
5898 struct bgp_info *ri;
5899
5900 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5901 {
5902 afi = family2afi (p->family);
5903
5904 if (bgp->redist[afi][type])
5905 {
5906 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5907
5908 for (ri = rn->info; ri; ri = ri->next)
5909 if (ri->peer == bgp->peer_self
5910 && ri->type == type)
5911 break;
5912
5913 if (ri)
5914 {
5915 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5916 bgp_info_delete (rn, ri);
5917 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5918 }
5919 bgp_unlock_node (rn);
5920 }
5921 }
5922 }
5923
5924 /* Withdraw specified route type's route. */
5925 void
5926 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5927 {
5928 struct bgp_node *rn;
5929 struct bgp_info *ri;
5930 struct bgp_table *table;
5931
5932 table = bgp->rib[afi][SAFI_UNICAST];
5933
5934 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5935 {
5936 for (ri = rn->info; ri; ri = ri->next)
5937 if (ri->peer == bgp->peer_self
5938 && ri->type == type)
5939 break;
5940
5941 if (ri)
5942 {
5943 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5944 bgp_info_delete (rn, ri);
5945 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5946 }
5947 }
5948 }
5949
5950 /* Static function to display route. */
5951 static void
5952 route_vty_out_route (struct prefix *p, struct vty *vty)
5953 {
5954 int len;
5955 u_int32_t destination;
5956 char buf[BUFSIZ];
5957
5958 if (p->family == AF_INET)
5959 {
5960 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5961 destination = ntohl (p->u.prefix4.s_addr);
5962
5963 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5964 || (IN_CLASSB (destination) && p->prefixlen == 16)
5965 || (IN_CLASSA (destination) && p->prefixlen == 8)
5966 || p->u.prefix4.s_addr == 0)
5967 {
5968 /* When mask is natural, mask is not displayed. */
5969 }
5970 else
5971 len += vty_out (vty, "/%d", p->prefixlen);
5972 }
5973 else
5974 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5975 p->prefixlen);
5976
5977 len = 17 - len;
5978 if (len < 1)
5979 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5980 else
5981 vty_out (vty, "%*s", len, " ");
5982 }
5983
5984 enum bgp_display_type
5985 {
5986 normal_list,
5987 };
5988
5989 /* Print the short form route status for a bgp_info */
5990 static void
5991 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
5992 {
5993 /* Route status display. */
5994 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5995 vty_out (vty, "R");
5996 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5997 vty_out (vty, "S");
5998 else if (binfo->extra && binfo->extra->suppress)
5999 vty_out (vty, "s");
6000 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6001 vty_out (vty, "*");
6002 else
6003 vty_out (vty, " ");
6004
6005 /* Selected */
6006 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6007 vty_out (vty, "h");
6008 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6009 vty_out (vty, "d");
6010 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6011 vty_out (vty, ">");
6012 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6013 vty_out (vty, "=");
6014 else
6015 vty_out (vty, " ");
6016
6017 /* Internal route. */
6018 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6019 vty_out (vty, "i");
6020 else
6021 vty_out (vty, " ");
6022 }
6023
6024 /* called from terminal list command */
6025 void
6026 route_vty_out (struct vty *vty, struct prefix *p,
6027 struct bgp_info *binfo, int display, safi_t safi, char *delim)
6028 {
6029 struct attr *attr;
6030
6031 /* short status lead text */
6032 route_vty_short_status_out (vty, binfo);
6033
6034 if (delim)
6035 vty_out (vty, "%c", *delim);
6036
6037 /* print prefix and mask */
6038 if (! display)
6039 route_vty_out_route (p, vty);
6040 else
6041 vty_out (vty, "%*s", 17, " ");
6042
6043 if (delim)
6044 vty_out (vty, "%c", *delim);
6045
6046 /* Print attribute */
6047 attr = binfo->attr;
6048 if (attr)
6049 {
6050 if (p->family == AF_INET)
6051 {
6052 if (safi == SAFI_MPLS_VPN)
6053 vty_out (vty, "%-16s",
6054 inet_ntoa (attr->extra->mp_nexthop_global_in));
6055 else
6056 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6057 }
6058 #ifdef HAVE_IPV6
6059 else if (p->family == AF_INET6)
6060 {
6061 int len;
6062 char buf[BUFSIZ];
6063
6064 len = vty_out (vty, "%s",
6065 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6066 buf, BUFSIZ));
6067 len = 16 - len;
6068 if (len < 1)
6069 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6070 else
6071 vty_out (vty, "%*s", len, " ");
6072 }
6073 #endif /* HAVE_IPV6 */
6074
6075 if (delim)
6076 vty_out (vty, "%c", *delim);
6077
6078 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6079 vty_out (vty, "%10u", attr->med);
6080 else
6081 vty_out (vty, " ");
6082
6083 if (delim)
6084 vty_out (vty, "%c", *delim);
6085
6086 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6087 vty_out (vty, "%7u", attr->local_pref);
6088 else
6089 vty_out (vty, " ");
6090
6091 if (delim)
6092 vty_out (vty, "%c", *delim);
6093
6094 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6095
6096 if (delim)
6097 vty_out (vty, "%c", *delim);
6098
6099 /* Print aspath */
6100 if (attr->aspath)
6101 aspath_print_vty (vty, "%s", attr->aspath, " ");
6102
6103 if (delim)
6104 vty_out (vty, "%c", *delim);
6105
6106 /* Print origin */
6107 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6108 }
6109 vty_out (vty, "%s", VTY_NEWLINE);
6110 }
6111
6112 /* called from terminal list command */
6113 void
6114 route_vty_out_tmp (struct vty *vty, struct prefix *p,
6115 struct attr *attr, safi_t safi, char *delim)
6116 {
6117 /* Route status display. */
6118 vty_out (vty, "*");
6119 vty_out (vty, ">");
6120 vty_out (vty, " ");
6121
6122 if (delim)
6123 vty_out (vty, "%c", *delim);
6124
6125 /* print prefix and mask */
6126 route_vty_out_route (p, vty);
6127
6128 if (delim)
6129 vty_out (vty, "%c", *delim);
6130
6131 /* Print attribute */
6132 if (attr)
6133 {
6134 if (p->family == AF_INET)
6135 {
6136 if (safi == SAFI_MPLS_VPN)
6137 vty_out (vty, "%-16s",
6138 inet_ntoa (attr->extra->mp_nexthop_global_in));
6139 else
6140 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6141 }
6142 #ifdef HAVE_IPV6
6143 else if (p->family == AF_INET6)
6144 {
6145 int len;
6146 char buf[BUFSIZ];
6147
6148 assert (attr->extra);
6149
6150 len = vty_out (vty, "%s",
6151 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6152 buf, BUFSIZ));
6153 len = 16 - len;
6154 if (len < 1)
6155 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6156 else
6157 vty_out (vty, "%*s", len, " ");
6158 }
6159 #endif /* HAVE_IPV6 */
6160
6161 if (delim)
6162 vty_out (vty, "%c", *delim);
6163
6164 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6165 vty_out (vty, "%10u", attr->med);
6166 else
6167 vty_out (vty, " ");
6168
6169 if (delim)
6170 vty_out (vty, "%c", *delim);
6171
6172 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6173 vty_out (vty, "%7u", attr->local_pref);
6174 else
6175 vty_out (vty, " ");
6176
6177 if (delim)
6178 vty_out (vty, "%c", *delim);
6179
6180 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6181
6182 if (delim)
6183 vty_out (vty, "%c", *delim);
6184
6185 /* Print aspath */
6186 if (attr->aspath)
6187 aspath_print_vty (vty, "%s", attr->aspath, " ");
6188
6189 if (delim)
6190 vty_out (vty, "%c", *delim);
6191
6192 /* Print origin */
6193 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6194 }
6195
6196 vty_out (vty, "%s", VTY_NEWLINE);
6197 }
6198
6199 void
6200 route_vty_out_tag (struct vty *vty, struct prefix *p,
6201 struct bgp_info *binfo, int display, safi_t safi)
6202 {
6203 struct attr *attr;
6204 u_int32_t label = 0;
6205
6206 if (!binfo->extra)
6207 return;
6208
6209 /* short status lead text */
6210 route_vty_short_status_out (vty, binfo);
6211
6212 /* print prefix and mask */
6213 if (! display)
6214 route_vty_out_route (p, vty);
6215 else
6216 vty_out (vty, "%*s", 17, " ");
6217
6218 /* Print attribute */
6219 attr = binfo->attr;
6220 if (attr)
6221 {
6222 if (p->family == AF_INET)
6223 {
6224 if (safi == SAFI_MPLS_VPN)
6225 vty_out (vty, "%-16s",
6226 inet_ntoa (attr->extra->mp_nexthop_global_in));
6227 else
6228 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6229 }
6230 #ifdef HAVE_IPV6
6231 else if (p->family == AF_INET6)
6232 {
6233 assert (attr->extra);
6234 char buf[BUFSIZ];
6235 char buf1[BUFSIZ];
6236 if (attr->extra->mp_nexthop_len == 16)
6237 vty_out (vty, "%s",
6238 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6239 buf, BUFSIZ));
6240 else if (attr->extra->mp_nexthop_len == 32)
6241 vty_out (vty, "%s(%s)",
6242 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6243 buf, BUFSIZ),
6244 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6245 buf1, BUFSIZ));
6246
6247 }
6248 #endif /* HAVE_IPV6 */
6249 }
6250
6251 label = decode_label (binfo->extra->tag);
6252
6253 vty_out (vty, "notag/%d", label);
6254
6255 vty_out (vty, "%s", VTY_NEWLINE);
6256 }
6257
6258 /* dampening route */
6259 static void
6260 damp_route_vty_out (struct vty *vty, struct prefix *p,
6261 struct bgp_info *binfo, int display, safi_t safi)
6262 {
6263 struct attr *attr;
6264 int len;
6265 char timebuf[BGP_UPTIME_LEN];
6266
6267 /* short status lead text */
6268 route_vty_short_status_out (vty, binfo);
6269
6270 /* print prefix and mask */
6271 if (! display)
6272 route_vty_out_route (p, vty);
6273 else
6274 vty_out (vty, "%*s", 17, " ");
6275
6276 len = vty_out (vty, "%s", binfo->peer->host);
6277 len = 17 - len;
6278 if (len < 1)
6279 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6280 else
6281 vty_out (vty, "%*s", len, " ");
6282
6283 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
6284
6285 /* Print attribute */
6286 attr = binfo->attr;
6287 if (attr)
6288 {
6289 /* Print aspath */
6290 if (attr->aspath)
6291 aspath_print_vty (vty, "%s", attr->aspath, " ");
6292
6293 /* Print origin */
6294 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6295 }
6296 vty_out (vty, "%s", VTY_NEWLINE);
6297 }
6298
6299 /* flap route */
6300 static void
6301 flap_route_vty_out (struct vty *vty, struct prefix *p,
6302 struct bgp_info *binfo, int display, safi_t safi)
6303 {
6304 struct attr *attr;
6305 struct bgp_damp_info *bdi;
6306 char timebuf[BGP_UPTIME_LEN];
6307 int len;
6308
6309 if (!binfo->extra)
6310 return;
6311
6312 bdi = binfo->extra->damp_info;
6313
6314 /* short status lead text */
6315 route_vty_short_status_out (vty, binfo);
6316
6317 /* print prefix and mask */
6318 if (! display)
6319 route_vty_out_route (p, vty);
6320 else
6321 vty_out (vty, "%*s", 17, " ");
6322
6323 len = vty_out (vty, "%s", binfo->peer->host);
6324 len = 16 - len;
6325 if (len < 1)
6326 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6327 else
6328 vty_out (vty, "%*s", len, " ");
6329
6330 len = vty_out (vty, "%d", bdi->flap);
6331 len = 5 - len;
6332 if (len < 1)
6333 vty_out (vty, " ");
6334 else
6335 vty_out (vty, "%*s ", len, " ");
6336
6337 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6338 timebuf, BGP_UPTIME_LEN));
6339
6340 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6341 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6342 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
6343 else
6344 vty_out (vty, "%*s ", 8, " ");
6345
6346 /* Print attribute */
6347 attr = binfo->attr;
6348 if (attr)
6349 {
6350 /* Print aspath */
6351 if (attr->aspath)
6352 aspath_print_vty (vty, "%s", attr->aspath, " ");
6353
6354 /* Print origin */
6355 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6356 }
6357 vty_out (vty, "%s", VTY_NEWLINE);
6358 }
6359
6360 static void
6361 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6362 struct bgp_info *binfo, afi_t afi, safi_t safi)
6363 {
6364 char buf[INET6_ADDRSTRLEN];
6365 char buf1[BUFSIZ];
6366 struct attr *attr;
6367 int sockunion_vty_out (struct vty *, union sockunion *);
6368 #ifdef HAVE_CLOCK_MONOTONIC
6369 time_t tbuf;
6370 #endif
6371
6372 attr = binfo->attr;
6373
6374 if (attr)
6375 {
6376 /* Line1 display AS-path, Aggregator */
6377 if (attr->aspath)
6378 {
6379 vty_out (vty, " ");
6380 if (aspath_count_hops (attr->aspath) == 0)
6381 vty_out (vty, "Local");
6382 else
6383 aspath_print_vty (vty, "%s", attr->aspath, "");
6384 }
6385
6386 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6387 vty_out (vty, ", (removed)");
6388 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6389 vty_out (vty, ", (stale)");
6390 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6391 vty_out (vty, ", (aggregated by %u %s)",
6392 attr->extra->aggregator_as,
6393 inet_ntoa (attr->extra->aggregator_addr));
6394 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6395 vty_out (vty, ", (Received from a RR-client)");
6396 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6397 vty_out (vty, ", (Received from a RS-client)");
6398 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6399 vty_out (vty, ", (history entry)");
6400 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6401 vty_out (vty, ", (suppressed due to dampening)");
6402 vty_out (vty, "%s", VTY_NEWLINE);
6403
6404 /* Line2 display Next-hop, Neighbor, Router-id */
6405 if (p->family == AF_INET)
6406 {
6407 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
6408 inet_ntoa (attr->extra->mp_nexthop_global_in) :
6409 inet_ntoa (attr->nexthop));
6410 }
6411 #ifdef HAVE_IPV6
6412 else
6413 {
6414 assert (attr->extra);
6415 vty_out (vty, " %s",
6416 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6417 buf, INET6_ADDRSTRLEN));
6418 }
6419 #endif /* HAVE_IPV6 */
6420
6421 if (binfo->peer == bgp->peer_self)
6422 {
6423 vty_out (vty, " from %s ",
6424 p->family == AF_INET ? "0.0.0.0" : "::");
6425 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6426 }
6427 else
6428 {
6429 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6430 vty_out (vty, " (inaccessible)");
6431 else if (binfo->extra && binfo->extra->igpmetric)
6432 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
6433 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6434 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6435 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6436 else
6437 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6438 }
6439 vty_out (vty, "%s", VTY_NEWLINE);
6440
6441 #ifdef HAVE_IPV6
6442 /* display nexthop local */
6443 if (attr->extra && attr->extra->mp_nexthop_len == 32)
6444 {
6445 vty_out (vty, " (%s)%s",
6446 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6447 buf, INET6_ADDRSTRLEN),
6448 VTY_NEWLINE);
6449 }
6450 #endif /* HAVE_IPV6 */
6451
6452 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
6453 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6454
6455 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6456 vty_out (vty, ", metric %u", attr->med);
6457
6458 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6459 vty_out (vty, ", localpref %u", attr->local_pref);
6460 else
6461 vty_out (vty, ", localpref %u", bgp->default_local_pref);
6462
6463 if (attr->extra && attr->extra->weight != 0)
6464 vty_out (vty, ", weight %u", attr->extra->weight);
6465
6466 if (attr->extra && attr->extra->tag != 0)
6467 vty_out (vty, ", tag %d", attr->extra->tag);
6468
6469 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6470 vty_out (vty, ", valid");
6471
6472 if (binfo->peer != bgp->peer_self)
6473 {
6474 if (binfo->peer->as == binfo->peer->local_as)
6475 vty_out (vty, ", internal");
6476 else
6477 vty_out (vty, ", %s",
6478 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6479 }
6480 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6481 vty_out (vty, ", aggregated, local");
6482 else if (binfo->type != ZEBRA_ROUTE_BGP)
6483 vty_out (vty, ", sourced");
6484 else
6485 vty_out (vty, ", sourced, local");
6486
6487 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6488 vty_out (vty, ", atomic-aggregate");
6489
6490 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6491 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6492 bgp_info_mpath_count (binfo)))
6493 vty_out (vty, ", multipath");
6494
6495 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6496 vty_out (vty, ", best");
6497
6498 vty_out (vty, "%s", VTY_NEWLINE);
6499
6500 /* Line 4 display Community */
6501 if (attr->community)
6502 vty_out (vty, " Community: %s%s", attr->community->str,
6503 VTY_NEWLINE);
6504
6505 /* Line 5 display Extended-community */
6506 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
6507 vty_out (vty, " Extended Community: %s%s",
6508 attr->extra->ecommunity->str, VTY_NEWLINE);
6509
6510 /* Line 6 display Originator, Cluster-id */
6511 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6512 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6513 {
6514 assert (attr->extra);
6515 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6516 vty_out (vty, " Originator: %s",
6517 inet_ntoa (attr->extra->originator_id));
6518
6519 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6520 {
6521 int i;
6522 vty_out (vty, ", Cluster list: ");
6523 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6524 vty_out (vty, "%s ",
6525 inet_ntoa (attr->extra->cluster->list[i]));
6526 }
6527 vty_out (vty, "%s", VTY_NEWLINE);
6528 }
6529
6530 if (binfo->extra && binfo->extra->damp_info)
6531 bgp_damp_info_vty (vty, binfo);
6532
6533 /* Line 7 display Uptime */
6534 #ifdef HAVE_CLOCK_MONOTONIC
6535 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
6536 vty_out (vty, " Last update: %s", ctime(&tbuf));
6537 #else
6538 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6539 #endif /* HAVE_CLOCK_MONOTONIC */
6540 }
6541 vty_out (vty, "%s", VTY_NEWLINE);
6542 }
6543
6544 #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6545 "h history, * valid, > best, = multipath,%s"\
6546 " i internal, r RIB-failure, S Stale, R Removed%s"
6547 #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
6548 #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6549 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
6550 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6551 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6552
6553 enum bgp_show_type
6554 {
6555 bgp_show_type_normal,
6556 bgp_show_type_regexp,
6557 bgp_show_type_prefix_list,
6558 bgp_show_type_filter_list,
6559 bgp_show_type_route_map,
6560 bgp_show_type_neighbor,
6561 bgp_show_type_cidr_only,
6562 bgp_show_type_prefix_longer,
6563 bgp_show_type_community_all,
6564 bgp_show_type_community,
6565 bgp_show_type_community_exact,
6566 bgp_show_type_community_list,
6567 bgp_show_type_community_list_exact,
6568 bgp_show_type_flap_statistics,
6569 bgp_show_type_flap_address,
6570 bgp_show_type_flap_prefix,
6571 bgp_show_type_flap_cidr_only,
6572 bgp_show_type_flap_regexp,
6573 bgp_show_type_flap_filter_list,
6574 bgp_show_type_flap_prefix_list,
6575 bgp_show_type_flap_prefix_longer,
6576 bgp_show_type_flap_route_map,
6577 bgp_show_type_flap_neighbor,
6578 bgp_show_type_dampend_paths,
6579 bgp_show_type_damp_neighbor
6580 };
6581
6582 static int
6583 bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
6584 enum bgp_show_type type, void *output_arg, char *delim)
6585 {
6586 struct bgp_info *ri;
6587 struct bgp_node *rn;
6588 int header = 1;
6589 int display;
6590 unsigned long output_count;
6591
6592 /* This is first entry point, so reset total line. */
6593 output_count = 0;
6594
6595 /* Start processing of routes. */
6596 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6597 if (rn->info != NULL)
6598 {
6599 display = 0;
6600
6601 for (ri = rn->info; ri; ri = ri->next)
6602 {
6603 if (type == bgp_show_type_flap_statistics
6604 || type == bgp_show_type_flap_address
6605 || type == bgp_show_type_flap_prefix
6606 || type == bgp_show_type_flap_cidr_only
6607 || type == bgp_show_type_flap_regexp
6608 || type == bgp_show_type_flap_filter_list
6609 || type == bgp_show_type_flap_prefix_list
6610 || type == bgp_show_type_flap_prefix_longer
6611 || type == bgp_show_type_flap_route_map
6612 || type == bgp_show_type_flap_neighbor
6613 || type == bgp_show_type_dampend_paths
6614 || type == bgp_show_type_damp_neighbor)
6615 {
6616 if (!(ri->extra && ri->extra->damp_info))
6617 continue;
6618 }
6619 if (type == bgp_show_type_regexp
6620 || type == bgp_show_type_flap_regexp)
6621 {
6622 regex_t *regex = output_arg;
6623
6624 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6625 continue;
6626 }
6627 if (type == bgp_show_type_prefix_list
6628 || type == bgp_show_type_flap_prefix_list)
6629 {
6630 struct prefix_list *plist = output_arg;
6631
6632 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6633 continue;
6634 }
6635 if (type == bgp_show_type_filter_list
6636 || type == bgp_show_type_flap_filter_list)
6637 {
6638 struct as_list *as_list = output_arg;
6639
6640 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6641 continue;
6642 }
6643 if (type == bgp_show_type_route_map
6644 || type == bgp_show_type_flap_route_map)
6645 {
6646 struct route_map *rmap = output_arg;
6647 struct bgp_info binfo;
6648 struct attr dummy_attr;
6649 struct attr_extra dummy_extra;
6650 int ret;
6651
6652 dummy_attr.extra = &dummy_extra;
6653 bgp_attr_dup (&dummy_attr, ri->attr);
6654
6655 binfo.peer = ri->peer;
6656 binfo.attr = &dummy_attr;
6657
6658 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
6659 if (ret == RMAP_DENYMATCH)
6660 continue;
6661 }
6662 if (type == bgp_show_type_neighbor
6663 || type == bgp_show_type_flap_neighbor
6664 || type == bgp_show_type_damp_neighbor)
6665 {
6666 union sockunion *su = output_arg;
6667
6668 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6669 continue;
6670 }
6671 if (type == bgp_show_type_cidr_only
6672 || type == bgp_show_type_flap_cidr_only)
6673 {
6674 u_int32_t destination;
6675
6676 destination = ntohl (rn->p.u.prefix4.s_addr);
6677 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6678 continue;
6679 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6680 continue;
6681 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6682 continue;
6683 }
6684 if (type == bgp_show_type_prefix_longer
6685 || type == bgp_show_type_flap_prefix_longer)
6686 {
6687 struct prefix *p = output_arg;
6688
6689 if (! prefix_match (p, &rn->p))
6690 continue;
6691 }
6692 if (type == bgp_show_type_community_all)
6693 {
6694 if (! ri->attr->community)
6695 continue;
6696 }
6697 if (type == bgp_show_type_community)
6698 {
6699 struct community *com = output_arg;
6700
6701 if (! ri->attr->community ||
6702 ! community_match (ri->attr->community, com))
6703 continue;
6704 }
6705 if (type == bgp_show_type_community_exact)
6706 {
6707 struct community *com = output_arg;
6708
6709 if (! ri->attr->community ||
6710 ! community_cmp (ri->attr->community, com))
6711 continue;
6712 }
6713 if (type == bgp_show_type_community_list)
6714 {
6715 struct community_list *list = output_arg;
6716
6717 if (! community_list_match (ri->attr->community, list))
6718 continue;
6719 }
6720 if (type == bgp_show_type_community_list_exact)
6721 {
6722 struct community_list *list = output_arg;
6723
6724 if (! community_list_exact_match (ri->attr->community, list))
6725 continue;
6726 }
6727 if (type == bgp_show_type_flap_address
6728 || type == bgp_show_type_flap_prefix)
6729 {
6730 struct prefix *p = output_arg;
6731
6732 if (! prefix_match (&rn->p, p))
6733 continue;
6734
6735 if (type == bgp_show_type_flap_prefix)
6736 if (p->prefixlen != rn->p.prefixlen)
6737 continue;
6738 }
6739 if (type == bgp_show_type_dampend_paths
6740 || type == bgp_show_type_damp_neighbor)
6741 {
6742 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6743 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6744 continue;
6745 }
6746
6747 if (delim)
6748 {
6749 if (header)
6750 {
6751 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
6752 header = 0;
6753 }
6754 }
6755 else if (header)
6756 {
6757 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6758 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6759 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6760 if (type == bgp_show_type_dampend_paths
6761 || type == bgp_show_type_damp_neighbor)
6762 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6763 else if (type == bgp_show_type_flap_statistics
6764 || type == bgp_show_type_flap_address
6765 || type == bgp_show_type_flap_prefix
6766 || type == bgp_show_type_flap_cidr_only
6767 || type == bgp_show_type_flap_regexp
6768 || type == bgp_show_type_flap_filter_list
6769 || type == bgp_show_type_flap_prefix_list
6770 || type == bgp_show_type_flap_prefix_longer
6771 || type == bgp_show_type_flap_route_map
6772 || type == bgp_show_type_flap_neighbor)
6773 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6774 else
6775 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
6776 header = 0;
6777 }
6778
6779 if (type == bgp_show_type_dampend_paths
6780 || type == bgp_show_type_damp_neighbor)
6781 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6782 else if (type == bgp_show_type_flap_statistics
6783 || type == bgp_show_type_flap_address
6784 || type == bgp_show_type_flap_prefix
6785 || type == bgp_show_type_flap_cidr_only
6786 || type == bgp_show_type_flap_regexp
6787 || type == bgp_show_type_flap_filter_list
6788 || type == bgp_show_type_flap_prefix_list
6789 || type == bgp_show_type_flap_prefix_longer
6790 || type == bgp_show_type_flap_route_map
6791 || type == bgp_show_type_flap_neighbor)
6792 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6793 else
6794 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, delim);
6795 display++;
6796 }
6797 if (display)
6798 output_count++;
6799 }
6800
6801 /* No route is displayed */
6802 if (output_count == 0)
6803 {
6804 if (type == bgp_show_type_normal)
6805 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6806 }
6807 else
6808 vty_out (vty, "%sTotal number of prefixes %ld%s",
6809 VTY_NEWLINE, output_count, VTY_NEWLINE);
6810
6811 return CMD_SUCCESS;
6812 }
6813
6814 static int
6815 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
6816 enum bgp_show_type type, void *output_arg, char *delim)
6817 {
6818 struct bgp_table *table;
6819
6820 if (bgp == NULL) {
6821 bgp = bgp_get_default ();
6822 }
6823
6824 if (bgp == NULL)
6825 {
6826 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6827 return CMD_WARNING;
6828 }
6829
6830
6831 table = bgp->rib[afi][safi];
6832
6833 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, delim);
6834 }
6835
6836 /* Header of detailed BGP route information */
6837 static void
6838 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6839 struct bgp_node *rn,
6840 struct prefix_rd *prd, afi_t afi, safi_t safi)
6841 {
6842 struct bgp_info *ri;
6843 struct prefix *p;
6844 struct peer *peer;
6845 struct listnode *node, *nnode;
6846 char buf1[INET6_ADDRSTRLEN];
6847 char buf2[INET6_ADDRSTRLEN];
6848 int count = 0;
6849 int best = 0;
6850 int suppress = 0;
6851 int no_export = 0;
6852 int no_advertise = 0;
6853 int local_as = 0;
6854 int first = 0;
6855
6856 p = &rn->p;
6857 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6858 (safi == SAFI_MPLS_VPN ?
6859 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6860 safi == SAFI_MPLS_VPN ? ":" : "",
6861 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6862 p->prefixlen, VTY_NEWLINE);
6863
6864 for (ri = rn->info; ri; ri = ri->next)
6865 {
6866 count++;
6867 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6868 {
6869 best = count;
6870 if (ri->extra && ri->extra->suppress)
6871 suppress = 1;
6872 if (ri->attr->community != NULL)
6873 {
6874 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6875 no_advertise = 1;
6876 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6877 no_export = 1;
6878 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6879 local_as = 1;
6880 }
6881 }
6882 }
6883
6884 vty_out (vty, "Paths: (%d available", count);
6885 if (best)
6886 {
6887 vty_out (vty, ", best #%d", best);
6888 if (safi == SAFI_UNICAST)
6889 vty_out (vty, ", table Default-IP-Routing-Table");
6890 }
6891 else
6892 vty_out (vty, ", no best path");
6893 if (no_advertise)
6894 vty_out (vty, ", not advertised to any peer");
6895 else if (no_export)
6896 vty_out (vty, ", not advertised to EBGP peer");
6897 else if (local_as)
6898 vty_out (vty, ", not advertised outside local AS");
6899 if (suppress)
6900 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6901 vty_out (vty, ")%s", VTY_NEWLINE);
6902
6903 /* advertised peer */
6904 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6905 {
6906 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6907 {
6908 if (! first)
6909 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6910 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6911 first = 1;
6912 }
6913 }
6914 if (! first)
6915 vty_out (vty, " Not advertised to any peer");
6916 vty_out (vty, "%s", VTY_NEWLINE);
6917 }
6918
6919 /* Display specified route of BGP table. */
6920 static int
6921 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
6922 struct bgp_table *rib, const char *ip_str,
6923 afi_t afi, safi_t safi, struct prefix_rd *prd,
6924 int prefix_check, enum bgp_path_type pathtype)
6925 {
6926 int ret;
6927 int header;
6928 int display = 0;
6929 struct prefix match;
6930 struct bgp_node *rn;
6931 struct bgp_node *rm;
6932 struct bgp_info *ri;
6933 struct bgp_table *table;
6934
6935 /* Check IP address argument. */
6936 ret = str2prefix (ip_str, &match);
6937 if (! ret)
6938 {
6939 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6940 return CMD_WARNING;
6941 }
6942
6943 match.family = afi2family (afi);
6944
6945 if (safi == SAFI_MPLS_VPN)
6946 {
6947 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
6948 {
6949 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6950 continue;
6951
6952 if ((table = rn->info) != NULL)
6953 {
6954 header = 1;
6955
6956 if ((rm = bgp_node_match (table, &match)) != NULL)
6957 {
6958 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6959 {
6960 bgp_unlock_node (rm);
6961 continue;
6962 }
6963
6964 for (ri = rm->info; ri; ri = ri->next)
6965 {
6966 if (header)
6967 {
6968 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6969 AFI_IP, SAFI_MPLS_VPN);
6970
6971 header = 0;
6972 }
6973 display++;
6974
6975 if (pathtype == BGP_PATH_ALL ||
6976 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6977 (pathtype == BGP_PATH_MULTIPATH &&
6978 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6979 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6980 }
6981
6982 bgp_unlock_node (rm);
6983 }
6984 }
6985 }
6986 }
6987 else
6988 {
6989 header = 1;
6990
6991 if ((rn = bgp_node_match (rib, &match)) != NULL)
6992 {
6993 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6994 {
6995 for (ri = rn->info; ri; ri = ri->next)
6996 {
6997 if (header)
6998 {
6999 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
7000 header = 0;
7001 }
7002 display++;
7003
7004 if (pathtype == BGP_PATH_ALL ||
7005 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7006 (pathtype == BGP_PATH_MULTIPATH &&
7007 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7008 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
7009 }
7010 }
7011
7012 bgp_unlock_node (rn);
7013 }
7014 }
7015
7016 if (! display)
7017 {
7018 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7019 return CMD_WARNING;
7020 }
7021
7022 return CMD_SUCCESS;
7023 }
7024
7025 /* Display specified route of Main RIB */
7026 static int
7027 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
7028 afi_t afi, safi_t safi, struct prefix_rd *prd,
7029 int prefix_check, enum bgp_path_type pathtype)
7030 {
7031 struct bgp *bgp;
7032
7033 /* BGP structure lookup. */
7034 if (view_name)
7035 {
7036 bgp = bgp_lookup_by_name (view_name);
7037 if (bgp == NULL)
7038 {
7039 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7040 return CMD_WARNING;
7041 }
7042 }
7043 else
7044 {
7045 bgp = bgp_get_default ();
7046 if (bgp == NULL)
7047 {
7048 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7049 return CMD_WARNING;
7050 }
7051 }
7052
7053 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
7054 afi, safi, prd, prefix_check, pathtype);
7055 }
7056
7057 /* BGP route print out function. */
7058 DEFUN (show_ip_bgp,
7059 show_ip_bgp_cmd,
7060 "show ip bgp",
7061 SHOW_STR
7062 IP_STR
7063 BGP_STR)
7064 {
7065 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7066 }
7067
7068 DEFUN (show_ip_bgp_csv,
7069 show_ip_bgp_csv_cmd,
7070 "show ip bgp csv",
7071 SHOW_STR
7072 IP_STR
7073 BGP_STR)
7074 {
7075 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
7076 }
7077
7078 DEFUN (show_ip_bgp_ipv4,
7079 show_ip_bgp_ipv4_cmd,
7080 "show ip bgp ipv4 (unicast|multicast)",
7081 SHOW_STR
7082 IP_STR
7083 BGP_STR
7084 "Address family\n"
7085 "Address Family modifier\n"
7086 "Address Family modifier\n")
7087 {
7088 if (strncmp (argv[0], "m", 1) == 0)
7089 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7090 NULL, NULL);
7091
7092 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7093 }
7094
7095 ALIAS (show_ip_bgp_ipv4,
7096 show_bgp_ipv4_safi_cmd,
7097 "show bgp ipv4 (unicast|multicast)",
7098 SHOW_STR
7099 BGP_STR
7100 "Address family\n"
7101 "Address Family modifier\n"
7102 "Address Family modifier\n")
7103
7104 DEFUN (show_ip_bgp_ipv4_csv,
7105 show_bgp_ipv4_safi_csv_cmd,
7106 "show bgp ipv4 (unicast|multicast) csv",
7107 SHOW_STR
7108 BGP_STR
7109 "Address family\n"
7110 "Address Family modifier\n"
7111 "Address Family modifier\n")
7112 {
7113 if (strncmp (argv[0], "m", 1) == 0)
7114 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7115 NULL, &csv);
7116
7117 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
7118 }
7119
7120 DEFUN (show_ip_bgp_route,
7121 show_ip_bgp_route_cmd,
7122 "show ip bgp A.B.C.D",
7123 SHOW_STR
7124 IP_STR
7125 BGP_STR
7126 "Network in the BGP routing table to display\n")
7127 {
7128 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7129 }
7130
7131 DEFUN (show_ip_bgp_route_pathtype,
7132 show_ip_bgp_route_pathtype_cmd,
7133 "show ip bgp A.B.C.D (bestpath|multipath)",
7134 SHOW_STR
7135 IP_STR
7136 BGP_STR
7137 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7138 "Display only the bestpath\n"
7139 "Display only multipaths\n")
7140 {
7141 if (strncmp (argv[1], "b", 1) == 0)
7142 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7143 else
7144 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7145 }
7146
7147 DEFUN (show_bgp_ipv4_safi_route_pathtype,
7148 show_bgp_ipv4_safi_route_pathtype_cmd,
7149 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath)",
7150 SHOW_STR
7151 BGP_STR
7152 "Address family\n"
7153 "Address Family modifier\n"
7154 "Address Family modifier\n"
7155 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7156 "Display only the bestpath\n"
7157 "Display only multipaths\n")
7158 {
7159 if (strncmp (argv[0], "m", 1) == 0)
7160 if (strncmp (argv[2], "b", 1) == 0)
7161 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7162 else
7163 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7164 else
7165 if (strncmp (argv[2], "b", 1) == 0)
7166 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7167 else
7168 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7169 }
7170
7171 DEFUN (show_ip_bgp_ipv4_route,
7172 show_ip_bgp_ipv4_route_cmd,
7173 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
7174 SHOW_STR
7175 IP_STR
7176 BGP_STR
7177 "Address family\n"
7178 "Address Family modifier\n"
7179 "Address Family modifier\n"
7180 "Network in the BGP routing table to display\n")
7181 {
7182 if (strncmp (argv[0], "m", 1) == 0)
7183 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
7184
7185 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7186 }
7187
7188 ALIAS (show_ip_bgp_ipv4_route,
7189 show_bgp_ipv4_safi_route_cmd,
7190 "show bgp ipv4 (unicast|multicast) A.B.C.D",
7191 SHOW_STR
7192 BGP_STR
7193 "Address family\n"
7194 "Address Family modifier\n"
7195 "Address Family modifier\n"
7196 "Network in the BGP routing table to display\n")
7197
7198 DEFUN (show_ip_bgp_vpnv4_all_route,
7199 show_ip_bgp_vpnv4_all_route_cmd,
7200 "show ip bgp vpnv4 all A.B.C.D",
7201 SHOW_STR
7202 IP_STR
7203 BGP_STR
7204 "Display VPNv4 NLRI specific information\n"
7205 "Display information about all VPNv4 NLRIs\n"
7206 "Network in the BGP routing table to display\n")
7207 {
7208 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
7209 }
7210
7211
7212 DEFUN (show_ip_bgp_vpnv4_rd_route,
7213 show_ip_bgp_vpnv4_rd_route_cmd,
7214 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
7215 SHOW_STR
7216 IP_STR
7217 BGP_STR
7218 "Display VPNv4 NLRI specific information\n"
7219 "Display information for a route distinguisher\n"
7220 "VPN Route Distinguisher\n"
7221 "Network in the BGP routing table to display\n")
7222 {
7223 int ret;
7224 struct prefix_rd prd;
7225
7226 ret = str2prefix_rd (argv[0], &prd);
7227 if (! ret)
7228 {
7229 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7230 return CMD_WARNING;
7231 }
7232 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
7233 }
7234
7235 DEFUN (show_ip_bgp_prefix,
7236 show_ip_bgp_prefix_cmd,
7237 "show ip bgp A.B.C.D/M",
7238 SHOW_STR
7239 IP_STR
7240 BGP_STR
7241 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7242 {
7243 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7244 }
7245
7246 DEFUN (show_ip_bgp_prefix_pathtype,
7247 show_ip_bgp_prefix_pathtype_cmd,
7248 "show ip bgp A.B.C.D/M (bestpath|multipath)",
7249 SHOW_STR
7250 IP_STR
7251 BGP_STR
7252 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7253 "Display only the bestpath\n"
7254 "Display only multipaths\n")
7255 {
7256 if (strncmp (argv[1], "b", 1) == 0)
7257 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7258 else
7259 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7260 }
7261
7262 DEFUN (show_ip_bgp_ipv4_prefix,
7263 show_ip_bgp_ipv4_prefix_cmd,
7264 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7265 SHOW_STR
7266 IP_STR
7267 BGP_STR
7268 "Address family\n"
7269 "Address Family modifier\n"
7270 "Address Family modifier\n"
7271 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7272 {
7273 if (strncmp (argv[0], "m", 1) == 0)
7274 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
7275
7276 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7277 }
7278
7279 ALIAS (show_ip_bgp_ipv4_prefix,
7280 show_bgp_ipv4_safi_prefix_cmd,
7281 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
7282 SHOW_STR
7283 BGP_STR
7284 "Address family\n"
7285 "Address Family modifier\n"
7286 "Address Family modifier\n"
7287 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7288
7289 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7290 show_ip_bgp_ipv4_prefix_pathtype_cmd,
7291 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7292 SHOW_STR
7293 IP_STR
7294 BGP_STR
7295 "Address family\n"
7296 "Address Family modifier\n"
7297 "Address Family modifier\n"
7298 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7299 "Display only the bestpath\n"
7300 "Display only multipaths\n")
7301 {
7302 if (strncmp (argv[0], "m", 1) == 0)
7303 if (strncmp (argv[2], "b", 1) == 0)
7304 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7305 else
7306 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7307 else
7308 if (strncmp (argv[2], "b", 1) == 0)
7309 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7310 else
7311 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7312 }
7313
7314 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7315 show_bgp_ipv4_safi_prefix_pathtype_cmd,
7316 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7317 SHOW_STR
7318 BGP_STR
7319 "Address family\n"
7320 "Address Family modifier\n"
7321 "Address Family modifier\n"
7322 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7323 "Display only the bestpath\n"
7324 "Display only multipaths\n")
7325
7326 DEFUN (show_ip_bgp_vpnv4_all_prefix,
7327 show_ip_bgp_vpnv4_all_prefix_cmd,
7328 "show ip bgp vpnv4 all A.B.C.D/M",
7329 SHOW_STR
7330 IP_STR
7331 BGP_STR
7332 "Display VPNv4 NLRI specific information\n"
7333 "Display information about all VPNv4 NLRIs\n"
7334 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7335 {
7336 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
7337 }
7338
7339 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7340 show_ip_bgp_vpnv4_rd_prefix_cmd,
7341 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7342 SHOW_STR
7343 IP_STR
7344 BGP_STR
7345 "Display VPNv4 NLRI specific information\n"
7346 "Display information for a route distinguisher\n"
7347 "VPN Route Distinguisher\n"
7348 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7349 {
7350 int ret;
7351 struct prefix_rd prd;
7352
7353 ret = str2prefix_rd (argv[0], &prd);
7354 if (! ret)
7355 {
7356 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7357 return CMD_WARNING;
7358 }
7359 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1, BGP_PATH_ALL);
7360 }
7361
7362 DEFUN (show_ip_bgp_view,
7363 show_ip_bgp_view_cmd,
7364 "show ip bgp view WORD",
7365 SHOW_STR
7366 IP_STR
7367 BGP_STR
7368 "BGP view\n"
7369 "View name\n")
7370 {
7371 struct bgp *bgp;
7372
7373 /* BGP structure lookup. */
7374 bgp = bgp_lookup_by_name (argv[0]);
7375 if (bgp == NULL)
7376 {
7377 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7378 return CMD_WARNING;
7379 }
7380
7381 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7382 }
7383
7384 DEFUN (show_ip_bgp_view_route,
7385 show_ip_bgp_view_route_cmd,
7386 "show ip bgp view WORD A.B.C.D",
7387 SHOW_STR
7388 IP_STR
7389 BGP_STR
7390 "BGP view\n"
7391 "View name\n"
7392 "Network in the BGP routing table to display\n")
7393 {
7394 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7395 }
7396
7397 DEFUN (show_ip_bgp_view_prefix,
7398 show_ip_bgp_view_prefix_cmd,
7399 "show ip bgp view WORD A.B.C.D/M",
7400 SHOW_STR
7401 IP_STR
7402 BGP_STR
7403 "BGP view\n"
7404 "View name\n"
7405 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7406 {
7407 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7408 }
7409
7410 #ifdef HAVE_IPV6
7411 DEFUN (show_bgp,
7412 show_bgp_cmd,
7413 "show bgp",
7414 SHOW_STR
7415 BGP_STR)
7416 {
7417 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7418 NULL, NULL);
7419 }
7420
7421 ALIAS (show_bgp,
7422 show_bgp_ipv6_cmd,
7423 "show bgp ipv6",
7424 SHOW_STR
7425 BGP_STR
7426 "Address family\n")
7427
7428 DEFUN (show_bgp_ipv6_safi,
7429 show_bgp_ipv6_safi_cmd,
7430 "show bgp ipv6 (unicast|multicast)",
7431 SHOW_STR
7432 BGP_STR
7433 "Address family\n"
7434 "Address Family modifier\n"
7435 "Address Family modifier\n")
7436 {
7437 if (strncmp (argv[0], "m", 1) == 0)
7438 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7439 NULL, NULL);
7440
7441 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7442 }
7443
7444 DEFUN (show_bgp_ipv6_safi_csv,
7445 show_bgp_ipv6_safi_csv_cmd,
7446 "show bgp ipv6 (unicast|multicast) csv",
7447 SHOW_STR
7448 BGP_STR
7449 "Address family\n"
7450 "Address Family modifier\n"
7451 "Address Family modifier\n")
7452 {
7453 if (strncmp (argv[0], "m", 1) == 0)
7454 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7455 NULL, &csv);
7456
7457 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, &csv);
7458 }
7459
7460 /* old command */
7461 DEFUN (show_ipv6_bgp,
7462 show_ipv6_bgp_cmd,
7463 "show ipv6 bgp",
7464 SHOW_STR
7465 IP_STR
7466 BGP_STR)
7467 {
7468 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7469 NULL, NULL);
7470 }
7471
7472 DEFUN (show_bgp_route,
7473 show_bgp_route_cmd,
7474 "show bgp X:X::X:X",
7475 SHOW_STR
7476 BGP_STR
7477 "Network in the BGP routing table to display\n")
7478 {
7479 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7480 }
7481
7482 ALIAS (show_bgp_route,
7483 show_bgp_ipv6_route_cmd,
7484 "show bgp ipv6 X:X::X:X",
7485 SHOW_STR
7486 BGP_STR
7487 "Address family\n"
7488 "Network in the BGP routing table to display\n")
7489
7490 DEFUN (show_bgp_ipv6_safi_route,
7491 show_bgp_ipv6_safi_route_cmd,
7492 "show bgp ipv6 (unicast|multicast) X:X::X:X",
7493 SHOW_STR
7494 BGP_STR
7495 "Address family\n"
7496 "Address Family modifier\n"
7497 "Address Family modifier\n"
7498 "Network in the BGP routing table to display\n")
7499 {
7500 if (strncmp (argv[0], "m", 1) == 0)
7501 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
7502
7503 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7504 }
7505
7506 DEFUN (show_bgp_route_pathtype,
7507 show_bgp_route_pathtype_cmd,
7508 "show bgp X:X::X:X (bestpath|multipath)",
7509 SHOW_STR
7510 BGP_STR
7511 "Network in the BGP routing table to display\n"
7512 "Display only the bestpath\n"
7513 "Display only multipaths\n")
7514 {
7515 if (strncmp (argv[1], "b", 1) == 0)
7516 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7517 else
7518 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7519 }
7520
7521 ALIAS (show_bgp_route_pathtype,
7522 show_bgp_ipv6_route_pathtype_cmd,
7523 "show bgp ipv6 X:X::X:X (bestpath|multipath)",
7524 SHOW_STR
7525 BGP_STR
7526 "Address family\n"
7527 "Network in the BGP routing table to display\n"
7528 "Display only the bestpath\n"
7529 "Display only multipaths\n")
7530
7531 DEFUN (show_bgp_ipv6_safi_route_pathtype,
7532 show_bgp_ipv6_safi_route_pathtype_cmd,
7533 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath)",
7534 SHOW_STR
7535 BGP_STR
7536 "Address family\n"
7537 "Address Family modifier\n"
7538 "Address Family modifier\n"
7539 "Network in the BGP routing table to display\n"
7540 "Display only the bestpath\n"
7541 "Display only multipaths\n")
7542 {
7543 if (strncmp (argv[0], "m", 1) == 0)
7544 if (strncmp (argv[2], "b", 1) == 0)
7545 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7546 else
7547 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7548 else
7549 if (strncmp (argv[2], "b", 1) == 0)
7550 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7551 else
7552 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7553 }
7554
7555 /* old command */
7556 DEFUN (show_ipv6_bgp_route,
7557 show_ipv6_bgp_route_cmd,
7558 "show ipv6 bgp X:X::X:X",
7559 SHOW_STR
7560 IP_STR
7561 BGP_STR
7562 "Network in the BGP routing table to display\n")
7563 {
7564 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7565 }
7566
7567 DEFUN (show_bgp_prefix,
7568 show_bgp_prefix_cmd,
7569 "show bgp X:X::X:X/M",
7570 SHOW_STR
7571 BGP_STR
7572 "IPv6 prefix <network>/<length>\n")
7573 {
7574 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7575 }
7576
7577 ALIAS (show_bgp_prefix,
7578 show_bgp_ipv6_prefix_cmd,
7579 "show bgp ipv6 X:X::X:X/M",
7580 SHOW_STR
7581 BGP_STR
7582 "Address family\n"
7583 "IPv6 prefix <network>/<length>\n")
7584
7585 DEFUN (show_bgp_ipv6_safi_prefix,
7586 show_bgp_ipv6_safi_prefix_cmd,
7587 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7588 SHOW_STR
7589 BGP_STR
7590 "Address family\n"
7591 "Address Family modifier\n"
7592 "Address Family modifier\n"
7593 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7594 {
7595 if (strncmp (argv[0], "m", 1) == 0)
7596 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
7597
7598 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7599 }
7600
7601 DEFUN (show_bgp_prefix_pathtype,
7602 show_bgp_prefix_pathtype_cmd,
7603 "show bgp X:X::X:X/M (bestpath|multipath)",
7604 SHOW_STR
7605 BGP_STR
7606 "IPv6 prefix <network>/<length>\n"
7607 "Display only the bestpath\n"
7608 "Display only multipaths\n")
7609 {
7610 if (strncmp (argv[1], "b", 1) == 0)
7611 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7612 else
7613 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7614 }
7615
7616 ALIAS (show_bgp_prefix_pathtype,
7617 show_bgp_ipv6_prefix_pathtype_cmd,
7618 "show bgp ipv6 X:X::X:X/M (bestpath|multipath)",
7619 SHOW_STR
7620 BGP_STR
7621 "Address family\n"
7622 "IPv6 prefix <network>/<length>\n"
7623 "Display only the bestpath\n"
7624 "Display only multipaths\n")
7625
7626 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
7627 show_bgp_ipv6_safi_prefix_pathtype_cmd,
7628 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath)",
7629 SHOW_STR
7630 BGP_STR
7631 "Address family\n"
7632 "Address Family modifier\n"
7633 "Address Family modifier\n"
7634 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7635 "Display only the bestpath\n"
7636 "Display only multipaths\n")
7637 {
7638 if (strncmp (argv[0], "m", 1) == 0)
7639 if (strncmp (argv[2], "b", 1) == 0)
7640 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7641 else
7642 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7643 else
7644 if (strncmp (argv[2], "b", 1) == 0)
7645 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7646 else
7647 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7648 }
7649
7650 /* old command */
7651 DEFUN (show_ipv6_bgp_prefix,
7652 show_ipv6_bgp_prefix_cmd,
7653 "show ipv6 bgp X:X::X:X/M",
7654 SHOW_STR
7655 IP_STR
7656 BGP_STR
7657 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7658 {
7659 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7660 }
7661
7662 DEFUN (show_bgp_view,
7663 show_bgp_view_cmd,
7664 "show bgp view WORD",
7665 SHOW_STR
7666 BGP_STR
7667 "BGP view\n"
7668 "View name\n")
7669 {
7670 struct bgp *bgp;
7671
7672 /* BGP structure lookup. */
7673 bgp = bgp_lookup_by_name (argv[0]);
7674 if (bgp == NULL)
7675 {
7676 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7677 return CMD_WARNING;
7678 }
7679
7680 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, NULL);
7681 }
7682
7683 ALIAS (show_bgp_view,
7684 show_bgp_view_ipv6_cmd,
7685 "show bgp view WORD ipv6",
7686 SHOW_STR
7687 BGP_STR
7688 "BGP view\n"
7689 "View name\n"
7690 "Address family\n")
7691
7692 DEFUN (show_bgp_view_route,
7693 show_bgp_view_route_cmd,
7694 "show bgp view WORD X:X::X:X",
7695 SHOW_STR
7696 BGP_STR
7697 "BGP view\n"
7698 "View name\n"
7699 "Network in the BGP routing table to display\n")
7700 {
7701 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7702 }
7703
7704 ALIAS (show_bgp_view_route,
7705 show_bgp_view_ipv6_route_cmd,
7706 "show bgp view WORD ipv6 X:X::X:X",
7707 SHOW_STR
7708 BGP_STR
7709 "BGP view\n"
7710 "View name\n"
7711 "Address family\n"
7712 "Network in the BGP routing table to display\n")
7713
7714 DEFUN (show_bgp_view_prefix,
7715 show_bgp_view_prefix_cmd,
7716 "show bgp view WORD X:X::X:X/M",
7717 SHOW_STR
7718 BGP_STR
7719 "BGP view\n"
7720 "View name\n"
7721 "IPv6 prefix <network>/<length>\n")
7722 {
7723 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7724 }
7725
7726 ALIAS (show_bgp_view_prefix,
7727 show_bgp_view_ipv6_prefix_cmd,
7728 "show bgp view WORD ipv6 X:X::X:X/M",
7729 SHOW_STR
7730 BGP_STR
7731 "BGP view\n"
7732 "View name\n"
7733 "Address family\n"
7734 "IPv6 prefix <network>/<length>\n")
7735
7736 /* old command */
7737 DEFUN (show_ipv6_mbgp,
7738 show_ipv6_mbgp_cmd,
7739 "show ipv6 mbgp",
7740 SHOW_STR
7741 IP_STR
7742 MBGP_STR)
7743 {
7744 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7745 NULL, NULL);
7746 }
7747
7748 /* old command */
7749 DEFUN (show_ipv6_mbgp_route,
7750 show_ipv6_mbgp_route_cmd,
7751 "show ipv6 mbgp X:X::X:X",
7752 SHOW_STR
7753 IP_STR
7754 MBGP_STR
7755 "Network in the MBGP routing table to display\n")
7756 {
7757 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
7758 }
7759
7760 /* old command */
7761 DEFUN (show_ipv6_mbgp_prefix,
7762 show_ipv6_mbgp_prefix_cmd,
7763 "show ipv6 mbgp X:X::X:X/M",
7764 SHOW_STR
7765 IP_STR
7766 MBGP_STR
7767 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7768 {
7769 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
7770 }
7771 #endif
7772
7773
7774 static int
7775 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
7776 safi_t safi, enum bgp_show_type type)
7777 {
7778 int i;
7779 struct buffer *b;
7780 char *regstr;
7781 int first;
7782 regex_t *regex;
7783 int rc;
7784
7785 first = 0;
7786 b = buffer_new (1024);
7787 for (i = 0; i < argc; i++)
7788 {
7789 if (first)
7790 buffer_putc (b, ' ');
7791 else
7792 {
7793 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7794 continue;
7795 first = 1;
7796 }
7797
7798 buffer_putstr (b, argv[i]);
7799 }
7800 buffer_putc (b, '\0');
7801
7802 regstr = buffer_getstr (b);
7803 buffer_free (b);
7804
7805 regex = bgp_regcomp (regstr);
7806 XFREE(MTYPE_TMP, regstr);
7807 if (! regex)
7808 {
7809 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7810 VTY_NEWLINE);
7811 return CMD_WARNING;
7812 }
7813
7814 rc = bgp_show (vty, NULL, afi, safi, type, regex, NULL);
7815 bgp_regex_free (regex);
7816 return rc;
7817 }
7818
7819 DEFUN (show_ip_bgp_regexp,
7820 show_ip_bgp_regexp_cmd,
7821 "show ip bgp regexp .LINE",
7822 SHOW_STR
7823 IP_STR
7824 BGP_STR
7825 "Display routes matching the AS path regular expression\n"
7826 "A regular-expression to match the BGP AS paths\n")
7827 {
7828 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7829 bgp_show_type_regexp);
7830 }
7831
7832 DEFUN (show_ip_bgp_flap_regexp,
7833 show_ip_bgp_flap_regexp_cmd,
7834 "show ip bgp flap-statistics regexp .LINE",
7835 SHOW_STR
7836 IP_STR
7837 BGP_STR
7838 "Display flap statistics of routes\n"
7839 "Display routes matching the AS path regular expression\n"
7840 "A regular-expression to match the BGP AS paths\n")
7841 {
7842 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7843 bgp_show_type_flap_regexp);
7844 }
7845
7846 DEFUN (show_ip_bgp_ipv4_regexp,
7847 show_ip_bgp_ipv4_regexp_cmd,
7848 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7849 SHOW_STR
7850 IP_STR
7851 BGP_STR
7852 "Address family\n"
7853 "Address Family modifier\n"
7854 "Address Family modifier\n"
7855 "Display routes matching the AS path regular expression\n"
7856 "A regular-expression to match the BGP AS paths\n")
7857 {
7858 if (strncmp (argv[0], "m", 1) == 0)
7859 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7860 bgp_show_type_regexp);
7861
7862 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7863 bgp_show_type_regexp);
7864 }
7865
7866 #ifdef HAVE_IPV6
7867 DEFUN (show_bgp_regexp,
7868 show_bgp_regexp_cmd,
7869 "show bgp regexp .LINE",
7870 SHOW_STR
7871 BGP_STR
7872 "Display routes matching the AS path regular expression\n"
7873 "A regular-expression to match the BGP AS paths\n")
7874 {
7875 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7876 bgp_show_type_regexp);
7877 }
7878
7879 ALIAS (show_bgp_regexp,
7880 show_bgp_ipv6_regexp_cmd,
7881 "show bgp ipv6 regexp .LINE",
7882 SHOW_STR
7883 BGP_STR
7884 "Address family\n"
7885 "Display routes matching the AS path regular expression\n"
7886 "A regular-expression to match the BGP AS paths\n")
7887
7888 /* old command */
7889 DEFUN (show_ipv6_bgp_regexp,
7890 show_ipv6_bgp_regexp_cmd,
7891 "show ipv6 bgp regexp .LINE",
7892 SHOW_STR
7893 IP_STR
7894 BGP_STR
7895 "Display routes matching the AS path regular expression\n"
7896 "A regular-expression to match the BGP AS paths\n")
7897 {
7898 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7899 bgp_show_type_regexp);
7900 }
7901
7902 /* old command */
7903 DEFUN (show_ipv6_mbgp_regexp,
7904 show_ipv6_mbgp_regexp_cmd,
7905 "show ipv6 mbgp regexp .LINE",
7906 SHOW_STR
7907 IP_STR
7908 BGP_STR
7909 "Display routes matching the AS path regular expression\n"
7910 "A regular-expression to match the MBGP AS paths\n")
7911 {
7912 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7913 bgp_show_type_regexp);
7914 }
7915 #endif /* HAVE_IPV6 */
7916
7917 static int
7918 bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
7919 safi_t safi, enum bgp_show_type type)
7920 {
7921 struct prefix_list *plist;
7922
7923 plist = prefix_list_lookup (afi, prefix_list_str);
7924 if (plist == NULL)
7925 {
7926 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7927 prefix_list_str, VTY_NEWLINE);
7928 return CMD_WARNING;
7929 }
7930
7931 return bgp_show (vty, NULL, afi, safi, type, plist, NULL);
7932 }
7933
7934 DEFUN (show_ip_bgp_prefix_list,
7935 show_ip_bgp_prefix_list_cmd,
7936 "show ip bgp prefix-list WORD",
7937 SHOW_STR
7938 IP_STR
7939 BGP_STR
7940 "Display routes conforming to the prefix-list\n"
7941 "IP prefix-list name\n")
7942 {
7943 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7944 bgp_show_type_prefix_list);
7945 }
7946
7947 DEFUN (show_ip_bgp_flap_prefix_list,
7948 show_ip_bgp_flap_prefix_list_cmd,
7949 "show ip bgp flap-statistics prefix-list WORD",
7950 SHOW_STR
7951 IP_STR
7952 BGP_STR
7953 "Display flap statistics of routes\n"
7954 "Display routes conforming to the prefix-list\n"
7955 "IP prefix-list name\n")
7956 {
7957 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7958 bgp_show_type_flap_prefix_list);
7959 }
7960
7961 DEFUN (show_ip_bgp_ipv4_prefix_list,
7962 show_ip_bgp_ipv4_prefix_list_cmd,
7963 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7964 SHOW_STR
7965 IP_STR
7966 BGP_STR
7967 "Address family\n"
7968 "Address Family modifier\n"
7969 "Address Family modifier\n"
7970 "Display routes conforming to the prefix-list\n"
7971 "IP prefix-list name\n")
7972 {
7973 if (strncmp (argv[0], "m", 1) == 0)
7974 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7975 bgp_show_type_prefix_list);
7976
7977 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7978 bgp_show_type_prefix_list);
7979 }
7980
7981 #ifdef HAVE_IPV6
7982 DEFUN (show_bgp_prefix_list,
7983 show_bgp_prefix_list_cmd,
7984 "show bgp prefix-list WORD",
7985 SHOW_STR
7986 BGP_STR
7987 "Display routes conforming to the prefix-list\n"
7988 "IPv6 prefix-list name\n")
7989 {
7990 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7991 bgp_show_type_prefix_list);
7992 }
7993
7994 ALIAS (show_bgp_prefix_list,
7995 show_bgp_ipv6_prefix_list_cmd,
7996 "show bgp ipv6 prefix-list WORD",
7997 SHOW_STR
7998 BGP_STR
7999 "Address family\n"
8000 "Display routes conforming to the prefix-list\n"
8001 "IPv6 prefix-list name\n")
8002
8003 /* old command */
8004 DEFUN (show_ipv6_bgp_prefix_list,
8005 show_ipv6_bgp_prefix_list_cmd,
8006 "show ipv6 bgp prefix-list WORD",
8007 SHOW_STR
8008 IPV6_STR
8009 BGP_STR
8010 "Display routes matching the prefix-list\n"
8011 "IPv6 prefix-list name\n")
8012 {
8013 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8014 bgp_show_type_prefix_list);
8015 }
8016
8017 /* old command */
8018 DEFUN (show_ipv6_mbgp_prefix_list,
8019 show_ipv6_mbgp_prefix_list_cmd,
8020 "show ipv6 mbgp prefix-list WORD",
8021 SHOW_STR
8022 IPV6_STR
8023 MBGP_STR
8024 "Display routes matching the prefix-list\n"
8025 "IPv6 prefix-list name\n")
8026 {
8027 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8028 bgp_show_type_prefix_list);
8029 }
8030 #endif /* HAVE_IPV6 */
8031
8032 static int
8033 bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
8034 safi_t safi, enum bgp_show_type type)
8035 {
8036 struct as_list *as_list;
8037
8038 as_list = as_list_lookup (filter);
8039 if (as_list == NULL)
8040 {
8041 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8042 return CMD_WARNING;
8043 }
8044
8045 return bgp_show (vty, NULL, afi, safi, type, as_list, NULL);
8046 }
8047
8048 DEFUN (show_ip_bgp_filter_list,
8049 show_ip_bgp_filter_list_cmd,
8050 "show ip bgp filter-list WORD",
8051 SHOW_STR
8052 IP_STR
8053 BGP_STR
8054 "Display routes conforming to the filter-list\n"
8055 "Regular expression access list name\n")
8056 {
8057 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8058 bgp_show_type_filter_list);
8059 }
8060
8061 DEFUN (show_ip_bgp_flap_filter_list,
8062 show_ip_bgp_flap_filter_list_cmd,
8063 "show ip bgp flap-statistics filter-list WORD",
8064 SHOW_STR
8065 IP_STR
8066 BGP_STR
8067 "Display flap statistics of routes\n"
8068 "Display routes conforming to the filter-list\n"
8069 "Regular expression access list name\n")
8070 {
8071 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8072 bgp_show_type_flap_filter_list);
8073 }
8074
8075 DEFUN (show_ip_bgp_ipv4_filter_list,
8076 show_ip_bgp_ipv4_filter_list_cmd,
8077 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8078 SHOW_STR
8079 IP_STR
8080 BGP_STR
8081 "Address family\n"
8082 "Address Family modifier\n"
8083 "Address Family modifier\n"
8084 "Display routes conforming to the filter-list\n"
8085 "Regular expression access list name\n")
8086 {
8087 if (strncmp (argv[0], "m", 1) == 0)
8088 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8089 bgp_show_type_filter_list);
8090
8091 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8092 bgp_show_type_filter_list);
8093 }
8094
8095 #ifdef HAVE_IPV6
8096 DEFUN (show_bgp_filter_list,
8097 show_bgp_filter_list_cmd,
8098 "show bgp filter-list WORD",
8099 SHOW_STR
8100 BGP_STR
8101 "Display routes conforming to the filter-list\n"
8102 "Regular expression access list name\n")
8103 {
8104 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8105 bgp_show_type_filter_list);
8106 }
8107
8108 ALIAS (show_bgp_filter_list,
8109 show_bgp_ipv6_filter_list_cmd,
8110 "show bgp ipv6 filter-list WORD",
8111 SHOW_STR
8112 BGP_STR
8113 "Address family\n"
8114 "Display routes conforming to the filter-list\n"
8115 "Regular expression access list name\n")
8116
8117 /* old command */
8118 DEFUN (show_ipv6_bgp_filter_list,
8119 show_ipv6_bgp_filter_list_cmd,
8120 "show ipv6 bgp filter-list WORD",
8121 SHOW_STR
8122 IPV6_STR
8123 BGP_STR
8124 "Display routes conforming to the filter-list\n"
8125 "Regular expression access list name\n")
8126 {
8127 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8128 bgp_show_type_filter_list);
8129 }
8130
8131 /* old command */
8132 DEFUN (show_ipv6_mbgp_filter_list,
8133 show_ipv6_mbgp_filter_list_cmd,
8134 "show ipv6 mbgp filter-list WORD",
8135 SHOW_STR
8136 IPV6_STR
8137 MBGP_STR
8138 "Display routes conforming to the filter-list\n"
8139 "Regular expression access list name\n")
8140 {
8141 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8142 bgp_show_type_filter_list);
8143 }
8144 #endif /* HAVE_IPV6 */
8145
8146 static int
8147 bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
8148 safi_t safi, enum bgp_show_type type)
8149 {
8150 struct route_map *rmap;
8151
8152 rmap = route_map_lookup_by_name (rmap_str);
8153 if (! rmap)
8154 {
8155 vty_out (vty, "%% %s is not a valid route-map name%s",
8156 rmap_str, VTY_NEWLINE);
8157 return CMD_WARNING;
8158 }
8159
8160 return bgp_show (vty, NULL, afi, safi, type, rmap, NULL);
8161 }
8162
8163 DEFUN (show_ip_bgp_route_map,
8164 show_ip_bgp_route_map_cmd,
8165 "show ip bgp route-map WORD",
8166 SHOW_STR
8167 IP_STR
8168 BGP_STR
8169 "Display routes matching the route-map\n"
8170 "A route-map to match on\n")
8171 {
8172 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8173 bgp_show_type_route_map);
8174 }
8175
8176 DEFUN (show_ip_bgp_flap_route_map,
8177 show_ip_bgp_flap_route_map_cmd,
8178 "show ip bgp flap-statistics route-map WORD",
8179 SHOW_STR
8180 IP_STR
8181 BGP_STR
8182 "Display flap statistics of routes\n"
8183 "Display routes matching the route-map\n"
8184 "A route-map to match on\n")
8185 {
8186 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8187 bgp_show_type_flap_route_map);
8188 }
8189
8190 DEFUN (show_ip_bgp_ipv4_route_map,
8191 show_ip_bgp_ipv4_route_map_cmd,
8192 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8193 SHOW_STR
8194 IP_STR
8195 BGP_STR
8196 "Address family\n"
8197 "Address Family modifier\n"
8198 "Address Family modifier\n"
8199 "Display routes matching the route-map\n"
8200 "A route-map to match on\n")
8201 {
8202 if (strncmp (argv[0], "m", 1) == 0)
8203 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8204 bgp_show_type_route_map);
8205
8206 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8207 bgp_show_type_route_map);
8208 }
8209
8210 DEFUN (show_bgp_route_map,
8211 show_bgp_route_map_cmd,
8212 "show bgp route-map WORD",
8213 SHOW_STR
8214 BGP_STR
8215 "Display routes matching the route-map\n"
8216 "A route-map to match on\n")
8217 {
8218 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8219 bgp_show_type_route_map);
8220 }
8221
8222 ALIAS (show_bgp_route_map,
8223 show_bgp_ipv6_route_map_cmd,
8224 "show bgp ipv6 route-map WORD",
8225 SHOW_STR
8226 BGP_STR
8227 "Address family\n"
8228 "Display routes matching the route-map\n"
8229 "A route-map to match on\n")
8230
8231 DEFUN (show_ip_bgp_cidr_only,
8232 show_ip_bgp_cidr_only_cmd,
8233 "show ip bgp cidr-only",
8234 SHOW_STR
8235 IP_STR
8236 BGP_STR
8237 "Display only routes with non-natural netmasks\n")
8238 {
8239 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8240 bgp_show_type_cidr_only, NULL, NULL);
8241 }
8242
8243 DEFUN (show_ip_bgp_flap_cidr_only,
8244 show_ip_bgp_flap_cidr_only_cmd,
8245 "show ip bgp flap-statistics cidr-only",
8246 SHOW_STR
8247 IP_STR
8248 BGP_STR
8249 "Display flap statistics of routes\n"
8250 "Display only routes with non-natural netmasks\n")
8251 {
8252 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8253 bgp_show_type_flap_cidr_only, NULL, NULL);
8254 }
8255
8256 DEFUN (show_ip_bgp_ipv4_cidr_only,
8257 show_ip_bgp_ipv4_cidr_only_cmd,
8258 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8259 SHOW_STR
8260 IP_STR
8261 BGP_STR
8262 "Address family\n"
8263 "Address Family modifier\n"
8264 "Address Family modifier\n"
8265 "Display only routes with non-natural netmasks\n")
8266 {
8267 if (strncmp (argv[0], "m", 1) == 0)
8268 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8269 bgp_show_type_cidr_only, NULL, NULL);
8270
8271 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8272 bgp_show_type_cidr_only, NULL, NULL);
8273 }
8274
8275 DEFUN (show_ip_bgp_community_all,
8276 show_ip_bgp_community_all_cmd,
8277 "show ip bgp community",
8278 SHOW_STR
8279 IP_STR
8280 BGP_STR
8281 "Display routes matching the communities\n")
8282 {
8283 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8284 bgp_show_type_community_all, NULL, NULL);
8285 }
8286
8287 DEFUN (show_ip_bgp_ipv4_community_all,
8288 show_ip_bgp_ipv4_community_all_cmd,
8289 "show ip bgp ipv4 (unicast|multicast) community",
8290 SHOW_STR
8291 IP_STR
8292 BGP_STR
8293 "Address family\n"
8294 "Address Family modifier\n"
8295 "Address Family modifier\n"
8296 "Display routes matching the communities\n")
8297 {
8298 if (strncmp (argv[0], "m", 1) == 0)
8299 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8300 bgp_show_type_community_all, NULL, NULL);
8301
8302 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8303 bgp_show_type_community_all, NULL, NULL);
8304 }
8305
8306 #ifdef HAVE_IPV6
8307 DEFUN (show_bgp_community_all,
8308 show_bgp_community_all_cmd,
8309 "show bgp community",
8310 SHOW_STR
8311 BGP_STR
8312 "Display routes matching the communities\n")
8313 {
8314 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8315 bgp_show_type_community_all, NULL, NULL);
8316 }
8317
8318 ALIAS (show_bgp_community_all,
8319 show_bgp_ipv6_community_all_cmd,
8320 "show bgp ipv6 community",
8321 SHOW_STR
8322 BGP_STR
8323 "Address family\n"
8324 "Display routes matching the communities\n")
8325
8326 /* old command */
8327 DEFUN (show_ipv6_bgp_community_all,
8328 show_ipv6_bgp_community_all_cmd,
8329 "show ipv6 bgp community",
8330 SHOW_STR
8331 IPV6_STR
8332 BGP_STR
8333 "Display routes matching the communities\n")
8334 {
8335 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8336 bgp_show_type_community_all, NULL, NULL);
8337 }
8338
8339 /* old command */
8340 DEFUN (show_ipv6_mbgp_community_all,
8341 show_ipv6_mbgp_community_all_cmd,
8342 "show ipv6 mbgp community",
8343 SHOW_STR
8344 IPV6_STR
8345 MBGP_STR
8346 "Display routes matching the communities\n")
8347 {
8348 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
8349 bgp_show_type_community_all, NULL, NULL);
8350 }
8351 #endif /* HAVE_IPV6 */
8352
8353 static int
8354 bgp_show_community (struct vty *vty, const char *view_name, int argc,
8355 const char **argv, int exact, afi_t afi, safi_t safi)
8356 {
8357 struct community *com;
8358 struct buffer *b;
8359 struct bgp *bgp;
8360 int i;
8361 char *str;
8362 int first = 0;
8363
8364 /* BGP structure lookup */
8365 if (view_name)
8366 {
8367 bgp = bgp_lookup_by_name (view_name);
8368 if (bgp == NULL)
8369 {
8370 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8371 return CMD_WARNING;
8372 }
8373 }
8374 else
8375 {
8376 bgp = bgp_get_default ();
8377 if (bgp == NULL)
8378 {
8379 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8380 return CMD_WARNING;
8381 }
8382 }
8383
8384 b = buffer_new (1024);
8385 for (i = 0; i < argc; i++)
8386 {
8387 if (first)
8388 buffer_putc (b, ' ');
8389 else
8390 {
8391 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8392 continue;
8393 first = 1;
8394 }
8395
8396 buffer_putstr (b, argv[i]);
8397 }
8398 buffer_putc (b, '\0');
8399
8400 str = buffer_getstr (b);
8401 buffer_free (b);
8402
8403 com = community_str2com (str);
8404 XFREE (MTYPE_TMP, str);
8405 if (! com)
8406 {
8407 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
8408 return CMD_WARNING;
8409 }
8410
8411 return bgp_show (vty, bgp, afi, safi,
8412 (exact ? bgp_show_type_community_exact :
8413 bgp_show_type_community), com, NULL);
8414 }
8415
8416 DEFUN (show_ip_bgp_community,
8417 show_ip_bgp_community_cmd,
8418 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
8419 SHOW_STR
8420 IP_STR
8421 BGP_STR
8422 "Display routes matching the communities\n"
8423 "community number\n"
8424 "Do not send outside local AS (well-known community)\n"
8425 "Do not advertise to any peer (well-known community)\n"
8426 "Do not export to next AS (well-known community)\n")
8427 {
8428 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
8429 }
8430
8431 ALIAS (show_ip_bgp_community,
8432 show_ip_bgp_community2_cmd,
8433 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8434 SHOW_STR
8435 IP_STR
8436 BGP_STR
8437 "Display routes matching the communities\n"
8438 "community number\n"
8439 "Do not send outside local AS (well-known community)\n"
8440 "Do not advertise to any peer (well-known community)\n"
8441 "Do not export to next AS (well-known community)\n"
8442 "community number\n"
8443 "Do not send outside local AS (well-known community)\n"
8444 "Do not advertise to any peer (well-known community)\n"
8445 "Do not export to next AS (well-known community)\n")
8446
8447 ALIAS (show_ip_bgp_community,
8448 show_ip_bgp_community3_cmd,
8449 "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)",
8450 SHOW_STR
8451 IP_STR
8452 BGP_STR
8453 "Display routes matching the communities\n"
8454 "community number\n"
8455 "Do not send outside local AS (well-known community)\n"
8456 "Do not advertise to any peer (well-known community)\n"
8457 "Do not export to next AS (well-known community)\n"
8458 "community number\n"
8459 "Do not send outside local AS (well-known community)\n"
8460 "Do not advertise to any peer (well-known community)\n"
8461 "Do not export to next AS (well-known community)\n"
8462 "community number\n"
8463 "Do not send outside local AS (well-known community)\n"
8464 "Do not advertise to any peer (well-known community)\n"
8465 "Do not export to next AS (well-known community)\n")
8466
8467 ALIAS (show_ip_bgp_community,
8468 show_ip_bgp_community4_cmd,
8469 "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)",
8470 SHOW_STR
8471 IP_STR
8472 BGP_STR
8473 "Display routes matching the communities\n"
8474 "community number\n"
8475 "Do not send outside local AS (well-known community)\n"
8476 "Do not advertise to any peer (well-known community)\n"
8477 "Do not export to next AS (well-known community)\n"
8478 "community number\n"
8479 "Do not send outside local AS (well-known community)\n"
8480 "Do not advertise to any peer (well-known community)\n"
8481 "Do not export to next AS (well-known community)\n"
8482 "community number\n"
8483 "Do not send outside local AS (well-known community)\n"
8484 "Do not advertise to any peer (well-known community)\n"
8485 "Do not export to next AS (well-known community)\n"
8486 "community number\n"
8487 "Do not send outside local AS (well-known community)\n"
8488 "Do not advertise to any peer (well-known community)\n"
8489 "Do not export to next AS (well-known community)\n")
8490
8491 DEFUN (show_ip_bgp_ipv4_community,
8492 show_ip_bgp_ipv4_community_cmd,
8493 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8494 SHOW_STR
8495 IP_STR
8496 BGP_STR
8497 "Address family\n"
8498 "Address Family modifier\n"
8499 "Address Family modifier\n"
8500 "Display routes matching the communities\n"
8501 "community number\n"
8502 "Do not send outside local AS (well-known community)\n"
8503 "Do not advertise to any peer (well-known community)\n"
8504 "Do not export to next AS (well-known community)\n")
8505 {
8506 if (strncmp (argv[0], "m", 1) == 0)
8507 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
8508
8509 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
8510 }
8511
8512 ALIAS (show_ip_bgp_ipv4_community,
8513 show_ip_bgp_ipv4_community2_cmd,
8514 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8515 SHOW_STR
8516 IP_STR
8517 BGP_STR
8518 "Address family\n"
8519 "Address Family modifier\n"
8520 "Address Family modifier\n"
8521 "Display routes matching the communities\n"
8522 "community number\n"
8523 "Do not send outside local AS (well-known community)\n"
8524 "Do not advertise to any peer (well-known community)\n"
8525 "Do not export to next AS (well-known community)\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
8531 ALIAS (show_ip_bgp_ipv4_community,
8532 show_ip_bgp_ipv4_community3_cmd,
8533 "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)",
8534 SHOW_STR
8535 IP_STR
8536 BGP_STR
8537 "Address family\n"
8538 "Address Family modifier\n"
8539 "Address Family modifier\n"
8540 "Display routes matching the communities\n"
8541 "community number\n"
8542 "Do not send outside local AS (well-known community)\n"
8543 "Do not advertise to any peer (well-known community)\n"
8544 "Do not export to next AS (well-known community)\n"
8545 "community number\n"
8546 "Do not send outside local AS (well-known community)\n"
8547 "Do not advertise to any peer (well-known community)\n"
8548 "Do not export to next AS (well-known community)\n"
8549 "community number\n"
8550 "Do not send outside local AS (well-known community)\n"
8551 "Do not advertise to any peer (well-known community)\n"
8552 "Do not export to next AS (well-known community)\n")
8553
8554 ALIAS (show_ip_bgp_ipv4_community,
8555 show_ip_bgp_ipv4_community4_cmd,
8556 "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)",
8557 SHOW_STR
8558 IP_STR
8559 BGP_STR
8560 "Address family\n"
8561 "Address Family modifier\n"
8562 "Address Family modifier\n"
8563 "Display routes matching the communities\n"
8564 "community number\n"
8565 "Do not send outside local AS (well-known community)\n"
8566 "Do not advertise to any peer (well-known community)\n"
8567 "Do not export to next AS (well-known community)\n"
8568 "community number\n"
8569 "Do not send outside local AS (well-known community)\n"
8570 "Do not advertise to any peer (well-known community)\n"
8571 "Do not export to next AS (well-known community)\n"
8572 "community number\n"
8573 "Do not send outside local AS (well-known community)\n"
8574 "Do not advertise to any peer (well-known community)\n"
8575 "Do not export to next AS (well-known community)\n"
8576 "community number\n"
8577 "Do not send outside local AS (well-known community)\n"
8578 "Do not advertise to any peer (well-known community)\n"
8579 "Do not export to next AS (well-known community)\n")
8580
8581 DEFUN (show_bgp_view_afi_safi_community_all,
8582 show_bgp_view_afi_safi_community_all_cmd,
8583 #ifdef HAVE_IPV6
8584 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
8585 #else
8586 "show bgp view WORD ipv4 (unicast|multicast) community",
8587 #endif
8588 SHOW_STR
8589 BGP_STR
8590 "BGP view\n"
8591 "View name\n"
8592 "Address family\n"
8593 #ifdef HAVE_IPV6
8594 "Address family\n"
8595 #endif
8596 "Address Family modifier\n"
8597 "Address Family modifier\n"
8598 "Display routes matching the communities\n")
8599 {
8600 int afi;
8601 int safi;
8602 struct bgp *bgp;
8603
8604 /* BGP structure lookup. */
8605 bgp = bgp_lookup_by_name (argv[0]);
8606 if (bgp == NULL)
8607 {
8608 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8609 return CMD_WARNING;
8610 }
8611
8612 #ifdef HAVE_IPV6
8613 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8614 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8615 #else
8616 afi = AFI_IP;
8617 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8618 #endif
8619 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, NULL);
8620 }
8621
8622 DEFUN (show_bgp_view_afi_safi_community,
8623 show_bgp_view_afi_safi_community_cmd,
8624 #ifdef HAVE_IPV6
8625 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8626 #else
8627 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8628 #endif
8629 SHOW_STR
8630 BGP_STR
8631 "BGP view\n"
8632 "View name\n"
8633 "Address family\n"
8634 #ifdef HAVE_IPV6
8635 "Address family\n"
8636 #endif
8637 "Address family modifier\n"
8638 "Address family modifier\n"
8639 "Display routes matching the communities\n"
8640 "community number\n"
8641 "Do not send outside local AS (well-known community)\n"
8642 "Do not advertise to any peer (well-known community)\n"
8643 "Do not export to next AS (well-known community)\n")
8644 {
8645 int afi;
8646 int safi;
8647
8648 #ifdef HAVE_IPV6
8649 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8650 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8651 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
8652 #else
8653 afi = AFI_IP;
8654 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8655 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
8656 #endif
8657 }
8658
8659 ALIAS (show_bgp_view_afi_safi_community,
8660 show_bgp_view_afi_safi_community2_cmd,
8661 #ifdef HAVE_IPV6
8662 "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)",
8663 #else
8664 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8665 #endif
8666 SHOW_STR
8667 BGP_STR
8668 "BGP view\n"
8669 "View name\n"
8670 "Address family\n"
8671 #ifdef HAVE_IPV6
8672 "Address family\n"
8673 #endif
8674 "Address family modifier\n"
8675 "Address family modifier\n"
8676 "Display routes matching the communities\n"
8677 "community number\n"
8678 "Do not send outside local AS (well-known community)\n"
8679 "Do not advertise to any peer (well-known community)\n"
8680 "Do not export to next AS (well-known community)\n"
8681 "community number\n"
8682 "Do not send outside local AS (well-known community)\n"
8683 "Do not advertise to any peer (well-known community)\n"
8684 "Do not export to next AS (well-known community)\n")
8685
8686 ALIAS (show_bgp_view_afi_safi_community,
8687 show_bgp_view_afi_safi_community3_cmd,
8688 #ifdef HAVE_IPV6
8689 "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)",
8690 #else
8691 "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)",
8692 #endif
8693 SHOW_STR
8694 BGP_STR
8695 "BGP view\n"
8696 "View name\n"
8697 "Address family\n"
8698 #ifdef HAVE_IPV6
8699 "Address family\n"
8700 #endif
8701 "Address family modifier\n"
8702 "Address family modifier\n"
8703 "Display routes matching the communities\n"
8704 "community number\n"
8705 "Do not send outside local AS (well-known community)\n"
8706 "Do not advertise to any peer (well-known community)\n"
8707 "Do not export to next AS (well-known community)\n"
8708 "community number\n"
8709 "Do not send outside local AS (well-known community)\n"
8710 "Do not advertise to any peer (well-known community)\n"
8711 "Do not export to next AS (well-known community)\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 ALIAS (show_bgp_view_afi_safi_community,
8718 show_bgp_view_afi_safi_community4_cmd,
8719 #ifdef HAVE_IPV6
8720 "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)",
8721 #else
8722 "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)",
8723 #endif
8724 SHOW_STR
8725 BGP_STR
8726 "BGP view\n"
8727 "View name\n"
8728 "Address family\n"
8729 #ifdef HAVE_IPV6
8730 "Address family\n"
8731 #endif
8732 "Address family modifier\n"
8733 "Address family modifier\n"
8734 "Display routes matching the communities\n"
8735 "community number\n"
8736 "Do not send outside local AS (well-known community)\n"
8737 "Do not advertise to any peer (well-known community)\n"
8738 "Do not export to next AS (well-known community)\n"
8739 "community number\n"
8740 "Do not send outside local AS (well-known community)\n"
8741 "Do not advertise to any peer (well-known community)\n"
8742 "Do not export to next AS (well-known community)\n"
8743 "community number\n"
8744 "Do not send outside local AS (well-known community)\n"
8745 "Do not advertise to any peer (well-known community)\n"
8746 "Do not export to next AS (well-known community)\n"
8747 "community number\n"
8748 "Do not send outside local AS (well-known community)\n"
8749 "Do not advertise to any peer (well-known community)\n"
8750 "Do not export to next AS (well-known community)\n")
8751
8752 DEFUN (show_ip_bgp_community_exact,
8753 show_ip_bgp_community_exact_cmd,
8754 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8755 SHOW_STR
8756 IP_STR
8757 BGP_STR
8758 "Display routes matching the communities\n"
8759 "community number\n"
8760 "Do not send outside local AS (well-known community)\n"
8761 "Do not advertise to any peer (well-known community)\n"
8762 "Do not export to next AS (well-known community)\n"
8763 "Exact match of the communities")
8764 {
8765 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
8766 }
8767
8768 ALIAS (show_ip_bgp_community_exact,
8769 show_ip_bgp_community2_exact_cmd,
8770 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8771 SHOW_STR
8772 IP_STR
8773 BGP_STR
8774 "Display routes matching the communities\n"
8775 "community number\n"
8776 "Do not send outside local AS (well-known community)\n"
8777 "Do not advertise to any peer (well-known community)\n"
8778 "Do not export to next AS (well-known community)\n"
8779 "community number\n"
8780 "Do not send outside local AS (well-known community)\n"
8781 "Do not advertise to any peer (well-known community)\n"
8782 "Do not export to next AS (well-known community)\n"
8783 "Exact match of the communities")
8784
8785 ALIAS (show_ip_bgp_community_exact,
8786 show_ip_bgp_community3_exact_cmd,
8787 "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",
8788 SHOW_STR
8789 IP_STR
8790 BGP_STR
8791 "Display routes matching the communities\n"
8792 "community number\n"
8793 "Do not send outside local AS (well-known community)\n"
8794 "Do not advertise to any peer (well-known community)\n"
8795 "Do not export to next AS (well-known community)\n"
8796 "community number\n"
8797 "Do not send outside local AS (well-known community)\n"
8798 "Do not advertise to any peer (well-known community)\n"
8799 "Do not export to next AS (well-known community)\n"
8800 "community number\n"
8801 "Do not send outside local AS (well-known community)\n"
8802 "Do not advertise to any peer (well-known community)\n"
8803 "Do not export to next AS (well-known community)\n"
8804 "Exact match of the communities")
8805
8806 ALIAS (show_ip_bgp_community_exact,
8807 show_ip_bgp_community4_exact_cmd,
8808 "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",
8809 SHOW_STR
8810 IP_STR
8811 BGP_STR
8812 "Display routes matching the communities\n"
8813 "community number\n"
8814 "Do not send outside local AS (well-known community)\n"
8815 "Do not advertise to any peer (well-known community)\n"
8816 "Do not export to next AS (well-known community)\n"
8817 "community number\n"
8818 "Do not send outside local AS (well-known community)\n"
8819 "Do not advertise to any peer (well-known community)\n"
8820 "Do not export to next AS (well-known community)\n"
8821 "community number\n"
8822 "Do not send outside local AS (well-known community)\n"
8823 "Do not advertise to any peer (well-known community)\n"
8824 "Do not export to next AS (well-known community)\n"
8825 "community number\n"
8826 "Do not send outside local AS (well-known community)\n"
8827 "Do not advertise to any peer (well-known community)\n"
8828 "Do not export to next AS (well-known community)\n"
8829 "Exact match of the communities")
8830
8831 DEFUN (show_ip_bgp_ipv4_community_exact,
8832 show_ip_bgp_ipv4_community_exact_cmd,
8833 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8834 SHOW_STR
8835 IP_STR
8836 BGP_STR
8837 "Address family\n"
8838 "Address Family modifier\n"
8839 "Address Family modifier\n"
8840 "Display routes matching the communities\n"
8841 "community number\n"
8842 "Do not send outside local AS (well-known community)\n"
8843 "Do not advertise to any peer (well-known community)\n"
8844 "Do not export to next AS (well-known community)\n"
8845 "Exact match of the communities")
8846 {
8847 if (strncmp (argv[0], "m", 1) == 0)
8848 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
8849
8850 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
8851 }
8852
8853 ALIAS (show_ip_bgp_ipv4_community_exact,
8854 show_ip_bgp_ipv4_community2_exact_cmd,
8855 "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",
8856 SHOW_STR
8857 IP_STR
8858 BGP_STR
8859 "Address family\n"
8860 "Address Family modifier\n"
8861 "Address Family modifier\n"
8862 "Display routes matching the communities\n"
8863 "community number\n"
8864 "Do not send outside local AS (well-known community)\n"
8865 "Do not advertise to any peer (well-known community)\n"
8866 "Do not export to next AS (well-known community)\n"
8867 "community number\n"
8868 "Do not send outside local AS (well-known community)\n"
8869 "Do not advertise to any peer (well-known community)\n"
8870 "Do not export to next AS (well-known community)\n"
8871 "Exact match of the communities")
8872
8873 ALIAS (show_ip_bgp_ipv4_community_exact,
8874 show_ip_bgp_ipv4_community3_exact_cmd,
8875 "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",
8876 SHOW_STR
8877 IP_STR
8878 BGP_STR
8879 "Address family\n"
8880 "Address Family modifier\n"
8881 "Address Family modifier\n"
8882 "Display routes matching the communities\n"
8883 "community number\n"
8884 "Do not send outside local AS (well-known community)\n"
8885 "Do not advertise to any peer (well-known community)\n"
8886 "Do not export to next AS (well-known community)\n"
8887 "community number\n"
8888 "Do not send outside local AS (well-known community)\n"
8889 "Do not advertise to any peer (well-known community)\n"
8890 "Do not export to next AS (well-known community)\n"
8891 "community number\n"
8892 "Do not send outside local AS (well-known community)\n"
8893 "Do not advertise to any peer (well-known community)\n"
8894 "Do not export to next AS (well-known community)\n"
8895 "Exact match of the communities")
8896
8897 ALIAS (show_ip_bgp_ipv4_community_exact,
8898 show_ip_bgp_ipv4_community4_exact_cmd,
8899 "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",
8900 SHOW_STR
8901 IP_STR
8902 BGP_STR
8903 "Address family\n"
8904 "Address Family modifier\n"
8905 "Address Family modifier\n"
8906 "Display routes matching the communities\n"
8907 "community number\n"
8908 "Do not send outside local AS (well-known community)\n"
8909 "Do not advertise to any peer (well-known community)\n"
8910 "Do not export to next AS (well-known community)\n"
8911 "community number\n"
8912 "Do not send outside local AS (well-known community)\n"
8913 "Do not advertise to any peer (well-known community)\n"
8914 "Do not export to next AS (well-known community)\n"
8915 "community number\n"
8916 "Do not send outside local AS (well-known community)\n"
8917 "Do not advertise to any peer (well-known community)\n"
8918 "Do not export to next AS (well-known community)\n"
8919 "community number\n"
8920 "Do not send outside local AS (well-known community)\n"
8921 "Do not advertise to any peer (well-known community)\n"
8922 "Do not export to next AS (well-known community)\n"
8923 "Exact match of the communities")
8924
8925 #ifdef HAVE_IPV6
8926 DEFUN (show_bgp_community,
8927 show_bgp_community_cmd,
8928 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8929 SHOW_STR
8930 BGP_STR
8931 "Display routes matching the communities\n"
8932 "community number\n"
8933 "Do not send outside local AS (well-known community)\n"
8934 "Do not advertise to any peer (well-known community)\n"
8935 "Do not export to next AS (well-known community)\n")
8936 {
8937 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8938 }
8939
8940 ALIAS (show_bgp_community,
8941 show_bgp_ipv6_community_cmd,
8942 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8943 SHOW_STR
8944 BGP_STR
8945 "Address family\n"
8946 "Display routes matching the communities\n"
8947 "community number\n"
8948 "Do not send outside local AS (well-known community)\n"
8949 "Do not advertise to any peer (well-known community)\n"
8950 "Do not export to next AS (well-known community)\n")
8951
8952 ALIAS (show_bgp_community,
8953 show_bgp_community2_cmd,
8954 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8955 SHOW_STR
8956 BGP_STR
8957 "Display routes matching the communities\n"
8958 "community number\n"
8959 "Do not send outside local AS (well-known community)\n"
8960 "Do not advertise to any peer (well-known community)\n"
8961 "Do not export to next AS (well-known community)\n"
8962 "community number\n"
8963 "Do not send outside local AS (well-known community)\n"
8964 "Do not advertise to any peer (well-known community)\n"
8965 "Do not export to next AS (well-known community)\n")
8966
8967 ALIAS (show_bgp_community,
8968 show_bgp_ipv6_community2_cmd,
8969 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8970 SHOW_STR
8971 BGP_STR
8972 "Address family\n"
8973 "Display routes matching the communities\n"
8974 "community number\n"
8975 "Do not send outside local AS (well-known community)\n"
8976 "Do not advertise to any peer (well-known community)\n"
8977 "Do not export to next AS (well-known community)\n"
8978 "community number\n"
8979 "Do not send outside local AS (well-known community)\n"
8980 "Do not advertise to any peer (well-known community)\n"
8981 "Do not export to next AS (well-known community)\n")
8982
8983 ALIAS (show_bgp_community,
8984 show_bgp_community3_cmd,
8985 "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)",
8986 SHOW_STR
8987 BGP_STR
8988 "Display routes matching the communities\n"
8989 "community number\n"
8990 "Do not send outside local AS (well-known community)\n"
8991 "Do not advertise to any peer (well-known community)\n"
8992 "Do not export to next AS (well-known community)\n"
8993 "community number\n"
8994 "Do not send outside local AS (well-known community)\n"
8995 "Do not advertise to any peer (well-known community)\n"
8996 "Do not export to next AS (well-known community)\n"
8997 "community number\n"
8998 "Do not send outside local AS (well-known community)\n"
8999 "Do not advertise to any peer (well-known community)\n"
9000 "Do not export to next AS (well-known community)\n")
9001
9002 ALIAS (show_bgp_community,
9003 show_bgp_ipv6_community3_cmd,
9004 "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)",
9005 SHOW_STR
9006 BGP_STR
9007 "Address family\n"
9008 "Display routes matching the communities\n"
9009 "community number\n"
9010 "Do not send outside local AS (well-known community)\n"
9011 "Do not advertise to any peer (well-known community)\n"
9012 "Do not export to next AS (well-known community)\n"
9013 "community number\n"
9014 "Do not send outside local AS (well-known community)\n"
9015 "Do not advertise to any peer (well-known community)\n"
9016 "Do not export to next AS (well-known community)\n"
9017 "community number\n"
9018 "Do not send outside local AS (well-known community)\n"
9019 "Do not advertise to any peer (well-known community)\n"
9020 "Do not export to next AS (well-known community)\n")
9021
9022 ALIAS (show_bgp_community,
9023 show_bgp_community4_cmd,
9024 "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)",
9025 SHOW_STR
9026 BGP_STR
9027 "Display routes matching the communities\n"
9028 "community number\n"
9029 "Do not send outside local AS (well-known community)\n"
9030 "Do not advertise to any peer (well-known community)\n"
9031 "Do not export to next AS (well-known community)\n"
9032 "community number\n"
9033 "Do not send outside local AS (well-known community)\n"
9034 "Do not advertise to any peer (well-known community)\n"
9035 "Do not export to next AS (well-known community)\n"
9036 "community number\n"
9037 "Do not send outside local AS (well-known community)\n"
9038 "Do not advertise to any peer (well-known community)\n"
9039 "Do not export to next AS (well-known community)\n"
9040 "community number\n"
9041 "Do not send outside local AS (well-known community)\n"
9042 "Do not advertise to any peer (well-known community)\n"
9043 "Do not export to next AS (well-known community)\n")
9044
9045 ALIAS (show_bgp_community,
9046 show_bgp_ipv6_community4_cmd,
9047 "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)",
9048 SHOW_STR
9049 BGP_STR
9050 "Address family\n"
9051 "Display routes matching the communities\n"
9052 "community number\n"
9053 "Do not send outside local AS (well-known community)\n"
9054 "Do not advertise to any peer (well-known community)\n"
9055 "Do not export to next AS (well-known community)\n"
9056 "community number\n"
9057 "Do not send outside local AS (well-known community)\n"
9058 "Do not advertise to any peer (well-known community)\n"
9059 "Do not export to next AS (well-known community)\n"
9060 "community number\n"
9061 "Do not send outside local AS (well-known community)\n"
9062 "Do not advertise to any peer (well-known community)\n"
9063 "Do not export to next AS (well-known community)\n"
9064 "community number\n"
9065 "Do not send outside local AS (well-known community)\n"
9066 "Do not advertise to any peer (well-known community)\n"
9067 "Do not export to next AS (well-known community)\n")
9068
9069 /* old command */
9070 DEFUN (show_ipv6_bgp_community,
9071 show_ipv6_bgp_community_cmd,
9072 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9073 SHOW_STR
9074 IPV6_STR
9075 BGP_STR
9076 "Display routes matching the communities\n"
9077 "community number\n"
9078 "Do not send outside local AS (well-known community)\n"
9079 "Do not advertise to any peer (well-known community)\n"
9080 "Do not export to next AS (well-known community)\n")
9081 {
9082 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9083 }
9084
9085 /* old command */
9086 ALIAS (show_ipv6_bgp_community,
9087 show_ipv6_bgp_community2_cmd,
9088 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9089 SHOW_STR
9090 IPV6_STR
9091 BGP_STR
9092 "Display routes matching the communities\n"
9093 "community number\n"
9094 "Do not send outside local AS (well-known community)\n"
9095 "Do not advertise to any peer (well-known community)\n"
9096 "Do not export to next AS (well-known community)\n"
9097 "community number\n"
9098 "Do not send outside local AS (well-known community)\n"
9099 "Do not advertise to any peer (well-known community)\n"
9100 "Do not export to next AS (well-known community)\n")
9101
9102 /* old command */
9103 ALIAS (show_ipv6_bgp_community,
9104 show_ipv6_bgp_community3_cmd,
9105 "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)",
9106 SHOW_STR
9107 IPV6_STR
9108 BGP_STR
9109 "Display routes matching the communities\n"
9110 "community number\n"
9111 "Do not send outside local AS (well-known community)\n"
9112 "Do not advertise to any peer (well-known community)\n"
9113 "Do not export to next AS (well-known community)\n"
9114 "community number\n"
9115 "Do not send outside local AS (well-known community)\n"
9116 "Do not advertise to any peer (well-known community)\n"
9117 "Do not export to next AS (well-known community)\n"
9118 "community number\n"
9119 "Do not send outside local AS (well-known community)\n"
9120 "Do not advertise to any peer (well-known community)\n"
9121 "Do not export to next AS (well-known community)\n")
9122
9123 /* old command */
9124 ALIAS (show_ipv6_bgp_community,
9125 show_ipv6_bgp_community4_cmd,
9126 "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)",
9127 SHOW_STR
9128 IPV6_STR
9129 BGP_STR
9130 "Display routes matching the communities\n"
9131 "community number\n"
9132 "Do not send outside local AS (well-known community)\n"
9133 "Do not advertise to any peer (well-known community)\n"
9134 "Do not export to next AS (well-known community)\n"
9135 "community number\n"
9136 "Do not send outside local AS (well-known community)\n"
9137 "Do not advertise to any peer (well-known community)\n"
9138 "Do not export to next AS (well-known community)\n"
9139 "community number\n"
9140 "Do not send outside local AS (well-known community)\n"
9141 "Do not advertise to any peer (well-known community)\n"
9142 "Do not export to next AS (well-known community)\n"
9143 "community number\n"
9144 "Do not send outside local AS (well-known community)\n"
9145 "Do not advertise to any peer (well-known community)\n"
9146 "Do not export to next AS (well-known community)\n")
9147
9148 DEFUN (show_bgp_community_exact,
9149 show_bgp_community_exact_cmd,
9150 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9151 SHOW_STR
9152 BGP_STR
9153 "Display routes matching the communities\n"
9154 "community number\n"
9155 "Do not send outside local AS (well-known community)\n"
9156 "Do not advertise to any peer (well-known community)\n"
9157 "Do not export to next AS (well-known community)\n"
9158 "Exact match of the communities")
9159 {
9160 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9161 }
9162
9163 ALIAS (show_bgp_community_exact,
9164 show_bgp_ipv6_community_exact_cmd,
9165 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9166 SHOW_STR
9167 BGP_STR
9168 "Address family\n"
9169 "Display routes matching the communities\n"
9170 "community number\n"
9171 "Do not send outside local AS (well-known community)\n"
9172 "Do not advertise to any peer (well-known community)\n"
9173 "Do not export to next AS (well-known community)\n"
9174 "Exact match of the communities")
9175
9176 ALIAS (show_bgp_community_exact,
9177 show_bgp_community2_exact_cmd,
9178 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9179 SHOW_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 "Exact match of the communities")
9191
9192 ALIAS (show_bgp_community_exact,
9193 show_bgp_ipv6_community2_exact_cmd,
9194 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9195 SHOW_STR
9196 BGP_STR
9197 "Address family\n"
9198 "Display routes matching the communities\n"
9199 "community number\n"
9200 "Do not send outside local AS (well-known community)\n"
9201 "Do not advertise to any peer (well-known community)\n"
9202 "Do not export to next AS (well-known community)\n"
9203 "community number\n"
9204 "Do not send outside local AS (well-known community)\n"
9205 "Do not advertise to any peer (well-known community)\n"
9206 "Do not export to next AS (well-known community)\n"
9207 "Exact match of the communities")
9208
9209 ALIAS (show_bgp_community_exact,
9210 show_bgp_community3_exact_cmd,
9211 "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",
9212 SHOW_STR
9213 BGP_STR
9214 "Display routes matching the communities\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 "community number\n"
9220 "Do not send outside local AS (well-known community)\n"
9221 "Do not advertise to any peer (well-known community)\n"
9222 "Do not export to next AS (well-known community)\n"
9223 "community number\n"
9224 "Do not send outside local AS (well-known community)\n"
9225 "Do not advertise to any peer (well-known community)\n"
9226 "Do not export to next AS (well-known community)\n"
9227 "Exact match of the communities")
9228
9229 ALIAS (show_bgp_community_exact,
9230 show_bgp_ipv6_community3_exact_cmd,
9231 "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",
9232 SHOW_STR
9233 BGP_STR
9234 "Address family\n"
9235 "Display routes matching the communities\n"
9236 "community number\n"
9237 "Do not send outside local AS (well-known community)\n"
9238 "Do not advertise to any peer (well-known community)\n"
9239 "Do not export to next AS (well-known community)\n"
9240 "community number\n"
9241 "Do not send outside local AS (well-known community)\n"
9242 "Do not advertise to any peer (well-known community)\n"
9243 "Do not export to next AS (well-known community)\n"
9244 "community number\n"
9245 "Do not send outside local AS (well-known community)\n"
9246 "Do not advertise to any peer (well-known community)\n"
9247 "Do not export to next AS (well-known community)\n"
9248 "Exact match of the communities")
9249
9250 ALIAS (show_bgp_community_exact,
9251 show_bgp_community4_exact_cmd,
9252 "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",
9253 SHOW_STR
9254 BGP_STR
9255 "Display routes matching the communities\n"
9256 "community number\n"
9257 "Do not send outside local AS (well-known community)\n"
9258 "Do not advertise to any peer (well-known community)\n"
9259 "Do not export to next AS (well-known community)\n"
9260 "community number\n"
9261 "Do not send outside local AS (well-known community)\n"
9262 "Do not advertise to any peer (well-known community)\n"
9263 "Do not export to next AS (well-known community)\n"
9264 "community number\n"
9265 "Do not send outside local AS (well-known community)\n"
9266 "Do not advertise to any peer (well-known community)\n"
9267 "Do not export to next AS (well-known community)\n"
9268 "community number\n"
9269 "Do not send outside local AS (well-known community)\n"
9270 "Do not advertise to any peer (well-known community)\n"
9271 "Do not export to next AS (well-known community)\n"
9272 "Exact match of the communities")
9273
9274 ALIAS (show_bgp_community_exact,
9275 show_bgp_ipv6_community4_exact_cmd,
9276 "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",
9277 SHOW_STR
9278 BGP_STR
9279 "Address family\n"
9280 "Display routes matching the communities\n"
9281 "community number\n"
9282 "Do not send outside local AS (well-known community)\n"
9283 "Do not advertise to any peer (well-known community)\n"
9284 "Do not export to next AS (well-known community)\n"
9285 "community number\n"
9286 "Do not send outside local AS (well-known community)\n"
9287 "Do not advertise to any peer (well-known community)\n"
9288 "Do not export to next AS (well-known community)\n"
9289 "community number\n"
9290 "Do not send outside local AS (well-known community)\n"
9291 "Do not advertise to any peer (well-known community)\n"
9292 "Do not export to next AS (well-known community)\n"
9293 "community number\n"
9294 "Do not send outside local AS (well-known community)\n"
9295 "Do not advertise to any peer (well-known community)\n"
9296 "Do not export to next AS (well-known community)\n"
9297 "Exact match of the communities")
9298
9299 /* old command */
9300 DEFUN (show_ipv6_bgp_community_exact,
9301 show_ipv6_bgp_community_exact_cmd,
9302 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9303 SHOW_STR
9304 IPV6_STR
9305 BGP_STR
9306 "Display routes matching the communities\n"
9307 "community number\n"
9308 "Do not send outside local AS (well-known community)\n"
9309 "Do not advertise to any peer (well-known community)\n"
9310 "Do not export to next AS (well-known community)\n"
9311 "Exact match of the communities")
9312 {
9313 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9314 }
9315
9316 /* old command */
9317 ALIAS (show_ipv6_bgp_community_exact,
9318 show_ipv6_bgp_community2_exact_cmd,
9319 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9320 SHOW_STR
9321 IPV6_STR
9322 BGP_STR
9323 "Display routes matching the communities\n"
9324 "community number\n"
9325 "Do not send outside local AS (well-known community)\n"
9326 "Do not advertise to any peer (well-known community)\n"
9327 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9333
9334 /* old command */
9335 ALIAS (show_ipv6_bgp_community_exact,
9336 show_ipv6_bgp_community3_exact_cmd,
9337 "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",
9338 SHOW_STR
9339 IPV6_STR
9340 BGP_STR
9341 "Display routes matching the communities\n"
9342 "community number\n"
9343 "Do not send outside local AS (well-known community)\n"
9344 "Do not advertise to any peer (well-known community)\n"
9345 "Do not export to next AS (well-known community)\n"
9346 "community number\n"
9347 "Do not send outside local AS (well-known community)\n"
9348 "Do not advertise to any peer (well-known community)\n"
9349 "Do not export to next AS (well-known community)\n"
9350 "community number\n"
9351 "Do not send outside local AS (well-known community)\n"
9352 "Do not advertise to any peer (well-known community)\n"
9353 "Do not export to next AS (well-known community)\n"
9354 "Exact match of the communities")
9355
9356 /* old command */
9357 ALIAS (show_ipv6_bgp_community_exact,
9358 show_ipv6_bgp_community4_exact_cmd,
9359 "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",
9360 SHOW_STR
9361 IPV6_STR
9362 BGP_STR
9363 "Display routes matching the communities\n"
9364 "community number\n"
9365 "Do not send outside local AS (well-known community)\n"
9366 "Do not advertise to any peer (well-known community)\n"
9367 "Do not export to next AS (well-known community)\n"
9368 "community number\n"
9369 "Do not send outside local AS (well-known community)\n"
9370 "Do not advertise to any peer (well-known community)\n"
9371 "Do not export to next AS (well-known community)\n"
9372 "community number\n"
9373 "Do not send outside local AS (well-known community)\n"
9374 "Do not advertise to any peer (well-known community)\n"
9375 "Do not export to next AS (well-known community)\n"
9376 "community number\n"
9377 "Do not send outside local AS (well-known community)\n"
9378 "Do not advertise to any peer (well-known community)\n"
9379 "Do not export to next AS (well-known community)\n"
9380 "Exact match of the communities")
9381
9382 /* old command */
9383 DEFUN (show_ipv6_mbgp_community,
9384 show_ipv6_mbgp_community_cmd,
9385 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
9386 SHOW_STR
9387 IPV6_STR
9388 MBGP_STR
9389 "Display routes matching the communities\n"
9390 "community number\n"
9391 "Do not send outside local AS (well-known community)\n"
9392 "Do not advertise to any peer (well-known community)\n"
9393 "Do not export to next AS (well-known community)\n")
9394 {
9395 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
9396 }
9397
9398 /* old command */
9399 ALIAS (show_ipv6_mbgp_community,
9400 show_ipv6_mbgp_community2_cmd,
9401 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9402 SHOW_STR
9403 IPV6_STR
9404 MBGP_STR
9405 "Display routes matching the communities\n"
9406 "community number\n"
9407 "Do not send outside local AS (well-known community)\n"
9408 "Do not advertise to any peer (well-known community)\n"
9409 "Do not export to next AS (well-known community)\n"
9410 "community number\n"
9411 "Do not send outside local AS (well-known community)\n"
9412 "Do not advertise to any peer (well-known community)\n"
9413 "Do not export to next AS (well-known community)\n")
9414
9415 /* old command */
9416 ALIAS (show_ipv6_mbgp_community,
9417 show_ipv6_mbgp_community3_cmd,
9418 "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)",
9419 SHOW_STR
9420 IPV6_STR
9421 MBGP_STR
9422 "Display routes matching the communities\n"
9423 "community number\n"
9424 "Do not send outside local AS (well-known community)\n"
9425 "Do not advertise to any peer (well-known community)\n"
9426 "Do not export to next AS (well-known community)\n"
9427 "community number\n"
9428 "Do not send outside local AS (well-known community)\n"
9429 "Do not advertise to any peer (well-known community)\n"
9430 "Do not export to next AS (well-known community)\n"
9431 "community number\n"
9432 "Do not send outside local AS (well-known community)\n"
9433 "Do not advertise to any peer (well-known community)\n"
9434 "Do not export to next AS (well-known community)\n")
9435
9436 /* old command */
9437 ALIAS (show_ipv6_mbgp_community,
9438 show_ipv6_mbgp_community4_cmd,
9439 "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)",
9440 SHOW_STR
9441 IPV6_STR
9442 MBGP_STR
9443 "Display routes matching the communities\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 "community number\n"
9453 "Do not send outside local AS (well-known community)\n"
9454 "Do not advertise to any peer (well-known community)\n"
9455 "Do not export to next AS (well-known community)\n"
9456 "community number\n"
9457 "Do not send outside local AS (well-known community)\n"
9458 "Do not advertise to any peer (well-known community)\n"
9459 "Do not export to next AS (well-known community)\n")
9460
9461 /* old command */
9462 DEFUN (show_ipv6_mbgp_community_exact,
9463 show_ipv6_mbgp_community_exact_cmd,
9464 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9465 SHOW_STR
9466 IPV6_STR
9467 MBGP_STR
9468 "Display routes matching the communities\n"
9469 "community number\n"
9470 "Do not send outside local AS (well-known community)\n"
9471 "Do not advertise to any peer (well-known community)\n"
9472 "Do not export to next AS (well-known community)\n"
9473 "Exact match of the communities")
9474 {
9475 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
9476 }
9477
9478 /* old command */
9479 ALIAS (show_ipv6_mbgp_community_exact,
9480 show_ipv6_mbgp_community2_exact_cmd,
9481 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9482 SHOW_STR
9483 IPV6_STR
9484 MBGP_STR
9485 "Display routes matching the communities\n"
9486 "community number\n"
9487 "Do not send outside local AS (well-known community)\n"
9488 "Do not advertise to any peer (well-known community)\n"
9489 "Do not export to next AS (well-known community)\n"
9490 "community number\n"
9491 "Do not send outside local AS (well-known community)\n"
9492 "Do not advertise to any peer (well-known community)\n"
9493 "Do not export to next AS (well-known community)\n"
9494 "Exact match of the communities")
9495
9496 /* old command */
9497 ALIAS (show_ipv6_mbgp_community_exact,
9498 show_ipv6_mbgp_community3_exact_cmd,
9499 "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",
9500 SHOW_STR
9501 IPV6_STR
9502 MBGP_STR
9503 "Display routes matching the communities\n"
9504 "community number\n"
9505 "Do not send outside local AS (well-known community)\n"
9506 "Do not advertise to any peer (well-known community)\n"
9507 "Do not export to next AS (well-known community)\n"
9508 "community number\n"
9509 "Do not send outside local AS (well-known community)\n"
9510 "Do not advertise to any peer (well-known community)\n"
9511 "Do not export to next AS (well-known community)\n"
9512 "community number\n"
9513 "Do not send outside local AS (well-known community)\n"
9514 "Do not advertise to any peer (well-known community)\n"
9515 "Do not export to next AS (well-known community)\n"
9516 "Exact match of the communities")
9517
9518 /* old command */
9519 ALIAS (show_ipv6_mbgp_community_exact,
9520 show_ipv6_mbgp_community4_exact_cmd,
9521 "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",
9522 SHOW_STR
9523 IPV6_STR
9524 MBGP_STR
9525 "Display routes matching the communities\n"
9526 "community number\n"
9527 "Do not send outside local AS (well-known community)\n"
9528 "Do not advertise to any peer (well-known community)\n"
9529 "Do not export to next AS (well-known community)\n"
9530 "community number\n"
9531 "Do not send outside local AS (well-known community)\n"
9532 "Do not advertise to any peer (well-known community)\n"
9533 "Do not export to next AS (well-known community)\n"
9534 "community number\n"
9535 "Do not send outside local AS (well-known community)\n"
9536 "Do not advertise to any peer (well-known community)\n"
9537 "Do not export to next AS (well-known community)\n"
9538 "community number\n"
9539 "Do not send outside local AS (well-known community)\n"
9540 "Do not advertise to any peer (well-known community)\n"
9541 "Do not export to next AS (well-known community)\n"
9542 "Exact match of the communities")
9543 #endif /* HAVE_IPV6 */
9544
9545 static int
9546 bgp_show_community_list (struct vty *vty, const char *com, int exact,
9547 afi_t afi, safi_t safi)
9548 {
9549 struct community_list *list;
9550
9551 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
9552 if (list == NULL)
9553 {
9554 vty_out (vty, "%% %s is not a valid community-list name%s", com,
9555 VTY_NEWLINE);
9556 return CMD_WARNING;
9557 }
9558
9559 return bgp_show (vty, NULL, afi, safi,
9560 (exact ? bgp_show_type_community_list_exact :
9561 bgp_show_type_community_list), list, NULL);
9562 }
9563
9564 DEFUN (show_ip_bgp_community_list,
9565 show_ip_bgp_community_list_cmd,
9566 "show ip bgp community-list (<1-500>|WORD)",
9567 SHOW_STR
9568 IP_STR
9569 BGP_STR
9570 "Display routes matching the community-list\n"
9571 "community-list number\n"
9572 "community-list name\n")
9573 {
9574 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
9575 }
9576
9577 DEFUN (show_ip_bgp_ipv4_community_list,
9578 show_ip_bgp_ipv4_community_list_cmd,
9579 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
9580 SHOW_STR
9581 IP_STR
9582 BGP_STR
9583 "Address family\n"
9584 "Address Family modifier\n"
9585 "Address Family modifier\n"
9586 "Display routes matching the community-list\n"
9587 "community-list number\n"
9588 "community-list name\n")
9589 {
9590 if (strncmp (argv[0], "m", 1) == 0)
9591 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
9592
9593 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
9594 }
9595
9596 DEFUN (show_ip_bgp_community_list_exact,
9597 show_ip_bgp_community_list_exact_cmd,
9598 "show ip bgp community-list (<1-500>|WORD) exact-match",
9599 SHOW_STR
9600 IP_STR
9601 BGP_STR
9602 "Display routes matching the community-list\n"
9603 "community-list number\n"
9604 "community-list name\n"
9605 "Exact match of the communities\n")
9606 {
9607 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9608 }
9609
9610 DEFUN (show_ip_bgp_ipv4_community_list_exact,
9611 show_ip_bgp_ipv4_community_list_exact_cmd,
9612 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
9613 SHOW_STR
9614 IP_STR
9615 BGP_STR
9616 "Address family\n"
9617 "Address Family modifier\n"
9618 "Address Family modifier\n"
9619 "Display routes matching the community-list\n"
9620 "community-list number\n"
9621 "community-list name\n"
9622 "Exact match of the communities\n")
9623 {
9624 if (strncmp (argv[0], "m", 1) == 0)
9625 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9626
9627 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9628 }
9629
9630 #ifdef HAVE_IPV6
9631 DEFUN (show_bgp_community_list,
9632 show_bgp_community_list_cmd,
9633 "show bgp community-list (<1-500>|WORD)",
9634 SHOW_STR
9635 BGP_STR
9636 "Display routes matching the community-list\n"
9637 "community-list number\n"
9638 "community-list name\n")
9639 {
9640 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9641 }
9642
9643 ALIAS (show_bgp_community_list,
9644 show_bgp_ipv6_community_list_cmd,
9645 "show bgp ipv6 community-list (<1-500>|WORD)",
9646 SHOW_STR
9647 BGP_STR
9648 "Address family\n"
9649 "Display routes matching the community-list\n"
9650 "community-list number\n"
9651 "community-list name\n")
9652
9653 /* old command */
9654 DEFUN (show_ipv6_bgp_community_list,
9655 show_ipv6_bgp_community_list_cmd,
9656 "show ipv6 bgp community-list WORD",
9657 SHOW_STR
9658 IPV6_STR
9659 BGP_STR
9660 "Display routes matching the community-list\n"
9661 "community-list name\n")
9662 {
9663 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9664 }
9665
9666 /* old command */
9667 DEFUN (show_ipv6_mbgp_community_list,
9668 show_ipv6_mbgp_community_list_cmd,
9669 "show ipv6 mbgp community-list WORD",
9670 SHOW_STR
9671 IPV6_STR
9672 MBGP_STR
9673 "Display routes matching the community-list\n"
9674 "community-list name\n")
9675 {
9676 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9677 }
9678
9679 DEFUN (show_bgp_community_list_exact,
9680 show_bgp_community_list_exact_cmd,
9681 "show bgp community-list (<1-500>|WORD) exact-match",
9682 SHOW_STR
9683 BGP_STR
9684 "Display routes matching the community-list\n"
9685 "community-list number\n"
9686 "community-list name\n"
9687 "Exact match of the communities\n")
9688 {
9689 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9690 }
9691
9692 ALIAS (show_bgp_community_list_exact,
9693 show_bgp_ipv6_community_list_exact_cmd,
9694 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
9695 SHOW_STR
9696 BGP_STR
9697 "Address family\n"
9698 "Display routes matching the community-list\n"
9699 "community-list number\n"
9700 "community-list name\n"
9701 "Exact match of the communities\n")
9702
9703 /* old command */
9704 DEFUN (show_ipv6_bgp_community_list_exact,
9705 show_ipv6_bgp_community_list_exact_cmd,
9706 "show ipv6 bgp community-list WORD exact-match",
9707 SHOW_STR
9708 IPV6_STR
9709 BGP_STR
9710 "Display routes matching the community-list\n"
9711 "community-list name\n"
9712 "Exact match of the communities\n")
9713 {
9714 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9715 }
9716
9717 /* old command */
9718 DEFUN (show_ipv6_mbgp_community_list_exact,
9719 show_ipv6_mbgp_community_list_exact_cmd,
9720 "show ipv6 mbgp community-list WORD exact-match",
9721 SHOW_STR
9722 IPV6_STR
9723 MBGP_STR
9724 "Display routes matching the community-list\n"
9725 "community-list name\n"
9726 "Exact match of the communities\n")
9727 {
9728 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9729 }
9730 #endif /* HAVE_IPV6 */
9731
9732 static int
9733 bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
9734 safi_t safi, enum bgp_show_type type)
9735 {
9736 int ret;
9737 struct prefix *p;
9738
9739 p = prefix_new();
9740
9741 ret = str2prefix (prefix, p);
9742 if (! ret)
9743 {
9744 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9745 return CMD_WARNING;
9746 }
9747
9748 ret = bgp_show (vty, NULL, afi, safi, type, p, NULL);
9749 prefix_free(p);
9750 return ret;
9751 }
9752
9753 DEFUN (show_ip_bgp_prefix_longer,
9754 show_ip_bgp_prefix_longer_cmd,
9755 "show ip bgp A.B.C.D/M longer-prefixes",
9756 SHOW_STR
9757 IP_STR
9758 BGP_STR
9759 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9760 "Display route and more specific routes\n")
9761 {
9762 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9763 bgp_show_type_prefix_longer);
9764 }
9765
9766 DEFUN (show_ip_bgp_flap_prefix_longer,
9767 show_ip_bgp_flap_prefix_longer_cmd,
9768 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9769 SHOW_STR
9770 IP_STR
9771 BGP_STR
9772 "Display flap statistics of routes\n"
9773 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9774 "Display route and more specific routes\n")
9775 {
9776 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9777 bgp_show_type_flap_prefix_longer);
9778 }
9779
9780 DEFUN (show_ip_bgp_ipv4_prefix_longer,
9781 show_ip_bgp_ipv4_prefix_longer_cmd,
9782 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9783 SHOW_STR
9784 IP_STR
9785 BGP_STR
9786 "Address family\n"
9787 "Address Family modifier\n"
9788 "Address Family modifier\n"
9789 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9790 "Display route and more specific routes\n")
9791 {
9792 if (strncmp (argv[0], "m", 1) == 0)
9793 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9794 bgp_show_type_prefix_longer);
9795
9796 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9797 bgp_show_type_prefix_longer);
9798 }
9799
9800 DEFUN (show_ip_bgp_flap_address,
9801 show_ip_bgp_flap_address_cmd,
9802 "show ip bgp flap-statistics A.B.C.D",
9803 SHOW_STR
9804 IP_STR
9805 BGP_STR
9806 "Display flap statistics of routes\n"
9807 "Network in the BGP routing table to display\n")
9808 {
9809 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9810 bgp_show_type_flap_address);
9811 }
9812
9813 DEFUN (show_ip_bgp_flap_prefix,
9814 show_ip_bgp_flap_prefix_cmd,
9815 "show ip bgp flap-statistics A.B.C.D/M",
9816 SHOW_STR
9817 IP_STR
9818 BGP_STR
9819 "Display flap statistics of routes\n"
9820 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9821 {
9822 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9823 bgp_show_type_flap_prefix);
9824 }
9825 #ifdef HAVE_IPV6
9826 DEFUN (show_bgp_prefix_longer,
9827 show_bgp_prefix_longer_cmd,
9828 "show bgp X:X::X:X/M longer-prefixes",
9829 SHOW_STR
9830 BGP_STR
9831 "IPv6 prefix <network>/<length>\n"
9832 "Display route and more specific routes\n")
9833 {
9834 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9835 bgp_show_type_prefix_longer);
9836 }
9837
9838 ALIAS (show_bgp_prefix_longer,
9839 show_bgp_ipv6_prefix_longer_cmd,
9840 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9841 SHOW_STR
9842 BGP_STR
9843 "Address family\n"
9844 "IPv6 prefix <network>/<length>\n"
9845 "Display route and more specific routes\n")
9846
9847 /* old command */
9848 DEFUN (show_ipv6_bgp_prefix_longer,
9849 show_ipv6_bgp_prefix_longer_cmd,
9850 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9851 SHOW_STR
9852 IPV6_STR
9853 BGP_STR
9854 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9855 "Display route and more specific routes\n")
9856 {
9857 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9858 bgp_show_type_prefix_longer);
9859 }
9860
9861 /* old command */
9862 DEFUN (show_ipv6_mbgp_prefix_longer,
9863 show_ipv6_mbgp_prefix_longer_cmd,
9864 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9865 SHOW_STR
9866 IPV6_STR
9867 MBGP_STR
9868 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9869 "Display route and more specific routes\n")
9870 {
9871 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9872 bgp_show_type_prefix_longer);
9873 }
9874 #endif /* HAVE_IPV6 */
9875
9876 static struct peer *
9877 peer_lookup_in_view (struct vty *vty, const char *view_name,
9878 const char *ip_str)
9879 {
9880 int ret;
9881 struct bgp *bgp;
9882 struct peer *peer;
9883 union sockunion su;
9884
9885 /* BGP structure lookup. */
9886 if (view_name)
9887 {
9888 bgp = bgp_lookup_by_name (view_name);
9889 if (! bgp)
9890 {
9891 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9892 return NULL;
9893 }
9894 }
9895 else
9896 {
9897 bgp = bgp_get_default ();
9898 if (! bgp)
9899 {
9900 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9901 return NULL;
9902 }
9903 }
9904
9905 /* Get peer sockunion. */
9906 ret = str2sockunion (ip_str, &su);
9907 if (ret < 0)
9908 {
9909 peer = peer_lookup_by_conf_if (bgp, ip_str);
9910 if (!peer)
9911 {
9912 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
9913 return NULL;
9914 }
9915 return peer;
9916 }
9917
9918 /* Peer structure lookup. */
9919 peer = peer_lookup (bgp, &su);
9920 if (! peer)
9921 {
9922 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9923 return NULL;
9924 }
9925
9926 return peer;
9927 }
9928
9929 enum bgp_stats
9930 {
9931 BGP_STATS_MAXBITLEN = 0,
9932 BGP_STATS_RIB,
9933 BGP_STATS_PREFIXES,
9934 BGP_STATS_TOTPLEN,
9935 BGP_STATS_UNAGGREGATEABLE,
9936 BGP_STATS_MAX_AGGREGATEABLE,
9937 BGP_STATS_AGGREGATES,
9938 BGP_STATS_SPACE,
9939 BGP_STATS_ASPATH_COUNT,
9940 BGP_STATS_ASPATH_MAXHOPS,
9941 BGP_STATS_ASPATH_TOTHOPS,
9942 BGP_STATS_ASPATH_MAXSIZE,
9943 BGP_STATS_ASPATH_TOTSIZE,
9944 BGP_STATS_ASN_HIGHEST,
9945 BGP_STATS_MAX,
9946 };
9947
9948 static const char *table_stats_strs[] =
9949 {
9950 [BGP_STATS_PREFIXES] = "Total Prefixes",
9951 [BGP_STATS_TOTPLEN] = "Average prefix length",
9952 [BGP_STATS_RIB] = "Total Advertisements",
9953 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9954 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9955 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9956 [BGP_STATS_SPACE] = "Address space advertised",
9957 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9958 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9959 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9960 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9961 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9962 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9963 [BGP_STATS_MAX] = NULL,
9964 };
9965
9966 struct bgp_table_stats
9967 {
9968 struct bgp_table *table;
9969 unsigned long long counts[BGP_STATS_MAX];
9970 };
9971
9972 #if 0
9973 #define TALLY_SIGFIG 100000
9974 static unsigned long
9975 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9976 {
9977 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9978 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9979 unsigned long ret = newtot / count;
9980
9981 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9982 return ret + 1;
9983 else
9984 return ret;
9985 }
9986 #endif
9987
9988 static int
9989 bgp_table_stats_walker (struct thread *t)
9990 {
9991 struct bgp_node *rn;
9992 struct bgp_node *top;
9993 struct bgp_table_stats *ts = THREAD_ARG (t);
9994 unsigned int space = 0;
9995
9996 if (!(top = bgp_table_top (ts->table)))
9997 return 0;
9998
9999 switch (top->p.family)
10000 {
10001 case AF_INET:
10002 space = IPV4_MAX_BITLEN;
10003 break;
10004 case AF_INET6:
10005 space = IPV6_MAX_BITLEN;
10006 break;
10007 }
10008
10009 ts->counts[BGP_STATS_MAXBITLEN] = space;
10010
10011 for (rn = top; rn; rn = bgp_route_next (rn))
10012 {
10013 struct bgp_info *ri;
10014 struct bgp_node *prn = bgp_node_parent_nolock (rn);
10015 unsigned int rinum = 0;
10016
10017 if (rn == top)
10018 continue;
10019
10020 if (!rn->info)
10021 continue;
10022
10023 ts->counts[BGP_STATS_PREFIXES]++;
10024 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
10025
10026 #if 0
10027 ts->counts[BGP_STATS_AVGPLEN]
10028 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
10029 ts->counts[BGP_STATS_AVGPLEN],
10030 rn->p.prefixlen);
10031 #endif
10032
10033 /* check if the prefix is included by any other announcements */
10034 while (prn && !prn->info)
10035 prn = bgp_node_parent_nolock (prn);
10036
10037 if (prn == NULL || prn == top)
10038 {
10039 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
10040 /* announced address space */
10041 if (space)
10042 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
10043 }
10044 else if (prn->info)
10045 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
10046
10047 for (ri = rn->info; ri; ri = ri->next)
10048 {
10049 rinum++;
10050 ts->counts[BGP_STATS_RIB]++;
10051
10052 if (ri->attr &&
10053 (CHECK_FLAG (ri->attr->flag,
10054 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
10055 ts->counts[BGP_STATS_AGGREGATES]++;
10056
10057 /* as-path stats */
10058 if (ri->attr && ri->attr->aspath)
10059 {
10060 unsigned int hops = aspath_count_hops (ri->attr->aspath);
10061 unsigned int size = aspath_size (ri->attr->aspath);
10062 as_t highest = aspath_highest (ri->attr->aspath);
10063
10064 ts->counts[BGP_STATS_ASPATH_COUNT]++;
10065
10066 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
10067 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
10068
10069 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
10070 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
10071
10072 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
10073 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
10074 #if 0
10075 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
10076 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
10077 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
10078 hops);
10079 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
10080 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
10081 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
10082 size);
10083 #endif
10084 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
10085 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
10086 }
10087 }
10088 }
10089 return 0;
10090 }
10091
10092 static int
10093 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
10094 {
10095 struct bgp_table_stats ts;
10096 unsigned int i;
10097
10098 if (!bgp->rib[afi][safi])
10099 {
10100 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
10101 return CMD_WARNING;
10102 }
10103
10104 memset (&ts, 0, sizeof (ts));
10105 ts.table = bgp->rib[afi][safi];
10106 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
10107
10108 vty_out (vty, "BGP %s RIB statistics%s%s",
10109 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
10110
10111 for (i = 0; i < BGP_STATS_MAX; i++)
10112 {
10113 if (!table_stats_strs[i])
10114 continue;
10115
10116 switch (i)
10117 {
10118 #if 0
10119 case BGP_STATS_ASPATH_AVGHOPS:
10120 case BGP_STATS_ASPATH_AVGSIZE:
10121 case BGP_STATS_AVGPLEN:
10122 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10123 vty_out (vty, "%12.2f",
10124 (float)ts.counts[i] / (float)TALLY_SIGFIG);
10125 break;
10126 #endif
10127 case BGP_STATS_ASPATH_TOTHOPS:
10128 case BGP_STATS_ASPATH_TOTSIZE:
10129 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10130 vty_out (vty, "%12.2f",
10131 ts.counts[i] ?
10132 (float)ts.counts[i] /
10133 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
10134 : 0);
10135 break;
10136 case BGP_STATS_TOTPLEN:
10137 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10138 vty_out (vty, "%12.2f",
10139 ts.counts[i] ?
10140 (float)ts.counts[i] /
10141 (float)ts.counts[BGP_STATS_PREFIXES]
10142 : 0);
10143 break;
10144 case BGP_STATS_SPACE:
10145 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10146 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
10147 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
10148 break;
10149 vty_out (vty, "%30s: ", "%% announced ");
10150 vty_out (vty, "%12.2f%s",
10151 100 * (float)ts.counts[BGP_STATS_SPACE] /
10152 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
10153 VTY_NEWLINE);
10154 vty_out (vty, "%30s: ", "/8 equivalent ");
10155 vty_out (vty, "%12.2f%s",
10156 (float)ts.counts[BGP_STATS_SPACE] /
10157 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
10158 VTY_NEWLINE);
10159 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
10160 break;
10161 vty_out (vty, "%30s: ", "/24 equivalent ");
10162 vty_out (vty, "%12.2f",
10163 (float)ts.counts[BGP_STATS_SPACE] /
10164 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
10165 break;
10166 default:
10167 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10168 vty_out (vty, "%12llu", ts.counts[i]);
10169 }
10170
10171 vty_out (vty, "%s", VTY_NEWLINE);
10172 }
10173 return CMD_SUCCESS;
10174 }
10175
10176 static int
10177 bgp_table_stats_vty (struct vty *vty, const char *name,
10178 const char *afi_str, const char *safi_str)
10179 {
10180 struct bgp *bgp;
10181 afi_t afi;
10182 safi_t safi;
10183
10184 if (name)
10185 bgp = bgp_lookup_by_name (name);
10186 else
10187 bgp = bgp_get_default ();
10188
10189 if (!bgp)
10190 {
10191 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
10192 return CMD_WARNING;
10193 }
10194 if (strncmp (afi_str, "ipv", 3) == 0)
10195 {
10196 if (strncmp (afi_str, "ipv4", 4) == 0)
10197 afi = AFI_IP;
10198 else if (strncmp (afi_str, "ipv6", 4) == 0)
10199 afi = AFI_IP6;
10200 else
10201 {
10202 vty_out (vty, "%% Invalid address family %s%s",
10203 afi_str, VTY_NEWLINE);
10204 return CMD_WARNING;
10205 }
10206 if (strncmp (safi_str, "m", 1) == 0)
10207 safi = SAFI_MULTICAST;
10208 else if (strncmp (safi_str, "u", 1) == 0)
10209 safi = SAFI_UNICAST;
10210 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
10211 safi = SAFI_MPLS_LABELED_VPN;
10212 else
10213 {
10214 vty_out (vty, "%% Invalid subsequent address family %s%s",
10215 safi_str, VTY_NEWLINE);
10216 return CMD_WARNING;
10217 }
10218 }
10219 else
10220 {
10221 vty_out (vty, "%% Invalid address family %s%s",
10222 afi_str, VTY_NEWLINE);
10223 return CMD_WARNING;
10224 }
10225
10226 return bgp_table_stats (vty, bgp, afi, safi);
10227 }
10228
10229 DEFUN (show_bgp_statistics,
10230 show_bgp_statistics_cmd,
10231 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
10232 SHOW_STR
10233 BGP_STR
10234 "Address family\n"
10235 "Address family\n"
10236 "Address Family modifier\n"
10237 "Address Family modifier\n"
10238 "BGP RIB advertisement statistics\n")
10239 {
10240 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
10241 }
10242
10243 ALIAS (show_bgp_statistics,
10244 show_bgp_statistics_vpnv4_cmd,
10245 "show bgp (ipv4) (vpnv4) statistics",
10246 SHOW_STR
10247 BGP_STR
10248 "Address family\n"
10249 "Address Family modifier\n"
10250 "BGP RIB advertisement statistics\n")
10251
10252 DEFUN (show_bgp_statistics_view,
10253 show_bgp_statistics_view_cmd,
10254 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
10255 SHOW_STR
10256 BGP_STR
10257 "BGP view\n"
10258 "Address family\n"
10259 "Address family\n"
10260 "Address Family modifier\n"
10261 "Address Family modifier\n"
10262 "BGP RIB advertisement statistics\n")
10263 {
10264 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
10265 }
10266
10267 ALIAS (show_bgp_statistics_view,
10268 show_bgp_statistics_view_vpnv4_cmd,
10269 "show bgp view WORD (ipv4) (vpnv4) statistics",
10270 SHOW_STR
10271 BGP_STR
10272 "BGP view\n"
10273 "Address family\n"
10274 "Address Family modifier\n"
10275 "BGP RIB advertisement statistics\n")
10276
10277 enum bgp_pcounts
10278 {
10279 PCOUNT_ADJ_IN = 0,
10280 PCOUNT_DAMPED,
10281 PCOUNT_REMOVED,
10282 PCOUNT_HISTORY,
10283 PCOUNT_STALE,
10284 PCOUNT_VALID,
10285 PCOUNT_ALL,
10286 PCOUNT_COUNTED,
10287 PCOUNT_PFCNT, /* the figure we display to users */
10288 PCOUNT_MAX,
10289 };
10290
10291 static const char *pcount_strs[] =
10292 {
10293 [PCOUNT_ADJ_IN] = "Adj-in",
10294 [PCOUNT_DAMPED] = "Damped",
10295 [PCOUNT_REMOVED] = "Removed",
10296 [PCOUNT_HISTORY] = "History",
10297 [PCOUNT_STALE] = "Stale",
10298 [PCOUNT_VALID] = "Valid",
10299 [PCOUNT_ALL] = "All RIB",
10300 [PCOUNT_COUNTED] = "PfxCt counted",
10301 [PCOUNT_PFCNT] = "Useable",
10302 [PCOUNT_MAX] = NULL,
10303 };
10304
10305 struct peer_pcounts
10306 {
10307 unsigned int count[PCOUNT_MAX];
10308 const struct peer *peer;
10309 const struct bgp_table *table;
10310 };
10311
10312 static int
10313 bgp_peer_count_walker (struct thread *t)
10314 {
10315 struct bgp_node *rn;
10316 struct peer_pcounts *pc = THREAD_ARG (t);
10317 const struct peer *peer = pc->peer;
10318
10319 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
10320 {
10321 struct bgp_adj_in *ain;
10322 struct bgp_info *ri;
10323
10324 for (ain = rn->adj_in; ain; ain = ain->next)
10325 if (ain->peer == peer)
10326 pc->count[PCOUNT_ADJ_IN]++;
10327
10328 for (ri = rn->info; ri; ri = ri->next)
10329 {
10330 char buf[SU_ADDRSTRLEN];
10331
10332 if (ri->peer != peer)
10333 continue;
10334
10335 pc->count[PCOUNT_ALL]++;
10336
10337 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
10338 pc->count[PCOUNT_DAMPED]++;
10339 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
10340 pc->count[PCOUNT_HISTORY]++;
10341 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
10342 pc->count[PCOUNT_REMOVED]++;
10343 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
10344 pc->count[PCOUNT_STALE]++;
10345 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
10346 pc->count[PCOUNT_VALID]++;
10347 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
10348 pc->count[PCOUNT_PFCNT]++;
10349
10350 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
10351 {
10352 pc->count[PCOUNT_COUNTED]++;
10353 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
10354 plog_warn (peer->log,
10355 "%s [pcount] %s/%d is counted but flags 0x%x",
10356 peer->host,
10357 inet_ntop(rn->p.family, &rn->p.u.prefix,
10358 buf, SU_ADDRSTRLEN),
10359 rn->p.prefixlen,
10360 ri->flags);
10361 }
10362 else
10363 {
10364 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
10365 plog_warn (peer->log,
10366 "%s [pcount] %s/%d not counted but flags 0x%x",
10367 peer->host,
10368 inet_ntop(rn->p.family, &rn->p.u.prefix,
10369 buf, SU_ADDRSTRLEN),
10370 rn->p.prefixlen,
10371 ri->flags);
10372 }
10373 }
10374 }
10375 return 0;
10376 }
10377
10378 static int
10379 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
10380 {
10381 struct peer_pcounts pcounts = { .peer = peer };
10382 unsigned int i;
10383
10384 if (!peer || !peer->bgp || !peer->afc[afi][safi]
10385 || !peer->bgp->rib[afi][safi])
10386 {
10387 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10388 return CMD_WARNING;
10389 }
10390
10391 memset (&pcounts, 0, sizeof(pcounts));
10392 pcounts.peer = peer;
10393 pcounts.table = peer->bgp->rib[afi][safi];
10394
10395 /* in-place call via thread subsystem so as to record execution time
10396 * stats for the thread-walk (i.e. ensure this can't be blamed on
10397 * on just vty_read()).
10398 */
10399 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
10400
10401 vty_out (vty, "Prefix counts for %s, %s%s",
10402 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
10403 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
10404 vty_out (vty, "%sCounts from RIB table walk:%s%s",
10405 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
10406
10407 for (i = 0; i < PCOUNT_MAX; i++)
10408 vty_out (vty, "%20s: %-10d%s",
10409 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
10410
10411 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
10412 {
10413 vty_out (vty, "%s [pcount] PfxCt drift!%s",
10414 peer->host, VTY_NEWLINE);
10415 vty_out (vty, "Please report this bug, with the above command output%s",
10416 VTY_NEWLINE);
10417 }
10418
10419 return CMD_SUCCESS;
10420 }
10421
10422 DEFUN (show_ip_bgp_neighbor_prefix_counts,
10423 show_ip_bgp_neighbor_prefix_counts_cmd,
10424 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
10425 SHOW_STR
10426 IP_STR
10427 BGP_STR
10428 "Detailed information on TCP and BGP neighbor connections\n"
10429 "Neighbor to display information about\n"
10430 "Neighbor to display information about\n"
10431 "Neighbor on bgp configured interface\n"
10432 "Display detailed prefix count information\n")
10433 {
10434 struct peer *peer;
10435
10436 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10437 if (! peer)
10438 return CMD_WARNING;
10439
10440 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10441 }
10442
10443 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
10444 show_bgp_ipv6_neighbor_prefix_counts_cmd,
10445 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
10446 SHOW_STR
10447 BGP_STR
10448 "Address family\n"
10449 "Detailed information on TCP and BGP neighbor connections\n"
10450 "Neighbor to display information about\n"
10451 "Neighbor to display information about\n"
10452 "Neighbor on bgp configured interface\n"
10453 "Display detailed prefix count information\n")
10454 {
10455 struct peer *peer;
10456
10457 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10458 if (! peer)
10459 return CMD_WARNING;
10460
10461 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
10462 }
10463
10464 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
10465 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
10466 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
10467 SHOW_STR
10468 IP_STR
10469 BGP_STR
10470 "Address family\n"
10471 "Address Family modifier\n"
10472 "Address Family modifier\n"
10473 "Detailed information on TCP and BGP neighbor connections\n"
10474 "Neighbor to display information about\n"
10475 "Neighbor to display information about\n"
10476 "Neighbor on bgp configured interface\n"
10477 "Display detailed prefix count information\n")
10478 {
10479 struct peer *peer;
10480
10481 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10482 if (! peer)
10483 return CMD_WARNING;
10484
10485 if (strncmp (argv[0], "m", 1) == 0)
10486 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
10487
10488 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10489 }
10490
10491 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
10492 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
10493 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts",
10494 SHOW_STR
10495 IP_STR
10496 BGP_STR
10497 "Address family\n"
10498 "Address Family modifier\n"
10499 "Address Family modifier\n"
10500 "Detailed information on TCP and BGP neighbor connections\n"
10501 "Neighbor to display information about\n"
10502 "Neighbor to display information about\n"
10503 "Neighbor on bgp configured interface\n"
10504 "Display detailed prefix count information\n")
10505 {
10506 struct peer *peer;
10507
10508 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10509 if (! peer)
10510 return CMD_WARNING;
10511
10512 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
10513 }
10514
10515 static void
10516 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10517 int in, char *delim, char *rmap_name)
10518 {
10519 struct bgp_table *table;
10520 struct bgp_adj_in *ain;
10521 struct bgp_adj_out *adj;
10522 unsigned long output_count;
10523 unsigned long filtered_count;
10524 struct bgp_node *rn;
10525 int header1 = 1;
10526 struct bgp *bgp;
10527 int header2 = 1;
10528 struct attr attr;
10529 struct attr_extra extra;
10530 int ret;
10531
10532 bgp = peer->bgp;
10533
10534 if (! bgp)
10535 return;
10536
10537 if (delim)
10538 header1 = 0;
10539
10540 table = bgp->rib[afi][safi];
10541
10542 output_count = filtered_count = 0;
10543
10544 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
10545 PEER_STATUS_DEFAULT_ORIGINATE))
10546 {
10547 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
10548 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10549 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10550
10551 vty_out (vty, "Originating default network 0.0.0.0%s%s",
10552 VTY_NEWLINE, VTY_NEWLINE);
10553 header1 = 0;
10554 }
10555
10556 attr.extra = &extra;
10557 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10558 if (in)
10559 {
10560 for (ain = rn->adj_in; ain; ain = ain->next)
10561 if (ain->peer == peer)
10562 {
10563 if (header1)
10564 {
10565 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
10566 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10567 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10568 header1 = 0;
10569 }
10570 if (header2)
10571 {
10572 if (delim)
10573 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
10574 else
10575 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10576 header2 = 0;
10577 }
10578 if (ain->attr)
10579 {
10580 bgp_attr_dup(&attr, ain->attr);
10581 if (bgp_input_modifier(peer, &rn->p, &attr, afi,
10582 safi, rmap_name) != RMAP_DENY)
10583 {
10584 route_vty_out_tmp (vty, &rn->p, &attr, safi, delim);
10585 output_count++;
10586 }
10587 else
10588 filtered_count++;
10589 }
10590 }
10591 }
10592 else
10593 {
10594 for (adj = rn->adj_out; adj; adj = adj->next)
10595 if (adj->peer == peer)
10596 {
10597 if (header1)
10598 {
10599 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
10600 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10601 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10602 header1 = 0;
10603 }
10604 if (header2)
10605 {
10606 if (delim)
10607 vty_out (vty, BGP_SHOW_HEADER_CSV, VTY_NEWLINE);
10608 else
10609 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10610 header2 = 0;
10611 }
10612 if (adj->attr)
10613 {
10614 if (!CHECK_FLAG(peer->af_flags[afi][safi],
10615 PEER_FLAG_REFLECTOR_CLIENT)
10616 || bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
10617 {
10618
10619 bgp_attr_dup(&attr, adj->attr);
10620 ret = bgp_output_modifier(peer, &rn->p, &attr, afi,
10621 safi, rmap_name);
10622 }
10623 else
10624 ret = RMAP_PERMIT;
10625
10626 if (ret != RMAP_DENY)
10627 {
10628 route_vty_out_tmp (vty, &rn->p, &attr, safi, delim);
10629 output_count++;
10630 }
10631 else
10632 filtered_count++;
10633 }
10634 }
10635 }
10636
10637 if (output_count != 0)
10638 vty_out (vty, "%sTotal number of prefixes %ld%s",
10639 VTY_NEWLINE, output_count, VTY_NEWLINE);
10640 }
10641
10642 static int
10643 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10644 int in, char *delim, char *rmap_name)
10645 {
10646 if (! peer || ! peer->afc[afi][safi])
10647 {
10648 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10649 return CMD_WARNING;
10650 }
10651
10652 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10653 {
10654 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10655 VTY_NEWLINE);
10656 return CMD_WARNING;
10657 }
10658
10659 if (!in && (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)
10660 && !bgp_flag_check(peer->bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)))
10661 {
10662 vty_out (vty, "%% Cannot apply outgoing route-map on route-reflector clients%s",
10663 VTY_NEWLINE);
10664 vty_out (vty, "%% Enable bgp route-reflector allow-outbound-policy flag%s",
10665 VTY_NEWLINE);
10666 return CMD_WARNING;
10667 }
10668
10669 show_adj_route (vty, peer, afi, safi, in, delim, rmap_name);
10670
10671 return CMD_SUCCESS;
10672 }
10673
10674 DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10675 show_ip_bgp_view_neighbor_advertised_route_cmd,
10676 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10677 SHOW_STR
10678 IP_STR
10679 BGP_STR
10680 "BGP view\n"
10681 "View name\n"
10682 "Detailed information on TCP and BGP neighbor connections\n"
10683 "Neighbor to display information about\n"
10684 "Neighbor to display information about\n"
10685 "Display the routes advertised to a BGP neighbor\n")
10686 {
10687 struct peer *peer;
10688
10689 if (argc == 2)
10690 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10691 else
10692 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10693
10694 if (! peer)
10695 return CMD_WARNING;
10696
10697 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, NULL);
10698 }
10699
10700 DEFUN (show_ip_bgp_neighbor_advertised_route,
10701 show_ip_bgp_neighbor_advertised_route_cmd,
10702 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10703 SHOW_STR
10704 IP_STR
10705 BGP_STR
10706 "Detailed information on TCP and BGP neighbor connections\n"
10707 "Neighbor to display information about\n"
10708 "Neighbor to display information about\n"
10709 "Neighbor on bgp configured interface\n"
10710 "Display the routes advertised to a BGP neighbor\n")
10711
10712 {
10713 struct peer *peer;
10714 char *rmap_name = NULL;
10715
10716 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10717
10718 if (! peer)
10719 return CMD_WARNING;
10720
10721 if (argc == 2)
10722 rmap_name = argv[1];
10723
10724 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, rmap_name);
10725 }
10726
10727 ALIAS (show_ip_bgp_neighbor_advertised_route,
10728 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
10729 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
10730 SHOW_STR
10731 IP_STR
10732 BGP_STR
10733 "Detailed information on TCP and BGP neighbor connections\n"
10734 "Neighbor to display information about\n"
10735 "Neighbor to display information about\n"
10736 "Neighbor on bgp configured interface\n"
10737 "Display the routes advertised to a BGP neighbor\n")
10738
10739 DEFUN (show_ip_bgp_neighbor_advertised_route_csv,
10740 show_ip_bgp_neighbor_advertised_route_csv_cmd,
10741 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
10742 SHOW_STR
10743 IP_STR
10744 BGP_STR
10745 "BGP view\n"
10746 "View name\n"
10747 "Detailed information on TCP and BGP neighbor connections\n"
10748 "Neighbor to display information about\n"
10749 "Neighbor to display information about\n"
10750 "Neighbor on bgp configured interface\n"
10751 "Display the routes advertised to a BGP neighbor\n")
10752 {
10753 struct peer *peer;
10754 char *rmap_name = NULL;
10755
10756 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10757
10758 if (! peer)
10759 return CMD_WARNING;
10760
10761 if (argc == 2)
10762 rmap_name = argv[1];
10763
10764 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, &csv, rmap_name);
10765 }
10766
10767 ALIAS (show_ip_bgp_neighbor_advertised_route_csv,
10768 show_ip_bgp_neighbor_advertised_route_csv_rmap_cmd,
10769 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv route-map WORD",
10770 SHOW_STR
10771 IP_STR
10772 BGP_STR
10773 "BGP view\n"
10774 "View name\n"
10775 "Detailed information on TCP and BGP neighbor connections\n"
10776 "Neighbor to display information about\n"
10777 "Neighbor to display information about\n"
10778 "Neighbor on bgp configured interface\n"
10779 "Display the routes advertised to a BGP neighbor\n"
10780 "Apply this route-map to display what would've been advertised\n")
10781
10782 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10783 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10784 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10785 SHOW_STR
10786 IP_STR
10787 BGP_STR
10788 "Address family\n"
10789 "Address Family modifier\n"
10790 "Address Family modifier\n"
10791 "Detailed information on TCP and BGP neighbor connections\n"
10792 "Neighbor to display information about\n"
10793 "Neighbor to display information about\n"
10794 "Neighbor on bgp configured interface\n"
10795 "Display the routes advertised to a BGP neighbor\n")
10796 {
10797 struct peer *peer;
10798 char *rmap_name = NULL;
10799
10800 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10801 if (! peer)
10802 return CMD_WARNING;
10803
10804 if (argc == 3)
10805 rmap_name = argv[2];
10806
10807 if (strncmp (argv[0], "m", 1) == 0)
10808 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, NULL, rmap_name);
10809
10810 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, rmap_name);
10811 }
10812
10813 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
10814 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
10815 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
10816 SHOW_STR
10817 IP_STR
10818 BGP_STR
10819 "Address family\n"
10820 "Address Family modifier\n"
10821 "Address Family modifier\n"
10822 "Detailed information on TCP and BGP neighbor connections\n"
10823 "Neighbor to display information about\n"
10824 "Neighbor to display information about\n"
10825 "Neighbor on bgp configured interface\n"
10826 "Display the routes advertised to a BGP neighbor\n"
10827 "Route-map to control what is displayed\n")
10828
10829 #ifdef HAVE_IPV6
10830 DEFUN (show_bgp_view_neighbor_advertised_route,
10831 show_bgp_view_neighbor_advertised_route_cmd,
10832 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10833 SHOW_STR
10834 BGP_STR
10835 "BGP view\n"
10836 "View name\n"
10837 "Detailed information on TCP and BGP neighbor connections\n"
10838 "Neighbor to display information about\n"
10839 "Neighbor to display information about\n"
10840 "Neighbor on bgp configured interface\n"
10841 "Display the routes advertised to a BGP neighbor\n")
10842 {
10843 struct peer *peer;
10844
10845 if (argc == 2)
10846 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10847 else
10848 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10849
10850 if (! peer)
10851 return CMD_WARNING;
10852
10853 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, NULL);
10854 }
10855
10856 ALIAS (show_bgp_view_neighbor_advertised_route,
10857 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10858 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10859 SHOW_STR
10860 BGP_STR
10861 "BGP view\n"
10862 "View name\n"
10863 "Address family\n"
10864 "Detailed information on TCP and BGP neighbor connections\n"
10865 "Neighbor to display information about\n"
10866 "Neighbor to display information about\n"
10867 "Neighbor on bgp configured interface\n"
10868 "Display the routes advertised to a BGP neighbor\n")
10869
10870 DEFUN (show_bgp_view_neighbor_advertised_route_csv,
10871 show_bgp_view_neighbor_advertised_route_csv_cmd,
10872 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
10873 SHOW_STR
10874 BGP_STR
10875 "BGP view\n"
10876 "View name\n"
10877 "Detailed information on TCP and BGP neighbor connections\n"
10878 "Neighbor to display information about\n"
10879 "Neighbor to display information about\n"
10880 "Neighbor on bgp configured interface\n"
10881 "Display the routes advertised to a BGP neighbor\n")
10882 {
10883 struct peer *peer;
10884
10885 if (argc == 2)
10886 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10887 else
10888 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10889
10890 if (! peer)
10891 return CMD_WARNING;
10892
10893 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, &csv, NULL);
10894 }
10895
10896 ALIAS (show_bgp_view_neighbor_advertised_route_csv,
10897 show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd,
10898 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
10899 SHOW_STR
10900 BGP_STR
10901 "BGP view\n"
10902 "View name\n"
10903 "Address family\n"
10904 "Detailed information on TCP and BGP neighbor connections\n"
10905 "Neighbor to display information about\n"
10906 "Neighbor to display information about\n"
10907 "Neighbor on bgp configured interface\n"
10908 "Display the routes advertised to a BGP neighbor\n")
10909
10910 DEFUN (show_bgp_neighbor_advertised_route,
10911 show_bgp_neighbor_advertised_route_cmd,
10912 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10913 SHOW_STR
10914 BGP_STR
10915 "Detailed information on TCP and BGP neighbor connections\n"
10916 "Neighbor to display information about\n"
10917 "Neighbor to display information about\n"
10918 "Neighbor on bgp configured interface\n"
10919 "Display the routes advertised to a BGP neighbor\n")
10920
10921 {
10922 struct peer *peer;
10923 char *rmap_name = NULL;
10924
10925 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10926
10927 if (! peer)
10928 return CMD_WARNING;
10929
10930 if (argc == 2)
10931 rmap_name = argv[1];
10932
10933 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, rmap_name);
10934 }
10935
10936 ALIAS (show_bgp_neighbor_advertised_route,
10937 show_bgp_neighbor_advertised_route_rmap_cmd,
10938 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
10939 SHOW_STR
10940 BGP_STR
10941 "Detailed information on TCP and BGP neighbor connections\n"
10942 "Neighbor to display information about\n"
10943 "Neighbor to display information about\n"
10944 "Neighbor on bgp configured interface\n"
10945 "Display the routes advertised to a BGP neighbor\n")
10946
10947 ALIAS (show_bgp_neighbor_advertised_route,
10948 show_bgp_ipv6_neighbor_advertised_route_cmd,
10949 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
10950 SHOW_STR
10951 BGP_STR
10952 "Address family\n"
10953 "Detailed information on TCP and BGP neighbor connections\n"
10954 "Neighbor to display information about\n"
10955 "Neighbor to display information about\n"
10956 "Neighbor on bgp configured interface\n"
10957 "Display the routes advertised to a BGP neighbor\n")
10958
10959 ALIAS (show_bgp_neighbor_advertised_route,
10960 show_bgp_ipv6_neighbor_advertised_route_rmap_cmd,
10961 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD",
10962 SHOW_STR
10963 BGP_STR
10964 "Address family\n"
10965 "Detailed information on TCP and BGP neighbor connections\n"
10966 "Neighbor to display information about\n"
10967 "Neighbor to display information about\n"
10968 "Neighbor on bgp configured interface\n"
10969 "Display the routes advertised to a BGP neighbor\n")
10970
10971 DEFUN (show_bgp_neighbor_advertised_route_csv,
10972 show_bgp_neighbor_advertised_route_csv_cmd,
10973 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
10974 SHOW_STR
10975 BGP_STR
10976 "Detailed information on TCP and BGP neighbor connections\n"
10977 "Neighbor to display information about\n"
10978 "Neighbor to display information about\n"
10979 "Neighbor on bgp configured interface\n"
10980 "Display the routes advertised to a BGP neighbor\n")
10981 {
10982 struct peer *peer;
10983 char *rmap_name = NULL;
10984
10985 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10986
10987 if (! peer)
10988 return CMD_WARNING;
10989
10990 if (argc == 2)
10991 rmap_name = argv[1];
10992
10993 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, &csv, rmap_name);
10994 }
10995
10996 ALIAS (show_bgp_neighbor_advertised_route_csv,
10997 show_bgp_neighbor_advertised_route_csv_rmap_cmd,
10998 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv route-map WORD",
10999 SHOW_STR
11000 BGP_STR
11001 "Detailed information on TCP and BGP neighbor connections\n"
11002 "Neighbor to display information about\n"
11003 "Neighbor to display information about\n"
11004 "Neighbor on bgp configured interface\n"
11005 "Display the routes advertised to a BGP neighbor\n")
11006
11007 ALIAS (show_bgp_neighbor_advertised_route_csv,
11008 show_bgp_ipv6_neighbor_advertised_route_csv_cmd,
11009 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv",
11010 SHOW_STR
11011 BGP_STR
11012 "Address family\n"
11013 "Detailed information on TCP and BGP neighbor connections\n"
11014 "Neighbor to display information about\n"
11015 "Neighbor to display information about\n"
11016 "Neighbor on bgp configured interface\n"
11017 "Display the routes advertised to a BGP neighbor\n")
11018
11019 ALIAS (show_bgp_neighbor_advertised_route_csv,
11020 show_bgp_ipv6_neighbor_advertised_route_csv_rmap_cmd,
11021 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes csv route-map WORD",
11022 SHOW_STR
11023 BGP_STR
11024 "Address family\n"
11025 "Detailed information on TCP and BGP neighbor connections\n"
11026 "Neighbor to display information about\n"
11027 "Neighbor to display information about\n"
11028 "Neighbor on bgp configured interface\n"
11029 "Display the routes advertised to a BGP neighbor\n")
11030
11031 /* old command */
11032 ALIAS (show_bgp_neighbor_advertised_route,
11033 ipv6_bgp_neighbor_advertised_route_cmd,
11034 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
11035 SHOW_STR
11036 IPV6_STR
11037 BGP_STR
11038 "Detailed information on TCP and BGP neighbor connections\n"
11039 "Neighbor to display information about\n"
11040 "Neighbor to display information about\n"
11041 "Neighbor on bgp configured interface\n"
11042 "Display the routes advertised to a BGP neighbor\n")
11043
11044 /* old command */
11045 DEFUN (ipv6_mbgp_neighbor_advertised_route,
11046 ipv6_mbgp_neighbor_advertised_route_cmd,
11047 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes",
11048 SHOW_STR
11049 IPV6_STR
11050 MBGP_STR
11051 "Detailed information on TCP and BGP neighbor connections\n"
11052 "Neighbor to display information about\n"
11053 "Neighbor to display information about\n"
11054 "Neighbor on bgp configured interface\n"
11055 "Neighbor on bgp configured interface\n"
11056 "Display the routes advertised to a BGP neighbor\n")
11057 {
11058 struct peer *peer;
11059
11060 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11061 if (! peer)
11062 return CMD_WARNING;
11063
11064 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, NULL);
11065 }
11066 #endif /* HAVE_IPV6 */
11067
11068 DEFUN (show_bgp_view_neighbor_received_routes,
11069 show_bgp_view_neighbor_received_routes_cmd,
11070 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11071 SHOW_STR
11072 BGP_STR
11073 "BGP view\n"
11074 "View name\n"
11075 "Detailed information on TCP and BGP neighbor connections\n"
11076 "Neighbor to display information about\n"
11077 "Neighbor to display information about\n"
11078 "Neighbor on bgp configured interface\n"
11079 "Display the received routes from neighbor\n")
11080 {
11081 struct peer *peer;
11082
11083 if (argc == 2)
11084 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11085 else
11086 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11087
11088 if (! peer)
11089 return CMD_WARNING;
11090
11091 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, NULL);
11092 }
11093
11094 DEFUN (show_ip_bgp_view_neighbor_received_routes,
11095 show_ip_bgp_view_neighbor_received_routes_cmd,
11096 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11097 SHOW_STR
11098 IP_STR
11099 BGP_STR
11100 "BGP view\n"
11101 "View name\n"
11102 "Detailed information on TCP and BGP neighbor connections\n"
11103 "Neighbor to display information about\n"
11104 "Neighbor to display information about\n"
11105 "Neighbor on bgp configured interface\n"
11106 "Display the received routes from neighbor\n")
11107 {
11108 struct peer *peer;
11109
11110 if (argc == 2)
11111 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11112 else
11113 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11114
11115 if (! peer)
11116 return CMD_WARNING;
11117
11118 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, NULL);
11119 }
11120
11121 ALIAS (show_bgp_view_neighbor_received_routes,
11122 show_bgp_view_ipv6_neighbor_received_routes_cmd,
11123 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11124 SHOW_STR
11125 BGP_STR
11126 "BGP view\n"
11127 "View name\n"
11128 "Address family\n"
11129 "Detailed information on TCP and BGP neighbor connections\n"
11130 "Neighbor to display information about\n"
11131 "Neighbor to display information about\n"
11132 "Neighbor on bgp configured interface\n"
11133 "Display the received routes from neighbor\n")
11134
11135 DEFUN (show_ip_bgp_neighbor_received_routes,
11136 show_ip_bgp_neighbor_received_routes_cmd,
11137 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11138 SHOW_STR
11139 IP_STR
11140 BGP_STR
11141 "Detailed information on TCP and BGP neighbor connections\n"
11142 "Neighbor to display information about\n"
11143 "Neighbor to display information about\n"
11144 "Neighbor on bgp configured interface\n"
11145 "Display the received routes from neighbor\n")
11146
11147 {
11148 struct peer *peer;
11149 char *rmap_name = NULL;
11150
11151 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11152
11153 if (! peer)
11154 return CMD_WARNING;
11155
11156 if (argc == 2)
11157 rmap_name = argv[1];
11158
11159 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, rmap_name);
11160 }
11161
11162 ALIAS (show_ip_bgp_neighbor_received_routes,
11163 show_ip_bgp_neighbor_received_routes_rmap_cmd,
11164 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11165 SHOW_STR
11166 IP_STR
11167 BGP_STR
11168 "Detailed information on TCP and BGP neighbor connections\n"
11169 "Neighbor to display information about\n"
11170 "Neighbor to display information about\n"
11171 "Neighbor on bgp configured interface\n"
11172 "Display the received routes from neighbor\n")
11173
11174 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
11175 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
11176 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11177 SHOW_STR
11178 IP_STR
11179 BGP_STR
11180 "Address family\n"
11181 "Address Family modifier\n"
11182 "Address Family modifier\n"
11183 "Detailed information on TCP and BGP neighbor connections\n"
11184 "Neighbor to display information about\n"
11185 "Neighbor to display information about\n"
11186 "Neighbor on bgp configured interface\n"
11187 "Display the received routes from neighbor\n")
11188 {
11189 struct peer *peer;
11190 char *rmap_name = NULL;
11191
11192 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11193 if (! peer)
11194 return CMD_WARNING;
11195
11196 if (argc == 3)
11197 rmap_name = argv[2];
11198
11199 if (strncmp (argv[0], "m", 1) == 0)
11200 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, NULL, rmap_name);
11201
11202 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, rmap_name);
11203 }
11204
11205 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
11206 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
11207 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11208 SHOW_STR
11209 IP_STR
11210 BGP_STR
11211 "Address family\n"
11212 "Address Family modifier\n"
11213 "Address Family modifier\n"
11214 "Detailed information on TCP and BGP neighbor connections\n"
11215 "Neighbor to display information about\n"
11216 "Neighbor to display information about\n"
11217 "Neighbor on bgp configured interface\n"
11218 "Display the received routes from neighbor\n")
11219
11220 DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
11221 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
11222 #ifdef HAVE_IPV6
11223 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
11224 #else
11225 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes)",
11226 #endif
11227 SHOW_STR
11228 BGP_STR
11229 "BGP view\n"
11230 "View name\n"
11231 "Address family\n"
11232 #ifdef HAVE_IPV6
11233 "Address family\n"
11234 #endif
11235 "Address family modifier\n"
11236 "Address family modifier\n"
11237 "Detailed information on TCP and BGP neighbor connections\n"
11238 "Neighbor to display information about\n"
11239 "Neighbor to display information about\n"
11240 "Neighbor on bgp configured interface\n"
11241 "Display the advertised routes to neighbor\n"
11242 "Display the received routes from neighbor\n")
11243 {
11244 int afi;
11245 int safi;
11246 int in;
11247 struct peer *peer;
11248
11249 #ifdef HAVE_IPV6
11250 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
11251 #else
11252 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11253 #endif
11254
11255 if (! peer)
11256 return CMD_WARNING;
11257
11258 #ifdef HAVE_IPV6
11259 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
11260 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11261 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
11262 #else
11263 afi = AFI_IP;
11264 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11265 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
11266 #endif
11267
11268 return peer_adj_routes (vty, peer, afi, safi, in, NULL, NULL);
11269 }
11270
11271 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
11272 show_ip_bgp_neighbor_received_prefix_filter_cmd,
11273 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11274 SHOW_STR
11275 IP_STR
11276 BGP_STR
11277 "Detailed information on TCP and BGP neighbor connections\n"
11278 "Neighbor to display information about\n"
11279 "Neighbor to display information about\n"
11280 "Neighbor on bgp configured interface\n"
11281 "Display information received from a BGP neighbor\n"
11282 "Display the prefixlist filter\n")
11283 {
11284 char name[BUFSIZ];
11285 union sockunion su;
11286 struct peer *peer;
11287 int count, ret;
11288
11289 ret = str2sockunion (argv[0], &su);
11290 if (ret < 0)
11291 {
11292 peer = peer_lookup_by_conf_if (NULL, argv[0]);
11293 if (!peer)
11294 {
11295 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
11296 return CMD_WARNING;
11297 }
11298 }
11299 else
11300 {
11301 peer = peer_lookup (NULL, &su);
11302 if (! peer)
11303 return CMD_WARNING;
11304 }
11305
11306 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
11307 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
11308 if (count)
11309 {
11310 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
11311 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
11312 }
11313
11314 return CMD_SUCCESS;
11315 }
11316
11317 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
11318 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
11319 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11320 SHOW_STR
11321 IP_STR
11322 BGP_STR
11323 "Address family\n"
11324 "Address Family modifier\n"
11325 "Address Family modifier\n"
11326 "Detailed information on TCP and BGP neighbor connections\n"
11327 "Neighbor to display information about\n"
11328 "Neighbor to display information about\n"
11329 "Neighbor on bgp configured interface\n"
11330 "Display information received from a BGP neighbor\n"
11331 "Display the prefixlist filter\n")
11332 {
11333 char name[BUFSIZ];
11334 union sockunion su;
11335 struct peer *peer;
11336 int count, ret;
11337
11338 ret = str2sockunion (argv[1], &su);
11339 if (ret < 0)
11340 {
11341 peer = peer_lookup_by_conf_if (NULL, argv[1]);
11342 if (!peer)
11343 {
11344 vty_out (vty, "Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
11345 return CMD_WARNING;
11346 }
11347 }
11348 else
11349 {
11350 peer = peer_lookup (NULL, &su);
11351 if (! peer)
11352 return CMD_WARNING;
11353 }
11354
11355 if (strncmp (argv[0], "m", 1) == 0)
11356 {
11357 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
11358 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
11359 if (count)
11360 {
11361 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
11362 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
11363 }
11364 }
11365 else
11366 {
11367 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
11368 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
11369 if (count)
11370 {
11371 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
11372 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
11373 }
11374 }
11375
11376 return CMD_SUCCESS;
11377 }
11378
11379
11380 #ifdef HAVE_IPV6
11381 ALIAS (show_bgp_view_neighbor_received_routes,
11382 show_bgp_neighbor_received_routes_cmd,
11383 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11384 SHOW_STR
11385 BGP_STR
11386 "Detailed information on TCP and BGP neighbor connections\n"
11387 "Neighbor to display information about\n"
11388 "Neighbor to display information about\n"
11389 "Neighbor on bgp configured interface\n"
11390 "Display the received routes from neighbor\n")
11391
11392 ALIAS (show_bgp_view_neighbor_received_routes,
11393 show_bgp_ipv6_neighbor_received_routes_cmd,
11394 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11395 SHOW_STR
11396 BGP_STR
11397 "Address family\n"
11398 "Detailed information on TCP and BGP neighbor connections\n"
11399 "Neighbor to display information about\n"
11400 "Neighbor to display information about\n"
11401 "Neighbor on bgp configured interface\n"
11402 "Display the received routes from neighbor\n")
11403
11404 ALIAS (show_bgp_view_neighbor_received_routes,
11405 show_bgp_neighbor_received_routes_rmap_cmd,
11406 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11407 SHOW_STR
11408 BGP_STR
11409 "Detailed information on TCP and BGP neighbor connections\n"
11410 "Neighbor to display information about\n"
11411 "Neighbor to display information about\n"
11412 "Neighbor on bgp configured interface\n"
11413 "Display the received routes from neighbor\n")
11414
11415 ALIAS (show_bgp_view_neighbor_received_routes,
11416 show_bgp_ipv6_neighbor_received_routes_rmap_cmd,
11417 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD",
11418 SHOW_STR
11419 BGP_STR
11420 "Address family\n"
11421 "Detailed information on TCP and BGP neighbor connections\n"
11422 "Neighbor to display information about\n"
11423 "Neighbor to display information about\n"
11424 "Neighbor on bgp configured interface\n"
11425 "Display the received routes from neighbor\n")
11426
11427 DEFUN (show_bgp_neighbor_received_prefix_filter,
11428 show_bgp_neighbor_received_prefix_filter_cmd,
11429 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11430 SHOW_STR
11431 BGP_STR
11432 "Detailed information on TCP and BGP neighbor connections\n"
11433 "Neighbor to display information about\n"
11434 "Neighbor to display information about\n"
11435 "Neighbor on bgp configured interface\n"
11436 "Display information received from a BGP neighbor\n"
11437 "Display the prefixlist filter\n")
11438 {
11439 char name[BUFSIZ];
11440 union sockunion su;
11441 struct peer *peer;
11442 int count, ret;
11443
11444 ret = str2sockunion (argv[0], &su);
11445 if (ret < 0)
11446 {
11447 peer = peer_lookup_by_conf_if (NULL, argv[0]);
11448 if (!peer)
11449 {
11450 vty_out (vty, "Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
11451 return CMD_WARNING;
11452 }
11453 }
11454 else
11455 {
11456 peer = peer_lookup (NULL, &su);
11457 if (! peer)
11458 return CMD_WARNING;
11459 }
11460
11461 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
11462 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
11463 if (count)
11464 {
11465 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
11466 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
11467 }
11468
11469 return CMD_SUCCESS;
11470 }
11471
11472 ALIAS (show_bgp_neighbor_received_prefix_filter,
11473 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
11474 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11475 SHOW_STR
11476 BGP_STR
11477 "Address family\n"
11478 "Detailed information on TCP and BGP neighbor connections\n"
11479 "Neighbor to display information about\n"
11480 "Neighbor to display information about\n"
11481 "Neighbor on bgp configured interface\n"
11482 "Display information received from a BGP neighbor\n"
11483 "Display the prefixlist filter\n")
11484
11485 /* old command */
11486 ALIAS (show_bgp_view_neighbor_received_routes,
11487 ipv6_bgp_neighbor_received_routes_cmd,
11488 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11489 SHOW_STR
11490 IPV6_STR
11491 BGP_STR
11492 "Detailed information on TCP and BGP neighbor connections\n"
11493 "Neighbor to display information about\n"
11494 "Neighbor to display information about\n"
11495 "Neighbor on bgp configured interface\n"
11496 "Display the received routes from neighbor\n")
11497
11498 /* old command */
11499 DEFUN (ipv6_mbgp_neighbor_received_routes,
11500 ipv6_mbgp_neighbor_received_routes_cmd,
11501 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes",
11502 SHOW_STR
11503 IPV6_STR
11504 MBGP_STR
11505 "Detailed information on TCP and BGP neighbor connections\n"
11506 "Neighbor to display information about\n"
11507 "Neighbor to display information about\n"
11508 "Neighbor on bgp configured interface\n"
11509 "Display the received routes from neighbor\n")
11510 {
11511 struct peer *peer;
11512
11513 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11514 if (! peer)
11515 return CMD_WARNING;
11516
11517 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, NULL);
11518 }
11519
11520 DEFUN (show_bgp_view_neighbor_received_prefix_filter,
11521 show_bgp_view_neighbor_received_prefix_filter_cmd,
11522 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11523 SHOW_STR
11524 BGP_STR
11525 "BGP view\n"
11526 "View name\n"
11527 "Detailed information on TCP and BGP neighbor connections\n"
11528 "Neighbor to display information about\n"
11529 "Neighbor to display information about\n"
11530 "Neighbor on bgp configured interface\n"
11531 "Display information received from a BGP neighbor\n"
11532 "Display the prefixlist filter\n")
11533 {
11534 char name[BUFSIZ];
11535 union sockunion su;
11536 struct peer *peer;
11537 struct bgp *bgp;
11538 int count, ret;
11539
11540 /* BGP structure lookup. */
11541 bgp = bgp_lookup_by_name (argv[0]);
11542 if (bgp == NULL)
11543 {
11544 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11545 return CMD_WARNING;
11546 }
11547
11548 ret = str2sockunion (argv[1], &su);
11549 if (ret < 0)
11550 {
11551 peer = peer_lookup_by_conf_if (bgp, argv[1]);
11552 if (!peer)
11553 {
11554 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
11555 return CMD_WARNING;
11556 }
11557 }
11558 else
11559 {
11560 peer = peer_lookup (bgp, &su);
11561 if (! peer)
11562 return CMD_WARNING;
11563 }
11564
11565 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
11566 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
11567 if (count)
11568 {
11569 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
11570 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
11571 }
11572
11573 return CMD_SUCCESS;
11574 }
11575
11576 ALIAS (show_bgp_view_neighbor_received_prefix_filter,
11577 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
11578 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter",
11579 SHOW_STR
11580 BGP_STR
11581 "BGP view\n"
11582 "View name\n"
11583 "Address family\n"
11584 "Detailed information on TCP and BGP neighbor connections\n"
11585 "Neighbor to display information about\n"
11586 "Neighbor to display information about\n"
11587 "Neighbor on bgp configured interface\n"
11588 "Display information received from a BGP neighbor\n"
11589 "Display the prefixlist filter\n")
11590 #endif /* HAVE_IPV6 */
11591
11592 static int
11593 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
11594 safi_t safi, enum bgp_show_type type, char *delim)
11595 {
11596 if (! peer || ! peer->afc[afi][safi])
11597 {
11598 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11599 return CMD_WARNING;
11600 }
11601
11602 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, delim);
11603 }
11604
11605 DEFUN (show_ip_bgp_neighbor_routes,
11606 show_ip_bgp_neighbor_routes_cmd,
11607 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
11608 SHOW_STR
11609 IP_STR
11610 BGP_STR
11611 "Detailed information on TCP and BGP neighbor connections\n"
11612 "Neighbor to display information about\n"
11613 "Neighbor to display information about\n"
11614 "Neighbor on bgp configured interface\n"
11615 "Display routes learned from neighbor\n")
11616 {
11617 struct peer *peer;
11618
11619 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11620 if (! peer)
11621 return CMD_WARNING;
11622
11623 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
11624 bgp_show_type_neighbor, NULL);
11625 }
11626
11627 DEFUN (show_ip_bgp_neighbor_routes_csv,
11628 show_ip_bgp_neighbor_routes_csv_cmd,
11629 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
11630 SHOW_STR
11631 IP_STR
11632 BGP_STR
11633 "Detailed information on TCP and BGP neighbor connections\n"
11634 "Neighbor to display information about\n"
11635 "Neighbor to display information about\n"
11636 "Neighbor on bgp configured interface\n"
11637 "Display routes learned from neighbor\n")
11638 {
11639 struct peer *peer;
11640
11641 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11642 if (! peer)
11643 return CMD_WARNING;
11644
11645 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
11646 bgp_show_type_neighbor, &csv);
11647 }
11648
11649 DEFUN (show_ip_bgp_neighbor_flap,
11650 show_ip_bgp_neighbor_flap_cmd,
11651 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
11652 SHOW_STR
11653 IP_STR
11654 BGP_STR
11655 "Detailed information on TCP and BGP neighbor connections\n"
11656 "Neighbor to display information about\n"
11657 "Neighbor to display information about\n"
11658 "Neighbor on bgp configured interface\n"
11659 "Display flap statistics of the routes learned from neighbor\n")
11660 {
11661 struct peer *peer;
11662
11663 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11664 if (! peer)
11665 return CMD_WARNING;
11666
11667 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
11668 bgp_show_type_flap_neighbor, NULL);
11669 }
11670
11671 DEFUN (show_ip_bgp_neighbor_damp,
11672 show_ip_bgp_neighbor_damp_cmd,
11673 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
11674 SHOW_STR
11675 IP_STR
11676 BGP_STR
11677 "Detailed information on TCP and BGP neighbor connections\n"
11678 "Neighbor to display information about\n"
11679 "Neighbor to display information about\n"
11680 "Neighbor on bgp configured interface\n"
11681 "Display the dampened routes received from neighbor\n")
11682 {
11683 struct peer *peer;
11684
11685 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11686 if (! peer)
11687 return CMD_WARNING;
11688
11689 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
11690 bgp_show_type_damp_neighbor, NULL);
11691 }
11692
11693 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
11694 show_ip_bgp_ipv4_neighbor_routes_cmd,
11695 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes",
11696 SHOW_STR
11697 IP_STR
11698 BGP_STR
11699 "Address family\n"
11700 "Address Family modifier\n"
11701 "Address Family modifier\n"
11702 "Detailed information on TCP and BGP neighbor connections\n"
11703 "Neighbor to display information about\n"
11704 "Neighbor to display information about\n"
11705 "Neighbor on bgp configured interface\n"
11706 "Display routes learned from neighbor\n")
11707 {
11708 struct peer *peer;
11709
11710 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11711 if (! peer)
11712 return CMD_WARNING;
11713
11714 if (strncmp (argv[0], "m", 1) == 0)
11715 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
11716 bgp_show_type_neighbor, NULL);
11717
11718 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
11719 bgp_show_type_neighbor, NULL);
11720 }
11721
11722 DEFUN (show_ip_bgp_view_rsclient,
11723 show_ip_bgp_view_rsclient_cmd,
11724 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
11725 SHOW_STR
11726 IP_STR
11727 BGP_STR
11728 "BGP view\n"
11729 "View name\n"
11730 "Information about Route Server Client\n"
11731 NEIGHBOR_ADDR_STR3)
11732 {
11733 struct bgp_table *table;
11734 struct peer *peer;
11735
11736 if (argc == 2)
11737 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11738 else
11739 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11740
11741 if (! peer)
11742 return CMD_WARNING;
11743
11744 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11745 {
11746 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11747 VTY_NEWLINE);
11748 return CMD_WARNING;
11749 }
11750
11751 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11752 PEER_FLAG_RSERVER_CLIENT))
11753 {
11754 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11755 VTY_NEWLINE);
11756 return CMD_WARNING;
11757 }
11758
11759 table = peer->rib[AFI_IP][SAFI_UNICAST];
11760
11761 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
11762 NULL, NULL);
11763 }
11764
11765 ALIAS (show_ip_bgp_view_rsclient,
11766 show_ip_bgp_rsclient_cmd,
11767 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
11768 SHOW_STR
11769 IP_STR
11770 BGP_STR
11771 "Information about Route Server Client\n"
11772 NEIGHBOR_ADDR_STR3)
11773
11774 DEFUN (show_bgp_view_ipv4_safi_rsclient,
11775 show_bgp_view_ipv4_safi_rsclient_cmd,
11776 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
11777 SHOW_STR
11778 BGP_STR
11779 "BGP view\n"
11780 "View name\n"
11781 "Address family\n"
11782 "Address Family modifier\n"
11783 "Address Family modifier\n"
11784 "Information about Route Server Client\n"
11785 NEIGHBOR_ADDR_STR3)
11786 {
11787 struct bgp_table *table;
11788 struct peer *peer;
11789 safi_t safi;
11790
11791 if (argc == 3) {
11792 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11793 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11794 } else {
11795 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11796 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11797 }
11798
11799 if (! peer)
11800 return CMD_WARNING;
11801
11802 if (! peer->afc[AFI_IP][safi])
11803 {
11804 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11805 VTY_NEWLINE);
11806 return CMD_WARNING;
11807 }
11808
11809 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11810 PEER_FLAG_RSERVER_CLIENT))
11811 {
11812 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11813 VTY_NEWLINE);
11814 return CMD_WARNING;
11815 }
11816
11817 table = peer->rib[AFI_IP][safi];
11818
11819 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
11820 NULL, NULL);
11821 }
11822
11823 ALIAS (show_bgp_view_ipv4_safi_rsclient,
11824 show_bgp_ipv4_safi_rsclient_cmd,
11825 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
11826 SHOW_STR
11827 BGP_STR
11828 "Address family\n"
11829 "Address Family modifier\n"
11830 "Address Family modifier\n"
11831 "Information about Route Server Client\n"
11832 NEIGHBOR_ADDR_STR3)
11833
11834 DEFUN (show_ip_bgp_view_rsclient_route,
11835 show_ip_bgp_view_rsclient_route_cmd,
11836 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
11837 SHOW_STR
11838 IP_STR
11839 BGP_STR
11840 "BGP view\n"
11841 "View name\n"
11842 "Information about Route Server Client\n"
11843 NEIGHBOR_ADDR_STR3
11844 "Network in the BGP routing table to display\n")
11845 {
11846 struct bgp *bgp;
11847 struct peer *peer;
11848
11849 /* BGP structure lookup. */
11850 if (argc == 3)
11851 {
11852 bgp = bgp_lookup_by_name (argv[0]);
11853 if (bgp == NULL)
11854 {
11855 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11856 return CMD_WARNING;
11857 }
11858 }
11859 else
11860 {
11861 bgp = bgp_get_default ();
11862 if (bgp == NULL)
11863 {
11864 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11865 return CMD_WARNING;
11866 }
11867 }
11868
11869 if (argc == 3)
11870 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11871 else
11872 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11873
11874 if (! peer)
11875 return CMD_WARNING;
11876
11877 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11878 {
11879 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11880 VTY_NEWLINE);
11881 return CMD_WARNING;
11882 }
11883
11884 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11885 PEER_FLAG_RSERVER_CLIENT))
11886 {
11887 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11888 VTY_NEWLINE);
11889 return CMD_WARNING;
11890 }
11891
11892 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11893 (argc == 3) ? argv[2] : argv[1],
11894 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
11895 }
11896
11897 ALIAS (show_ip_bgp_view_rsclient_route,
11898 show_ip_bgp_rsclient_route_cmd,
11899 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
11900 SHOW_STR
11901 IP_STR
11902 BGP_STR
11903 "Information about Route Server Client\n"
11904 NEIGHBOR_ADDR_STR3
11905 "Network in the BGP routing table to display\n")
11906
11907 DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
11908 show_bgp_view_ipv4_safi_rsclient_route_cmd,
11909 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
11910 SHOW_STR
11911 BGP_STR
11912 "BGP view\n"
11913 "View name\n"
11914 "Address family\n"
11915 "Address Family modifier\n"
11916 "Address Family modifier\n"
11917 "Information about Route Server Client\n"
11918 NEIGHBOR_ADDR_STR3
11919 "Network in the BGP routing table to display\n")
11920 {
11921 struct bgp *bgp;
11922 struct peer *peer;
11923 safi_t safi;
11924
11925 /* BGP structure lookup. */
11926 if (argc == 4)
11927 {
11928 bgp = bgp_lookup_by_name (argv[0]);
11929 if (bgp == NULL)
11930 {
11931 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11932 return CMD_WARNING;
11933 }
11934 }
11935 else
11936 {
11937 bgp = bgp_get_default ();
11938 if (bgp == NULL)
11939 {
11940 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11941 return CMD_WARNING;
11942 }
11943 }
11944
11945 if (argc == 4) {
11946 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11947 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11948 } else {
11949 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11950 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11951 }
11952
11953 if (! peer)
11954 return CMD_WARNING;
11955
11956 if (! peer->afc[AFI_IP][safi])
11957 {
11958 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11959 VTY_NEWLINE);
11960 return CMD_WARNING;
11961 }
11962
11963 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11964 PEER_FLAG_RSERVER_CLIENT))
11965 {
11966 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11967 VTY_NEWLINE);
11968 return CMD_WARNING;
11969 }
11970
11971 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11972 (argc == 4) ? argv[3] : argv[2],
11973 AFI_IP, safi, NULL, 0, BGP_PATH_ALL);
11974 }
11975
11976 ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
11977 show_bgp_ipv4_safi_rsclient_route_cmd,
11978 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D",
11979 SHOW_STR
11980 BGP_STR
11981 "Address family\n"
11982 "Address Family modifier\n"
11983 "Address Family modifier\n"
11984 "Information about Route Server Client\n"
11985 NEIGHBOR_ADDR_STR3
11986 "Network in the BGP routing table to display\n")
11987
11988 DEFUN (show_ip_bgp_view_rsclient_prefix,
11989 show_ip_bgp_view_rsclient_prefix_cmd,
11990 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
11991 SHOW_STR
11992 IP_STR
11993 BGP_STR
11994 "BGP view\n"
11995 "View name\n"
11996 "Information about Route Server Client\n"
11997 NEIGHBOR_ADDR_STR3
11998 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11999 {
12000 struct bgp *bgp;
12001 struct peer *peer;
12002
12003 /* BGP structure lookup. */
12004 if (argc == 3)
12005 {
12006 bgp = bgp_lookup_by_name (argv[0]);
12007 if (bgp == NULL)
12008 {
12009 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12010 return CMD_WARNING;
12011 }
12012 }
12013 else
12014 {
12015 bgp = bgp_get_default ();
12016 if (bgp == NULL)
12017 {
12018 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12019 return CMD_WARNING;
12020 }
12021 }
12022
12023 if (argc == 3)
12024 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12025 else
12026 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12027
12028 if (! peer)
12029 return CMD_WARNING;
12030
12031 if (! peer->afc[AFI_IP][SAFI_UNICAST])
12032 {
12033 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12034 VTY_NEWLINE);
12035 return CMD_WARNING;
12036 }
12037
12038 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
12039 PEER_FLAG_RSERVER_CLIENT))
12040 {
12041 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12042 VTY_NEWLINE);
12043 return CMD_WARNING;
12044 }
12045
12046 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
12047 (argc == 3) ? argv[2] : argv[1],
12048 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
12049 }
12050
12051 ALIAS (show_ip_bgp_view_rsclient_prefix,
12052 show_ip_bgp_rsclient_prefix_cmd,
12053 "show ip bgp rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
12054 SHOW_STR
12055 IP_STR
12056 BGP_STR
12057 "Information about Route Server Client\n"
12058 NEIGHBOR_ADDR_STR3
12059 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12060
12061 DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
12062 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
12063 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
12064 SHOW_STR
12065 BGP_STR
12066 "BGP view\n"
12067 "View name\n"
12068 "Address family\n"
12069 "Address Family modifier\n"
12070 "Address Family modifier\n"
12071 "Information about Route Server Client\n"
12072 NEIGHBOR_ADDR_STR3
12073 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12074 {
12075 struct bgp *bgp;
12076 struct peer *peer;
12077 safi_t safi;
12078
12079 /* BGP structure lookup. */
12080 if (argc == 4)
12081 {
12082 bgp = bgp_lookup_by_name (argv[0]);
12083 if (bgp == NULL)
12084 {
12085 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12086 return CMD_WARNING;
12087 }
12088 }
12089 else
12090 {
12091 bgp = bgp_get_default ();
12092 if (bgp == NULL)
12093 {
12094 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12095 return CMD_WARNING;
12096 }
12097 }
12098
12099 if (argc == 4) {
12100 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12101 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12102 } else {
12103 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12104 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12105 }
12106
12107 if (! peer)
12108 return CMD_WARNING;
12109
12110 if (! peer->afc[AFI_IP][safi])
12111 {
12112 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12113 VTY_NEWLINE);
12114 return CMD_WARNING;
12115 }
12116
12117 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
12118 PEER_FLAG_RSERVER_CLIENT))
12119 {
12120 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12121 VTY_NEWLINE);
12122 return CMD_WARNING;
12123 }
12124
12125 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
12126 (argc == 4) ? argv[3] : argv[2],
12127 AFI_IP, safi, NULL, 1, BGP_PATH_ALL);
12128 }
12129
12130 ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
12131 show_bgp_ipv4_safi_rsclient_prefix_cmd,
12132 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) A.B.C.D/M",
12133 SHOW_STR
12134 BGP_STR
12135 "Address family\n"
12136 "Address Family modifier\n"
12137 "Address Family modifier\n"
12138 "Information about Route Server Client\n"
12139 NEIGHBOR_ADDR_STR3
12140 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12141
12142 #ifdef HAVE_IPV6
12143 DEFUN (show_bgp_view_neighbor_routes,
12144 show_bgp_view_neighbor_routes_cmd,
12145 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12146 SHOW_STR
12147 BGP_STR
12148 "BGP view\n"
12149 "View name\n"
12150 "Detailed information on TCP and BGP neighbor connections\n"
12151 "Neighbor to display information about\n"
12152 "Neighbor to display information about\n"
12153 "Neighbor on bgp configured interface\n"
12154 "Display routes learned from neighbor\n")
12155 {
12156 struct peer *peer;
12157
12158 if (argc == 2)
12159 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12160 else
12161 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12162
12163 if (! peer)
12164 return CMD_WARNING;
12165
12166 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12167 bgp_show_type_neighbor, NULL);
12168 }
12169
12170 DEFUN (show_bgp_view_neighbor_routes_csv,
12171 show_bgp_view_neighbor_routes_csv_cmd,
12172 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
12173 SHOW_STR
12174 BGP_STR
12175 "BGP view\n"
12176 "BGP view name\n"
12177 "Detailed information on TCP and BGP neighbor connections\n"
12178 "Neighbor to display information about\n"
12179 "Neighbor to display information about\n"
12180 "Neighbor on bgp configured interface\n"
12181 "Display routes learned from neighbor\n")
12182 {
12183 struct peer *peer;
12184
12185 if (argc == 2)
12186 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12187 else
12188 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12189
12190 if (! peer)
12191 return CMD_WARNING;
12192
12193 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12194 bgp_show_type_neighbor, &csv);
12195 }
12196
12197 ALIAS (show_bgp_view_neighbor_routes,
12198 show_bgp_view_ipv6_neighbor_routes_cmd,
12199 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12200 SHOW_STR
12201 BGP_STR
12202 "BGP view\n"
12203 "View name\n"
12204 "Address family\n"
12205 "Detailed information on TCP and BGP neighbor connections\n"
12206 "Neighbor to display information about\n"
12207 "Neighbor to display information about\n"
12208 "Neighbor on bgp configured interface\n"
12209 "Display routes learned from neighbor\n")
12210
12211 DEFUN (show_bgp_view_neighbor_damp,
12212 show_bgp_view_neighbor_damp_cmd,
12213 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
12214 SHOW_STR
12215 BGP_STR
12216 "BGP view\n"
12217 "View name\n"
12218 "Detailed information on TCP and BGP neighbor connections\n"
12219 "Neighbor to display information about\n"
12220 "Neighbor to display information about\n"
12221 "Neighbor on bgp configured interface\n"
12222 "Display the dampened routes received from neighbor\n")
12223 {
12224 struct peer *peer;
12225
12226 if (argc == 2)
12227 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12228 else
12229 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12230
12231 if (! peer)
12232 return CMD_WARNING;
12233
12234 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12235 bgp_show_type_damp_neighbor, NULL);
12236 }
12237
12238 ALIAS (show_bgp_view_neighbor_damp,
12239 show_bgp_view_ipv6_neighbor_damp_cmd,
12240 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
12241 SHOW_STR
12242 BGP_STR
12243 "BGP view\n"
12244 "View name\n"
12245 "Address family\n"
12246 "Detailed information on TCP and BGP neighbor connections\n"
12247 "Neighbor to display information about\n"
12248 "Neighbor to display information about\n"
12249 "Neighbor on bgp configured interface\n"
12250 "Display the dampened routes received from neighbor\n")
12251
12252 DEFUN (show_bgp_view_neighbor_flap,
12253 show_bgp_view_neighbor_flap_cmd,
12254 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
12255 SHOW_STR
12256 BGP_STR
12257 "BGP view\n"
12258 "View name\n"
12259 "Detailed information on TCP and BGP neighbor connections\n"
12260 "Neighbor to display information about\n"
12261 "Neighbor to display information about\n"
12262 "Neighbor on bgp configured interface\n"
12263 "Display flap statistics of the routes learned from neighbor\n")
12264 {
12265 struct peer *peer;
12266
12267 if (argc == 2)
12268 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12269 else
12270 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12271
12272 if (! peer)
12273 return CMD_WARNING;
12274
12275 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12276 bgp_show_type_flap_neighbor, NULL);
12277 }
12278
12279 ALIAS (show_bgp_view_neighbor_flap,
12280 show_bgp_view_ipv6_neighbor_flap_cmd,
12281 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
12282 SHOW_STR
12283 BGP_STR
12284 "BGP view\n"
12285 "View name\n"
12286 "Address family\n"
12287 "Detailed information on TCP and BGP neighbor connections\n"
12288 "Neighbor to display information about\n"
12289 "Neighbor to display information about\n"
12290 "Neighbor on bgp configured interface\n"
12291 "Display flap statistics of the routes learned from neighbor\n")
12292
12293 ALIAS (show_bgp_view_neighbor_routes,
12294 show_bgp_neighbor_routes_cmd,
12295 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12296 SHOW_STR
12297 BGP_STR
12298 "Detailed information on TCP and BGP neighbor connections\n"
12299 "Neighbor to display information about\n"
12300 "Neighbor to display information about\n"
12301 "Neighbor on bgp configured interface\n"
12302 "Display routes learned from neighbor\n")
12303
12304
12305 ALIAS (show_bgp_view_neighbor_routes,
12306 show_bgp_ipv6_neighbor_routes_cmd,
12307 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12308 SHOW_STR
12309 BGP_STR
12310 "Address family\n"
12311 "Detailed information on TCP and BGP neighbor connections\n"
12312 "Neighbor to display information about\n"
12313 "Neighbor to display information about\n"
12314 "Neighbor on bgp configured interface\n"
12315 "Display routes learned from neighbor\n")
12316
12317 /* old command */
12318 ALIAS (show_bgp_view_neighbor_routes,
12319 ipv6_bgp_neighbor_routes_cmd,
12320 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12321 SHOW_STR
12322 IPV6_STR
12323 BGP_STR
12324 "Detailed information on TCP and BGP neighbor connections\n"
12325 "Neighbor to display information about\n"
12326 "Neighbor to display information about\n"
12327 "Neighbor on bgp configured interface\n"
12328 "Display routes learned from neighbor\n")
12329
12330 ALIAS (show_bgp_view_neighbor_routes_csv,
12331 show_bgp_neighbor_routes_csv_cmd,
12332 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
12333 SHOW_STR
12334 BGP_STR
12335 "Detailed information on TCP and BGP neighbor connections\n"
12336 "Neighbor to display information about\n"
12337 "Neighbor to display information about\n"
12338 "Neighbor on bgp configured interface\n"
12339 "Display routes learned from neighbor\n")
12340
12341
12342 ALIAS (show_bgp_view_neighbor_routes_csv,
12343 show_bgp_ipv6_neighbor_routes_csv_cmd,
12344 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
12345 SHOW_STR
12346 BGP_STR
12347 "Address family\n"
12348 "Detailed information on TCP and BGP neighbor connections\n"
12349 "Neighbor to display information about\n"
12350 "Neighbor to display information about\n"
12351 "Neighbor on bgp configured interface\n"
12352 "Display routes learned from neighbor\n")
12353
12354 /* old command */
12355 ALIAS (show_bgp_view_neighbor_routes_csv,
12356 ipv6_bgp_neighbor_routes_csv_cmd,
12357 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes csv",
12358 SHOW_STR
12359 IPV6_STR
12360 BGP_STR
12361 "Detailed information on TCP and BGP neighbor connections\n"
12362 "Neighbor to display information about\n"
12363 "Neighbor to display information about\n"
12364 "Neighbor on bgp configured interface\n"
12365 "Display routes learned from neighbor\n")
12366
12367 /* old command */
12368 DEFUN (ipv6_mbgp_neighbor_routes,
12369 ipv6_mbgp_neighbor_routes_cmd,
12370 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes",
12371 SHOW_STR
12372 IPV6_STR
12373 MBGP_STR
12374 "Detailed information on TCP and BGP neighbor connections\n"
12375 "Neighbor to display information about\n"
12376 "Neighbor to display information about\n"
12377 "Neighbor on bgp configured interface\n"
12378 "Display routes learned from neighbor\n")
12379 {
12380 struct peer *peer;
12381
12382 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12383 if (! peer)
12384 return CMD_WARNING;
12385
12386 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
12387 bgp_show_type_neighbor, NULL);
12388 }
12389
12390 ALIAS (show_bgp_view_neighbor_flap,
12391 show_bgp_neighbor_flap_cmd,
12392 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
12393 SHOW_STR
12394 BGP_STR
12395 "Detailed information on TCP and BGP neighbor connections\n"
12396 "Neighbor to display information about\n"
12397 "Neighbor to display information about\n"
12398 "Neighbor on bgp configured interface\n"
12399 "Display flap statistics of the routes learned from neighbor\n")
12400
12401 ALIAS (show_bgp_view_neighbor_flap,
12402 show_bgp_ipv6_neighbor_flap_cmd,
12403 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics",
12404 SHOW_STR
12405 BGP_STR
12406 "Address family\n"
12407 "Detailed information on TCP and BGP neighbor connections\n"
12408 "Neighbor to display information about\n"
12409 "Neighbor to display information about\n"
12410 "Neighbor on bgp configured interface\n"
12411 "Display flap statistics of the routes learned from neighbor\n")
12412
12413 ALIAS (show_bgp_view_neighbor_damp,
12414 show_bgp_neighbor_damp_cmd,
12415 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
12416 SHOW_STR
12417 BGP_STR
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 the dampened routes received from neighbor\n")
12423
12424 ALIAS (show_bgp_view_neighbor_damp,
12425 show_bgp_ipv6_neighbor_damp_cmd,
12426 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes",
12427 SHOW_STR
12428 BGP_STR
12429 "Address family\n"
12430 "Detailed information on TCP and BGP neighbor connections\n"
12431 "Neighbor to display information about\n"
12432 "Neighbor to display information about\n"
12433 "Neighbor on bgp configured interface\n"
12434 "Display the dampened routes received from neighbor\n")
12435
12436 DEFUN (show_bgp_view_rsclient,
12437 show_bgp_view_rsclient_cmd,
12438 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD)",
12439 SHOW_STR
12440 BGP_STR
12441 "BGP view\n"
12442 "View name\n"
12443 "Information about Route Server Client\n"
12444 NEIGHBOR_ADDR_STR3)
12445 {
12446 struct bgp_table *table;
12447 struct peer *peer;
12448
12449 if (argc == 2)
12450 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12451 else
12452 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12453
12454 if (! peer)
12455 return CMD_WARNING;
12456
12457 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
12458 {
12459 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12460 VTY_NEWLINE);
12461 return CMD_WARNING;
12462 }
12463
12464 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
12465 PEER_FLAG_RSERVER_CLIENT))
12466 {
12467 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12468 VTY_NEWLINE);
12469 return CMD_WARNING;
12470 }
12471
12472 table = peer->rib[AFI_IP6][SAFI_UNICAST];
12473
12474 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
12475 NULL, NULL);
12476 }
12477
12478 ALIAS (show_bgp_view_rsclient,
12479 show_bgp_rsclient_cmd,
12480 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD)",
12481 SHOW_STR
12482 BGP_STR
12483 "Information about Route Server Client\n"
12484 NEIGHBOR_ADDR_STR3)
12485
12486 DEFUN (show_bgp_view_ipv6_safi_rsclient,
12487 show_bgp_view_ipv6_safi_rsclient_cmd,
12488 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
12489 SHOW_STR
12490 BGP_STR
12491 "BGP view\n"
12492 "View name\n"
12493 "Address family\n"
12494 "Address Family modifier\n"
12495 "Address Family modifier\n"
12496 "Information about Route Server Client\n"
12497 NEIGHBOR_ADDR_STR3)
12498 {
12499 struct bgp_table *table;
12500 struct peer *peer;
12501 safi_t safi;
12502
12503 if (argc == 3) {
12504 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12505 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12506 } else {
12507 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12508 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12509 }
12510
12511 if (! peer)
12512 return CMD_WARNING;
12513
12514 if (! peer->afc[AFI_IP6][safi])
12515 {
12516 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12517 VTY_NEWLINE);
12518 return CMD_WARNING;
12519 }
12520
12521 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
12522 PEER_FLAG_RSERVER_CLIENT))
12523 {
12524 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12525 VTY_NEWLINE);
12526 return CMD_WARNING;
12527 }
12528
12529 table = peer->rib[AFI_IP6][safi];
12530
12531 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal,
12532 NULL, NULL);
12533 }
12534
12535 ALIAS (show_bgp_view_ipv6_safi_rsclient,
12536 show_bgp_ipv6_safi_rsclient_cmd,
12537 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD)",
12538 SHOW_STR
12539 BGP_STR
12540 "Address family\n"
12541 "Address Family modifier\n"
12542 "Address Family modifier\n"
12543 "Information about Route Server Client\n"
12544 NEIGHBOR_ADDR_STR3)
12545
12546 DEFUN (show_bgp_view_rsclient_route,
12547 show_bgp_view_rsclient_route_cmd,
12548 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
12549 SHOW_STR
12550 BGP_STR
12551 "BGP view\n"
12552 "View name\n"
12553 "Information about Route Server Client\n"
12554 NEIGHBOR_ADDR_STR3
12555 "Network in the BGP routing table to display\n")
12556 {
12557 struct bgp *bgp;
12558 struct peer *peer;
12559
12560 /* BGP structure lookup. */
12561 if (argc == 3)
12562 {
12563 bgp = bgp_lookup_by_name (argv[0]);
12564 if (bgp == NULL)
12565 {
12566 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12567 return CMD_WARNING;
12568 }
12569 }
12570 else
12571 {
12572 bgp = bgp_get_default ();
12573 if (bgp == NULL)
12574 {
12575 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12576 return CMD_WARNING;
12577 }
12578 }
12579
12580 if (argc == 3)
12581 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12582 else
12583 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12584
12585 if (! peer)
12586 return CMD_WARNING;
12587
12588 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
12589 {
12590 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12591 VTY_NEWLINE);
12592 return CMD_WARNING;
12593 }
12594
12595 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
12596 PEER_FLAG_RSERVER_CLIENT))
12597 {
12598 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12599 VTY_NEWLINE);
12600 return CMD_WARNING;
12601 }
12602
12603 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
12604 (argc == 3) ? argv[2] : argv[1],
12605 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
12606 }
12607
12608 ALIAS (show_bgp_view_rsclient_route,
12609 show_bgp_rsclient_route_cmd,
12610 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
12611 SHOW_STR
12612 BGP_STR
12613 "Information about Route Server Client\n"
12614 NEIGHBOR_ADDR_STR3
12615 "Network in the BGP routing table to display\n")
12616
12617 DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
12618 show_bgp_view_ipv6_safi_rsclient_route_cmd,
12619 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
12620 SHOW_STR
12621 BGP_STR
12622 "BGP view\n"
12623 "View name\n"
12624 "Address family\n"
12625 "Address Family modifier\n"
12626 "Address Family modifier\n"
12627 "Information about Route Server Client\n"
12628 NEIGHBOR_ADDR_STR3
12629 "Network in the BGP routing table to display\n")
12630 {
12631 struct bgp *bgp;
12632 struct peer *peer;
12633 safi_t safi;
12634
12635 /* BGP structure lookup. */
12636 if (argc == 4)
12637 {
12638 bgp = bgp_lookup_by_name (argv[0]);
12639 if (bgp == NULL)
12640 {
12641 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12642 return CMD_WARNING;
12643 }
12644 }
12645 else
12646 {
12647 bgp = bgp_get_default ();
12648 if (bgp == NULL)
12649 {
12650 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12651 return CMD_WARNING;
12652 }
12653 }
12654
12655 if (argc == 4) {
12656 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12657 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12658 } else {
12659 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12660 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12661 }
12662
12663 if (! peer)
12664 return CMD_WARNING;
12665
12666 if (! peer->afc[AFI_IP6][safi])
12667 {
12668 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12669 VTY_NEWLINE);
12670 return CMD_WARNING;
12671 }
12672
12673 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
12674 PEER_FLAG_RSERVER_CLIENT))
12675 {
12676 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12677 VTY_NEWLINE);
12678 return CMD_WARNING;
12679 }
12680
12681 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
12682 (argc == 4) ? argv[3] : argv[2],
12683 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL);
12684 }
12685
12686 ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
12687 show_bgp_ipv6_safi_rsclient_route_cmd,
12688 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X",
12689 SHOW_STR
12690 BGP_STR
12691 "Address family\n"
12692 "Address Family modifier\n"
12693 "Address Family modifier\n"
12694 "Information about Route Server Client\n"
12695 NEIGHBOR_ADDR_STR3
12696 "Network in the BGP routing table to display\n")
12697
12698 DEFUN (show_bgp_view_rsclient_prefix,
12699 show_bgp_view_rsclient_prefix_cmd,
12700 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
12701 SHOW_STR
12702 BGP_STR
12703 "BGP view\n"
12704 "View name\n"
12705 "Information about Route Server Client\n"
12706 NEIGHBOR_ADDR_STR3
12707 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
12708 {
12709 struct bgp *bgp;
12710 struct peer *peer;
12711
12712 /* BGP structure lookup. */
12713 if (argc == 3)
12714 {
12715 bgp = bgp_lookup_by_name (argv[0]);
12716 if (bgp == NULL)
12717 {
12718 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12719 return CMD_WARNING;
12720 }
12721 }
12722 else
12723 {
12724 bgp = bgp_get_default ();
12725 if (bgp == NULL)
12726 {
12727 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12728 return CMD_WARNING;
12729 }
12730 }
12731
12732 if (argc == 3)
12733 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12734 else
12735 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12736
12737 if (! peer)
12738 return CMD_WARNING;
12739
12740 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
12741 {
12742 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12743 VTY_NEWLINE);
12744 return CMD_WARNING;
12745 }
12746
12747 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
12748 PEER_FLAG_RSERVER_CLIENT))
12749 {
12750 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12751 VTY_NEWLINE);
12752 return CMD_WARNING;
12753 }
12754
12755 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
12756 (argc == 3) ? argv[2] : argv[1],
12757 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
12758 }
12759
12760 ALIAS (show_bgp_view_rsclient_prefix,
12761 show_bgp_rsclient_prefix_cmd,
12762 "show bgp rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
12763 SHOW_STR
12764 BGP_STR
12765 "Information about Route Server Client\n"
12766 NEIGHBOR_ADDR_STR3
12767 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
12768
12769 DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
12770 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
12771 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
12772 SHOW_STR
12773 BGP_STR
12774 "BGP view\n"
12775 "View name\n"
12776 "Address family\n"
12777 "Address Family modifier\n"
12778 "Address Family modifier\n"
12779 "Information about Route Server Client\n"
12780 NEIGHBOR_ADDR_STR3
12781 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
12782 {
12783 struct bgp *bgp;
12784 struct peer *peer;
12785 safi_t safi;
12786
12787 /* BGP structure lookup. */
12788 if (argc == 4)
12789 {
12790 bgp = bgp_lookup_by_name (argv[0]);
12791 if (bgp == NULL)
12792 {
12793 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12794 return CMD_WARNING;
12795 }
12796 }
12797 else
12798 {
12799 bgp = bgp_get_default ();
12800 if (bgp == NULL)
12801 {
12802 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
12803 return CMD_WARNING;
12804 }
12805 }
12806
12807 if (argc == 4) {
12808 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12809 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12810 } else {
12811 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12812 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12813 }
12814
12815 if (! peer)
12816 return CMD_WARNING;
12817
12818 if (! peer->afc[AFI_IP6][safi])
12819 {
12820 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12821 VTY_NEWLINE);
12822 return CMD_WARNING;
12823 }
12824
12825 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
12826 PEER_FLAG_RSERVER_CLIENT))
12827 {
12828 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12829 VTY_NEWLINE);
12830 return CMD_WARNING;
12831 }
12832
12833 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
12834 (argc == 4) ? argv[3] : argv[2],
12835 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL);
12836 }
12837
12838 ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
12839 show_bgp_ipv6_safi_rsclient_prefix_cmd,
12840 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X|WORD) X:X::X:X/M",
12841 SHOW_STR
12842 BGP_STR
12843 "Address family\n"
12844 "Address Family modifier\n"
12845 "Address Family modifier\n"
12846 "Information about Route Server Client\n"
12847 NEIGHBOR_ADDR_STR3
12848 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
12849
12850 #endif /* HAVE_IPV6 */
12851
12852 struct bgp_table *bgp_distance_table;
12853
12854 struct bgp_distance
12855 {
12856 /* Distance value for the IP source prefix. */
12857 u_char distance;
12858
12859 /* Name of the access-list to be matched. */
12860 char *access_list;
12861 };
12862
12863 static struct bgp_distance *
12864 bgp_distance_new (void)
12865 {
12866 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
12867 }
12868
12869 static void
12870 bgp_distance_free (struct bgp_distance *bdistance)
12871 {
12872 XFREE (MTYPE_BGP_DISTANCE, bdistance);
12873 }
12874
12875 static int
12876 bgp_distance_set (struct vty *vty, const char *distance_str,
12877 const char *ip_str, const char *access_list_str)
12878 {
12879 int ret;
12880 struct prefix_ipv4 p;
12881 u_char distance;
12882 struct bgp_node *rn;
12883 struct bgp_distance *bdistance;
12884
12885 ret = str2prefix_ipv4 (ip_str, &p);
12886 if (ret == 0)
12887 {
12888 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12889 return CMD_WARNING;
12890 }
12891
12892 distance = atoi (distance_str);
12893
12894 /* Get BGP distance node. */
12895 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
12896 if (rn->info)
12897 {
12898 bdistance = rn->info;
12899 bgp_unlock_node (rn);
12900 }
12901 else
12902 {
12903 bdistance = bgp_distance_new ();
12904 rn->info = bdistance;
12905 }
12906
12907 /* Set distance value. */
12908 bdistance->distance = distance;
12909
12910 /* Reset access-list configuration. */
12911 if (bdistance->access_list)
12912 {
12913 free (bdistance->access_list);
12914 bdistance->access_list = NULL;
12915 }
12916 if (access_list_str)
12917 bdistance->access_list = strdup (access_list_str);
12918
12919 return CMD_SUCCESS;
12920 }
12921
12922 static int
12923 bgp_distance_unset (struct vty *vty, const char *distance_str,
12924 const char *ip_str, const char *access_list_str)
12925 {
12926 int ret;
12927 struct prefix_ipv4 p;
12928 u_char distance;
12929 struct bgp_node *rn;
12930 struct bgp_distance *bdistance;
12931
12932 ret = str2prefix_ipv4 (ip_str, &p);
12933 if (ret == 0)
12934 {
12935 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12936 return CMD_WARNING;
12937 }
12938
12939 distance = atoi (distance_str);
12940
12941 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
12942 if (! rn)
12943 {
12944 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
12945 return CMD_WARNING;
12946 }
12947
12948 bdistance = rn->info;
12949
12950 if (bdistance->access_list)
12951 free (bdistance->access_list);
12952 bgp_distance_free (bdistance);
12953
12954 rn->info = NULL;
12955 bgp_unlock_node (rn);
12956 bgp_unlock_node (rn);
12957
12958 return CMD_SUCCESS;
12959 }
12960
12961 /* Apply BGP information to distance method. */
12962 u_char
12963 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
12964 {
12965 struct bgp_node *rn;
12966 struct prefix_ipv4 q;
12967 struct peer *peer;
12968 struct bgp_distance *bdistance;
12969 struct access_list *alist;
12970 struct bgp_static *bgp_static;
12971
12972 if (! bgp)
12973 return 0;
12974
12975 if (p->family != AF_INET)
12976 return 0;
12977
12978 peer = rinfo->peer;
12979
12980 if (peer->su.sa.sa_family != AF_INET)
12981 return 0;
12982
12983 memset (&q, 0, sizeof (struct prefix_ipv4));
12984 q.family = AF_INET;
12985 q.prefix = peer->su.sin.sin_addr;
12986 q.prefixlen = IPV4_MAX_BITLEN;
12987
12988 /* Check source address. */
12989 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
12990 if (rn)
12991 {
12992 bdistance = rn->info;
12993 bgp_unlock_node (rn);
12994
12995 if (bdistance->access_list)
12996 {
12997 alist = access_list_lookup (AFI_IP, bdistance->access_list);
12998 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
12999 return bdistance->distance;
13000 }
13001 else
13002 return bdistance->distance;
13003 }
13004
13005 /* Backdoor check. */
13006 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
13007 if (rn)
13008 {
13009 bgp_static = rn->info;
13010 bgp_unlock_node (rn);
13011
13012 if (bgp_static->backdoor)
13013 {
13014 if (bgp->distance_local)
13015 return bgp->distance_local;
13016 else
13017 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13018 }
13019 }
13020
13021 if (peer->sort == BGP_PEER_EBGP)
13022 {
13023 if (bgp->distance_ebgp)
13024 return bgp->distance_ebgp;
13025 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13026 }
13027 else
13028 {
13029 if (bgp->distance_ibgp)
13030 return bgp->distance_ibgp;
13031 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13032 }
13033 }
13034
13035 DEFUN (bgp_distance,
13036 bgp_distance_cmd,
13037 "distance bgp <1-255> <1-255> <1-255>",
13038 "Define an administrative distance\n"
13039 "BGP distance\n"
13040 "Distance for routes external to the AS\n"
13041 "Distance for routes internal to the AS\n"
13042 "Distance for local routes\n")
13043 {
13044 struct bgp *bgp;
13045
13046 bgp = vty->index;
13047
13048 bgp->distance_ebgp = atoi (argv[0]);
13049 bgp->distance_ibgp = atoi (argv[1]);
13050 bgp->distance_local = atoi (argv[2]);
13051 return CMD_SUCCESS;
13052 }
13053
13054 DEFUN (no_bgp_distance,
13055 no_bgp_distance_cmd,
13056 "no distance bgp <1-255> <1-255> <1-255>",
13057 NO_STR
13058 "Define an administrative distance\n"
13059 "BGP distance\n"
13060 "Distance for routes external to the AS\n"
13061 "Distance for routes internal to the AS\n"
13062 "Distance for local routes\n")
13063 {
13064 struct bgp *bgp;
13065
13066 bgp = vty->index;
13067
13068 bgp->distance_ebgp= 0;
13069 bgp->distance_ibgp = 0;
13070 bgp->distance_local = 0;
13071 return CMD_SUCCESS;
13072 }
13073
13074 ALIAS (no_bgp_distance,
13075 no_bgp_distance2_cmd,
13076 "no distance bgp",
13077 NO_STR
13078 "Define an administrative distance\n"
13079 "BGP distance\n")
13080
13081 DEFUN (bgp_distance_source,
13082 bgp_distance_source_cmd,
13083 "distance <1-255> A.B.C.D/M",
13084 "Define an administrative distance\n"
13085 "Administrative distance\n"
13086 "IP source prefix\n")
13087 {
13088 bgp_distance_set (vty, argv[0], argv[1], NULL);
13089 return CMD_SUCCESS;
13090 }
13091
13092 DEFUN (no_bgp_distance_source,
13093 no_bgp_distance_source_cmd,
13094 "no distance <1-255> A.B.C.D/M",
13095 NO_STR
13096 "Define an administrative distance\n"
13097 "Administrative distance\n"
13098 "IP source prefix\n")
13099 {
13100 bgp_distance_unset (vty, argv[0], argv[1], NULL);
13101 return CMD_SUCCESS;
13102 }
13103
13104 DEFUN (bgp_distance_source_access_list,
13105 bgp_distance_source_access_list_cmd,
13106 "distance <1-255> A.B.C.D/M WORD",
13107 "Define an administrative distance\n"
13108 "Administrative distance\n"
13109 "IP source prefix\n"
13110 "Access list name\n")
13111 {
13112 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
13113 return CMD_SUCCESS;
13114 }
13115
13116 DEFUN (no_bgp_distance_source_access_list,
13117 no_bgp_distance_source_access_list_cmd,
13118 "no distance <1-255> A.B.C.D/M WORD",
13119 NO_STR
13120 "Define an administrative distance\n"
13121 "Administrative distance\n"
13122 "IP source prefix\n"
13123 "Access list name\n")
13124 {
13125 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
13126 return CMD_SUCCESS;
13127 }
13128
13129 DEFUN (bgp_damp_set,
13130 bgp_damp_set_cmd,
13131 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13132 "BGP Specific commands\n"
13133 "Enable route-flap dampening\n"
13134 "Half-life time for the penalty\n"
13135 "Value to start reusing a route\n"
13136 "Value to start suppressing a route\n"
13137 "Maximum duration to suppress a stable route\n")
13138 {
13139 struct bgp *bgp;
13140 int half = DEFAULT_HALF_LIFE * 60;
13141 int reuse = DEFAULT_REUSE;
13142 int suppress = DEFAULT_SUPPRESS;
13143 int max = 4 * half;
13144
13145 if (argc == 4)
13146 {
13147 half = atoi (argv[0]) * 60;
13148 reuse = atoi (argv[1]);
13149 suppress = atoi (argv[2]);
13150 max = atoi (argv[3]) * 60;
13151 }
13152 else if (argc == 1)
13153 {
13154 half = atoi (argv[0]) * 60;
13155 max = 4 * half;
13156 }
13157
13158 bgp = vty->index;
13159 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
13160 half, reuse, suppress, max);
13161 }
13162
13163 ALIAS (bgp_damp_set,
13164 bgp_damp_set2_cmd,
13165 "bgp dampening <1-45>",
13166 "BGP Specific commands\n"
13167 "Enable route-flap dampening\n"
13168 "Half-life time for the penalty\n")
13169
13170 ALIAS (bgp_damp_set,
13171 bgp_damp_set3_cmd,
13172 "bgp dampening",
13173 "BGP Specific commands\n"
13174 "Enable route-flap dampening\n")
13175
13176 DEFUN (bgp_damp_unset,
13177 bgp_damp_unset_cmd,
13178 "no bgp dampening",
13179 NO_STR
13180 "BGP Specific commands\n"
13181 "Enable route-flap dampening\n")
13182 {
13183 struct bgp *bgp;
13184
13185 bgp = vty->index;
13186 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
13187 }
13188
13189 ALIAS (bgp_damp_unset,
13190 bgp_damp_unset2_cmd,
13191 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13192 NO_STR
13193 "BGP Specific commands\n"
13194 "Enable route-flap dampening\n"
13195 "Half-life time for the penalty\n"
13196 "Value to start reusing a route\n"
13197 "Value to start suppressing a route\n"
13198 "Maximum duration to suppress a stable route\n")
13199
13200 DEFUN (show_ip_bgp_dampened_paths,
13201 show_ip_bgp_dampened_paths_cmd,
13202 "show ip bgp dampened-paths",
13203 SHOW_STR
13204 IP_STR
13205 BGP_STR
13206 "Display paths suppressed due to dampening\n")
13207 {
13208 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
13209 NULL, NULL);
13210 }
13211
13212 DEFUN (show_ip_bgp_flap_statistics,
13213 show_ip_bgp_flap_statistics_cmd,
13214 "show ip bgp flap-statistics",
13215 SHOW_STR
13216 IP_STR
13217 BGP_STR
13218 "Display flap statistics of routes\n")
13219 {
13220 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
13221 bgp_show_type_flap_statistics, NULL, NULL);
13222 }
13223
13224 /* Display specified route of BGP table. */
13225 static int
13226 bgp_clear_damp_route (struct vty *vty, const char *view_name,
13227 const char *ip_str, afi_t afi, safi_t safi,
13228 struct prefix_rd *prd, int prefix_check)
13229 {
13230 int ret;
13231 struct prefix match;
13232 struct bgp_node *rn;
13233 struct bgp_node *rm;
13234 struct bgp_info *ri;
13235 struct bgp_info *ri_temp;
13236 struct bgp *bgp;
13237 struct bgp_table *table;
13238
13239 /* BGP structure lookup. */
13240 if (view_name)
13241 {
13242 bgp = bgp_lookup_by_name (view_name);
13243 if (bgp == NULL)
13244 {
13245 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
13246 return CMD_WARNING;
13247 }
13248 }
13249 else
13250 {
13251 bgp = bgp_get_default ();
13252 if (bgp == NULL)
13253 {
13254 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
13255 return CMD_WARNING;
13256 }
13257 }
13258
13259 /* Check IP address argument. */
13260 ret = str2prefix (ip_str, &match);
13261 if (! ret)
13262 {
13263 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
13264 return CMD_WARNING;
13265 }
13266
13267 match.family = afi2family (afi);
13268
13269 if (safi == SAFI_MPLS_VPN)
13270 {
13271 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
13272 {
13273 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
13274 continue;
13275
13276 if ((table = rn->info) != NULL)
13277 if ((rm = bgp_node_match (table, &match)) != NULL)
13278 {
13279 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
13280 {
13281 ri = rm->info;
13282 while (ri)
13283 {
13284 if (ri->extra && ri->extra->damp_info)
13285 {
13286 ri_temp = ri->next;
13287 bgp_damp_info_free (ri->extra->damp_info, 1);
13288 ri = ri_temp;
13289 }
13290 else
13291 ri = ri->next;
13292 }
13293 }
13294
13295 bgp_unlock_node (rm);
13296 }
13297 }
13298 }
13299 else
13300 {
13301 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
13302 {
13303 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
13304 {
13305 ri = rn->info;
13306 while (ri)
13307 {
13308 if (ri->extra && ri->extra->damp_info)
13309 {
13310 ri_temp = ri->next;
13311 bgp_damp_info_free (ri->extra->damp_info, 1);
13312 ri = ri_temp;
13313 }
13314 else
13315 ri = ri->next;
13316 }
13317 }
13318
13319 bgp_unlock_node (rn);
13320 }
13321 }
13322
13323 return CMD_SUCCESS;
13324 }
13325
13326 DEFUN (clear_ip_bgp_dampening,
13327 clear_ip_bgp_dampening_cmd,
13328 "clear ip bgp dampening",
13329 CLEAR_STR
13330 IP_STR
13331 BGP_STR
13332 "Clear route flap dampening information\n")
13333 {
13334 bgp_damp_info_clean ();
13335 return CMD_SUCCESS;
13336 }
13337
13338 DEFUN (clear_ip_bgp_dampening_prefix,
13339 clear_ip_bgp_dampening_prefix_cmd,
13340 "clear ip bgp dampening A.B.C.D/M",
13341 CLEAR_STR
13342 IP_STR
13343 BGP_STR
13344 "Clear route flap dampening information\n"
13345 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13346 {
13347 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13348 SAFI_UNICAST, NULL, 1);
13349 }
13350
13351 DEFUN (clear_ip_bgp_dampening_address,
13352 clear_ip_bgp_dampening_address_cmd,
13353 "clear ip bgp dampening A.B.C.D",
13354 CLEAR_STR
13355 IP_STR
13356 BGP_STR
13357 "Clear route flap dampening information\n"
13358 "Network to clear damping information\n")
13359 {
13360 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13361 SAFI_UNICAST, NULL, 0);
13362 }
13363
13364 DEFUN (clear_ip_bgp_dampening_address_mask,
13365 clear_ip_bgp_dampening_address_mask_cmd,
13366 "clear ip bgp dampening A.B.C.D A.B.C.D",
13367 CLEAR_STR
13368 IP_STR
13369 BGP_STR
13370 "Clear route flap dampening information\n"
13371 "Network to clear damping information\n"
13372 "Network mask\n")
13373 {
13374 int ret;
13375 char prefix_str[BUFSIZ];
13376
13377 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
13378 if (! ret)
13379 {
13380 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
13381 return CMD_WARNING;
13382 }
13383
13384 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
13385 SAFI_UNICAST, NULL, 0);
13386 }
13387
13388 static int
13389 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
13390 afi_t afi, safi_t safi, int *write)
13391 {
13392 struct bgp_node *prn;
13393 struct bgp_node *rn;
13394 struct bgp_table *table;
13395 struct prefix *p;
13396 struct prefix_rd *prd;
13397 struct bgp_static *bgp_static;
13398 u_int32_t label;
13399 char buf[SU_ADDRSTRLEN];
13400 char rdbuf[RD_ADDRSTRLEN];
13401
13402 /* Network configuration. */
13403 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
13404 if ((table = prn->info) != NULL)
13405 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
13406 if ((bgp_static = rn->info) != NULL)
13407 {
13408 p = &rn->p;
13409 prd = (struct prefix_rd *) &prn->p;
13410
13411 /* "address-family" display. */
13412 bgp_config_write_family_header (vty, afi, safi, write);
13413
13414 /* "network" configuration display. */
13415 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
13416 label = decode_label (bgp_static->tag);
13417
13418 vty_out (vty, " network %s/%d rd %s tag %d",
13419 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13420 p->prefixlen,
13421 rdbuf, label);
13422 vty_out (vty, "%s", VTY_NEWLINE);
13423 }
13424 return 0;
13425 }
13426
13427 /* Configuration of static route announcement and aggregate
13428 information. */
13429 int
13430 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
13431 afi_t afi, safi_t safi, int *write)
13432 {
13433 struct bgp_node *rn;
13434 struct prefix *p;
13435 struct bgp_static *bgp_static;
13436 struct bgp_aggregate *bgp_aggregate;
13437 char buf[SU_ADDRSTRLEN];
13438
13439 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
13440 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
13441
13442 /* Network configuration. */
13443 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
13444 if ((bgp_static = rn->info) != NULL)
13445 {
13446 p = &rn->p;
13447
13448 /* "address-family" display. */
13449 bgp_config_write_family_header (vty, afi, safi, write);
13450
13451 /* "network" configuration display. */
13452 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13453 {
13454 u_int32_t destination;
13455 struct in_addr netmask;
13456
13457 destination = ntohl (p->u.prefix4.s_addr);
13458 masklen2ip (p->prefixlen, &netmask);
13459 vty_out (vty, " network %s",
13460 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
13461
13462 if ((IN_CLASSC (destination) && p->prefixlen == 24)
13463 || (IN_CLASSB (destination) && p->prefixlen == 16)
13464 || (IN_CLASSA (destination) && p->prefixlen == 8)
13465 || p->u.prefix4.s_addr == 0)
13466 {
13467 /* Natural mask is not display. */
13468 }
13469 else
13470 vty_out (vty, " mask %s", inet_ntoa (netmask));
13471 }
13472 else
13473 {
13474 vty_out (vty, " network %s/%d",
13475 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13476 p->prefixlen);
13477 }
13478
13479 if (bgp_static->rmap.name)
13480 vty_out (vty, " route-map %s", bgp_static->rmap.name);
13481 else
13482 {
13483 if (bgp_static->backdoor)
13484 vty_out (vty, " backdoor");
13485 }
13486
13487 vty_out (vty, "%s", VTY_NEWLINE);
13488 }
13489
13490 /* Aggregate-address configuration. */
13491 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
13492 if ((bgp_aggregate = rn->info) != NULL)
13493 {
13494 p = &rn->p;
13495
13496 /* "address-family" display. */
13497 bgp_config_write_family_header (vty, afi, safi, write);
13498
13499 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13500 {
13501 struct in_addr netmask;
13502
13503 masklen2ip (p->prefixlen, &netmask);
13504 vty_out (vty, " aggregate-address %s %s",
13505 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13506 inet_ntoa (netmask));
13507 }
13508 else
13509 {
13510 vty_out (vty, " aggregate-address %s/%d",
13511 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13512 p->prefixlen);
13513 }
13514
13515 if (bgp_aggregate->as_set)
13516 vty_out (vty, " as-set");
13517
13518 if (bgp_aggregate->summary_only)
13519 vty_out (vty, " summary-only");
13520
13521 vty_out (vty, "%s", VTY_NEWLINE);
13522 }
13523
13524 return 0;
13525 }
13526
13527 int
13528 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
13529 {
13530 struct bgp_node *rn;
13531 struct bgp_distance *bdistance;
13532
13533 /* Distance configuration. */
13534 if (bgp->distance_ebgp
13535 && bgp->distance_ibgp
13536 && bgp->distance_local
13537 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
13538 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
13539 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
13540 vty_out (vty, " distance bgp %d %d %d%s",
13541 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
13542 VTY_NEWLINE);
13543
13544 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
13545 if ((bdistance = rn->info) != NULL)
13546 {
13547 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
13548 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
13549 bdistance->access_list ? bdistance->access_list : "",
13550 VTY_NEWLINE);
13551 }
13552
13553 return 0;
13554 }
13555
13556 /* Allocate routing table structure and install commands. */
13557 void
13558 bgp_route_init (void)
13559 {
13560 /* Init BGP distance table. */
13561 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
13562
13563 /* IPv4 BGP commands. */
13564 install_element (BGP_NODE, &bgp_table_map_cmd);
13565 install_element (BGP_NODE, &bgp_network_cmd);
13566 install_element (BGP_NODE, &bgp_network_mask_cmd);
13567 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
13568 install_element (BGP_NODE, &bgp_network_route_map_cmd);
13569 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
13570 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
13571 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
13572 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
13573 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
13574 install_element (BGP_NODE, &no_bgp_table_map_cmd);
13575 install_element (BGP_NODE, &no_bgp_network_cmd);
13576 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
13577 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
13578 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
13579 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
13580 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13581 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
13582 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
13583 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
13584
13585 install_element (BGP_NODE, &aggregate_address_cmd);
13586 install_element (BGP_NODE, &aggregate_address_mask_cmd);
13587 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
13588 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
13589 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
13590 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
13591 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
13592 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
13593 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
13594 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
13595 install_element (BGP_NODE, &no_aggregate_address_cmd);
13596 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
13597 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
13598 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
13599 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
13600 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
13601 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
13602 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
13603 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13604 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13605
13606 /* IPv4 unicast configuration. */
13607 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
13608 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
13609 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
13610 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
13611 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
13612 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
13613 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
13614 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
13615 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
13616 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
13617 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
13618 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
13619 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
13620 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13621
13622 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
13623 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
13624 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
13625 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
13626 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
13627 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
13628 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
13629 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
13630 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
13631 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
13632 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
13633 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
13634 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
13635 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
13636 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
13637 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
13638 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
13639 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
13640 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13641 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13642
13643 /* IPv4 multicast configuration. */
13644 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
13645 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
13646 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
13647 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
13648 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
13649 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
13650 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
13651 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
13652 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
13653 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
13654 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
13655 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
13656 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
13657 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13658 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
13659 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
13660 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
13661 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
13662 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
13663 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
13664 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
13665 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
13666 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
13667 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
13668 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
13669 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
13670 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
13671 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
13672 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
13673 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
13674 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
13675 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
13676 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13677 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13678
13679 install_element (VIEW_NODE, &show_ip_bgp_cmd);
13680 install_element (VIEW_NODE, &show_ip_bgp_csv_cmd);
13681 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
13682 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
13683 install_element (VIEW_NODE, &show_bgp_ipv4_safi_csv_cmd);
13684 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
13685 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
13686 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
13687 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
13688 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
13689 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
13690 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13691 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
13692 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
13693 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13694 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
13695 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
13696 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
13697 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13698 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13699 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
13700 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
13701 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
13702 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
13703 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
13704 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
13705 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
13706 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
13707 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
13708 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
13709 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
13710 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
13711 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
13712 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
13713 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
13714 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
13715 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
13716 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
13717 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
13718 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
13719 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
13720 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
13721 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
13722 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13723 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
13724 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
13725 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
13726 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
13727 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
13728 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
13729 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
13730 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
13731 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13732 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13733 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13734 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13735 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
13736 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
13737 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
13738 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
13739 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
13740 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
13741 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
13742 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
13743 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_csv_cmd);
13744 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_csv_rmap_cmd);
13745 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
13746 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
13747 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
13748 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
13749 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
13750 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
13751 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
13752 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
13753 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_csv_cmd);
13754 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
13755 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
13756 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
13757 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
13758 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
13759 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
13760 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
13761 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
13762 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
13763 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
13764 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
13765 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
13766 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
13767 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
13768 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
13769 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
13770 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
13771 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
13772 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
13773 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
13774 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
13775 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13776 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
13777 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
13778 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
13779 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
13780 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
13781 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
13782 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
13783
13784 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
13785 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
13786 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
13787 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
13788 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
13789 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
13790 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13791 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
13792 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
13793 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13794 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
13795 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
13796 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
13797 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13798 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13799 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
13800 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
13801 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
13802 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
13803 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
13804 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
13805 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
13806 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
13807 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
13808 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
13809 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13810 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
13811 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
13812 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
13813 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
13814 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
13815 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
13816 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
13817 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
13818 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13819 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13820 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13821 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13822 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
13823 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
13824 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
13825 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
13826 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
13827 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
13828 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
13829 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
13830
13831 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
13832 install_element (ENABLE_NODE, &show_ip_bgp_csv_cmd);
13833 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
13834 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
13835 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_csv_cmd);
13836 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
13837 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
13838 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
13839 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
13840 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
13841 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
13842 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13843 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
13844 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
13845 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13846 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
13847 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
13848 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
13849 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13850 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13851 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
13852 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
13853 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
13854 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
13855 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
13856 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
13857 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
13858 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
13859 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
13860 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
13861 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
13862 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
13863 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
13864 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
13865 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
13866 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
13867 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
13868 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
13869 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
13870 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
13871 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
13872 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
13873 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
13874 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13875 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
13876 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
13877 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
13878 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
13879 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
13880 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
13881 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
13882 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
13883 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13884 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13885 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13886 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13887 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
13888 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
13889 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
13890 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
13891 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
13892 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
13893 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
13894 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_csv_cmd);
13895 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
13896 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_csv_rmap_cmd);
13897 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
13898 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
13899 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
13900 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
13901 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
13902 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
13903 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
13904 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
13905 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_csv_cmd);
13906 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
13907 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
13908 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
13909 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
13910 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
13911 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
13912 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
13913 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
13914 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
13915 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
13916 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
13917 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
13918 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
13919 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
13920 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
13921 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
13922 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
13923 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
13924 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
13925 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
13926 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
13927 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13928 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
13929 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
13930 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
13931 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
13932 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
13933 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
13934 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
13935
13936 /* BGP dampening clear commands */
13937 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
13938 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
13939 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
13940 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
13941
13942 /* prefix count */
13943 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
13944 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
13945 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
13946 #ifdef HAVE_IPV6
13947 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
13948
13949 /* New config IPv6 BGP commands. */
13950 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
13951 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
13952 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
13953 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
13954 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
13955 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
13956
13957 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
13958 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
13959 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
13960 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
13961
13962 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
13963 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
13964
13965 /* Old config IPv6 BGP commands. */
13966 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
13967 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
13968
13969 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
13970 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
13971 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
13972 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
13973
13974 install_element (VIEW_NODE, &show_bgp_cmd);
13975 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
13976 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
13977 install_element (VIEW_NODE, &show_bgp_ipv6_safi_csv_cmd);
13978 install_element (VIEW_NODE, &show_bgp_route_cmd);
13979 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
13980 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
13981 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
13982 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
13983 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
13984 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
13985 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
13986 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
13987 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
13988 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
13989 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
13990 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
13991 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
13992 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
13993 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
13994 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
13995 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
13996 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
13997 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
13998 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
13999 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14000 install_element (VIEW_NODE, &show_bgp_community_cmd);
14001 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14002 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14003 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14004 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14005 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14006 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14007 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14008 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14009 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14010 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14011 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14012 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14013 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14014 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14015 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14016 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14017 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14018 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14019 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14020 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14021 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14022 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14023 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14024 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_csv_cmd);
14025 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_csv_cmd);
14026 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14027 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14028 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14029 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14030 install_element (VIEW_NODE, &show_bgp_neighbor_routes_csv_cmd);
14031 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_csv_cmd);
14032 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14033 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14034 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14035 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14036 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14037 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14038 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
14039 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
14040 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
14041 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
14042 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
14043 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
14044 install_element (VIEW_NODE, &show_bgp_view_cmd);
14045 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
14046 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
14047 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
14048 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
14049 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
14050 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
14051 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
14052 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_csv_cmd);
14053 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd);
14054 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
14055 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
14056 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
14057 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_csv_cmd);
14058 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
14059 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
14060 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
14061 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
14062 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
14063 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
14064 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
14065 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
14066 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
14067 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
14068 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
14069 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
14070 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
14071
14072 /* Restricted:
14073 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
14074 */
14075 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
14076 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
14077 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
14078 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
14079 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14080 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14081 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
14082 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
14083 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14084 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
14085 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14086 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14087 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
14088 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
14089 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
14090 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
14091 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
14092 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
14093 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
14094 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
14095 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
14096 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
14097 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
14098 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
14099 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
14100 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
14101 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
14102 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
14103 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
14104 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
14105 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
14106 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
14107 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
14108 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
14109 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
14110 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
14111 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
14112 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
14113 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
14114 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
14115 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
14116 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
14117
14118 install_element (ENABLE_NODE, &show_bgp_cmd);
14119 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
14120 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
14121 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_csv_cmd);
14122 install_element (ENABLE_NODE, &show_bgp_route_cmd);
14123 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
14124 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
14125 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
14126 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14127 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14128 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
14129 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
14130 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14131 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14132 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
14133 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14134 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
14135 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
14136 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
14137 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
14138 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
14139 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
14140 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
14141 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
14142 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
14143 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
14144 install_element (ENABLE_NODE, &show_bgp_community_cmd);
14145 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
14146 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
14147 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
14148 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
14149 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
14150 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
14151 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
14152 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
14153 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
14154 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
14155 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
14156 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
14157 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
14158 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
14159 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
14160 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
14161 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
14162 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
14163 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14164 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
14165 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14166 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
14167 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14168 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_csv_cmd);
14169 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_csv_cmd);
14170 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
14171 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14172 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
14173 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14174 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_csv_cmd);
14175 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_csv_cmd);
14176 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14177 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14178 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
14179 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14180 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
14181 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14182 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
14183 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
14184 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
14185 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
14186 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
14187 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
14188 install_element (ENABLE_NODE, &show_bgp_view_cmd);
14189 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
14190 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
14191 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
14192 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
14193 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
14194 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
14195 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
14196 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_csv_cmd);
14197 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_csv_cmd);
14198 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
14199 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
14200 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
14201 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_csv_cmd);
14202 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
14203 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
14204 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
14205 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
14206 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
14207 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
14208 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
14209 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
14210 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
14211 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
14212 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
14213 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
14214 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
14215
14216 /* Statistics */
14217 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
14218 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
14219 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
14220 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
14221
14222 /* old command */
14223 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14224 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14225 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
14226 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
14227 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
14228 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
14229 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
14230 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
14231 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
14232 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
14233 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
14234 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
14235 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
14236 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
14237 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
14238 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
14239 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14240 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14241 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
14242 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
14243 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
14244 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
14245 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14246 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
14247 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
14248 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
14249 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
14250 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
14251 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
14252 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
14253 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14254 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14255 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14256 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
14257 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14258 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14259
14260 /* old command */
14261 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
14262 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
14263 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
14264 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
14265 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
14266 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
14267 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
14268 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
14269 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
14270 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
14271 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
14272 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
14273 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
14274 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
14275 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
14276 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
14277 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14278 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14279 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
14280 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
14281 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
14282 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
14283 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14284 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
14285 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
14286 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
14287 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
14288 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
14289 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
14290 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
14291 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14292 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14293 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14294 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
14295 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14296 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14297
14298 /* old command */
14299 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14300 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14301 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14302 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14303
14304 /* old command */
14305 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14306 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14307 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14308 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14309
14310 /* old command */
14311 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
14312 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
14313 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14314 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14315 #endif /* HAVE_IPV6 */
14316
14317 install_element (BGP_NODE, &bgp_distance_cmd);
14318 install_element (BGP_NODE, &no_bgp_distance_cmd);
14319 install_element (BGP_NODE, &no_bgp_distance2_cmd);
14320 install_element (BGP_NODE, &bgp_distance_source_cmd);
14321 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
14322 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
14323 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
14324
14325 install_element (BGP_NODE, &bgp_damp_set_cmd);
14326 install_element (BGP_NODE, &bgp_damp_set2_cmd);
14327 install_element (BGP_NODE, &bgp_damp_set3_cmd);
14328 install_element (BGP_NODE, &bgp_damp_unset_cmd);
14329 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
14330 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
14331 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
14332 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
14333 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
14334 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
14335
14336 /* Deprecated AS-Pathlimit commands */
14337 install_element (BGP_NODE, &bgp_network_ttl_cmd);
14338 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
14339 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
14340 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
14341 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
14342 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
14343
14344 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
14345 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
14346 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
14347 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
14348 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
14349 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
14350
14351 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
14352 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
14353 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
14354 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
14355 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
14356 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
14357
14358 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
14359 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
14360 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
14361 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
14362 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
14363 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
14364
14365 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
14366 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
14367 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
14368 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
14369 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
14370 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
14371
14372 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
14373 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
14374 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
14375 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
14376 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
14377 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
14378
14379 #ifdef HAVE_IPV6
14380 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
14381 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
14382 #endif
14383 }
14384
14385 void
14386 bgp_route_finish (void)
14387 {
14388 bgp_table_unlock (bgp_distance_table);
14389 bgp_distance_table = NULL;
14390 }