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