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