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