]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
Quagga: prefix2str fixup
[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 "lib/json.h"
24 #include "prefix.h"
25 #include "linklist.h"
26 #include "memory.h"
27 #include "command.h"
28 #include "stream.h"
29 #include "filter.h"
30 #include "str.h"
31 #include "log.h"
32 #include "routemap.h"
33 #include "buffer.h"
34 #include "sockunion.h"
35 #include "plist.h"
36 #include "thread.h"
37 #include "workqueue.h"
38 #include "queue.h"
39 #include "memory.h"
40
41 #include "bgpd/bgpd.h"
42 #include "bgpd/bgp_table.h"
43 #include "bgpd/bgp_route.h"
44 #include "bgpd/bgp_attr.h"
45 #include "bgpd/bgp_debug.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_regex.h"
48 #include "bgpd/bgp_community.h"
49 #include "bgpd/bgp_ecommunity.h"
50 #include "bgpd/bgp_clist.h"
51 #include "bgpd/bgp_packet.h"
52 #include "bgpd/bgp_filter.h"
53 #include "bgpd/bgp_fsm.h"
54 #include "bgpd/bgp_mplsvpn.h"
55 #include "bgpd/bgp_nexthop.h"
56 #include "bgpd/bgp_damp.h"
57 #include "bgpd/bgp_advertise.h"
58 #include "bgpd/bgp_zebra.h"
59 #include "bgpd/bgp_vty.h"
60 #include "bgpd/bgp_mpath.h"
61 #include "bgpd/bgp_nht.h"
62 #include "bgpd/bgp_updgrp.h"
63
64 /* Extern from bgp_dump.c */
65 extern const char *bgp_origin_str[];
66 extern const char *bgp_origin_long_str[];
67
68 struct bgp_node *
69 bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
70 struct prefix_rd *prd)
71 {
72 struct bgp_node *rn;
73 struct bgp_node *prn = NULL;
74
75 assert (table);
76 if (!table)
77 return NULL;
78
79 if (safi == SAFI_MPLS_VPN)
80 {
81 prn = bgp_node_get (table, (struct prefix *) prd);
82
83 if (prn->info == NULL)
84 prn->info = bgp_table_init (afi, safi);
85 else
86 bgp_unlock_node (prn);
87 table = prn->info;
88 }
89
90 rn = bgp_node_get (table, p);
91
92 if (safi == SAFI_MPLS_VPN)
93 rn->prn = prn;
94
95 return rn;
96 }
97
98 /* Allocate bgp_info_extra */
99 static struct bgp_info_extra *
100 bgp_info_extra_new (void)
101 {
102 struct bgp_info_extra *new;
103 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
104 return new;
105 }
106
107 static void
108 bgp_info_extra_free (struct bgp_info_extra **extra)
109 {
110 if (extra && *extra)
111 {
112 if ((*extra)->damp_info)
113 bgp_damp_info_free ((*extra)->damp_info, 0);
114
115 (*extra)->damp_info = NULL;
116
117 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
118
119 *extra = NULL;
120 }
121 }
122
123 /* Get bgp_info extra information for the given bgp_info, lazy allocated
124 * if required.
125 */
126 struct bgp_info_extra *
127 bgp_info_extra_get (struct bgp_info *ri)
128 {
129 if (!ri->extra)
130 ri->extra = bgp_info_extra_new();
131 return ri->extra;
132 }
133
134 /* Free bgp route information. */
135 static void
136 bgp_info_free (struct bgp_info *binfo)
137 {
138 if (binfo->attr)
139 bgp_attr_unintern (&binfo->attr);
140
141 bgp_unlink_nexthop(binfo);
142 bgp_info_extra_free (&binfo->extra);
143 bgp_info_mpath_free (&binfo->mpath);
144
145 peer_unlock (binfo->peer); /* bgp_info peer reference */
146
147 XFREE (MTYPE_BGP_ROUTE, binfo);
148 }
149
150 struct bgp_info *
151 bgp_info_lock (struct bgp_info *binfo)
152 {
153 binfo->lock++;
154 return binfo;
155 }
156
157 struct bgp_info *
158 bgp_info_unlock (struct bgp_info *binfo)
159 {
160 assert (binfo && binfo->lock > 0);
161 binfo->lock--;
162
163 if (binfo->lock == 0)
164 {
165 #if 0
166 zlog_debug ("%s: unlocked and freeing", __func__);
167 zlog_backtrace (LOG_DEBUG);
168 #endif
169 bgp_info_free (binfo);
170 return NULL;
171 }
172
173 #if 0
174 if (binfo->lock == 1)
175 {
176 zlog_debug ("%s: unlocked to 1", __func__);
177 zlog_backtrace (LOG_DEBUG);
178 }
179 #endif
180
181 return binfo;
182 }
183
184 void
185 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
186 {
187 struct bgp_info *top;
188
189 top = rn->info;
190
191 ri->next = rn->info;
192 ri->prev = NULL;
193 if (top)
194 top->prev = ri;
195 rn->info = ri;
196
197 bgp_info_lock (ri);
198 bgp_lock_node (rn);
199 peer_lock (ri->peer); /* bgp_info peer reference */
200 }
201
202 /* Do the actual removal of info from RIB, for use by bgp_process
203 completion callback *only* */
204 static void
205 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
206 {
207 if (ri->next)
208 ri->next->prev = ri->prev;
209 if (ri->prev)
210 ri->prev->next = ri->next;
211 else
212 rn->info = ri->next;
213
214 bgp_info_mpath_dequeue (ri);
215 bgp_info_unlock (ri);
216 bgp_unlock_node (rn);
217 }
218
219 void
220 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
221 {
222 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
223 /* set of previous already took care of pcount */
224 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
225 }
226
227 /* undo the effects of a previous call to bgp_info_delete; typically
228 called when a route is deleted and then quickly re-added before the
229 deletion has been processed */
230 static void
231 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
232 {
233 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
234 /* unset of previous already took care of pcount */
235 SET_FLAG (ri->flags, BGP_INFO_VALID);
236 }
237
238 /* Adjust pcount as required */
239 static void
240 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
241 {
242 struct bgp_table *table;
243
244 assert (rn && bgp_node_table (rn));
245 assert (ri && ri->peer && ri->peer->bgp);
246
247 table = bgp_node_table (rn);
248
249 if (ri->peer == ri->peer->bgp->peer_self)
250 return;
251
252 if (!BGP_INFO_COUNTABLE (ri)
253 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
254 {
255
256 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
257
258 /* slight hack, but more robust against errors. */
259 if (ri->peer->pcount[table->afi][table->safi])
260 ri->peer->pcount[table->afi][table->safi]--;
261 else
262 {
263 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
264 __func__, ri->peer->host);
265 zlog_backtrace (LOG_WARNING);
266 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
267 }
268 }
269 else if (BGP_INFO_COUNTABLE (ri)
270 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
271 {
272 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
273 ri->peer->pcount[table->afi][table->safi]++;
274 }
275 }
276
277
278 /* Set/unset bgp_info flags, adjusting any other state as needed.
279 * This is here primarily to keep prefix-count in check.
280 */
281 void
282 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
283 {
284 SET_FLAG (ri->flags, flag);
285
286 /* early bath if we know it's not a flag that changes countability state */
287 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
288 return;
289
290 bgp_pcount_adjust (rn, ri);
291 }
292
293 void
294 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
295 {
296 UNSET_FLAG (ri->flags, flag);
297
298 /* early bath if we know it's not a flag that changes countability state */
299 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
300 return;
301
302 bgp_pcount_adjust (rn, ri);
303 }
304
305 /* Get MED value. If MED value is missing and "bgp bestpath
306 missing-as-worst" is specified, treat it as the worst value. */
307 static u_int32_t
308 bgp_med_value (struct attr *attr, struct bgp *bgp)
309 {
310 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
311 return attr->med;
312 else
313 {
314 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
315 return BGP_MED_MAX;
316 else
317 return 0;
318 }
319 }
320
321 /* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
322 static int
323 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
324 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
325 char *pfx_buf)
326 {
327 struct attr *newattr, *existattr;
328 struct attr_extra *newattre, *existattre;
329 bgp_peer_sort_t new_sort;
330 bgp_peer_sort_t exist_sort;
331 u_int32_t new_pref;
332 u_int32_t exist_pref;
333 u_int32_t new_med;
334 u_int32_t exist_med;
335 u_int32_t new_weight;
336 u_int32_t exist_weight;
337 uint32_t newm, existm;
338 struct in_addr new_id;
339 struct in_addr exist_id;
340 int new_cluster;
341 int exist_cluster;
342 int internal_as_route;
343 int confed_as_route;
344 int ret;
345
346 *paths_eq = 0;
347
348 /* 0. Null check. */
349 if (new == NULL)
350 {
351 if (debug)
352 zlog_debug("%s: new is NULL", pfx_buf);
353 return 0;
354 }
355
356 if (exist == NULL)
357 {
358 if (debug)
359 zlog_debug("%s: path %s is the initial bestpath",
360 pfx_buf, new->peer->host);
361 return 1;
362 }
363
364 newattr = new->attr;
365 existattr = exist->attr;
366 newattre = newattr->extra;
367 existattre = existattr->extra;
368
369 /* 1. Weight check. */
370 new_weight = exist_weight = 0;
371
372 if (newattre)
373 new_weight = newattre->weight;
374 if (existattre)
375 exist_weight = existattre->weight;
376
377 if (new_weight > exist_weight)
378 {
379 if (debug)
380 zlog_debug("%s: path %s wins over path %s due to weight %d > %d",
381 pfx_buf, new->peer->host, exist->peer->host, new_weight,
382 exist_weight);
383 return 1;
384 }
385
386 if (new_weight < exist_weight)
387 {
388 if (debug)
389 zlog_debug("%s: path %s loses to path %s due to weight %d < %d",
390 pfx_buf, new->peer->host, exist->peer->host, new_weight,
391 exist_weight);
392 return 0;
393 }
394
395 /* 2. Local preference check. */
396 new_pref = exist_pref = bgp->default_local_pref;
397
398 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
399 new_pref = newattr->local_pref;
400 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
401 exist_pref = existattr->local_pref;
402
403 if (new_pref > exist_pref)
404 {
405 if (debug)
406 zlog_debug("%s: path %s wins over path %s due to localpref %d > %d",
407 pfx_buf, new->peer->host, exist->peer->host, new_pref,
408 exist_pref);
409 return 1;
410 }
411
412 if (new_pref < exist_pref)
413 {
414 if (debug)
415 zlog_debug("%s: path %s loses to path %s due to localpref %d < %d",
416 pfx_buf, new->peer->host, exist->peer->host, new_pref,
417 exist_pref);
418 return 0;
419 }
420
421 /* 3. Local route check. We prefer:
422 * - BGP_ROUTE_STATIC
423 * - BGP_ROUTE_AGGREGATE
424 * - BGP_ROUTE_REDISTRIBUTE
425 */
426 if (! (new->sub_type == BGP_ROUTE_NORMAL))
427 {
428 if (debug)
429 zlog_debug("%s: path %s wins over path %s due to preferred BGP_ROUTE type",
430 pfx_buf, new->peer->host, exist->peer->host);
431 return 1;
432 }
433
434 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
435 {
436 if (debug)
437 zlog_debug("%s: path %s loses to path %s due to preferred BGP_ROUTE type",
438 pfx_buf, new->peer->host, exist->peer->host);
439 return 0;
440 }
441
442 /* 4. AS path length check. */
443 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
444 {
445 int exist_hops = aspath_count_hops (existattr->aspath);
446 int exist_confeds = aspath_count_confeds (existattr->aspath);
447
448 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
449 {
450 int aspath_hops;
451
452 aspath_hops = aspath_count_hops (newattr->aspath);
453 aspath_hops += aspath_count_confeds (newattr->aspath);
454
455 if ( aspath_hops < (exist_hops + exist_confeds))
456 {
457 if (debug)
458 zlog_debug("%s: path %s wins over path %s due to aspath (with confeds) hopcount %d < %d",
459 pfx_buf, new->peer->host, exist->peer->host,
460 aspath_hops, (exist_hops + exist_confeds));
461 return 1;
462 }
463
464 if ( aspath_hops > (exist_hops + exist_confeds))
465 {
466 if (debug)
467 zlog_debug("%s: path %s loses to path %s due to aspath (with confeds) hopcount %d > %d",
468 pfx_buf, new->peer->host, exist->peer->host,
469 aspath_hops, (exist_hops + exist_confeds));
470 return 0;
471 }
472 }
473 else
474 {
475 int newhops = aspath_count_hops (newattr->aspath);
476
477 if (newhops < exist_hops)
478 {
479 if (debug)
480 zlog_debug("%s: path %s wins over path %s due to aspath hopcount %d < %d",
481 pfx_buf, new->peer->host, exist->peer->host,
482 newhops, exist_hops);
483 return 1;
484 }
485
486 if (newhops > exist_hops)
487 {
488 if (debug)
489 zlog_debug("%s: path %s loses to path %s due to aspath hopcount %d > %d",
490 pfx_buf, new->peer->host, exist->peer->host,
491 newhops, exist_hops);
492 return 0;
493 }
494 }
495 }
496
497 /* 5. Origin check. */
498 if (newattr->origin < existattr->origin)
499 {
500 if (debug)
501 zlog_debug("%s: path %s wins over path %s due to ORIGIN %s < %s",
502 pfx_buf, new->peer->host, exist->peer->host,
503 bgp_origin_long_str[newattr->origin],
504 bgp_origin_long_str[existattr->origin]);
505 return 1;
506 }
507
508 if (newattr->origin > existattr->origin)
509 {
510 if (debug)
511 zlog_debug("%s: path %s loses to path %s due to ORIGIN %s > %s",
512 pfx_buf, new->peer->host, exist->peer->host,
513 bgp_origin_long_str[newattr->origin],
514 bgp_origin_long_str[existattr->origin]);
515 return 0;
516 }
517
518 /* 6. MED check. */
519 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
520 && aspath_count_hops (existattr->aspath) == 0);
521 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
522 && aspath_count_confeds (existattr->aspath) > 0
523 && aspath_count_hops (newattr->aspath) == 0
524 && aspath_count_hops (existattr->aspath) == 0);
525
526 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
527 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
528 && confed_as_route)
529 || aspath_cmp_left (newattr->aspath, existattr->aspath)
530 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
531 || internal_as_route)
532 {
533 new_med = bgp_med_value (new->attr, bgp);
534 exist_med = bgp_med_value (exist->attr, bgp);
535
536 if (new_med < exist_med)
537 {
538 if (debug)
539 zlog_debug("%s: path %s wins over path %s due to MED %d < %d",
540 pfx_buf, new->peer->host, exist->peer->host, new_med,
541 exist_med);
542 return 1;
543 }
544
545 if (new_med > exist_med)
546 {
547 if (debug)
548 zlog_debug("%s: path %s loses to path %s due to MED %d > %d",
549 pfx_buf, new->peer->host, exist->peer->host, new_med,
550 exist_med);
551 return 0;
552 }
553 }
554
555 /* 7. Peer type check. */
556 new_sort = new->peer->sort;
557 exist_sort = exist->peer->sort;
558
559 if (new_sort == BGP_PEER_EBGP
560 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
561 {
562 if (debug)
563 zlog_debug("%s: path %s wins over path %s due to eBGP peer > iBGP peer",
564 pfx_buf, new->peer->host, exist->peer->host);
565 return 1;
566 }
567
568 if (exist_sort == BGP_PEER_EBGP
569 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
570 {
571 if (debug)
572 zlog_debug("%s: path %s loses to path %s due to iBGP peer < eBGP peer",
573 pfx_buf, new->peer->host, exist->peer->host);
574 return 0;
575 }
576
577 /* 8. IGP metric check. */
578 newm = existm = 0;
579
580 if (new->extra)
581 newm = new->extra->igpmetric;
582 if (exist->extra)
583 existm = exist->extra->igpmetric;
584
585 if (newm < existm)
586 {
587 if (debug)
588 zlog_debug("%s: path %s wins over path %s due to IGP metric %d < %d",
589 pfx_buf, new->peer->host, exist->peer->host, newm, existm);
590 ret = 1;
591 }
592
593 if (newm > existm)
594 {
595 if (debug)
596 zlog_debug("%s: path %s loses to path %s due to IGP metric %d > %d",
597 pfx_buf, new->peer->host, exist->peer->host, newm, existm);
598 ret = 0;
599 }
600
601 /* 9. Same IGP metric. Compare the cluster list length as
602 representative of IGP hops metric. Rewrite the metric value
603 pair (newm, existm) with the cluster list length. Prefer the
604 path with smaller cluster list length. */
605 if (newm == existm)
606 {
607 if (peer_sort (new->peer) == BGP_PEER_IBGP
608 && peer_sort (exist->peer) == BGP_PEER_IBGP
609 && CHECK_FLAG (mpath_cfg->ibgp_flags,
610 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
611 {
612 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
613 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
614
615 if (newm < existm)
616 {
617 if (debug)
618 zlog_debug("%s: path %s wins over path %s due to CLUSTER_LIST length %d < %d",
619 pfx_buf, new->peer->host, exist->peer->host, newm,
620 existm);
621 ret = 1;
622 }
623
624 if (newm > existm)
625 {
626 if (debug)
627 zlog_debug("%s: path %s loses to path %s due to CLUSTER_LIST length %d > %d",
628 pfx_buf, new->peer->host, exist->peer->host, newm,
629 existm);
630 ret = 0;
631 }
632 }
633 }
634
635 /* 10. confed-external vs. confed-internal */
636 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
637 {
638 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
639 {
640 if (debug)
641 zlog_debug("%s: path %s wins over path %s due to confed-external peer > confed-internal peer",
642 pfx_buf, new->peer->host, exist->peer->host);
643 return 1;
644 }
645
646 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
647 {
648 if (debug)
649 zlog_debug("%s: path %s loses to path %s due to confed-internal peer < confed-external peer",
650 pfx_buf, new->peer->host, exist->peer->host);
651 return 0;
652 }
653 }
654
655 /* 11. Maximum path check. */
656 if (newm == existm)
657 {
658 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
659 {
660
661 /*
662 * For the two paths, all comparison steps till IGP metric
663 * have succeeded - including AS_PATH hop count. Since 'bgp
664 * bestpath as-path multipath-relax' knob is on, we don't need
665 * an exact match of AS_PATH. Thus, mark the paths are equal.
666 * That will trigger both these paths to get into the multipath
667 * array.
668 */
669 *paths_eq = 1;
670
671 if (debug)
672 zlog_debug("%s: path %s and path %s are equal via multipath-relax",
673 pfx_buf, new->peer->host, exist->peer->host);
674 }
675 else if (new->peer->sort == BGP_PEER_IBGP)
676 {
677 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
678 {
679 *paths_eq = 1;
680
681 if (debug)
682 zlog_debug("%s: path %s and path %s are equal via matching aspaths",
683 pfx_buf, new->peer->host, exist->peer->host);
684 }
685 }
686 else if (new->peer->as == exist->peer->as)
687 {
688 *paths_eq = 1;
689
690 if (debug)
691 zlog_debug("%s: path %s and path %s are equal via same remote-as",
692 pfx_buf, new->peer->host, exist->peer->host);
693 }
694 }
695 else
696 {
697 /*
698 * TODO: If unequal cost ibgp multipath is enabled we can
699 * mark the paths as equal here instead of returning
700 */
701 return ret;
702 }
703
704 /* 12. If both paths are external, prefer the path that was received
705 first (the oldest one). This step minimizes route-flap, since a
706 newer path won't displace an older one, even if it was the
707 preferred route based on the additional decision criteria below. */
708 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
709 && new_sort == BGP_PEER_EBGP
710 && exist_sort == BGP_PEER_EBGP)
711 {
712 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
713 {
714 if (debug)
715 zlog_debug("%s: path %s wins over path %s due to oldest external",
716 pfx_buf, new->peer->host, exist->peer->host);
717 return 1;
718 }
719
720 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
721 {
722 if (debug)
723 zlog_debug("%s: path %s loses to path %s due to oldest external",
724 pfx_buf, new->peer->host, exist->peer->host);
725 return 0;
726 }
727 }
728
729 /* 13. Router-ID comparision. */
730 /* If one of the paths is "stale", the corresponding peer router-id will
731 * be 0 and would always win over the other path. If originator id is
732 * used for the comparision, it will decide which path is better.
733 */
734 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
735 new_id.s_addr = newattre->originator_id.s_addr;
736 else
737 new_id.s_addr = new->peer->remote_id.s_addr;
738 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
739 exist_id.s_addr = existattre->originator_id.s_addr;
740 else
741 exist_id.s_addr = exist->peer->remote_id.s_addr;
742
743 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
744 {
745 if (debug)
746 zlog_debug("%s: path %s wins over path %s due to Router-ID comparison",
747 pfx_buf, new->peer->host, exist->peer->host);
748 return 1;
749 }
750
751 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
752 {
753 if (debug)
754 zlog_debug("%s: path %s loses to path %s due to Router-ID comparison",
755 pfx_buf, new->peer->host, exist->peer->host);
756 return 0;
757 }
758
759 /* 14. Cluster length comparision. */
760 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
761 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
762
763 if (new_cluster < exist_cluster)
764 {
765 if (debug)
766 zlog_debug("%s: path %s wins over path %s due to CLUSTER_LIST length %d < %d",
767 pfx_buf, new->peer->host, exist->peer->host, new_cluster,
768 exist_cluster);
769 return 1;
770 }
771
772 if (new_cluster > exist_cluster)
773 {
774 if (debug)
775 zlog_debug("%s: path %s loses to path %s due to CLUSTER_LIST length %d > %d",
776 pfx_buf, new->peer->host, exist->peer->host, new_cluster,
777 exist_cluster);
778 return 0;
779 }
780
781 /* 15. Neighbor address comparision. */
782 /* Do this only if neither path is "stale" as stale paths do not have
783 * valid peer information (as the connection may or may not be up).
784 */
785 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
786 {
787 if (debug)
788 zlog_debug("%s: path %s wins over path %s due to latter path being STALE",
789 pfx_buf, new->peer->host, exist->peer->host);
790 return 1;
791 }
792
793 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
794 {
795 if (debug)
796 zlog_debug("%s: path %s loses to path %s due to former path being STALE",
797 pfx_buf, new->peer->host, exist->peer->host);
798 return 0;
799 }
800
801 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
802
803 if (ret == 1)
804 {
805 if (debug)
806 zlog_debug("%s: path %s loses to path %s due to Neighor IP comparison",
807 pfx_buf, new->peer->host, exist->peer->host);
808 return 0;
809 }
810
811 if (ret == -1)
812 {
813 if (debug)
814 zlog_debug("%s: path %s wins over path %s due to Neighor IP comparison",
815 pfx_buf, new->peer->host, exist->peer->host);
816 return 1;
817 }
818
819 if (debug)
820 zlog_debug("%s: path %s wins over path %s due to nothing left to compare",
821 pfx_buf, new->peer->host, exist->peer->host);
822
823 return 1;
824 }
825
826 static enum filter_type
827 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
828 afi_t afi, safi_t safi)
829 {
830 struct bgp_filter *filter;
831
832 filter = &peer->filter[afi][safi];
833
834 #define FILTER_EXIST_WARN(F,f,filter) \
835 if (BGP_DEBUG (update, UPDATE_IN) \
836 && !(F ## _IN (filter))) \
837 zlog_warn ("%s: Could not find configured input %s-list %s!", \
838 peer->host, #f, F ## _IN_NAME(filter));
839
840 if (DISTRIBUTE_IN_NAME (filter)) {
841 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
842
843 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
844 return FILTER_DENY;
845 }
846
847 if (PREFIX_LIST_IN_NAME (filter)) {
848 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
849
850 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
851 return FILTER_DENY;
852 }
853
854 if (FILTER_LIST_IN_NAME (filter)) {
855 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
856
857 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
858 return FILTER_DENY;
859 }
860
861 return FILTER_PERMIT;
862 #undef FILTER_EXIST_WARN
863 }
864
865 static enum filter_type
866 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
867 afi_t afi, safi_t safi)
868 {
869 struct bgp_filter *filter;
870
871 filter = &peer->filter[afi][safi];
872
873 #define FILTER_EXIST_WARN(F,f,filter) \
874 if (BGP_DEBUG (update, UPDATE_OUT) \
875 && !(F ## _OUT (filter))) \
876 zlog_warn ("%s: Could not find configured output %s-list %s!", \
877 peer->host, #f, F ## _OUT_NAME(filter));
878
879 if (DISTRIBUTE_OUT_NAME (filter)) {
880 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
881
882 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
883 return FILTER_DENY;
884 }
885
886 if (PREFIX_LIST_OUT_NAME (filter)) {
887 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
888
889 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
890 return FILTER_DENY;
891 }
892
893 if (FILTER_LIST_OUT_NAME (filter)) {
894 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
895
896 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
897 return FILTER_DENY;
898 }
899
900 return FILTER_PERMIT;
901 #undef FILTER_EXIST_WARN
902 }
903
904 /* If community attribute includes no_export then return 1. */
905 static int
906 bgp_community_filter (struct peer *peer, struct attr *attr)
907 {
908 if (attr->community)
909 {
910 /* NO_ADVERTISE check. */
911 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
912 return 1;
913
914 /* NO_EXPORT check. */
915 if (peer->sort == BGP_PEER_EBGP &&
916 community_include (attr->community, COMMUNITY_NO_EXPORT))
917 return 1;
918
919 /* NO_EXPORT_SUBCONFED check. */
920 if (peer->sort == BGP_PEER_EBGP
921 || peer->sort == BGP_PEER_CONFED)
922 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
923 return 1;
924 }
925 return 0;
926 }
927
928 /* Route reflection loop check. */
929 static int
930 bgp_cluster_filter (struct peer *peer, struct attr *attr)
931 {
932 struct in_addr cluster_id;
933
934 if (attr->extra && attr->extra->cluster)
935 {
936 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
937 cluster_id = peer->bgp->cluster_id;
938 else
939 cluster_id = peer->bgp->router_id;
940
941 if (cluster_loop_check (attr->extra->cluster, cluster_id))
942 return 1;
943 }
944 return 0;
945 }
946
947 static int
948 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
949 afi_t afi, safi_t safi, const char *rmap_name)
950 {
951 struct bgp_filter *filter;
952 struct bgp_info info;
953 route_map_result_t ret;
954 struct route_map *rmap = NULL;
955
956 filter = &peer->filter[afi][safi];
957
958 /* Apply default weight value. */
959 if (peer->weight)
960 (bgp_attr_extra_get (attr))->weight = peer->weight;
961
962 if (rmap_name)
963 {
964 rmap = route_map_lookup_by_name(rmap_name);
965
966 if (rmap == NULL)
967 return RMAP_DENY;
968 }
969 else
970 {
971 if (ROUTE_MAP_IN_NAME(filter))
972 {
973 rmap = ROUTE_MAP_IN (filter);
974
975 if (rmap == NULL)
976 return RMAP_DENY;
977 }
978 }
979
980 /* Route map apply. */
981 if (rmap)
982 {
983 /* Duplicate current value to new strucutre for modification. */
984 info.peer = peer;
985 info.attr = attr;
986
987 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
988
989 /* Apply BGP route map to the attribute. */
990 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
991
992 peer->rmap_type = 0;
993
994 if (ret == RMAP_DENYMATCH)
995 {
996 /* Free newly generated AS path and community by route-map. */
997 bgp_attr_flush (attr);
998 return RMAP_DENY;
999 }
1000 }
1001 return RMAP_PERMIT;
1002 }
1003
1004 static int
1005 bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1006 afi_t afi, safi_t safi, const char *rmap_name)
1007 {
1008 struct bgp_filter *filter;
1009 struct bgp_info info;
1010 route_map_result_t ret;
1011 struct route_map *rmap = NULL;
1012
1013 filter = &peer->filter[afi][safi];
1014
1015 /* Apply default weight value. */
1016 if (peer->weight)
1017 (bgp_attr_extra_get (attr))->weight = peer->weight;
1018
1019 if (rmap_name)
1020 {
1021 rmap = route_map_lookup_by_name(rmap_name);
1022
1023 if (rmap == NULL)
1024 return RMAP_DENY;
1025 }
1026 else
1027 {
1028 if (ROUTE_MAP_OUT_NAME(filter))
1029 {
1030 rmap = ROUTE_MAP_OUT (filter);
1031
1032 if (rmap == NULL)
1033 return RMAP_DENY;
1034 }
1035 }
1036
1037 /* Route map apply. */
1038 if (rmap)
1039 {
1040 /* Duplicate current value to new strucutre for modification. */
1041 info.peer = peer;
1042 info.attr = attr;
1043
1044 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1045
1046 /* Apply BGP route map to the attribute. */
1047 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1048
1049 peer->rmap_type = 0;
1050
1051 if (ret == RMAP_DENYMATCH)
1052 /* caller has multiple error paths with bgp_attr_flush() */
1053 return RMAP_DENY;
1054 }
1055 return RMAP_PERMIT;
1056 }
1057
1058 /* If this is an EBGP peer with remove-private-AS */
1059 static void
1060 bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1061 struct peer *peer, struct attr *attr)
1062 {
1063 if (peer->sort == BGP_PEER_EBGP &&
1064 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1065 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1066 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1067 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
1068 {
1069 // Take action on the entire aspath
1070 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1071 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
1072 {
1073 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
1074 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1075
1076 // The entire aspath consists of private ASNs so create an empty aspath
1077 else if (aspath_private_as_check (attr->aspath))
1078 attr->aspath = aspath_empty_get ();
1079
1080 // There are some public and some private ASNs, remove the private ASNs
1081 else
1082 attr->aspath = aspath_remove_private_asns (attr->aspath);
1083 }
1084
1085 // 'all' was not specified so the entire aspath must be private ASNs
1086 // for us to do anything
1087 else if (aspath_private_as_check (attr->aspath))
1088 {
1089 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1090 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1091 else
1092 attr->aspath = aspath_empty_get ();
1093 }
1094 }
1095 }
1096
1097 /* If this is an EBGP peer with as-override */
1098 static void
1099 bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1100 struct peer *peer, struct attr *attr)
1101 {
1102 if (peer->sort == BGP_PEER_EBGP &&
1103 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1104 {
1105 if (aspath_single_asn_check (attr->aspath, peer->as))
1106 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1107 }
1108 }
1109
1110 static void
1111 subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1112 {
1113 if (family == AF_INET)
1114 attr->nexthop.s_addr = 0;
1115 #ifdef HAVE_IPV6
1116 if (family == AF_INET6)
1117 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1118 #endif
1119 }
1120
1121 int
1122 subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1123 struct prefix *p, struct attr *attr)
1124 {
1125 struct bgp_filter *filter;
1126 struct peer *from;
1127 struct peer *peer;
1128 struct peer *onlypeer;
1129 struct bgp *bgp;
1130 struct attr *riattr;
1131 struct peer_af *paf;
1132 char buf[SU_ADDRSTRLEN];
1133 int ret;
1134 int transparent;
1135 int reflect;
1136 afi_t afi;
1137 safi_t safi;
1138
1139 if (DISABLE_BGP_ANNOUNCE)
1140 return 0;
1141
1142 afi = SUBGRP_AFI(subgrp);
1143 safi = SUBGRP_SAFI(subgrp);
1144 peer = SUBGRP_PEER(subgrp);
1145 onlypeer = NULL;
1146 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1147 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1148
1149 from = ri->peer;
1150 filter = &peer->filter[afi][safi];
1151 bgp = SUBGRP_INST(subgrp);
1152 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1153
1154 /* With addpath we may be asked to TX all kinds of paths so make sure
1155 * ri is valid */
1156 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1157 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1158 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1159 {
1160 return 0;
1161 }
1162
1163 /* If this is not the bestpath then check to see if there is an enabled addpath
1164 * feature that requires us to advertise it */
1165 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1166 {
1167 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1168 {
1169 return 0;
1170 }
1171 }
1172
1173 /* Aggregate-address suppress check. */
1174 if (ri->extra && ri->extra->suppress)
1175 if (! UNSUPPRESS_MAP_NAME (filter))
1176 {
1177 return 0;
1178 }
1179
1180 /* Do not send back route to sender. */
1181 if (onlypeer && from == onlypeer)
1182 {
1183 return 0;
1184 }
1185
1186 /* Do not send the default route in the BGP table if the neighbor is
1187 * configured for default-originate */
1188 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1189 {
1190 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1191 return 0;
1192 #ifdef HAVE_IPV6
1193 else if (p->family == AF_INET6 && p->prefixlen == 0)
1194 return 0;
1195 #endif /* HAVE_IPV6 */
1196 }
1197
1198 /* Transparency check. */
1199 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1200 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1201 transparent = 1;
1202 else
1203 transparent = 0;
1204
1205 /* If community is not disabled check the no-export and local. */
1206 if (! transparent && bgp_community_filter (peer, riattr))
1207 {
1208 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1209 zlog_debug ("subgrpannouncecheck: community filter check fail");
1210 return 0;
1211 }
1212
1213 /* If the attribute has originator-id and it is same as remote
1214 peer's id. */
1215 if (onlypeer &&
1216 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1217 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1218 {
1219 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1220 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1221 "remote router-id",
1222 onlypeer->host,
1223 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1224 p->prefixlen);
1225 return 0;
1226 }
1227
1228 /* ORF prefix-list filter check */
1229 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1230 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1231 || CHECK_FLAG (peer->af_cap[afi][safi],
1232 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1233 if (peer->orf_plist[afi][safi])
1234 {
1235 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1236 {
1237 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1238 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1239 peer->host,
1240 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1241 p->prefixlen);
1242 return 0;
1243 }
1244 }
1245
1246 /* Output filter check. */
1247 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1248 {
1249 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1250 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1251 peer->host,
1252 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1253 p->prefixlen);
1254 return 0;
1255 }
1256
1257 #ifdef BGP_SEND_ASPATH_CHECK
1258 /* AS path loop check. */
1259 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1260 {
1261 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1262 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1263 "that is part of AS path.",
1264 onlypeer->host, onlypeer->as);
1265 return 0;
1266 }
1267 #endif /* BGP_SEND_ASPATH_CHECK */
1268
1269 /* If we're a CONFED we need to loop check the CONFED ID too */
1270 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1271 {
1272 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1273 {
1274 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1275 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1276 " is AS path.",
1277 peer->host,
1278 bgp->confed_id);
1279 return 0;
1280 }
1281 }
1282
1283 /* Route-Reflect check. */
1284 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1285 reflect = 1;
1286 else
1287 reflect = 0;
1288
1289 /* IBGP reflection check. */
1290 if (reflect)
1291 {
1292 /* A route from a Client peer. */
1293 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1294 {
1295 /* Reflect to all the Non-Client peers and also to the
1296 Client peers other than the originator. Originator check
1297 is already done. So there is noting to do. */
1298 /* no bgp client-to-client reflection check. */
1299 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1300 if (CHECK_FLAG (peer->af_flags[afi][safi],
1301 PEER_FLAG_REFLECTOR_CLIENT))
1302 return 0;
1303 }
1304 else
1305 {
1306 /* A route from a Non-client peer. Reflect to all other
1307 clients. */
1308 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1309 PEER_FLAG_REFLECTOR_CLIENT))
1310 return 0;
1311 }
1312 }
1313
1314 /* For modify attribute, copy it to temporary structure. */
1315 bgp_attr_dup (attr, riattr);
1316
1317 /* If local-preference is not set. */
1318 if ((peer->sort == BGP_PEER_IBGP
1319 || peer->sort == BGP_PEER_CONFED)
1320 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1321 {
1322 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1323 attr->local_pref = bgp->default_local_pref;
1324 }
1325
1326 /* If originator-id is not set and the route is to be reflected,
1327 set the originator id */
1328 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1329 {
1330 attr->extra = bgp_attr_extra_get(attr);
1331 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1332 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1333 }
1334
1335 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1336 if (peer->sort == BGP_PEER_EBGP
1337 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1338 {
1339 if (from != bgp->peer_self && ! transparent
1340 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1341 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1342 }
1343
1344 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1345 * in announce check, only certain flags and length (or number of nexthops
1346 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1347 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1348 * Typically, the source nexthop in the attribute is preserved but in the
1349 * scenarios where we know it will always be overwritten, we reset the
1350 * nexthop to "0" in an attempt to achieve better Update packing. An
1351 * example of this is when a prefix from each of 2 IBGP peers needs to be
1352 * announced to an EBGP peer (and they have the same attributes barring
1353 * their nexthop).
1354 */
1355 if (reflect)
1356 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1357
1358 #ifdef HAVE_IPV6
1359 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1360 * the peer (group) is configured to receive link-local nexthop unchanged
1361 * and it is available in the prefix OR we're not reflecting the route and
1362 * the peer (group) to whom we're going to announce is on a shared network
1363 * and this is either a self-originated route or the peer is EBGP.
1364 */
1365 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1366 {
1367 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
1368 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1369 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1370 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1371 (!reflect && peer->shared_network &&
1372 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
1373 {
1374 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
1375 }
1376
1377 /* Clear off link-local nexthop in source, whenever it is not needed to
1378 * ensure more prefixes share the same attribute for announcement.
1379 */
1380 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1381 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1382 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1383 }
1384 #endif /* HAVE_IPV6 */
1385
1386 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1387 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1388
1389 /* Route map & unsuppress-map apply. */
1390 if (ROUTE_MAP_OUT_NAME (filter)
1391 || (ri->extra && ri->extra->suppress) )
1392 {
1393 struct bgp_info info;
1394 struct attr dummy_attr;
1395 struct attr_extra dummy_extra;
1396
1397 dummy_attr.extra = &dummy_extra;
1398
1399 info.peer = peer;
1400 info.attr = attr;
1401 /* don't confuse inbound and outbound setting */
1402 RESET_FLAG(attr->rmap_change_flags);
1403
1404 /*
1405 * The route reflector is not allowed to modify the attributes
1406 * of the reflected IBGP routes unless explicitly allowed.
1407 */
1408 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1409 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1410 {
1411 bgp_attr_dup (&dummy_attr, attr);
1412 info.attr = &dummy_attr;
1413 }
1414
1415 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1416
1417 if (ri->extra && ri->extra->suppress)
1418 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1419 else
1420 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1421
1422 peer->rmap_type = 0;
1423
1424 if (ret == RMAP_DENYMATCH)
1425 {
1426 bgp_attr_flush (attr);
1427 return 0;
1428 }
1429 }
1430
1431 /* After route-map has been applied, we check to see if the nexthop to
1432 * be carried in the attribute (that is used for the announcement) can
1433 * be cleared off or not. We do this in all cases where we would be
1434 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1435 * the global nexthop here; the link-local nexthop would have been cleared
1436 * already, and if not, it is required by the update formation code.
1437 * Also see earlier comments in this function.
1438 */
1439 /*
1440 * If route-map has performed some operation on the nexthop or the peer
1441 * configuration says to pass it unchanged, we cannot reset the nexthop
1442 * here, so only attempt to do it if these aren't true. Note that the
1443 * route-map handler itself might have cleared the nexthop, if for example,
1444 * it is configured as 'peer-address'.
1445 */
1446 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1447 riattr->rmap_change_flags) &&
1448 !transparent &&
1449 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
1450 {
1451 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
1452 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1453 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
1454 {
1455 if (!reflect ||
1456 CHECK_FLAG (peer->af_flags[afi][safi],
1457 PEER_FLAG_FORCE_NEXTHOP_SELF))
1458 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1459 AF_INET6 : p->family), attr);
1460 }
1461 else if (peer->sort == BGP_PEER_EBGP)
1462 {
1463 /* Can also reset the nexthop if announcing to EBGP, but only if
1464 * no peer in the subgroup is on a shared subnet.
1465 * Note: 3rd party nexthop currently implemented for IPv4 only.
1466 */
1467 SUBGRP_FOREACH_PEER (subgrp, paf)
1468 {
1469 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1470 break;
1471 }
1472 if (!paf)
1473 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
1474 }
1475 /* If IPv6/MP and nexthop does not have any override and happens to
1476 * be a link-local address, reset it so that we don't pass along the
1477 * source's link-local IPv6 address to recipients who may not be on
1478 * the same interface.
1479 */
1480 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1481 {
1482 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1483 subgroup_announce_reset_nhop (AF_INET6, attr);
1484 }
1485 }
1486
1487 return 1;
1488 }
1489
1490 struct bgp_info_pair
1491 {
1492 struct bgp_info *old;
1493 struct bgp_info *new;
1494 };
1495
1496 static void
1497 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1498 struct bgp_maxpaths_cfg *mpath_cfg,
1499 struct bgp_info_pair *result)
1500 {
1501 struct bgp_info *new_select;
1502 struct bgp_info *old_select;
1503 struct bgp_info *ri;
1504 struct bgp_info *ri1;
1505 struct bgp_info *ri2;
1506 struct bgp_info *nextri = NULL;
1507 int paths_eq, do_mpath, debug;
1508 struct list mp_list;
1509 char pfx_buf[PREFIX2STR_BUFFER];
1510
1511 bgp_mp_list_init (&mp_list);
1512 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
1513
1514 debug = bgp_debug_bestpath(&rn->p);
1515
1516 if (debug)
1517 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1518
1519 /* bgp deterministic-med */
1520 new_select = NULL;
1521 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1522 {
1523
1524 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1525 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1526 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1527
1528 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1529 {
1530 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1531 continue;
1532 if (BGP_INFO_HOLDDOWN (ri1))
1533 continue;
1534 if (ri1->peer && ri1->peer != bgp->peer_self)
1535 if (ri1->peer->status != Established)
1536 continue;
1537
1538 new_select = ri1;
1539 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
1540 if (ri1->next)
1541 {
1542 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1543 {
1544 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1545 continue;
1546 if (BGP_INFO_HOLDDOWN (ri2))
1547 continue;
1548 if (ri2->peer &&
1549 ri2->peer != bgp->peer_self &&
1550 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1551 if (ri2->peer->status != Established)
1552 continue;
1553
1554 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1555 || aspath_cmp_left_confed (ri1->attr->aspath,
1556 ri2->attr->aspath))
1557 {
1558 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1559 old_select = ri2;
1560 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1561 mpath_cfg, debug, pfx_buf))
1562 {
1563 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1564 new_select = ri2;
1565 }
1566
1567 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1568 }
1569 }
1570 }
1571 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1572 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1573
1574 if (debug)
1575 zlog_debug("%s: path %s is the bestpath from AS %d",
1576 pfx_buf, new_select->peer->host,
1577 aspath_get_firstas(new_select->attr->aspath));
1578 }
1579 }
1580
1581 /* Check old selected route and new selected route. */
1582 old_select = NULL;
1583 new_select = NULL;
1584 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1585 {
1586 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1587 old_select = ri;
1588
1589 if (BGP_INFO_HOLDDOWN (ri))
1590 {
1591 /* reap REMOVED routes, if needs be
1592 * selected route must stay for a while longer though
1593 */
1594 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1595 && (ri != old_select))
1596 bgp_info_reap (rn, ri);
1597
1598 continue;
1599 }
1600
1601 if (ri->peer &&
1602 ri->peer != bgp->peer_self &&
1603 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1604 if (ri->peer->status != Established)
1605 continue;
1606
1607 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1608 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1609 {
1610 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1611 continue;
1612 }
1613
1614 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1615
1616 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
1617 {
1618 new_select = ri;
1619 }
1620 }
1621
1622 /* Now that we know which path is the bestpath see if any of the other paths
1623 * qualify as multipaths
1624 */
1625 if (do_mpath && new_select)
1626 {
1627 if (debug)
1628 zlog_debug("%s: path %s is the bestpath, now find multipaths",
1629 pfx_buf, new_select->peer->host);
1630
1631 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1632 {
1633 if (ri == new_select)
1634 {
1635 if (debug)
1636 zlog_debug("%s: path %s is the bestpath, add to the multipath list",
1637 pfx_buf, ri->peer->host);
1638 bgp_mp_list_add (&mp_list, ri);
1639 continue;
1640 }
1641
1642 if (BGP_INFO_HOLDDOWN (ri))
1643 continue;
1644
1645 if (ri->peer &&
1646 ri->peer != bgp->peer_self &&
1647 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1648 if (ri->peer->status != Established)
1649 continue;
1650
1651 if (!bgp_info_nexthop_cmp (ri, new_select))
1652 {
1653 if (debug)
1654 zlog_debug("%s: path %s has the same nexthop as the bestpath, skip it",
1655 pfx_buf, ri->peer->host);
1656 continue;
1657 }
1658
1659 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
1660
1661 if (paths_eq)
1662 {
1663 if (debug)
1664 zlog_debug("%s: path %s is equivalent to the bestpath, add to the multipath list",
1665 pfx_buf, ri->peer->host);
1666 bgp_mp_list_add (&mp_list, ri);
1667 }
1668 }
1669 }
1670
1671 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1672 bgp_info_mpath_aggregate_update (new_select, old_select);
1673 bgp_mp_list_clear (&mp_list);
1674
1675 result->old = old_select;
1676 result->new = new_select;
1677
1678 return;
1679 }
1680
1681 /*
1682 * A new route/change in bestpath of an existing route. Evaluate the path
1683 * for advertisement to the subgroup.
1684 */
1685 int
1686 subgroup_process_announce_selected (struct update_subgroup *subgrp,
1687 struct bgp_info *selected,
1688 struct bgp_node *rn,
1689 u_int32_t addpath_tx_id)
1690 {
1691 struct prefix *p;
1692 struct peer *onlypeer;
1693 struct attr attr;
1694 struct attr_extra extra;
1695 afi_t afi;
1696 safi_t safi;
1697
1698 p = &rn->p;
1699 afi = SUBGRP_AFI(subgrp);
1700 safi = SUBGRP_SAFI(subgrp);
1701 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1702 (SUBGRP_PFIRST(subgrp))->peer : NULL);
1703
1704 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1705 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1706 PEER_STATUS_ORF_WAIT_REFRESH))
1707 return 0;
1708
1709 /* It's initialized in bgp_announce_check() */
1710 attr.extra = &extra;
1711
1712 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1713 if (selected)
1714 {
1715 if (subgroup_announce_check(selected, subgrp, p, &attr))
1716 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1717 else
1718 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1719 }
1720
1721 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1722 else
1723 {
1724 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
1725 }
1726
1727 return 0;
1728 }
1729
1730 struct bgp_process_queue
1731 {
1732 struct bgp *bgp;
1733 struct bgp_node *rn;
1734 afi_t afi;
1735 safi_t safi;
1736 };
1737
1738 static wq_item_status
1739 bgp_process_main (struct work_queue *wq, void *data)
1740 {
1741 struct bgp_process_queue *pq = data;
1742 struct bgp *bgp = pq->bgp;
1743 struct bgp_node *rn = pq->rn;
1744 afi_t afi = pq->afi;
1745 safi_t safi = pq->safi;
1746 struct prefix *p = &rn->p;
1747 struct bgp_info *new_select;
1748 struct bgp_info *old_select;
1749 struct bgp_info_pair old_and_new;
1750
1751 /* Is it end of initial update? (after startup) */
1752 if (!rn)
1753 {
1754 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1755 sizeof(bgp->update_delay_zebra_resume_time));
1756
1757 bgp->main_zebra_update_hold = 0;
1758 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1759 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1760 {
1761 bgp_zebra_announce_table(bgp, afi, safi);
1762 }
1763 bgp->main_peers_update_hold = 0;
1764
1765 bgp_start_routeadv(bgp);
1766 return WQ_SUCCESS;
1767 }
1768
1769 /* Best path selection. */
1770 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1771 old_select = old_and_new.old;
1772 new_select = old_and_new.new;
1773
1774 /* Nothing to do. */
1775 if (old_select && old_select == new_select &&
1776 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1777 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1778 !bgp->addpath_tx_used[afi][safi])
1779 {
1780 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1781 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
1782 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1783
1784 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1785 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1786 return WQ_SUCCESS;
1787 }
1788
1789 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1790 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1791
1792 /* bestpath has changed; bump version */
1793 if (old_select || new_select)
1794 {
1795 bgp_bump_version(rn);
1796
1797 if (!bgp->t_rmap_def_originate_eval)
1798 {
1799 bgp_lock (bgp);
1800 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
1801 update_group_refresh_default_originate_route_map,
1802 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1803 }
1804 }
1805
1806 if (old_select)
1807 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1808 if (new_select)
1809 {
1810 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1811 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1812 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1813 }
1814
1815 group_announce_route(bgp, afi, safi, rn, new_select);
1816
1817 /* FIB update. */
1818 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1819 ! bgp_option_check (BGP_OPT_NO_FIB)))
1820 {
1821 if (new_select
1822 && new_select->type == ZEBRA_ROUTE_BGP
1823 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1824 new_select->sub_type == BGP_ROUTE_AGGREGATE))
1825 bgp_zebra_announce (p, new_select, bgp, afi, safi);
1826 else
1827 {
1828 /* Withdraw the route from the kernel. */
1829 if (old_select
1830 && old_select->type == ZEBRA_ROUTE_BGP
1831 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
1832 old_select->sub_type == BGP_ROUTE_AGGREGATE))
1833 bgp_zebra_withdraw (p, old_select, safi);
1834 }
1835 }
1836
1837 /* Reap old select bgp_info, if it has been removed */
1838 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1839 bgp_info_reap (rn, old_select);
1840
1841 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1842 return WQ_SUCCESS;
1843 }
1844
1845 static void
1846 bgp_processq_del (struct work_queue *wq, void *data)
1847 {
1848 struct bgp_process_queue *pq = data;
1849 struct bgp_table *table;
1850
1851 bgp_unlock (pq->bgp);
1852 if (pq->rn)
1853 {
1854 table = bgp_node_table (pq->rn);
1855 bgp_unlock_node (pq->rn);
1856 bgp_table_unlock (table);
1857 }
1858 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1859 }
1860
1861 void
1862 bgp_process_queue_init (void)
1863 {
1864 if (!bm->process_main_queue)
1865 {
1866 bm->process_main_queue
1867 = work_queue_new (bm->master, "process_main_queue");
1868
1869 if ( !bm->process_main_queue)
1870 {
1871 zlog_err ("%s: Failed to allocate work queue", __func__);
1872 exit (1);
1873 }
1874 }
1875
1876 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1877 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1878 bm->process_main_queue->spec.max_retries = 0;
1879 bm->process_main_queue->spec.hold = 50;
1880 /* Use a higher yield value of 50ms for main queue processing */
1881 bm->process_main_queue->spec.yield = 50 * 1000L;
1882 }
1883
1884 void
1885 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1886 {
1887 struct bgp_process_queue *pqnode;
1888
1889 /* already scheduled for processing? */
1890 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1891 return;
1892
1893 if (bm->process_main_queue == NULL)
1894 bgp_process_queue_init ();
1895
1896 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1897 sizeof (struct bgp_process_queue));
1898 if (!pqnode)
1899 return;
1900
1901 /* all unlocked in bgp_processq_del */
1902 bgp_table_lock (bgp_node_table (rn));
1903 pqnode->rn = bgp_lock_node (rn);
1904 pqnode->bgp = bgp;
1905 bgp_lock (bgp);
1906 pqnode->afi = afi;
1907 pqnode->safi = safi;
1908 work_queue_add (bm->process_main_queue, pqnode);
1909 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1910 return;
1911 }
1912
1913 void
1914 bgp_add_eoiu_mark (struct bgp *bgp)
1915 {
1916 struct bgp_process_queue *pqnode;
1917
1918 if (bm->process_main_queue == NULL)
1919 bgp_process_queue_init ();
1920
1921 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1922 sizeof (struct bgp_process_queue));
1923 if (!pqnode)
1924 return;
1925
1926 pqnode->rn = NULL;
1927 pqnode->bgp = bgp;
1928 bgp_lock (bgp);
1929 work_queue_add (bm->process_main_queue, pqnode);
1930 }
1931
1932 static int
1933 bgp_maximum_prefix_restart_timer (struct thread *thread)
1934 {
1935 struct peer *peer;
1936
1937 peer = THREAD_ARG (thread);
1938 peer->t_pmax_restart = NULL;
1939
1940 if (bgp_debug_neighbor_events(peer))
1941 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1942 peer->host);
1943
1944 peer_clear (peer, NULL);
1945
1946 return 0;
1947 }
1948
1949 int
1950 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1951 safi_t safi, int always)
1952 {
1953 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1954 return 0;
1955
1956 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
1957 {
1958 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1959 && ! always)
1960 return 0;
1961
1962 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1963 "limit %ld", afi_safi_print (afi, safi), peer->host,
1964 peer->pcount[afi][safi], peer->pmax[afi][safi]);
1965 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1966
1967 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1968 return 0;
1969
1970 {
1971 u_int8_t ndata[7];
1972
1973 if (safi == SAFI_MPLS_VPN)
1974 safi = SAFI_MPLS_LABELED_VPN;
1975
1976 ndata[0] = (afi >> 8);
1977 ndata[1] = afi;
1978 ndata[2] = safi;
1979 ndata[3] = (peer->pmax[afi][safi] >> 24);
1980 ndata[4] = (peer->pmax[afi][safi] >> 16);
1981 ndata[5] = (peer->pmax[afi][safi] >> 8);
1982 ndata[6] = (peer->pmax[afi][safi]);
1983
1984 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1985 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1986 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1987 }
1988
1989 /* Dynamic peers will just close their connection. */
1990 if (peer_dynamic_neighbor (peer))
1991 return 1;
1992
1993 /* restart timer start */
1994 if (peer->pmax_restart[afi][safi])
1995 {
1996 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1997
1998 if (bgp_debug_neighbor_events(peer))
1999 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2000 peer->host, peer->v_pmax_restart);
2001
2002 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2003 peer->v_pmax_restart);
2004 }
2005
2006 return 1;
2007 }
2008 else
2009 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2010
2011 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2012 {
2013 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2014 && ! always)
2015 return 0;
2016
2017 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2018 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2019 peer->pmax[afi][safi]);
2020 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2021 }
2022 else
2023 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2024 return 0;
2025 }
2026
2027 /* Unconditionally remove the route from the RIB, without taking
2028 * damping into consideration (eg, because the session went down)
2029 */
2030 static void
2031 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2032 afi_t afi, safi_t safi)
2033 {
2034 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2035
2036 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2037 bgp_info_delete (rn, ri); /* keep historical info */
2038
2039 bgp_process (peer->bgp, rn, afi, safi);
2040 }
2041
2042 static void
2043 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2044 afi_t afi, safi_t safi)
2045 {
2046 int status = BGP_DAMP_NONE;
2047
2048 /* apply dampening, if result is suppressed, we'll be retaining
2049 * the bgp_info in the RIB for historical reference.
2050 */
2051 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2052 && peer->sort == BGP_PEER_EBGP)
2053 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2054 == BGP_DAMP_SUPPRESSED)
2055 {
2056 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2057 return;
2058 }
2059
2060 bgp_rib_remove (rn, ri, peer, afi, safi);
2061 }
2062
2063 static struct bgp_info *
2064 info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
2065 struct bgp_node *rn)
2066 {
2067 struct bgp_info *new;
2068
2069 /* Make new BGP info. */
2070 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2071 new->type = type;
2072 new->instance = instance;
2073 new->sub_type = sub_type;
2074 new->peer = peer;
2075 new->attr = attr;
2076 new->uptime = bgp_clock ();
2077 new->net = rn;
2078 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
2079 return new;
2080 }
2081
2082 static void
2083 bgp_info_addpath_rx_str(struct bgp_info *ri, char *buf)
2084 {
2085 if (ri && ri->addpath_rx_id)
2086 sprintf(buf, " with addpath ID %d", ri->addpath_rx_id);
2087 }
2088
2089 /* Check if received nexthop is valid or not. */
2090 static int
2091 bgp_update_martian_nexthop (afi_t afi, safi_t safi, struct attr *attr)
2092 {
2093 struct attr_extra *attre = attr->extra;
2094 int ret = 0;
2095
2096 /* Only validated for unicast and multicast currently. */
2097 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2098 return 0;
2099
2100 /* If NEXT_HOP is present, validate it. */
2101 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2102 {
2103 if (attr->nexthop.s_addr == 0 ||
2104 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2105 bgp_nexthop_self (attr))
2106 ret = 1;
2107 }
2108
2109 /* If MP_NEXTHOP is present, validate it. */
2110 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2111 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2112 * it is not an IPv6 link-local address.
2113 */
2114 if (attre && attre->mp_nexthop_len)
2115 {
2116 switch (attre->mp_nexthop_len)
2117 {
2118 case BGP_ATTR_NHLEN_IPV4:
2119 case BGP_ATTR_NHLEN_VPNV4:
2120 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2121 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2122 break;
2123
2124 #ifdef HAVE_IPV6
2125 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2126 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2127 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2128 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2129 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2130 break;
2131 #endif /* HAVE_IPV6 */
2132
2133 default:
2134 ret = 1;
2135 break;
2136 }
2137 }
2138
2139 return ret;
2140 }
2141
2142 static int
2143 bgp_update_main (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2144 struct attr *attr, afi_t afi, safi_t safi, int type,
2145 int sub_type, struct prefix_rd *prd, u_char *tag,
2146 int soft_reconfig)
2147 {
2148 int ret;
2149 int aspath_loop_count = 0;
2150 struct bgp_node *rn;
2151 struct bgp *bgp;
2152 struct attr new_attr;
2153 struct attr_extra new_extra;
2154 struct attr *attr_new;
2155 struct bgp_info *ri;
2156 struct bgp_info *new;
2157 const char *reason;
2158 char buf[SU_ADDRSTRLEN];
2159 char buf2[30];
2160 int connected = 0;
2161
2162 bgp = peer->bgp;
2163 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2164
2165 /* When peer's soft reconfiguration enabled. Record input packet in
2166 Adj-RIBs-In. */
2167 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2168 && peer != bgp->peer_self)
2169 bgp_adj_in_set (rn, peer, attr, addpath_id);
2170
2171 /* Check previously received route. */
2172 for (ri = rn->info; ri; ri = ri->next)
2173 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2174 ri->addpath_rx_id == addpath_id)
2175 break;
2176
2177 /* AS path local-as loop check. */
2178 if (peer->change_local_as)
2179 {
2180 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2181 aspath_loop_count = 1;
2182
2183 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2184 {
2185 reason = "as-path contains our own AS;";
2186 goto filtered;
2187 }
2188 }
2189
2190 /* AS path loop check. */
2191 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2192 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2193 && aspath_loop_check(attr->aspath, bgp->confed_id)
2194 > peer->allowas_in[afi][safi]))
2195 {
2196 reason = "as-path contains our own AS;";
2197 goto filtered;
2198 }
2199
2200 /* Route reflector originator ID check. */
2201 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2202 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2203 {
2204 reason = "originator is us;";
2205 goto filtered;
2206 }
2207
2208 /* Route reflector cluster ID check. */
2209 if (bgp_cluster_filter (peer, attr))
2210 {
2211 reason = "reflected from the same cluster;";
2212 goto filtered;
2213 }
2214
2215 /* Apply incoming filter. */
2216 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2217 {
2218 reason = "filter;";
2219 goto filtered;
2220 }
2221
2222 new_attr.extra = &new_extra;
2223 bgp_attr_dup (&new_attr, attr);
2224
2225 /* Apply incoming route-map.
2226 * NB: new_attr may now contain newly allocated values from route-map "set"
2227 * commands, so we need bgp_attr_flush in the error paths, until we intern
2228 * the attr (which takes over the memory references) */
2229 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2230 {
2231 reason = "route-map;";
2232 bgp_attr_flush (&new_attr);
2233 goto filtered;
2234 }
2235
2236 /* next hop check. */
2237 if (bgp_update_martian_nexthop (afi, safi, &new_attr))
2238 {
2239 reason = "martian or self next-hop;";
2240 bgp_attr_flush (&new_attr);
2241 goto filtered;
2242 }
2243
2244 attr_new = bgp_attr_intern (&new_attr);
2245
2246 /* If the update is implicit withdraw. */
2247 if (ri)
2248 {
2249 ri->uptime = bgp_clock ();
2250
2251 /* Same attribute comes in. */
2252 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2253 && attrhash_cmp (ri->attr, attr_new))
2254 {
2255 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2256 && peer->sort == BGP_PEER_EBGP
2257 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2258 {
2259 if (bgp_debug_update(peer, p, NULL, 1))
2260 {
2261 bgp_info_addpath_rx_str(ri, buf2);
2262 zlog_debug ("%s rcvd %s/%d%s",
2263 peer->host,
2264 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2265 p->prefixlen, buf2);
2266 }
2267
2268 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2269 {
2270 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2271 bgp_process (bgp, rn, afi, safi);
2272 }
2273 }
2274 else /* Duplicate - odd */
2275 {
2276 if (bgp_debug_update(peer, p, NULL, 1))
2277 {
2278 if (!peer->rcvd_attr_printed)
2279 {
2280 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2281 peer->rcvd_attr_printed = 1;
2282 }
2283
2284 bgp_info_addpath_rx_str(ri, buf2);
2285 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
2286 peer->host,
2287 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2288 p->prefixlen, buf2);
2289 }
2290
2291 /* graceful restart STALE flag unset. */
2292 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2293 {
2294 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2295 bgp_process (bgp, rn, afi, safi);
2296 }
2297 }
2298
2299 bgp_unlock_node (rn);
2300 bgp_attr_unintern (&attr_new);
2301
2302 return 0;
2303 }
2304
2305 /* Withdraw/Announce before we fully processed the withdraw */
2306 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2307 {
2308 if (bgp_debug_update(peer, p, NULL, 1))
2309 {
2310 bgp_info_addpath_rx_str(ri, buf2);
2311 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2312 peer->host,
2313 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2314 p->prefixlen, buf2);
2315 }
2316 bgp_info_restore (rn, ri);
2317 }
2318
2319 /* Received Logging. */
2320 if (bgp_debug_update(peer, p, NULL, 1))
2321 {
2322 bgp_info_addpath_rx_str(ri, buf2);
2323 zlog_debug ("%s rcvd %s/%d%s",
2324 peer->host,
2325 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2326 p->prefixlen, buf2);
2327 }
2328
2329 /* graceful restart STALE flag unset. */
2330 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2331 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2332
2333 /* The attribute is changed. */
2334 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2335
2336 /* implicit withdraw, decrement aggregate and pcount here.
2337 * only if update is accepted, they'll increment below.
2338 */
2339 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2340
2341 /* Update bgp route dampening information. */
2342 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2343 && peer->sort == BGP_PEER_EBGP)
2344 {
2345 /* This is implicit withdraw so we should update dampening
2346 information. */
2347 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2348 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2349 }
2350
2351 /* Update to new attribute. */
2352 bgp_attr_unintern (&ri->attr);
2353 ri->attr = attr_new;
2354
2355 /* Update MPLS tag. */
2356 if (safi == SAFI_MPLS_VPN)
2357 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2358
2359 /* Update bgp route dampening information. */
2360 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2361 && peer->sort == BGP_PEER_EBGP)
2362 {
2363 /* Now we do normal update dampening. */
2364 ret = bgp_damp_update (ri, rn, afi, safi);
2365 if (ret == BGP_DAMP_SUPPRESSED)
2366 {
2367 bgp_unlock_node (rn);
2368 return 0;
2369 }
2370 }
2371
2372 /* Nexthop reachability check. */
2373 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2374 {
2375 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2376 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2377 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2378 connected = 1;
2379 else
2380 connected = 0;
2381
2382 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
2383 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2384 else
2385 {
2386 if (BGP_DEBUG(nht, NHT))
2387 {
2388 char buf1[INET6_ADDRSTRLEN];
2389 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2390 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2391 }
2392 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2393 }
2394 }
2395 else
2396 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2397
2398 /* Process change. */
2399 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2400
2401 bgp_process (bgp, rn, afi, safi);
2402 bgp_unlock_node (rn);
2403
2404 return 0;
2405 } // End of implicit withdraw
2406
2407 /* Received Logging. */
2408 if (bgp_debug_update(peer, p, NULL, 1))
2409 {
2410 if (!peer->rcvd_attr_printed)
2411 {
2412 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2413 peer->rcvd_attr_printed = 1;
2414 }
2415
2416 bgp_info_addpath_rx_str(ri, buf2);
2417 zlog_debug ("%s rcvd %s/%d%s",
2418 peer->host,
2419 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2420 p->prefixlen, buf2);
2421 }
2422
2423 /* Make new BGP info. */
2424 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2425
2426 /* Update MPLS tag. */
2427 if (safi == SAFI_MPLS_VPN)
2428 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2429
2430 /* Nexthop reachability check. */
2431 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2432 {
2433 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2434 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2435 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2436 connected = 1;
2437 else
2438 connected = 0;
2439
2440 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
2441 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2442 else
2443 {
2444 if (BGP_DEBUG(nht, NHT))
2445 {
2446 char buf1[INET6_ADDRSTRLEN];
2447 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2448 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2449 }
2450 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2451 }
2452 }
2453 else
2454 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2455
2456 /* Addpath ID */
2457 new->addpath_rx_id = addpath_id;
2458
2459 /* Increment prefix */
2460 bgp_aggregate_increment (bgp, p, new, afi, safi);
2461
2462 /* Register new BGP information. */
2463 bgp_info_add (rn, new);
2464
2465 /* route_node_get lock */
2466 bgp_unlock_node (rn);
2467
2468 /* If maximum prefix count is configured and current prefix
2469 count exeed it. */
2470 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2471 return -1;
2472
2473 /* Process change. */
2474 bgp_process (bgp, rn, afi, safi);
2475
2476 return 0;
2477
2478 /* This BGP update is filtered. Log the reason then update BGP
2479 entry. */
2480 filtered:
2481 if (bgp_debug_update(peer, p, NULL, 1))
2482 {
2483 if (!peer->rcvd_attr_printed)
2484 {
2485 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2486 peer->rcvd_attr_printed = 1;
2487 }
2488
2489 bgp_info_addpath_rx_str(ri, buf2);
2490 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
2491 peer->host,
2492 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2493 p->prefixlen, buf2, reason);
2494 }
2495
2496 if (ri)
2497 bgp_rib_remove (rn, ri, peer, afi, safi);
2498
2499 bgp_unlock_node (rn);
2500
2501 return 0;
2502 }
2503
2504 int
2505 bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2506 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2507 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2508 {
2509 return bgp_update_main (peer, p, addpath_id, attr, afi, safi, type, sub_type,
2510 prd, tag, soft_reconfig);
2511 }
2512
2513 int
2514 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2515 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2516 struct prefix_rd *prd, u_char *tag)
2517 {
2518 struct bgp *bgp;
2519 char buf[SU_ADDRSTRLEN];
2520 char buf2[30];
2521 struct bgp_node *rn;
2522 struct bgp_info *ri;
2523
2524 bgp = peer->bgp;
2525
2526 /* Lookup node. */
2527 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2528
2529 /* If peer is soft reconfiguration enabled. Record input packet for
2530 further calculation. */
2531 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2532 && peer != bgp->peer_self)
2533 bgp_adj_in_unset (rn, peer, addpath_id);
2534
2535 /* Lookup withdrawn route. */
2536 for (ri = rn->info; ri; ri = ri->next)
2537 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2538 ri->addpath_rx_id == addpath_id)
2539 break;
2540
2541 /* Logging. */
2542 if (bgp_debug_update(peer, p, NULL, 1))
2543 {
2544 bgp_info_addpath_rx_str(ri, buf2);
2545 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2546 peer->host,
2547 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2548 p->prefixlen, buf2);
2549 }
2550
2551 /* Withdraw specified route from routing table. */
2552 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2553 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2554 else if (bgp_debug_update(peer, p, NULL, 1))
2555 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2556 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2557 p->prefixlen);
2558
2559 /* Unlock bgp_node_get() lock. */
2560 bgp_unlock_node (rn);
2561
2562 return 0;
2563 }
2564
2565 void
2566 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2567 {
2568 struct update_subgroup *subgrp;
2569 subgrp = peer_subgroup(peer, afi, safi);
2570 subgroup_default_originate(subgrp, withdraw);
2571 }
2572
2573
2574 /*
2575 * bgp_stop_announce_route_timer
2576 */
2577 void
2578 bgp_stop_announce_route_timer (struct peer_af *paf)
2579 {
2580 if (!paf->t_announce_route)
2581 return;
2582
2583 THREAD_TIMER_OFF (paf->t_announce_route);
2584 }
2585
2586 /*
2587 * bgp_announce_route_timer_expired
2588 *
2589 * Callback that is invoked when the route announcement timer for a
2590 * peer_af expires.
2591 */
2592 static int
2593 bgp_announce_route_timer_expired (struct thread *t)
2594 {
2595 struct peer_af *paf;
2596 struct peer *peer;
2597
2598
2599 paf = THREAD_ARG (t);
2600 peer = paf->peer;
2601
2602 assert (paf->t_announce_route);
2603 paf->t_announce_route = NULL;
2604
2605 if (peer->status != Established)
2606 return 0;
2607
2608 if (!peer->afc_nego[paf->afi][paf->safi])
2609 return 0;
2610
2611 peer_af_announce_route (paf, 1);
2612 return 0;
2613 }
2614
2615 /*
2616 * bgp_announce_route
2617 *
2618 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2619 */
2620 void
2621 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2622 {
2623 struct peer_af *paf;
2624 struct update_subgroup *subgrp;
2625
2626 paf = peer_af_find (peer, afi, safi);
2627 if (!paf)
2628 return;
2629 subgrp = PAF_SUBGRP(paf);
2630
2631 /*
2632 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2633 * or a refresh has already been triggered.
2634 */
2635 if (!subgrp || paf->t_announce_route)
2636 return;
2637
2638 /*
2639 * Start a timer to stagger/delay the announce. This serves
2640 * two purposes - announcement can potentially be combined for
2641 * multiple peers and the announcement doesn't happen in the
2642 * vty context.
2643 */
2644 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
2645 bgp_announce_route_timer_expired, paf,
2646 (subgrp->peer_count == 1) ?
2647 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2648 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2649 }
2650
2651 /*
2652 * Announce routes from all AF tables to a peer.
2653 *
2654 * This should ONLY be called when there is a need to refresh the
2655 * routes to the peer based on a policy change for this peer alone
2656 * or a route refresh request received from the peer.
2657 * The operation will result in splitting the peer from its existing
2658 * subgroups and putting it in new subgroups.
2659 */
2660 void
2661 bgp_announce_route_all (struct peer *peer)
2662 {
2663 afi_t afi;
2664 safi_t safi;
2665
2666 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2667 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2668 bgp_announce_route (peer, afi, safi);
2669 }
2670
2671 static void
2672 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2673 struct bgp_table *table, struct prefix_rd *prd)
2674 {
2675 int ret;
2676 struct bgp_node *rn;
2677 struct bgp_adj_in *ain;
2678
2679 if (! table)
2680 table = peer->bgp->rib[afi][safi];
2681
2682 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2683 for (ain = rn->adj_in; ain; ain = ain->next)
2684 {
2685 if (ain->peer == peer)
2686 {
2687 struct bgp_info *ri = rn->info;
2688 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2689
2690 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
2691 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2692 prd, tag, 1);
2693
2694 if (ret < 0)
2695 {
2696 bgp_unlock_node (rn);
2697 return;
2698 }
2699 }
2700 }
2701 }
2702
2703 void
2704 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2705 {
2706 struct bgp_node *rn;
2707 struct bgp_table *table;
2708
2709 if (peer->status != Established)
2710 return;
2711
2712 if (safi != SAFI_MPLS_VPN)
2713 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
2714 else
2715 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2716 rn = bgp_route_next (rn))
2717 if ((table = rn->info) != NULL)
2718 {
2719 struct prefix_rd prd;
2720 prd.family = AF_UNSPEC;
2721 prd.prefixlen = 64;
2722 memcpy(&prd.val, rn->p.u.val, 8);
2723
2724 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2725 }
2726 }
2727
2728
2729 struct bgp_clear_node_queue
2730 {
2731 struct bgp_node *rn;
2732 };
2733
2734 static wq_item_status
2735 bgp_clear_route_node (struct work_queue *wq, void *data)
2736 {
2737 struct bgp_clear_node_queue *cnq = data;
2738 struct bgp_node *rn = cnq->rn;
2739 struct peer *peer = wq->spec.data;
2740 struct bgp_info *ri;
2741 afi_t afi = bgp_node_table (rn)->afi;
2742 safi_t safi = bgp_node_table (rn)->safi;
2743
2744 assert (rn && peer);
2745
2746 /* It is possible that we have multiple paths for a prefix from a peer
2747 * if that peer is using AddPath.
2748 */
2749 for (ri = rn->info; ri; ri = ri->next)
2750 if (ri->peer == peer)
2751 {
2752 /* graceful restart STALE flag set. */
2753 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2754 && peer->nsf[afi][safi]
2755 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2756 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2757 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
2758 else
2759 bgp_rib_remove (rn, ri, peer, afi, safi);
2760 }
2761 return WQ_SUCCESS;
2762 }
2763
2764 static void
2765 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
2766 {
2767 struct bgp_clear_node_queue *cnq = data;
2768 struct bgp_node *rn = cnq->rn;
2769 struct bgp_table *table = bgp_node_table (rn);
2770
2771 bgp_unlock_node (rn);
2772 bgp_table_unlock (table);
2773 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
2774 }
2775
2776 static void
2777 bgp_clear_node_complete (struct work_queue *wq)
2778 {
2779 struct peer *peer = wq->spec.data;
2780
2781 /* Tickle FSM to start moving again */
2782 BGP_EVENT_ADD (peer, Clearing_Completed);
2783
2784 peer_unlock (peer); /* bgp_clear_route */
2785 }
2786
2787 static void
2788 bgp_clear_node_queue_init (struct peer *peer)
2789 {
2790 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
2791
2792 snprintf (wname, sizeof(wname), "clear %s", peer->host);
2793 #undef CLEAR_QUEUE_NAME_LEN
2794
2795 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
2796 {
2797 zlog_err ("%s: Failed to allocate work queue", __func__);
2798 exit (1);
2799 }
2800 peer->clear_node_queue->spec.hold = 10;
2801 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2802 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2803 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2804 peer->clear_node_queue->spec.max_retries = 0;
2805
2806 /* we only 'lock' this peer reference when the queue is actually active */
2807 peer->clear_node_queue->spec.data = peer;
2808 }
2809
2810 static void
2811 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2812 struct bgp_table *table)
2813 {
2814 struct bgp_node *rn;
2815
2816
2817 if (! table)
2818 table = peer->bgp->rib[afi][safi];
2819
2820 /* If still no table => afi/safi isn't configured at all or smth. */
2821 if (! table)
2822 return;
2823
2824 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2825 {
2826 struct bgp_info *ri;
2827 struct bgp_adj_in *ain;
2828 struct bgp_adj_in *ain_next;
2829
2830 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2831 * queued for every clearing peer, regardless of whether it is
2832 * relevant to the peer at hand.
2833 *
2834 * Overview: There are 3 different indices which need to be
2835 * scrubbed, potentially, when a peer is removed:
2836 *
2837 * 1 peer's routes visible via the RIB (ie accepted routes)
2838 * 2 peer's routes visible by the (optional) peer's adj-in index
2839 * 3 other routes visible by the peer's adj-out index
2840 *
2841 * 3 there is no hurry in scrubbing, once the struct peer is
2842 * removed from bgp->peer, we could just GC such deleted peer's
2843 * adj-outs at our leisure.
2844 *
2845 * 1 and 2 must be 'scrubbed' in some way, at least made
2846 * invisible via RIB index before peer session is allowed to be
2847 * brought back up. So one needs to know when such a 'search' is
2848 * complete.
2849 *
2850 * Ideally:
2851 *
2852 * - there'd be a single global queue or a single RIB walker
2853 * - rather than tracking which route_nodes still need to be
2854 * examined on a peer basis, we'd track which peers still
2855 * aren't cleared
2856 *
2857 * Given that our per-peer prefix-counts now should be reliable,
2858 * this may actually be achievable. It doesn't seem to be a huge
2859 * problem at this time,
2860 *
2861 * It is possible that we have multiple paths for a prefix from a peer
2862 * if that peer is using AddPath.
2863 */
2864 ain = rn->adj_in;
2865 while (ain)
2866 {
2867 ain_next = ain->next;
2868
2869 if (ain->peer == peer)
2870 {
2871 bgp_adj_in_remove (rn, ain);
2872 bgp_unlock_node (rn);
2873 }
2874
2875 ain = ain_next;
2876 }
2877
2878 for (ri = rn->info; ri; ri = ri->next)
2879 if (ri->peer == peer)
2880 {
2881 struct bgp_clear_node_queue *cnq;
2882
2883 /* both unlocked in bgp_clear_node_queue_del */
2884 bgp_table_lock (bgp_node_table (rn));
2885 bgp_lock_node (rn);
2886 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2887 sizeof (struct bgp_clear_node_queue));
2888 cnq->rn = rn;
2889 work_queue_add (peer->clear_node_queue, cnq);
2890 break;
2891 }
2892 }
2893 return;
2894 }
2895
2896 void
2897 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2898 {
2899 struct bgp_node *rn;
2900 struct bgp_table *table;
2901
2902 if (peer->clear_node_queue == NULL)
2903 bgp_clear_node_queue_init (peer);
2904
2905 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2906 * Idle until it receives a Clearing_Completed event. This protects
2907 * against peers which flap faster than we can we clear, which could
2908 * lead to:
2909 *
2910 * a) race with routes from the new session being installed before
2911 * clear_route_node visits the node (to delete the route of that
2912 * peer)
2913 * b) resource exhaustion, clear_route_node likely leads to an entry
2914 * on the process_main queue. Fast-flapping could cause that queue
2915 * to grow and grow.
2916 */
2917
2918 /* lock peer in assumption that clear-node-queue will get nodes; if so,
2919 * the unlock will happen upon work-queue completion; other wise, the
2920 * unlock happens at the end of this function.
2921 */
2922 if (!peer->clear_node_queue->thread)
2923 peer_lock (peer);
2924
2925 if (safi != SAFI_MPLS_VPN)
2926 bgp_clear_route_table (peer, afi, safi, NULL);
2927 else
2928 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2929 rn = bgp_route_next (rn))
2930 if ((table = rn->info) != NULL)
2931 bgp_clear_route_table (peer, afi, safi, table);
2932
2933 /* unlock if no nodes got added to the clear-node-queue. */
2934 if (!peer->clear_node_queue->thread)
2935 peer_unlock (peer);
2936
2937 }
2938
2939 void
2940 bgp_clear_route_all (struct peer *peer)
2941 {
2942 afi_t afi;
2943 safi_t safi;
2944
2945 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2946 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2947 bgp_clear_route (peer, afi, safi);
2948 }
2949
2950 void
2951 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2952 {
2953 struct bgp_table *table;
2954 struct bgp_node *rn;
2955 struct bgp_adj_in *ain;
2956 struct bgp_adj_in *ain_next;
2957
2958 table = peer->bgp->rib[afi][safi];
2959
2960 /* It is possible that we have multiple paths for a prefix from a peer
2961 * if that peer is using AddPath.
2962 */
2963 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2964 {
2965 ain = rn->adj_in;
2966
2967 while (ain)
2968 {
2969 ain_next = ain->next;
2970
2971 if (ain->peer == peer)
2972 {
2973 bgp_adj_in_remove (rn, ain);
2974 bgp_unlock_node (rn);
2975 }
2976
2977 ain = ain_next;
2978 }
2979 }
2980 }
2981
2982 void
2983 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2984 {
2985 struct bgp_node *rn;
2986 struct bgp_info *ri;
2987 struct bgp_table *table;
2988
2989 table = peer->bgp->rib[afi][safi];
2990
2991 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2992 {
2993 for (ri = rn->info; ri; ri = ri->next)
2994 if (ri->peer == peer)
2995 {
2996 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2997 bgp_rib_remove (rn, ri, peer, afi, safi);
2998 break;
2999 }
3000 }
3001 }
3002
3003 /* Delete all kernel routes. */
3004 void
3005 bgp_cleanup_routes (void)
3006 {
3007 struct bgp *bgp;
3008 struct listnode *node, *nnode;
3009 struct bgp_node *rn;
3010 struct bgp_table *table;
3011 struct bgp_info *ri;
3012
3013 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
3014 {
3015 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3016
3017 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3018 for (ri = rn->info; ri; ri = ri->next)
3019 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3020 && ri->type == ZEBRA_ROUTE_BGP
3021 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3022 ri->sub_type == BGP_ROUTE_AGGREGATE))
3023 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
3024
3025 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3026
3027 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3028 for (ri = rn->info; ri; ri = ri->next)
3029 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3030 && ri->type == ZEBRA_ROUTE_BGP
3031 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3032 ri->sub_type == BGP_ROUTE_AGGREGATE))
3033 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
3034 }
3035 }
3036
3037 void
3038 bgp_reset (void)
3039 {
3040 vty_reset ();
3041 bgp_zclient_reset ();
3042 access_list_reset ();
3043 prefix_list_reset ();
3044 }
3045
3046 static int
3047 bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3048 {
3049 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3050 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3051 }
3052
3053 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3054 value. */
3055 int
3056 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3057 {
3058 u_char *pnt;
3059 u_char *lim;
3060 struct prefix p;
3061 int psize;
3062 int ret;
3063 afi_t afi;
3064 safi_t safi;
3065 int addpath_encoded;
3066 u_int32_t addpath_id;
3067
3068 /* Check peer status. */
3069 if (peer->status != Established)
3070 return 0;
3071
3072 pnt = packet->nlri;
3073 lim = pnt + packet->length;
3074 afi = packet->afi;
3075 safi = packet->safi;
3076 addpath_id = 0;
3077 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3078
3079 for (; pnt < lim; pnt += psize)
3080 {
3081 /* Clear prefix structure. */
3082 memset (&p, 0, sizeof (struct prefix));
3083
3084 if (addpath_encoded)
3085 {
3086
3087 /* When packet overflow occurs return immediately. */
3088 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3089 return -1;
3090
3091 addpath_id = ntohl(*((uint32_t*) pnt));
3092 pnt += BGP_ADDPATH_ID_LEN;
3093 }
3094
3095 /* Fetch prefix length. */
3096 p.prefixlen = *pnt++;
3097 p.family = afi2family (afi);
3098
3099 /* Already checked in nlri_sanity_check(). We do double check
3100 here. */
3101 if ((afi == AFI_IP && p.prefixlen > 32)
3102 || (afi == AFI_IP6 && p.prefixlen > 128))
3103 return -1;
3104
3105 /* Packet size overflow check. */
3106 psize = PSIZE (p.prefixlen);
3107
3108 /* When packet overflow occur return immediately. */
3109 if (pnt + psize > lim)
3110 return -1;
3111
3112 /* Fetch prefix from NLRI packet. */
3113 memcpy (&p.u.prefix, pnt, psize);
3114
3115 /* Check address. */
3116 if (afi == AFI_IP && safi == SAFI_UNICAST)
3117 {
3118 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3119 {
3120 /*
3121 * From draft-ietf-idr-bgp4-22, Section 6.3:
3122 * If a BGP router receives an UPDATE message with a
3123 * semantically incorrect NLRI field, in which a prefix is
3124 * semantically incorrect (eg. an unexpected multicast IP
3125 * address), it should ignore the prefix.
3126 */
3127 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3128 inet_ntoa (p.u.prefix4));
3129
3130 return -1;
3131 }
3132 }
3133
3134 #ifdef HAVE_IPV6
3135 /* Check address. */
3136 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3137 {
3138 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3139 {
3140 char buf[BUFSIZ];
3141
3142 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3143 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3144
3145 continue;
3146 }
3147 }
3148 #endif /* HAVE_IPV6 */
3149
3150 /* Normal process. */
3151 if (attr)
3152 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3153 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3154 else
3155 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3156 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3157
3158 /* Address family configuration mismatch or maximum-prefix count
3159 overflow. */
3160 if (ret < 0)
3161 return -1;
3162 }
3163
3164 /* Packet length consistency check. */
3165 if (pnt != lim)
3166 return -1;
3167
3168 return 0;
3169 }
3170
3171 /* NLRI encode syntax check routine. */
3172 int
3173 bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
3174 bgp_size_t length, int *numpfx)
3175 {
3176 u_char *end;
3177 u_char prefixlen;
3178 int psize;
3179 int addpath_encoded;
3180
3181 *numpfx = 0;
3182 end = pnt + length;
3183 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3184
3185 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3186 syntactic validity. If the field is syntactically incorrect,
3187 then the Error Subcode is set to Invalid Network Field. */
3188
3189 while (pnt < end)
3190 {
3191
3192 /* If the NLRI is encoded using addpath then the first 4 bytes are
3193 * the addpath ID. */
3194 if (addpath_encoded)
3195 {
3196 if (pnt + BGP_ADDPATH_ID_LEN > end)
3197 {
3198 zlog_err ("%s [Error] Update packet error"
3199 " (prefix data addpath overflow)",
3200 peer->host);
3201 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3202 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3203 return -1;
3204 }
3205 pnt += BGP_ADDPATH_ID_LEN;
3206 }
3207
3208 prefixlen = *pnt++;
3209
3210 /* Prefix length check. */
3211 if ((afi == AFI_IP && prefixlen > 32)
3212 || (afi == AFI_IP6 && prefixlen > 128))
3213 {
3214 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
3215 peer->host, prefixlen);
3216 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3217 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3218 return -1;
3219 }
3220
3221 /* Packet size overflow check. */
3222 psize = PSIZE (prefixlen);
3223
3224 if (pnt + psize > end)
3225 {
3226 zlog_err ("%s [Error] Update packet error"
3227 " (prefix data overflow prefix size is %d)",
3228 peer->host, psize);
3229 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3230 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3231 return -1;
3232 }
3233
3234 pnt += psize;
3235 (*numpfx)++;
3236 }
3237
3238 /* Packet length consistency check. */
3239 if (pnt != end)
3240 {
3241 zlog_err ("%s [Error] Update packet error"
3242 " (prefix length mismatch with total length)",
3243 peer->host);
3244 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3245 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3246 return -1;
3247 }
3248 return 0;
3249 }
3250
3251 static struct bgp_static *
3252 bgp_static_new (void)
3253 {
3254 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3255 }
3256
3257 static void
3258 bgp_static_free (struct bgp_static *bgp_static)
3259 {
3260 if (bgp_static->rmap.name)
3261 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3262 XFREE (MTYPE_BGP_STATIC, bgp_static);
3263 }
3264
3265 static void
3266 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3267 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3268 {
3269 struct bgp_node *rn;
3270 struct bgp_info *ri;
3271 struct bgp_info *new;
3272 struct bgp_info info;
3273 struct attr attr;
3274 struct attr *attr_new;
3275 int ret;
3276
3277 assert (bgp_static);
3278 if (!bgp_static)
3279 return;
3280
3281 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3282
3283 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3284
3285 attr.nexthop = bgp_static->igpnexthop;
3286 attr.med = bgp_static->igpmetric;
3287 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3288
3289 if (bgp_static->atomic)
3290 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3291
3292 /* Apply route-map. */
3293 if (bgp_static->rmap.name)
3294 {
3295 struct attr attr_tmp = attr;
3296 info.peer = bgp->peer_self;
3297 info.attr = &attr_tmp;
3298
3299 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3300
3301 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3302
3303 bgp->peer_self->rmap_type = 0;
3304
3305 if (ret == RMAP_DENYMATCH)
3306 {
3307 /* Free uninterned attribute. */
3308 bgp_attr_flush (&attr_tmp);
3309
3310 /* Unintern original. */
3311 aspath_unintern (&attr.aspath);
3312 bgp_attr_extra_free (&attr);
3313 bgp_static_withdraw (bgp, p, afi, safi);
3314 return;
3315 }
3316 attr_new = bgp_attr_intern (&attr_tmp);
3317 }
3318 else
3319 attr_new = bgp_attr_intern (&attr);
3320
3321 for (ri = rn->info; ri; ri = ri->next)
3322 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3323 && ri->sub_type == BGP_ROUTE_STATIC)
3324 break;
3325
3326 if (ri)
3327 {
3328 if (attrhash_cmp (ri->attr, attr_new) &&
3329 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3330 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
3331 {
3332 bgp_unlock_node (rn);
3333 bgp_attr_unintern (&attr_new);
3334 aspath_unintern (&attr.aspath);
3335 bgp_attr_extra_free (&attr);
3336 return;
3337 }
3338 else
3339 {
3340 /* The attribute is changed. */
3341 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3342
3343 /* Rewrite BGP route information. */
3344 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3345 bgp_info_restore(rn, ri);
3346 else
3347 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3348 bgp_attr_unintern (&ri->attr);
3349 ri->attr = attr_new;
3350 ri->uptime = bgp_clock ();
3351
3352 /* Nexthop reachability check. */
3353 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3354 {
3355 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
3356 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3357 else
3358 {
3359 if (BGP_DEBUG(nht, NHT))
3360 {
3361 char buf1[INET6_ADDRSTRLEN];
3362 inet_ntop(p->family, &p->u.prefix, buf1,
3363 INET6_ADDRSTRLEN);
3364 zlog_debug("%s(%s): Route not in table, not advertising",
3365 __FUNCTION__, buf1);
3366 }
3367 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3368 }
3369 }
3370 else
3371 {
3372 /* Delete the NHT structure if any, if we're toggling between
3373 * enabling/disabling import check. We deregister the route
3374 * from NHT to avoid overloading NHT and the process interaction
3375 */
3376 bgp_unlink_nexthop(ri);
3377 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3378 }
3379 /* Process change. */
3380 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3381 bgp_process (bgp, rn, afi, safi);
3382 bgp_unlock_node (rn);
3383 aspath_unintern (&attr.aspath);
3384 bgp_attr_extra_free (&attr);
3385 return;
3386 }
3387 }
3388
3389 /* Make new BGP info. */
3390 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3391 rn);
3392 /* Nexthop reachability check. */
3393 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3394 {
3395 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
3396 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3397 else
3398 {
3399 if (BGP_DEBUG(nht, NHT))
3400 {
3401 char buf1[INET6_ADDRSTRLEN];
3402 inet_ntop(p->family, &p->u.prefix, buf1,
3403 INET6_ADDRSTRLEN);
3404 zlog_debug("%s(%s): Route not in table, not advertising",
3405 __FUNCTION__, buf1);
3406 }
3407 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3408 }
3409 }
3410 else
3411 {
3412 /* Delete the NHT structure if any, if we're toggling between
3413 * enabling/disabling import check. We deregister the route
3414 * from NHT to avoid overloading NHT and the process interaction
3415 */
3416 bgp_unlink_nexthop(new);
3417
3418 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3419 }
3420
3421 /* Aggregate address increment. */
3422 bgp_aggregate_increment (bgp, p, new, afi, safi);
3423
3424 /* Register new BGP information. */
3425 bgp_info_add (rn, new);
3426
3427 /* route_node_get lock */
3428 bgp_unlock_node (rn);
3429
3430 /* Process change. */
3431 bgp_process (bgp, rn, afi, safi);
3432
3433 /* Unintern original. */
3434 aspath_unintern (&attr.aspath);
3435 bgp_attr_extra_free (&attr);
3436 }
3437
3438 void
3439 bgp_static_update (struct bgp *bgp, struct prefix *p,
3440 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3441 {
3442 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3443 }
3444
3445 static void
3446 bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3447 safi_t safi, struct prefix_rd *prd, u_char *tag)
3448 {
3449 struct bgp_node *rn;
3450 struct bgp_info *new;
3451
3452 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3453
3454 /* Make new BGP info. */
3455 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
3456 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3457
3458 SET_FLAG (new->flags, BGP_INFO_VALID);
3459 new->extra = bgp_info_extra_new();
3460 memcpy (new->extra->tag, tag, 3);
3461
3462 /* Aggregate address increment. */
3463 bgp_aggregate_increment (bgp, p, new, afi, safi);
3464
3465 /* Register new BGP information. */
3466 bgp_info_add (rn, new);
3467
3468 /* route_node_get lock */
3469 bgp_unlock_node (rn);
3470
3471 /* Process change. */
3472 bgp_process (bgp, rn, afi, safi);
3473 }
3474
3475 void
3476 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3477 safi_t safi)
3478 {
3479 struct bgp_node *rn;
3480 struct bgp_info *ri;
3481
3482 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3483
3484 /* Check selected route and self inserted route. */
3485 for (ri = rn->info; ri; ri = ri->next)
3486 if (ri->peer == bgp->peer_self
3487 && ri->type == ZEBRA_ROUTE_BGP
3488 && ri->sub_type == BGP_ROUTE_STATIC)
3489 break;
3490
3491 /* Withdraw static BGP route from routing table. */
3492 if (ri)
3493 {
3494 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3495 bgp_unlink_nexthop(ri);
3496 bgp_info_delete (rn, ri);
3497 bgp_process (bgp, rn, afi, safi);
3498 }
3499
3500 /* Unlock bgp_node_lookup. */
3501 bgp_unlock_node (rn);
3502 }
3503
3504 static void
3505 bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3506 safi_t safi, struct prefix_rd *prd, u_char *tag)
3507 {
3508 struct bgp_node *rn;
3509 struct bgp_info *ri;
3510
3511 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3512
3513 /* Check selected route and self inserted route. */
3514 for (ri = rn->info; ri; ri = ri->next)
3515 if (ri->peer == bgp->peer_self
3516 && ri->type == ZEBRA_ROUTE_BGP
3517 && ri->sub_type == BGP_ROUTE_STATIC)
3518 break;
3519
3520 /* Withdraw static BGP route from routing table. */
3521 if (ri)
3522 {
3523 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3524 bgp_info_delete (rn, ri);
3525 bgp_process (bgp, rn, afi, safi);
3526 }
3527
3528 /* Unlock bgp_node_lookup. */
3529 bgp_unlock_node (rn);
3530 }
3531
3532 /* Configure static BGP network. When user don't run zebra, static
3533 route should be installed as valid. */
3534 static int
3535 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3536 afi_t afi, safi_t safi, const char *rmap, int backdoor)
3537 {
3538 int ret;
3539 struct prefix p;
3540 struct bgp_static *bgp_static;
3541 struct bgp_node *rn;
3542 u_char need_update = 0;
3543
3544 /* Convert IP prefix string to struct prefix. */
3545 ret = str2prefix (ip_str, &p);
3546 if (! ret)
3547 {
3548 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3549 return CMD_WARNING;
3550 }
3551 #ifdef HAVE_IPV6
3552 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3553 {
3554 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3555 VTY_NEWLINE);
3556 return CMD_WARNING;
3557 }
3558 #endif /* HAVE_IPV6 */
3559
3560 apply_mask (&p);
3561
3562 /* Set BGP static route configuration. */
3563 rn = bgp_node_get (bgp->route[afi][safi], &p);
3564
3565 if (rn->info)
3566 {
3567 /* Configuration change. */
3568 bgp_static = rn->info;
3569
3570 /* Check previous routes are installed into BGP. */
3571 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3572 need_update = 1;
3573
3574 bgp_static->backdoor = backdoor;
3575
3576 if (rmap)
3577 {
3578 if (bgp_static->rmap.name)
3579 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3580 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
3581 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3582 }
3583 else
3584 {
3585 if (bgp_static->rmap.name)
3586 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3587 bgp_static->rmap.name = NULL;
3588 bgp_static->rmap.map = NULL;
3589 bgp_static->valid = 0;
3590 }
3591 bgp_unlock_node (rn);
3592 }
3593 else
3594 {
3595 /* New configuration. */
3596 bgp_static = bgp_static_new ();
3597 bgp_static->backdoor = backdoor;
3598 bgp_static->valid = 0;
3599 bgp_static->igpmetric = 0;
3600 bgp_static->igpnexthop.s_addr = 0;
3601
3602 if (rmap)
3603 {
3604 if (bgp_static->rmap.name)
3605 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3606 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
3607 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3608 }
3609 rn->info = bgp_static;
3610 }
3611
3612 bgp_static->valid = 1;
3613 if (need_update)
3614 bgp_static_withdraw (bgp, &p, afi, safi);
3615
3616 if (! bgp_static->backdoor)
3617 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3618
3619 return CMD_SUCCESS;
3620 }
3621
3622 /* Configure static BGP network. */
3623 static int
3624 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
3625 afi_t afi, safi_t safi)
3626 {
3627 int ret;
3628 struct prefix p;
3629 struct bgp_static *bgp_static;
3630 struct bgp_node *rn;
3631
3632 /* Convert IP prefix string to struct prefix. */
3633 ret = str2prefix (ip_str, &p);
3634 if (! ret)
3635 {
3636 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3637 return CMD_WARNING;
3638 }
3639 #ifdef HAVE_IPV6
3640 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3641 {
3642 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3643 VTY_NEWLINE);
3644 return CMD_WARNING;
3645 }
3646 #endif /* HAVE_IPV6 */
3647
3648 apply_mask (&p);
3649
3650 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3651 if (! rn)
3652 {
3653 vty_out (vty, "%% Can't find specified static route configuration.%s",
3654 VTY_NEWLINE);
3655 return CMD_WARNING;
3656 }
3657
3658 bgp_static = rn->info;
3659
3660 /* Update BGP RIB. */
3661 if (! bgp_static->backdoor)
3662 bgp_static_withdraw (bgp, &p, afi, safi);
3663
3664 /* Clear configuration. */
3665 bgp_static_free (bgp_static);
3666 rn->info = NULL;
3667 bgp_unlock_node (rn);
3668 bgp_unlock_node (rn);
3669
3670 return CMD_SUCCESS;
3671 }
3672
3673 /* Called from bgp_delete(). Delete all static routes from the BGP
3674 instance. */
3675 void
3676 bgp_static_delete (struct bgp *bgp)
3677 {
3678 afi_t afi;
3679 safi_t safi;
3680 struct bgp_node *rn;
3681 struct bgp_node *rm;
3682 struct bgp_table *table;
3683 struct bgp_static *bgp_static;
3684
3685 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3686 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3687 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3688 if (rn->info != NULL)
3689 {
3690 if (safi == SAFI_MPLS_VPN)
3691 {
3692 table = rn->info;
3693
3694 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3695 {
3696 bgp_static = rn->info;
3697 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3698 AFI_IP, SAFI_MPLS_VPN,
3699 (struct prefix_rd *)&rn->p,
3700 bgp_static->tag);
3701 bgp_static_free (bgp_static);
3702 rn->info = NULL;
3703 bgp_unlock_node (rn);
3704 }
3705 }
3706 else
3707 {
3708 bgp_static = rn->info;
3709 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3710 bgp_static_free (bgp_static);
3711 rn->info = NULL;
3712 bgp_unlock_node (rn);
3713 }
3714 }
3715 }
3716
3717 void
3718 bgp_static_redo_import_check (struct bgp *bgp)
3719 {
3720 afi_t afi;
3721 safi_t safi;
3722 struct bgp_node *rn;
3723 struct bgp_static *bgp_static;
3724
3725 /* Use this flag to force reprocessing of the route */
3726 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3727 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3728 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3729 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3730 if (rn->info != NULL)
3731 {
3732 bgp_static = rn->info;
3733 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
3734 }
3735 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3736 }
3737
3738 int
3739 bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3740 const char *tag_str)
3741 {
3742 int ret;
3743 struct prefix p;
3744 struct prefix_rd prd;
3745 struct bgp *bgp;
3746 struct bgp_node *prn;
3747 struct bgp_node *rn;
3748 struct bgp_table *table;
3749 struct bgp_static *bgp_static;
3750 u_char tag[3];
3751
3752 bgp = vty->index;
3753
3754 ret = str2prefix (ip_str, &p);
3755 if (! ret)
3756 {
3757 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3758 return CMD_WARNING;
3759 }
3760 apply_mask (&p);
3761
3762 ret = str2prefix_rd (rd_str, &prd);
3763 if (! ret)
3764 {
3765 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3766 return CMD_WARNING;
3767 }
3768
3769 ret = str2tag (tag_str, tag);
3770 if (! ret)
3771 {
3772 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3773 return CMD_WARNING;
3774 }
3775
3776 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3777 (struct prefix *)&prd);
3778 if (prn->info == NULL)
3779 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3780 else
3781 bgp_unlock_node (prn);
3782 table = prn->info;
3783
3784 rn = bgp_node_get (table, &p);
3785
3786 if (rn->info)
3787 {
3788 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3789 bgp_unlock_node (rn);
3790 }
3791 else
3792 {
3793 /* New configuration. */
3794 bgp_static = bgp_static_new ();
3795 bgp_static->valid = 1;
3796 memcpy (bgp_static->tag, tag, 3);
3797 rn->info = bgp_static;
3798
3799 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3800 }
3801
3802 return CMD_SUCCESS;
3803 }
3804
3805 /* Configure static BGP network. */
3806 int
3807 bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3808 const char *rd_str, const char *tag_str)
3809 {
3810 int ret;
3811 struct bgp *bgp;
3812 struct prefix p;
3813 struct prefix_rd prd;
3814 struct bgp_node *prn;
3815 struct bgp_node *rn;
3816 struct bgp_table *table;
3817 struct bgp_static *bgp_static;
3818 u_char tag[3];
3819
3820 bgp = vty->index;
3821
3822 /* Convert IP prefix string to struct prefix. */
3823 ret = str2prefix (ip_str, &p);
3824 if (! ret)
3825 {
3826 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3827 return CMD_WARNING;
3828 }
3829 apply_mask (&p);
3830
3831 ret = str2prefix_rd (rd_str, &prd);
3832 if (! ret)
3833 {
3834 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3835 return CMD_WARNING;
3836 }
3837
3838 ret = str2tag (tag_str, tag);
3839 if (! ret)
3840 {
3841 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3842 return CMD_WARNING;
3843 }
3844
3845 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3846 (struct prefix *)&prd);
3847 if (prn->info == NULL)
3848 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3849 else
3850 bgp_unlock_node (prn);
3851 table = prn->info;
3852
3853 rn = bgp_node_lookup (table, &p);
3854
3855 if (rn)
3856 {
3857 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3858
3859 bgp_static = rn->info;
3860 bgp_static_free (bgp_static);
3861 rn->info = NULL;
3862 bgp_unlock_node (rn);
3863 bgp_unlock_node (rn);
3864 }
3865 else
3866 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3867
3868 return CMD_SUCCESS;
3869 }
3870
3871 static int
3872 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
3873 const char *rmap_name)
3874 {
3875 struct bgp_rmap *rmap;
3876
3877 rmap = &bgp->table_map[afi][safi];
3878 if (rmap_name)
3879 {
3880 if (rmap->name)
3881 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
3882 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
3883 rmap->map = route_map_lookup_by_name (rmap_name);
3884 }
3885 else
3886 {
3887 if (rmap->name)
3888 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
3889 rmap->name = NULL;
3890 rmap->map = NULL;
3891 }
3892
3893 bgp_zebra_announce_table(bgp, afi, safi);
3894
3895 return CMD_SUCCESS;
3896 }
3897
3898 static int
3899 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
3900 const char *rmap_name)
3901 {
3902 struct bgp_rmap *rmap;
3903
3904 rmap = &bgp->table_map[afi][safi];
3905 if (rmap->name)
3906 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
3907 rmap->name = NULL;
3908 rmap->map = NULL;
3909
3910 bgp_zebra_announce_table(bgp, afi, safi);
3911
3912 return CMD_SUCCESS;
3913 }
3914
3915 int
3916 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
3917 safi_t safi, int *write)
3918 {
3919 if (bgp->table_map[afi][safi].name)
3920 {
3921 bgp_config_write_family_header (vty, afi, safi, write);
3922 vty_out (vty, " table-map %s%s",
3923 bgp->table_map[afi][safi].name, VTY_NEWLINE);
3924 }
3925
3926 return 0;
3927 }
3928
3929
3930 DEFUN (bgp_table_map,
3931 bgp_table_map_cmd,
3932 "table-map WORD",
3933 "BGP table to RIB route download filter\n"
3934 "Name of the route map\n")
3935 {
3936 return bgp_table_map_set (vty, vty->index,
3937 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
3938 }
3939 DEFUN (no_bgp_table_map,
3940 no_bgp_table_map_cmd,
3941 "no table-map WORD",
3942 "BGP table to RIB route download filter\n"
3943 "Name of the route map\n")
3944 {
3945 return bgp_table_map_unset (vty, vty->index,
3946 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
3947 }
3948
3949 DEFUN (bgp_network,
3950 bgp_network_cmd,
3951 "network A.B.C.D/M",
3952 "Specify a network to announce via BGP\n"
3953 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3954 {
3955 return bgp_static_set (vty, vty->index, argv[0],
3956 AFI_IP, bgp_node_safi (vty), NULL, 0);
3957 }
3958
3959 DEFUN (bgp_network_route_map,
3960 bgp_network_route_map_cmd,
3961 "network A.B.C.D/M route-map WORD",
3962 "Specify a network to announce via BGP\n"
3963 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3964 "Route-map to modify the attributes\n"
3965 "Name of the route map\n")
3966 {
3967 return bgp_static_set (vty, vty->index, argv[0],
3968 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3969 }
3970
3971 DEFUN (bgp_network_backdoor,
3972 bgp_network_backdoor_cmd,
3973 "network A.B.C.D/M backdoor",
3974 "Specify a network to announce via BGP\n"
3975 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3976 "Specify a BGP backdoor route\n")
3977 {
3978 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
3979 NULL, 1);
3980 }
3981
3982 DEFUN (bgp_network_mask,
3983 bgp_network_mask_cmd,
3984 "network A.B.C.D mask A.B.C.D",
3985 "Specify a network to announce via BGP\n"
3986 "Network number\n"
3987 "Network mask\n"
3988 "Network mask\n")
3989 {
3990 int ret;
3991 char prefix_str[BUFSIZ];
3992
3993 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3994 if (! ret)
3995 {
3996 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3997 return CMD_WARNING;
3998 }
3999
4000 return bgp_static_set (vty, vty->index, prefix_str,
4001 AFI_IP, bgp_node_safi (vty), NULL, 0);
4002 }
4003
4004 DEFUN (bgp_network_mask_route_map,
4005 bgp_network_mask_route_map_cmd,
4006 "network A.B.C.D mask A.B.C.D route-map WORD",
4007 "Specify a network to announce via BGP\n"
4008 "Network number\n"
4009 "Network mask\n"
4010 "Network mask\n"
4011 "Route-map to modify the attributes\n"
4012 "Name of the route map\n")
4013 {
4014 int ret;
4015 char prefix_str[BUFSIZ];
4016
4017 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4018 if (! ret)
4019 {
4020 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4021 return CMD_WARNING;
4022 }
4023
4024 return bgp_static_set (vty, vty->index, prefix_str,
4025 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4026 }
4027
4028 DEFUN (bgp_network_mask_backdoor,
4029 bgp_network_mask_backdoor_cmd,
4030 "network A.B.C.D mask A.B.C.D backdoor",
4031 "Specify a network to announce via BGP\n"
4032 "Network number\n"
4033 "Network mask\n"
4034 "Network mask\n"
4035 "Specify a BGP backdoor route\n")
4036 {
4037 int ret;
4038 char prefix_str[BUFSIZ];
4039
4040 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4041 if (! ret)
4042 {
4043 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4044 return CMD_WARNING;
4045 }
4046
4047 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4048 NULL, 1);
4049 }
4050
4051 DEFUN (bgp_network_mask_natural,
4052 bgp_network_mask_natural_cmd,
4053 "network A.B.C.D",
4054 "Specify a network to announce via BGP\n"
4055 "Network number\n")
4056 {
4057 int ret;
4058 char prefix_str[BUFSIZ];
4059
4060 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4061 if (! ret)
4062 {
4063 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4064 return CMD_WARNING;
4065 }
4066
4067 return bgp_static_set (vty, vty->index, prefix_str,
4068 AFI_IP, bgp_node_safi (vty), NULL, 0);
4069 }
4070
4071 DEFUN (bgp_network_mask_natural_route_map,
4072 bgp_network_mask_natural_route_map_cmd,
4073 "network A.B.C.D route-map WORD",
4074 "Specify a network to announce via BGP\n"
4075 "Network number\n"
4076 "Route-map to modify the attributes\n"
4077 "Name of the route map\n")
4078 {
4079 int ret;
4080 char prefix_str[BUFSIZ];
4081
4082 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4083 if (! ret)
4084 {
4085 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4086 return CMD_WARNING;
4087 }
4088
4089 return bgp_static_set (vty, vty->index, prefix_str,
4090 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4091 }
4092
4093 DEFUN (bgp_network_mask_natural_backdoor,
4094 bgp_network_mask_natural_backdoor_cmd,
4095 "network A.B.C.D backdoor",
4096 "Specify a network to announce via BGP\n"
4097 "Network number\n"
4098 "Specify a BGP backdoor route\n")
4099 {
4100 int ret;
4101 char prefix_str[BUFSIZ];
4102
4103 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4104 if (! ret)
4105 {
4106 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4107 return CMD_WARNING;
4108 }
4109
4110 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4111 NULL, 1);
4112 }
4113
4114 DEFUN (no_bgp_network,
4115 no_bgp_network_cmd,
4116 "no network A.B.C.D/M",
4117 NO_STR
4118 "Specify a network to announce via BGP\n"
4119 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4120 {
4121 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4122 bgp_node_safi (vty));
4123 }
4124
4125 ALIAS (no_bgp_network,
4126 no_bgp_network_route_map_cmd,
4127 "no network A.B.C.D/M route-map WORD",
4128 NO_STR
4129 "Specify a network to announce via BGP\n"
4130 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4131 "Route-map to modify the attributes\n"
4132 "Name of the route map\n")
4133
4134 ALIAS (no_bgp_network,
4135 no_bgp_network_backdoor_cmd,
4136 "no network A.B.C.D/M backdoor",
4137 NO_STR
4138 "Specify a network to announce via BGP\n"
4139 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4140 "Specify a BGP backdoor route\n")
4141
4142 DEFUN (no_bgp_network_mask,
4143 no_bgp_network_mask_cmd,
4144 "no network A.B.C.D mask A.B.C.D",
4145 NO_STR
4146 "Specify a network to announce via BGP\n"
4147 "Network number\n"
4148 "Network mask\n"
4149 "Network mask\n")
4150 {
4151 int ret;
4152 char prefix_str[BUFSIZ];
4153
4154 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4155 if (! ret)
4156 {
4157 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4158 return CMD_WARNING;
4159 }
4160
4161 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4162 bgp_node_safi (vty));
4163 }
4164
4165 ALIAS (no_bgp_network_mask,
4166 no_bgp_network_mask_route_map_cmd,
4167 "no network A.B.C.D mask A.B.C.D route-map WORD",
4168 NO_STR
4169 "Specify a network to announce via BGP\n"
4170 "Network number\n"
4171 "Network mask\n"
4172 "Network mask\n"
4173 "Route-map to modify the attributes\n"
4174 "Name of the route map\n")
4175
4176 ALIAS (no_bgp_network_mask,
4177 no_bgp_network_mask_backdoor_cmd,
4178 "no network A.B.C.D mask A.B.C.D backdoor",
4179 NO_STR
4180 "Specify a network to announce via BGP\n"
4181 "Network number\n"
4182 "Network mask\n"
4183 "Network mask\n"
4184 "Specify a BGP backdoor route\n")
4185
4186 DEFUN (no_bgp_network_mask_natural,
4187 no_bgp_network_mask_natural_cmd,
4188 "no network A.B.C.D",
4189 NO_STR
4190 "Specify a network to announce via BGP\n"
4191 "Network number\n")
4192 {
4193 int ret;
4194 char prefix_str[BUFSIZ];
4195
4196 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4197 if (! ret)
4198 {
4199 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4200 return CMD_WARNING;
4201 }
4202
4203 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4204 bgp_node_safi (vty));
4205 }
4206
4207 ALIAS (no_bgp_network_mask_natural,
4208 no_bgp_network_mask_natural_route_map_cmd,
4209 "no network A.B.C.D route-map WORD",
4210 NO_STR
4211 "Specify a network to announce via BGP\n"
4212 "Network number\n"
4213 "Route-map to modify the attributes\n"
4214 "Name of the route map\n")
4215
4216 ALIAS (no_bgp_network_mask_natural,
4217 no_bgp_network_mask_natural_backdoor_cmd,
4218 "no network A.B.C.D backdoor",
4219 NO_STR
4220 "Specify a network to announce via BGP\n"
4221 "Network number\n"
4222 "Specify a BGP backdoor route\n")
4223
4224 #ifdef HAVE_IPV6
4225 DEFUN (ipv6_bgp_network,
4226 ipv6_bgp_network_cmd,
4227 "network X:X::X:X/M",
4228 "Specify a network to announce via BGP\n"
4229 "IPv6 prefix <network>/<length>\n")
4230 {
4231 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4232 NULL, 0);
4233 }
4234
4235 DEFUN (ipv6_bgp_network_route_map,
4236 ipv6_bgp_network_route_map_cmd,
4237 "network X:X::X:X/M route-map WORD",
4238 "Specify a network to announce via BGP\n"
4239 "IPv6 prefix <network>/<length>\n"
4240 "Route-map to modify the attributes\n"
4241 "Name of the route map\n")
4242 {
4243 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4244 bgp_node_safi (vty), argv[1], 0);
4245 }
4246
4247 DEFUN (no_ipv6_bgp_network,
4248 no_ipv6_bgp_network_cmd,
4249 "no network X:X::X:X/M",
4250 NO_STR
4251 "Specify a network to announce via BGP\n"
4252 "IPv6 prefix <network>/<length>\n")
4253 {
4254 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4255 }
4256
4257 ALIAS (no_ipv6_bgp_network,
4258 no_ipv6_bgp_network_route_map_cmd,
4259 "no network X:X::X:X/M route-map WORD",
4260 NO_STR
4261 "Specify a network to announce via BGP\n"
4262 "IPv6 prefix <network>/<length>\n"
4263 "Route-map to modify the attributes\n"
4264 "Name of the route map\n")
4265
4266 ALIAS (ipv6_bgp_network,
4267 old_ipv6_bgp_network_cmd,
4268 "ipv6 bgp network X:X::X:X/M",
4269 IPV6_STR
4270 BGP_STR
4271 "Specify a network to announce via BGP\n"
4272 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4273
4274 ALIAS (no_ipv6_bgp_network,
4275 old_no_ipv6_bgp_network_cmd,
4276 "no ipv6 bgp network X:X::X:X/M",
4277 NO_STR
4278 IPV6_STR
4279 BGP_STR
4280 "Specify a network to announce via BGP\n"
4281 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4282 #endif /* HAVE_IPV6 */
4283
4284 /* Aggreagete address:
4285
4286 advertise-map Set condition to advertise attribute
4287 as-set Generate AS set path information
4288 attribute-map Set attributes of aggregate
4289 route-map Set parameters of aggregate
4290 summary-only Filter more specific routes from updates
4291 suppress-map Conditionally filter more specific routes from updates
4292 <cr>
4293 */
4294 struct bgp_aggregate
4295 {
4296 /* Summary-only flag. */
4297 u_char summary_only;
4298
4299 /* AS set generation. */
4300 u_char as_set;
4301
4302 /* Route-map for aggregated route. */
4303 struct route_map *map;
4304
4305 /* Suppress-count. */
4306 unsigned long count;
4307
4308 /* SAFI configuration. */
4309 safi_t safi;
4310 };
4311
4312 static struct bgp_aggregate *
4313 bgp_aggregate_new (void)
4314 {
4315 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4316 }
4317
4318 static void
4319 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4320 {
4321 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4322 }
4323
4324 /* Update an aggregate as routes are added/removed from the BGP table */
4325 static void
4326 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4327 afi_t afi, safi_t safi, struct bgp_info *del,
4328 struct bgp_aggregate *aggregate)
4329 {
4330 struct bgp_table *table;
4331 struct bgp_node *top;
4332 struct bgp_node *rn;
4333 u_char origin;
4334 struct aspath *aspath = NULL;
4335 struct aspath *asmerge = NULL;
4336 struct community *community = NULL;
4337 struct community *commerge = NULL;
4338 #if defined(AGGREGATE_NEXTHOP_CHECK)
4339 struct in_addr nexthop;
4340 u_int32_t med = 0;
4341 #endif
4342 struct bgp_info *ri;
4343 struct bgp_info *new;
4344 int first = 1;
4345 unsigned long match = 0;
4346 u_char atomic_aggregate = 0;
4347
4348 /* Record adding route's nexthop and med. */
4349 if (rinew)
4350 {
4351 #if defined(AGGREGATE_NEXTHOP_CHECK)
4352 nexthop = rinew->attr->nexthop;
4353 med = rinew->attr->med;
4354 #endif
4355 }
4356
4357 /* ORIGIN attribute: If at least one route among routes that are
4358 aggregated has ORIGIN with the value INCOMPLETE, then the
4359 aggregated route must have the ORIGIN attribute with the value
4360 INCOMPLETE. Otherwise, if at least one route among routes that
4361 are aggregated has ORIGIN with the value EGP, then the aggregated
4362 route must have the origin attribute with the value EGP. In all
4363 other case the value of the ORIGIN attribute of the aggregated
4364 route is INTERNAL. */
4365 origin = BGP_ORIGIN_IGP;
4366
4367 table = bgp->rib[afi][safi];
4368
4369 top = bgp_node_get (table, p);
4370 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4371 if (rn->p.prefixlen > p->prefixlen)
4372 {
4373 match = 0;
4374
4375 for (ri = rn->info; ri; ri = ri->next)
4376 {
4377 if (BGP_INFO_HOLDDOWN (ri))
4378 continue;
4379
4380 if (del && ri == del)
4381 continue;
4382
4383 if (! rinew && first)
4384 {
4385 #if defined(AGGREGATE_NEXTHOP_CHECK)
4386 nexthop = ri->attr->nexthop;
4387 med = ri->attr->med;
4388 #endif
4389 first = 0;
4390 }
4391
4392 #ifdef AGGREGATE_NEXTHOP_CHECK
4393 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4394 || ri->attr->med != med)
4395 {
4396 if (aspath)
4397 aspath_free (aspath);
4398 if (community)
4399 community_free (community);
4400 bgp_unlock_node (rn);
4401 bgp_unlock_node (top);
4402 return;
4403 }
4404 #endif /* AGGREGATE_NEXTHOP_CHECK */
4405
4406 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4407 atomic_aggregate = 1;
4408
4409 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4410 {
4411 if (aggregate->summary_only)
4412 {
4413 (bgp_info_extra_get (ri))->suppress++;
4414 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4415 match++;
4416 }
4417
4418 aggregate->count++;
4419
4420 if (origin < ri->attr->origin)
4421 origin = ri->attr->origin;
4422
4423 if (aggregate->as_set)
4424 {
4425 if (aspath)
4426 {
4427 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4428 aspath_free (aspath);
4429 aspath = asmerge;
4430 }
4431 else
4432 aspath = aspath_dup (ri->attr->aspath);
4433
4434 if (ri->attr->community)
4435 {
4436 if (community)
4437 {
4438 commerge = community_merge (community,
4439 ri->attr->community);
4440 community = community_uniq_sort (commerge);
4441 community_free (commerge);
4442 }
4443 else
4444 community = community_dup (ri->attr->community);
4445 }
4446 }
4447 }
4448 }
4449 if (match)
4450 bgp_process (bgp, rn, afi, safi);
4451 }
4452 bgp_unlock_node (top);
4453
4454 if (rinew)
4455 {
4456 aggregate->count++;
4457
4458 if (aggregate->summary_only)
4459 (bgp_info_extra_get (rinew))->suppress++;
4460
4461 if (origin < rinew->attr->origin)
4462 origin = rinew->attr->origin;
4463
4464 if (aggregate->as_set)
4465 {
4466 if (aspath)
4467 {
4468 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4469 aspath_free (aspath);
4470 aspath = asmerge;
4471 }
4472 else
4473 aspath = aspath_dup (rinew->attr->aspath);
4474
4475 if (rinew->attr->community)
4476 {
4477 if (community)
4478 {
4479 commerge = community_merge (community,
4480 rinew->attr->community);
4481 community = community_uniq_sort (commerge);
4482 community_free (commerge);
4483 }
4484 else
4485 community = community_dup (rinew->attr->community);
4486 }
4487 }
4488 }
4489
4490 if (aggregate->count > 0)
4491 {
4492 rn = bgp_node_get (table, p);
4493 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
4494 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4495 aggregate->as_set,
4496 atomic_aggregate), rn);
4497 SET_FLAG (new->flags, BGP_INFO_VALID);
4498
4499 bgp_info_add (rn, new);
4500 bgp_unlock_node (rn);
4501 bgp_process (bgp, rn, afi, safi);
4502 }
4503 else
4504 {
4505 if (aspath)
4506 aspath_free (aspath);
4507 if (community)
4508 community_free (community);
4509 }
4510 }
4511
4512 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4513 struct bgp_aggregate *);
4514
4515 void
4516 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4517 struct bgp_info *ri, afi_t afi, safi_t safi)
4518 {
4519 struct bgp_node *child;
4520 struct bgp_node *rn;
4521 struct bgp_aggregate *aggregate;
4522 struct bgp_table *table;
4523
4524 /* MPLS-VPN aggregation is not yet supported. */
4525 if (safi == SAFI_MPLS_VPN)
4526 return;
4527
4528 table = bgp->aggregate[afi][safi];
4529
4530 /* No aggregates configured. */
4531 if (bgp_table_top_nolock (table) == NULL)
4532 return;
4533
4534 if (p->prefixlen == 0)
4535 return;
4536
4537 if (BGP_INFO_HOLDDOWN (ri))
4538 return;
4539
4540 child = bgp_node_get (table, p);
4541
4542 /* Aggregate address configuration check. */
4543 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
4544 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4545 {
4546 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4547 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
4548 }
4549 bgp_unlock_node (child);
4550 }
4551
4552 void
4553 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4554 struct bgp_info *del, afi_t afi, safi_t safi)
4555 {
4556 struct bgp_node *child;
4557 struct bgp_node *rn;
4558 struct bgp_aggregate *aggregate;
4559 struct bgp_table *table;
4560
4561 /* MPLS-VPN aggregation is not yet supported. */
4562 if (safi == SAFI_MPLS_VPN)
4563 return;
4564
4565 table = bgp->aggregate[afi][safi];
4566
4567 /* No aggregates configured. */
4568 if (bgp_table_top_nolock (table) == NULL)
4569 return;
4570
4571 if (p->prefixlen == 0)
4572 return;
4573
4574 child = bgp_node_get (table, p);
4575
4576 /* Aggregate address configuration check. */
4577 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
4578 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4579 {
4580 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4581 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
4582 }
4583 bgp_unlock_node (child);
4584 }
4585
4586 /* Called via bgp_aggregate_set when the user configures aggregate-address */
4587 static void
4588 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4589 struct bgp_aggregate *aggregate)
4590 {
4591 struct bgp_table *table;
4592 struct bgp_node *top;
4593 struct bgp_node *rn;
4594 struct bgp_info *new;
4595 struct bgp_info *ri;
4596 unsigned long match;
4597 u_char origin = BGP_ORIGIN_IGP;
4598 struct aspath *aspath = NULL;
4599 struct aspath *asmerge = NULL;
4600 struct community *community = NULL;
4601 struct community *commerge = NULL;
4602 u_char atomic_aggregate = 0;
4603
4604 table = bgp->rib[afi][safi];
4605
4606 /* Sanity check. */
4607 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4608 return;
4609 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4610 return;
4611
4612 /* If routes exists below this node, generate aggregate routes. */
4613 top = bgp_node_get (table, p);
4614 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4615 if (rn->p.prefixlen > p->prefixlen)
4616 {
4617 match = 0;
4618
4619 for (ri = rn->info; ri; ri = ri->next)
4620 {
4621 if (BGP_INFO_HOLDDOWN (ri))
4622 continue;
4623
4624 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4625 atomic_aggregate = 1;
4626
4627 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4628 {
4629 /* summary-only aggregate route suppress aggregated
4630 route announcement. */
4631 if (aggregate->summary_only)
4632 {
4633 (bgp_info_extra_get (ri))->suppress++;
4634 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4635 match++;
4636 }
4637
4638 /* If at least one route among routes that are aggregated has
4639 * ORIGIN with the value INCOMPLETE, then the aggregated route
4640 * MUST have the ORIGIN attribute with the value INCOMPLETE.
4641 * Otherwise, if at least one route among routes that are
4642 * aggregated has ORIGIN with the value EGP, then the aggregated
4643 * route MUST have the ORIGIN attribute with the value EGP.
4644 */
4645 if (origin < ri->attr->origin)
4646 origin = ri->attr->origin;
4647
4648 /* as-set aggregate route generate origin, as path,
4649 community aggregation. */
4650 if (aggregate->as_set)
4651 {
4652 if (aspath)
4653 {
4654 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4655 aspath_free (aspath);
4656 aspath = asmerge;
4657 }
4658 else
4659 aspath = aspath_dup (ri->attr->aspath);
4660
4661 if (ri->attr->community)
4662 {
4663 if (community)
4664 {
4665 commerge = community_merge (community,
4666 ri->attr->community);
4667 community = community_uniq_sort (commerge);
4668 community_free (commerge);
4669 }
4670 else
4671 community = community_dup (ri->attr->community);
4672 }
4673 }
4674 aggregate->count++;
4675 }
4676 }
4677
4678 /* If this node is suppressed, process the change. */
4679 if (match)
4680 bgp_process (bgp, rn, afi, safi);
4681 }
4682 bgp_unlock_node (top);
4683
4684 /* Add aggregate route to BGP table. */
4685 if (aggregate->count)
4686 {
4687 rn = bgp_node_get (table, p);
4688 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
4689 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4690 aggregate->as_set,
4691 atomic_aggregate), rn);
4692 SET_FLAG (new->flags, BGP_INFO_VALID);
4693
4694 bgp_info_add (rn, new);
4695 bgp_unlock_node (rn);
4696
4697 /* Process change. */
4698 bgp_process (bgp, rn, afi, safi);
4699 }
4700 else
4701 {
4702 if (aspath)
4703 aspath_free (aspath);
4704 if (community)
4705 community_free (community);
4706 }
4707 }
4708
4709 void
4710 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4711 safi_t safi, struct bgp_aggregate *aggregate)
4712 {
4713 struct bgp_table *table;
4714 struct bgp_node *top;
4715 struct bgp_node *rn;
4716 struct bgp_info *ri;
4717 unsigned long match;
4718
4719 table = bgp->rib[afi][safi];
4720
4721 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4722 return;
4723 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4724 return;
4725
4726 /* If routes exists below this node, generate aggregate routes. */
4727 top = bgp_node_get (table, p);
4728 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4729 if (rn->p.prefixlen > p->prefixlen)
4730 {
4731 match = 0;
4732
4733 for (ri = rn->info; ri; ri = ri->next)
4734 {
4735 if (BGP_INFO_HOLDDOWN (ri))
4736 continue;
4737
4738 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4739 {
4740 if (aggregate->summary_only && ri->extra)
4741 {
4742 ri->extra->suppress--;
4743
4744 if (ri->extra->suppress == 0)
4745 {
4746 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4747 match++;
4748 }
4749 }
4750 aggregate->count--;
4751 }
4752 }
4753
4754 /* If this node was suppressed, process the change. */
4755 if (match)
4756 bgp_process (bgp, rn, afi, safi);
4757 }
4758 bgp_unlock_node (top);
4759
4760 /* Delete aggregate route from BGP table. */
4761 rn = bgp_node_get (table, p);
4762
4763 for (ri = rn->info; ri; ri = ri->next)
4764 if (ri->peer == bgp->peer_self
4765 && ri->type == ZEBRA_ROUTE_BGP
4766 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4767 break;
4768
4769 /* Withdraw static BGP route from routing table. */
4770 if (ri)
4771 {
4772 bgp_info_delete (rn, ri);
4773 bgp_process (bgp, rn, afi, safi);
4774 }
4775
4776 /* Unlock bgp_node_lookup. */
4777 bgp_unlock_node (rn);
4778 }
4779
4780 /* Aggregate route attribute. */
4781 #define AGGREGATE_SUMMARY_ONLY 1
4782 #define AGGREGATE_AS_SET 1
4783
4784 static int
4785 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4786 afi_t afi, safi_t safi)
4787 {
4788 int ret;
4789 struct prefix p;
4790 struct bgp_node *rn;
4791 struct bgp *bgp;
4792 struct bgp_aggregate *aggregate;
4793
4794 /* Convert string to prefix structure. */
4795 ret = str2prefix (prefix_str, &p);
4796 if (!ret)
4797 {
4798 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4799 return CMD_WARNING;
4800 }
4801 apply_mask (&p);
4802
4803 /* Get BGP structure. */
4804 bgp = vty->index;
4805
4806 /* Old configuration check. */
4807 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4808 if (! rn)
4809 {
4810 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4811 VTY_NEWLINE);
4812 return CMD_WARNING;
4813 }
4814
4815 aggregate = rn->info;
4816 if (aggregate->safi & SAFI_UNICAST)
4817 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4818 if (aggregate->safi & SAFI_MULTICAST)
4819 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4820
4821 /* Unlock aggregate address configuration. */
4822 rn->info = NULL;
4823 bgp_aggregate_free (aggregate);
4824 bgp_unlock_node (rn);
4825 bgp_unlock_node (rn);
4826
4827 return CMD_SUCCESS;
4828 }
4829
4830 static int
4831 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4832 afi_t afi, safi_t safi,
4833 u_char summary_only, u_char as_set)
4834 {
4835 int ret;
4836 struct prefix p;
4837 struct bgp_node *rn;
4838 struct bgp *bgp;
4839 struct bgp_aggregate *aggregate;
4840
4841 /* Convert string to prefix structure. */
4842 ret = str2prefix (prefix_str, &p);
4843 if (!ret)
4844 {
4845 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4846 return CMD_WARNING;
4847 }
4848 apply_mask (&p);
4849
4850 /* Get BGP structure. */
4851 bgp = vty->index;
4852
4853 /* Old configuration check. */
4854 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4855
4856 if (rn->info)
4857 {
4858 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4859 /* try to remove the old entry */
4860 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4861 if (ret)
4862 {
4863 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4864 bgp_unlock_node (rn);
4865 return CMD_WARNING;
4866 }
4867 }
4868
4869 /* Make aggregate address structure. */
4870 aggregate = bgp_aggregate_new ();
4871 aggregate->summary_only = summary_only;
4872 aggregate->as_set = as_set;
4873 aggregate->safi = safi;
4874 rn->info = aggregate;
4875
4876 /* Aggregate address insert into BGP routing table. */
4877 if (safi & SAFI_UNICAST)
4878 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4879 if (safi & SAFI_MULTICAST)
4880 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4881
4882 return CMD_SUCCESS;
4883 }
4884
4885 DEFUN (aggregate_address,
4886 aggregate_address_cmd,
4887 "aggregate-address A.B.C.D/M",
4888 "Configure BGP aggregate entries\n"
4889 "Aggregate prefix\n")
4890 {
4891 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4892 }
4893
4894 DEFUN (aggregate_address_mask,
4895 aggregate_address_mask_cmd,
4896 "aggregate-address A.B.C.D A.B.C.D",
4897 "Configure BGP aggregate entries\n"
4898 "Aggregate address\n"
4899 "Aggregate mask\n")
4900 {
4901 int ret;
4902 char prefix_str[BUFSIZ];
4903
4904 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4905
4906 if (! ret)
4907 {
4908 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4909 return CMD_WARNING;
4910 }
4911
4912 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4913 0, 0);
4914 }
4915
4916 DEFUN (aggregate_address_summary_only,
4917 aggregate_address_summary_only_cmd,
4918 "aggregate-address A.B.C.D/M summary-only",
4919 "Configure BGP aggregate entries\n"
4920 "Aggregate prefix\n"
4921 "Filter more specific routes from updates\n")
4922 {
4923 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4924 AGGREGATE_SUMMARY_ONLY, 0);
4925 }
4926
4927 DEFUN (aggregate_address_mask_summary_only,
4928 aggregate_address_mask_summary_only_cmd,
4929 "aggregate-address A.B.C.D A.B.C.D summary-only",
4930 "Configure BGP aggregate entries\n"
4931 "Aggregate address\n"
4932 "Aggregate mask\n"
4933 "Filter more specific routes from updates\n")
4934 {
4935 int ret;
4936 char prefix_str[BUFSIZ];
4937
4938 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4939
4940 if (! ret)
4941 {
4942 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4943 return CMD_WARNING;
4944 }
4945
4946 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4947 AGGREGATE_SUMMARY_ONLY, 0);
4948 }
4949
4950 DEFUN (aggregate_address_as_set,
4951 aggregate_address_as_set_cmd,
4952 "aggregate-address A.B.C.D/M as-set",
4953 "Configure BGP aggregate entries\n"
4954 "Aggregate prefix\n"
4955 "Generate AS set path information\n")
4956 {
4957 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4958 0, AGGREGATE_AS_SET);
4959 }
4960
4961 DEFUN (aggregate_address_mask_as_set,
4962 aggregate_address_mask_as_set_cmd,
4963 "aggregate-address A.B.C.D A.B.C.D as-set",
4964 "Configure BGP aggregate entries\n"
4965 "Aggregate address\n"
4966 "Aggregate mask\n"
4967 "Generate AS set path information\n")
4968 {
4969 int ret;
4970 char prefix_str[BUFSIZ];
4971
4972 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4973
4974 if (! ret)
4975 {
4976 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4977 return CMD_WARNING;
4978 }
4979
4980 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4981 0, AGGREGATE_AS_SET);
4982 }
4983
4984
4985 DEFUN (aggregate_address_as_set_summary,
4986 aggregate_address_as_set_summary_cmd,
4987 "aggregate-address A.B.C.D/M as-set summary-only",
4988 "Configure BGP aggregate entries\n"
4989 "Aggregate prefix\n"
4990 "Generate AS set path information\n"
4991 "Filter more specific routes from updates\n")
4992 {
4993 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4994 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4995 }
4996
4997 ALIAS (aggregate_address_as_set_summary,
4998 aggregate_address_summary_as_set_cmd,
4999 "aggregate-address A.B.C.D/M summary-only as-set",
5000 "Configure BGP aggregate entries\n"
5001 "Aggregate prefix\n"
5002 "Filter more specific routes from updates\n"
5003 "Generate AS set path information\n")
5004
5005 DEFUN (aggregate_address_mask_as_set_summary,
5006 aggregate_address_mask_as_set_summary_cmd,
5007 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5008 "Configure BGP aggregate entries\n"
5009 "Aggregate address\n"
5010 "Aggregate mask\n"
5011 "Generate AS set path information\n"
5012 "Filter more specific routes from updates\n")
5013 {
5014 int ret;
5015 char prefix_str[BUFSIZ];
5016
5017 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5018
5019 if (! ret)
5020 {
5021 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5022 return CMD_WARNING;
5023 }
5024
5025 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5026 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5027 }
5028
5029 ALIAS (aggregate_address_mask_as_set_summary,
5030 aggregate_address_mask_summary_as_set_cmd,
5031 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5032 "Configure BGP aggregate entries\n"
5033 "Aggregate address\n"
5034 "Aggregate mask\n"
5035 "Filter more specific routes from updates\n"
5036 "Generate AS set path information\n")
5037
5038 DEFUN (no_aggregate_address,
5039 no_aggregate_address_cmd,
5040 "no aggregate-address A.B.C.D/M",
5041 NO_STR
5042 "Configure BGP aggregate entries\n"
5043 "Aggregate prefix\n")
5044 {
5045 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5046 }
5047
5048 ALIAS (no_aggregate_address,
5049 no_aggregate_address_summary_only_cmd,
5050 "no aggregate-address A.B.C.D/M summary-only",
5051 NO_STR
5052 "Configure BGP aggregate entries\n"
5053 "Aggregate prefix\n"
5054 "Filter more specific routes from updates\n")
5055
5056 ALIAS (no_aggregate_address,
5057 no_aggregate_address_as_set_cmd,
5058 "no aggregate-address A.B.C.D/M as-set",
5059 NO_STR
5060 "Configure BGP aggregate entries\n"
5061 "Aggregate prefix\n"
5062 "Generate AS set path information\n")
5063
5064 ALIAS (no_aggregate_address,
5065 no_aggregate_address_as_set_summary_cmd,
5066 "no aggregate-address A.B.C.D/M as-set summary-only",
5067 NO_STR
5068 "Configure BGP aggregate entries\n"
5069 "Aggregate prefix\n"
5070 "Generate AS set path information\n"
5071 "Filter more specific routes from updates\n")
5072
5073 ALIAS (no_aggregate_address,
5074 no_aggregate_address_summary_as_set_cmd,
5075 "no aggregate-address A.B.C.D/M summary-only as-set",
5076 NO_STR
5077 "Configure BGP aggregate entries\n"
5078 "Aggregate prefix\n"
5079 "Filter more specific routes from updates\n"
5080 "Generate AS set path information\n")
5081
5082 DEFUN (no_aggregate_address_mask,
5083 no_aggregate_address_mask_cmd,
5084 "no aggregate-address A.B.C.D A.B.C.D",
5085 NO_STR
5086 "Configure BGP aggregate entries\n"
5087 "Aggregate address\n"
5088 "Aggregate mask\n")
5089 {
5090 int ret;
5091 char prefix_str[BUFSIZ];
5092
5093 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5094
5095 if (! ret)
5096 {
5097 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5098 return CMD_WARNING;
5099 }
5100
5101 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5102 }
5103
5104 ALIAS (no_aggregate_address_mask,
5105 no_aggregate_address_mask_summary_only_cmd,
5106 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5107 NO_STR
5108 "Configure BGP aggregate entries\n"
5109 "Aggregate address\n"
5110 "Aggregate mask\n"
5111 "Filter more specific routes from updates\n")
5112
5113 ALIAS (no_aggregate_address_mask,
5114 no_aggregate_address_mask_as_set_cmd,
5115 "no aggregate-address A.B.C.D A.B.C.D as-set",
5116 NO_STR
5117 "Configure BGP aggregate entries\n"
5118 "Aggregate address\n"
5119 "Aggregate mask\n"
5120 "Generate AS set path information\n")
5121
5122 ALIAS (no_aggregate_address_mask,
5123 no_aggregate_address_mask_as_set_summary_cmd,
5124 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5125 NO_STR
5126 "Configure BGP aggregate entries\n"
5127 "Aggregate address\n"
5128 "Aggregate mask\n"
5129 "Generate AS set path information\n"
5130 "Filter more specific routes from updates\n")
5131
5132 ALIAS (no_aggregate_address_mask,
5133 no_aggregate_address_mask_summary_as_set_cmd,
5134 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5135 NO_STR
5136 "Configure BGP aggregate entries\n"
5137 "Aggregate address\n"
5138 "Aggregate mask\n"
5139 "Filter more specific routes from updates\n"
5140 "Generate AS set path information\n")
5141
5142 #ifdef HAVE_IPV6
5143 DEFUN (ipv6_aggregate_address,
5144 ipv6_aggregate_address_cmd,
5145 "aggregate-address X:X::X:X/M",
5146 "Configure BGP aggregate entries\n"
5147 "Aggregate prefix\n")
5148 {
5149 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5150 }
5151
5152 DEFUN (ipv6_aggregate_address_summary_only,
5153 ipv6_aggregate_address_summary_only_cmd,
5154 "aggregate-address X:X::X:X/M summary-only",
5155 "Configure BGP aggregate entries\n"
5156 "Aggregate prefix\n"
5157 "Filter more specific routes from updates\n")
5158 {
5159 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5160 AGGREGATE_SUMMARY_ONLY, 0);
5161 }
5162
5163 DEFUN (no_ipv6_aggregate_address,
5164 no_ipv6_aggregate_address_cmd,
5165 "no aggregate-address X:X::X:X/M",
5166 NO_STR
5167 "Configure BGP aggregate entries\n"
5168 "Aggregate prefix\n")
5169 {
5170 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5171 }
5172
5173 DEFUN (no_ipv6_aggregate_address_summary_only,
5174 no_ipv6_aggregate_address_summary_only_cmd,
5175 "no aggregate-address X:X::X:X/M summary-only",
5176 NO_STR
5177 "Configure BGP aggregate entries\n"
5178 "Aggregate prefix\n"
5179 "Filter more specific routes from updates\n")
5180 {
5181 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5182 }
5183
5184 ALIAS (ipv6_aggregate_address,
5185 old_ipv6_aggregate_address_cmd,
5186 "ipv6 bgp aggregate-address X:X::X:X/M",
5187 IPV6_STR
5188 BGP_STR
5189 "Configure BGP aggregate entries\n"
5190 "Aggregate prefix\n")
5191
5192 ALIAS (ipv6_aggregate_address_summary_only,
5193 old_ipv6_aggregate_address_summary_only_cmd,
5194 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5195 IPV6_STR
5196 BGP_STR
5197 "Configure BGP aggregate entries\n"
5198 "Aggregate prefix\n"
5199 "Filter more specific routes from updates\n")
5200
5201 ALIAS (no_ipv6_aggregate_address,
5202 old_no_ipv6_aggregate_address_cmd,
5203 "no ipv6 bgp aggregate-address X:X::X:X/M",
5204 NO_STR
5205 IPV6_STR
5206 BGP_STR
5207 "Configure BGP aggregate entries\n"
5208 "Aggregate prefix\n")
5209
5210 ALIAS (no_ipv6_aggregate_address_summary_only,
5211 old_no_ipv6_aggregate_address_summary_only_cmd,
5212 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5213 NO_STR
5214 IPV6_STR
5215 BGP_STR
5216 "Configure BGP aggregate entries\n"
5217 "Aggregate prefix\n"
5218 "Filter more specific routes from updates\n")
5219 #endif /* HAVE_IPV6 */
5220
5221 /* Redistribute route treatment. */
5222 void
5223 bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5224 const struct in6_addr *nexthop6, unsigned int ifindex,
5225 u_int32_t metric, u_char type, u_short instance, u_short tag)
5226 {
5227 struct bgp *bgp;
5228 struct listnode *node, *nnode;
5229 struct bgp_info *new;
5230 struct bgp_info *bi;
5231 struct bgp_info info;
5232 struct bgp_node *bn;
5233 struct attr attr;
5234 struct attr *new_attr;
5235 afi_t afi;
5236 int ret;
5237 struct bgp_redist *red;
5238
5239 /* Make default attribute. */
5240 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5241 if (nexthop)
5242 attr.nexthop = *nexthop;
5243 attr.nh_ifindex = ifindex;
5244
5245 #ifdef HAVE_IPV6
5246 if (nexthop6)
5247 {
5248 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5249 extra->mp_nexthop_global = *nexthop6;
5250 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
5251 }
5252 #endif
5253
5254 attr.med = metric;
5255 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5256 attr.extra->tag = tag;
5257
5258 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5259 {
5260 afi = family2afi (p->family);
5261
5262 red = bgp_redist_lookup(bgp, afi, type, instance);
5263 if (red)
5264 {
5265 struct attr attr_new;
5266 struct attr_extra extra_new;
5267
5268 /* Copy attribute for modification. */
5269 attr_new.extra = &extra_new;
5270 bgp_attr_dup (&attr_new, &attr);
5271
5272 if (red->redist_metric_flag)
5273 attr_new.med = red->redist_metric;
5274
5275 /* Apply route-map. */
5276 if (red->rmap.name)
5277 {
5278 info.peer = bgp->peer_self;
5279 info.attr = &attr_new;
5280
5281 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5282
5283 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5284
5285 bgp->peer_self->rmap_type = 0;
5286
5287 if (ret == RMAP_DENYMATCH)
5288 {
5289 /* Free uninterned attribute. */
5290 bgp_attr_flush (&attr_new);
5291
5292 /* Unintern original. */
5293 aspath_unintern (&attr.aspath);
5294 bgp_attr_extra_free (&attr);
5295 bgp_redistribute_delete (p, type, instance);
5296 return;
5297 }
5298 }
5299
5300 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5301 afi, SAFI_UNICAST, p, NULL);
5302
5303 new_attr = bgp_attr_intern (&attr_new);
5304
5305 for (bi = bn->info; bi; bi = bi->next)
5306 if (bi->peer == bgp->peer_self
5307 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5308 break;
5309
5310 if (bi)
5311 {
5312 /* Ensure the (source route) type is updated. */
5313 bi->type = type;
5314 if (attrhash_cmp (bi->attr, new_attr) &&
5315 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5316 {
5317 bgp_attr_unintern (&new_attr);
5318 aspath_unintern (&attr.aspath);
5319 bgp_attr_extra_free (&attr);
5320 bgp_unlock_node (bn);
5321 return;
5322 }
5323 else
5324 {
5325 /* The attribute is changed. */
5326 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5327
5328 /* Rewrite BGP route information. */
5329 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5330 bgp_info_restore(bn, bi);
5331 else
5332 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5333 bgp_attr_unintern (&bi->attr);
5334 bi->attr = new_attr;
5335 bi->uptime = bgp_clock ();
5336
5337 /* Process change. */
5338 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5339 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5340 bgp_unlock_node (bn);
5341 aspath_unintern (&attr.aspath);
5342 bgp_attr_extra_free (&attr);
5343 return;
5344 }
5345 }
5346
5347 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5348 new_attr, bn);
5349 SET_FLAG (new->flags, BGP_INFO_VALID);
5350
5351 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5352 bgp_info_add (bn, new);
5353 bgp_unlock_node (bn);
5354 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5355 }
5356 }
5357
5358 /* Unintern original. */
5359 aspath_unintern (&attr.aspath);
5360 bgp_attr_extra_free (&attr);
5361 }
5362
5363 void
5364 bgp_redistribute_delete (struct prefix *p, u_char type, u_short instance)
5365 {
5366 struct bgp *bgp;
5367 struct listnode *node, *nnode;
5368 afi_t afi;
5369 struct bgp_node *rn;
5370 struct bgp_info *ri;
5371 struct bgp_redist *red;
5372
5373 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5374 {
5375 afi = family2afi (p->family);
5376
5377 red = bgp_redist_lookup(bgp, afi, type, instance);
5378 if (red)
5379 {
5380 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5381
5382 for (ri = rn->info; ri; ri = ri->next)
5383 if (ri->peer == bgp->peer_self
5384 && ri->type == type)
5385 break;
5386
5387 if (ri)
5388 {
5389 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5390 bgp_info_delete (rn, ri);
5391 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5392 }
5393 bgp_unlock_node (rn);
5394 }
5395 }
5396 }
5397
5398 /* Withdraw specified route type's route. */
5399 void
5400 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
5401 {
5402 struct bgp_node *rn;
5403 struct bgp_info *ri;
5404 struct bgp_table *table;
5405
5406 table = bgp->rib[afi][SAFI_UNICAST];
5407
5408 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5409 {
5410 for (ri = rn->info; ri; ri = ri->next)
5411 if (ri->peer == bgp->peer_self
5412 && ri->type == type
5413 && ri->instance == instance)
5414 break;
5415
5416 if (ri)
5417 {
5418 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5419 bgp_info_delete (rn, ri);
5420 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5421 }
5422 }
5423 }
5424
5425 /* Static function to display route. */
5426 static void
5427 route_vty_out_route (struct prefix *p, struct vty *vty)
5428 {
5429 int len;
5430 u_int32_t destination;
5431 char buf[BUFSIZ];
5432
5433 if (p->family == AF_INET)
5434 {
5435 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5436 destination = ntohl (p->u.prefix4.s_addr);
5437
5438 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5439 || (IN_CLASSB (destination) && p->prefixlen == 16)
5440 || (IN_CLASSA (destination) && p->prefixlen == 8)
5441 || p->u.prefix4.s_addr == 0)
5442 {
5443 /* When mask is natural, mask is not displayed. */
5444 }
5445 else
5446 len += vty_out (vty, "/%d", p->prefixlen);
5447 }
5448 else
5449 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5450 p->prefixlen);
5451
5452 len = 17 - len;
5453 if (len < 1)
5454 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5455 else
5456 vty_out (vty, "%*s", len, " ");
5457 }
5458
5459 enum bgp_display_type
5460 {
5461 normal_list,
5462 };
5463
5464 /* Print the short form route status for a bgp_info */
5465 static void
5466 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
5467 json_object *json_path)
5468 {
5469 if (json_path)
5470 {
5471
5472 /* Route status display. */
5473 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5474 json_object_boolean_true_add(json_path, "removed");
5475
5476 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5477 json_object_boolean_true_add(json_path, "stale");
5478
5479 if (binfo->extra && binfo->extra->suppress)
5480 json_object_boolean_true_add(json_path, "suppressed");
5481
5482 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5483 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5484 json_object_boolean_true_add(json_path, "valid");
5485
5486 /* Selected */
5487 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5488 json_object_boolean_true_add(json_path, "history");
5489
5490 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5491 json_object_boolean_true_add(json_path, "damped");
5492
5493 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5494 json_object_boolean_true_add(json_path, "bestpath");
5495
5496 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5497 json_object_boolean_true_add(json_path, "multipath");
5498
5499 /* Internal route. */
5500 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5501 json_object_string_add(json_path, "pathFrom", "internal");
5502 else
5503 json_object_string_add(json_path, "pathFrom", "external");
5504
5505 return;
5506 }
5507
5508 /* Route status display. */
5509 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5510 vty_out (vty, "R");
5511 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5512 vty_out (vty, "S");
5513 else if (binfo->extra && binfo->extra->suppress)
5514 vty_out (vty, "s");
5515 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5516 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5517 vty_out (vty, "*");
5518 else
5519 vty_out (vty, " ");
5520
5521 /* Selected */
5522 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5523 vty_out (vty, "h");
5524 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5525 vty_out (vty, "d");
5526 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5527 vty_out (vty, ">");
5528 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5529 vty_out (vty, "=");
5530 else
5531 vty_out (vty, " ");
5532
5533 /* Internal route. */
5534 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5535 vty_out (vty, "i");
5536 else
5537 vty_out (vty, " ");
5538 }
5539
5540 /* called from terminal list command */
5541 void
5542 route_vty_out (struct vty *vty, struct prefix *p,
5543 struct bgp_info *binfo, int display, safi_t safi,
5544 json_object *json_paths)
5545 {
5546 struct attr *attr;
5547 json_object *json_path = NULL;
5548 json_object *json_nexthops = NULL;
5549 json_object *json_nexthop_global = NULL;
5550 json_object *json_nexthop_ll = NULL;
5551
5552 if (json_paths)
5553 json_path = json_object_new_object();
5554
5555 /* short status lead text */
5556 route_vty_short_status_out (vty, binfo, json_path);
5557
5558 if (!json_paths)
5559 {
5560 /* print prefix and mask */
5561 if (! display)
5562 route_vty_out_route (p, vty);
5563 else
5564 vty_out (vty, "%*s", 17, " ");
5565 }
5566
5567 /* Print attribute */
5568 attr = binfo->attr;
5569 if (attr)
5570 {
5571
5572 /* IPv4 Next Hop */
5573 if (p->family == AF_INET
5574 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5575 {
5576 if (json_paths)
5577 {
5578 json_nexthop_global = json_object_new_object();
5579
5580 if (safi == SAFI_MPLS_VPN)
5581 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
5582 else
5583 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
5584
5585 json_object_string_add(json_nexthop_global, "afi", "ipv4");
5586 json_object_boolean_true_add(json_nexthop_global, "used");
5587 }
5588 else
5589 {
5590 if (safi == SAFI_MPLS_VPN)
5591 vty_out (vty, "%-16s",
5592 inet_ntoa (attr->extra->mp_nexthop_global_in));
5593 else
5594 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5595 }
5596 }
5597
5598 #ifdef HAVE_IPV6
5599 /* IPv6 Next Hop */
5600 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5601 {
5602 int len;
5603 char buf[BUFSIZ];
5604
5605 if (json_paths)
5606 {
5607 json_nexthop_global = json_object_new_object();
5608 json_object_string_add(json_nexthop_global, "ip",
5609 inet_ntop (AF_INET6,
5610 &attr->extra->mp_nexthop_global,
5611 buf, BUFSIZ));
5612 json_object_string_add(json_nexthop_global, "afi", "ipv6");
5613 json_object_string_add(json_nexthop_global, "scope", "global");
5614
5615 /* We display both LL & GL if both have been received */
5616 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5617 {
5618 json_nexthop_ll = json_object_new_object();
5619 json_object_string_add(json_nexthop_ll, "ip",
5620 inet_ntop (AF_INET6,
5621 &attr->extra->mp_nexthop_local,
5622 buf, BUFSIZ));
5623 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
5624 json_object_string_add(json_nexthop_ll, "scope", "link-local");
5625
5626 if (IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
5627 &attr->extra->mp_nexthop_local) != 0)
5628 json_object_boolean_true_add(json_nexthop_ll, "used");
5629 else
5630 json_object_boolean_true_add(json_nexthop_global, "used");
5631 }
5632 else
5633 json_object_boolean_true_add(json_nexthop_global, "used");
5634 }
5635 else
5636 {
5637 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5638 {
5639 if (binfo->peer->conf_if)
5640 {
5641 len = vty_out (vty, "%s",
5642 binfo->peer->conf_if);
5643 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
5644
5645 if (len < 1)
5646 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
5647 else
5648 vty_out (vty, "%*s", len, " ");
5649 }
5650 else
5651 {
5652 len = vty_out (vty, "%s",
5653 inet_ntop (AF_INET6,
5654 &attr->extra->mp_nexthop_local,
5655 buf, BUFSIZ));
5656 len = 16 - len;
5657
5658 if (len < 1)
5659 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5660 else
5661 vty_out (vty, "%*s", len, " ");
5662 }
5663 }
5664 else
5665 {
5666 len = vty_out (vty, "%s",
5667 inet_ntop (AF_INET6,
5668 &attr->extra->mp_nexthop_global,
5669 buf, BUFSIZ));
5670 len = 16 - len;
5671
5672 if (len < 1)
5673 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5674 else
5675 vty_out (vty, "%*s", len, " ");
5676 }
5677 }
5678 }
5679 #endif /* HAVE_IPV6 */
5680
5681 /* MED/Metric */
5682 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5683 if (json_paths)
5684 json_object_int_add(json_path, "med", attr->med);
5685 else
5686 vty_out (vty, "%10u", attr->med);
5687 else
5688 if (!json_paths)
5689 vty_out (vty, " ");
5690
5691 /* Local Pref */
5692 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5693 if (json_paths)
5694 json_object_int_add(json_path, "localpref", attr->local_pref);
5695 else
5696 vty_out (vty, "%7u", attr->local_pref);
5697 else
5698 if (!json_paths)
5699 vty_out (vty, " ");
5700
5701 if (json_paths)
5702 {
5703 if (attr->extra)
5704 json_object_int_add(json_path, "weight", attr->extra->weight);
5705 else
5706 json_object_int_add(json_path, "weight", 0);
5707 }
5708 else
5709 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
5710
5711 /* Print aspath */
5712 if (attr->aspath)
5713 {
5714 if (json_paths)
5715 json_object_string_add(json_path, "aspath", attr->aspath->str);
5716 else
5717 aspath_print_vty (vty, "%s", attr->aspath, " ");
5718 }
5719
5720 /* Print origin */
5721 if (json_paths)
5722 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
5723 else
5724 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5725 }
5726 else
5727 {
5728 if (json_paths)
5729 json_object_string_add(json_path, "alert", "No attributes");
5730 else
5731 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
5732 }
5733
5734 if (json_paths)
5735 {
5736 if (json_nexthop_global || json_nexthop_ll)
5737 {
5738 json_nexthops = json_object_new_array();
5739
5740 if (json_nexthop_global)
5741 json_object_array_add(json_nexthops, json_nexthop_global);
5742
5743 if (json_nexthop_ll)
5744 json_object_array_add(json_nexthops, json_nexthop_ll);
5745
5746 json_object_object_add(json_path, "nexthops", json_nexthops);
5747 }
5748
5749 json_object_array_add(json_paths, json_path);
5750 }
5751 else
5752 vty_out (vty, "%s", VTY_NEWLINE);
5753 }
5754
5755 /* called from terminal list command */
5756 void
5757 route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
5758 u_char use_json, json_object *json_ar)
5759 {
5760 json_object *json_status = NULL;
5761 json_object *json_net = NULL;
5762 char buff[BUFSIZ];
5763 /* Route status display. */
5764 if (use_json)
5765 {
5766 json_status = json_object_new_object();
5767 json_net = json_object_new_object();
5768 }
5769 else
5770 {
5771 vty_out (vty, "*");
5772 vty_out (vty, ">");
5773 vty_out (vty, " ");
5774 }
5775
5776 /* print prefix and mask */
5777 if (use_json)
5778 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
5779 else
5780 route_vty_out_route (p, vty);
5781
5782 /* Print attribute */
5783 if (attr)
5784 {
5785 if (use_json)
5786 {
5787 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5788 {
5789 if (safi == SAFI_MPLS_VPN)
5790 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
5791 else
5792 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
5793 }
5794 #ifdef HAVE_IPV6
5795 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5796 {
5797 char buf[BUFSIZ];
5798
5799 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5800 buf, BUFSIZ));
5801 }
5802 #endif /* HAVE_IPV6 */
5803
5804 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5805 json_object_int_add(json_net, "metric", attr->med);
5806
5807 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5808 json_object_int_add(json_net, "localPref", attr->local_pref);
5809
5810 if (attr->extra)
5811 json_object_int_add(json_net, "weight", attr->extra->weight);
5812 else
5813 json_object_int_add(json_net, "weight", 0);
5814
5815 /* Print aspath */
5816 if (attr->aspath)
5817 json_object_string_add(json_net, "asPath", attr->aspath->str);
5818
5819 /* Print origin */
5820 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
5821 }
5822 else
5823 {
5824 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5825 {
5826 if (safi == SAFI_MPLS_VPN)
5827 vty_out (vty, "%-16s",
5828 inet_ntoa (attr->extra->mp_nexthop_global_in));
5829 else
5830 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5831 }
5832 #ifdef HAVE_IPV6
5833 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5834 {
5835 int len;
5836 char buf[BUFSIZ];
5837
5838 assert (attr->extra);
5839
5840 len = vty_out (vty, "%s",
5841 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5842 buf, BUFSIZ));
5843 len = 16 - len;
5844 if (len < 1)
5845 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5846 else
5847 vty_out (vty, "%*s", len, " ");
5848 }
5849 #endif /* HAVE_IPV6 */
5850 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5851 vty_out (vty, "%10u", attr->med);
5852 else
5853 vty_out (vty, " ");
5854
5855 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5856 vty_out (vty, "%7u", attr->local_pref);
5857 else
5858 vty_out (vty, " ");
5859
5860 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
5861
5862 /* Print aspath */
5863 if (attr->aspath)
5864 aspath_print_vty (vty, "%s", attr->aspath, " ");
5865
5866 /* Print origin */
5867 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5868 }
5869 }
5870 if (use_json)
5871 {
5872 json_object_boolean_true_add(json_status, "*");
5873 json_object_boolean_true_add(json_status, ">");
5874 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
5875 char buf_cut[BUFSIZ];
5876 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
5877 }
5878 else
5879 vty_out (vty, "%s", VTY_NEWLINE);
5880 }
5881
5882 void
5883 route_vty_out_tag (struct vty *vty, struct prefix *p,
5884 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
5885 {
5886 json_object *json_out = NULL;
5887 struct attr *attr;
5888 u_int32_t label = 0;
5889
5890 if (!binfo->extra)
5891 return;
5892
5893 if (json)
5894 json_out = json_object_new_object();
5895
5896 /* short status lead text */
5897 route_vty_short_status_out (vty, binfo, json_out);
5898
5899 /* print prefix and mask */
5900 if (json == NULL)
5901 {
5902 if (! display)
5903 route_vty_out_route (p, vty);
5904 else
5905 vty_out (vty, "%*s", 17, " ");
5906 }
5907
5908 /* Print attribute */
5909 attr = binfo->attr;
5910 if (attr)
5911 {
5912 if (p->family == AF_INET
5913 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5914 {
5915 if (safi == SAFI_MPLS_VPN)
5916 {
5917 if (json)
5918 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
5919 else
5920 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
5921 }
5922 else
5923 {
5924 if (json)
5925 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
5926 else
5927 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5928 }
5929 }
5930 #ifdef HAVE_IPV6
5931 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5932 {
5933 assert (attr->extra);
5934 char buf_a[BUFSIZ];
5935 char buf_b[BUFSIZ];
5936 char buf_c[BUFSIZ];
5937 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
5938 {
5939 if (json)
5940 json_object_string_add(json_out, "mpNexthopGlobalIn",
5941 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
5942 else
5943 vty_out (vty, "%s",
5944 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5945 buf_a, BUFSIZ));
5946 }
5947 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
5948 {
5949 if (json)
5950 {
5951 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5952 buf_a, BUFSIZ);
5953 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5954 buf_b, BUFSIZ);
5955 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
5956 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
5957 }
5958 else
5959 vty_out (vty, "%s(%s)",
5960 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5961 buf_a, BUFSIZ),
5962 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5963 buf_b, BUFSIZ));
5964 }
5965
5966 }
5967 #endif /* HAVE_IPV6 */
5968 }
5969
5970 label = decode_label (binfo->extra->tag);
5971
5972 if (json)
5973 {
5974 if (label)
5975 json_object_int_add(json_out, "notag", label);
5976 json_object_array_add(json, json_out);
5977 }
5978 else
5979 {
5980 vty_out (vty, "notag/%d", label);
5981 vty_out (vty, "%s", VTY_NEWLINE);
5982 }
5983 }
5984
5985 /* dampening route */
5986 static void
5987 damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
5988 int display, safi_t safi, u_char use_json, json_object *json)
5989 {
5990 struct attr *attr;
5991 int len;
5992 char timebuf[BGP_UPTIME_LEN];
5993
5994 /* short status lead text */
5995 route_vty_short_status_out (vty, binfo, json);
5996
5997 /* print prefix and mask */
5998 if (!use_json)
5999 {
6000 if (! display)
6001 route_vty_out_route (p, vty);
6002 else
6003 vty_out (vty, "%*s", 17, " ");
6004 }
6005
6006 len = vty_out (vty, "%s", binfo->peer->host);
6007 len = 17 - len;
6008 if (len < 1)
6009 {
6010 if (!use_json)
6011 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6012 }
6013 else
6014 {
6015 if (use_json)
6016 json_object_int_add(json, "peerHost", len);
6017 else
6018 vty_out (vty, "%*s", len, " ");
6019 }
6020
6021 if (use_json)
6022 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6023 else
6024 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6025
6026 /* Print attribute */
6027 attr = binfo->attr;
6028 if (attr)
6029 {
6030 /* Print aspath */
6031 if (attr->aspath)
6032 {
6033 if (use_json)
6034 json_object_string_add(json, "asPath", attr->aspath->str);
6035 else
6036 aspath_print_vty (vty, "%s", attr->aspath, " ");
6037 }
6038
6039 /* Print origin */
6040 if (use_json)
6041 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6042 else
6043 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6044 }
6045 if (!use_json)
6046 vty_out (vty, "%s", VTY_NEWLINE);
6047 }
6048
6049 /* flap route */
6050 static void
6051 flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6052 int display, safi_t safi, u_char use_json, json_object *json)
6053 {
6054 struct attr *attr;
6055 struct bgp_damp_info *bdi;
6056 char timebuf[BGP_UPTIME_LEN];
6057 int len;
6058
6059 if (!binfo->extra)
6060 return;
6061
6062 bdi = binfo->extra->damp_info;
6063
6064 /* short status lead text */
6065 route_vty_short_status_out (vty, binfo, json);
6066
6067 /* print prefix and mask */
6068 if (!use_json)
6069 {
6070 if (! display)
6071 route_vty_out_route (p, vty);
6072 else
6073 vty_out (vty, "%*s", 17, " ");
6074 }
6075
6076 len = vty_out (vty, "%s", binfo->peer->host);
6077 len = 16 - len;
6078 if (len < 1)
6079 {
6080 if (!use_json)
6081 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6082 }
6083 else
6084 {
6085 if (use_json)
6086 json_object_int_add(json, "peerHost", len);
6087 else
6088 vty_out (vty, "%*s", len, " ");
6089 }
6090
6091 len = vty_out (vty, "%d", bdi->flap);
6092 len = 5 - len;
6093 if (len < 1)
6094 {
6095 if (!use_json)
6096 vty_out (vty, " ");
6097 }
6098 else
6099 {
6100 if (use_json)
6101 json_object_int_add(json, "bdiFlap", len);
6102 else
6103 vty_out (vty, "%*s", len, " ");
6104 }
6105
6106 if (use_json)
6107 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6108 else
6109 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6110 timebuf, BGP_UPTIME_LEN, 0, NULL));
6111
6112 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6113 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6114 {
6115 if (use_json)
6116 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6117 else
6118 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6119 }
6120 else
6121 {
6122 if (!use_json)
6123 vty_out (vty, "%*s ", 8, " ");
6124 }
6125
6126 /* Print attribute */
6127 attr = binfo->attr;
6128 if (attr)
6129 {
6130 /* Print aspath */
6131 if (attr->aspath)
6132 {
6133 if (use_json)
6134 json_object_string_add(json, "asPath", attr->aspath->str);
6135 else
6136 aspath_print_vty (vty, "%s", attr->aspath, " ");
6137 }
6138
6139 /* Print origin */
6140 if (use_json)
6141 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6142 else
6143 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6144 }
6145 if (!use_json)
6146 vty_out (vty, "%s", VTY_NEWLINE);
6147 }
6148
6149 static void
6150 route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6151 const char *header, json_object *json_adv_to)
6152 {
6153 char buf1[INET6_ADDRSTRLEN];
6154 json_object *json_peer = NULL;
6155
6156 if (json_adv_to)
6157 {
6158 /* 'advertised-to' is a dictionary of peers we have advertised this
6159 * prefix too. The key is the peer's IP or swpX, the value is the
6160 * hostname if we know it and "" if not.
6161 */
6162 json_peer = json_object_new_object();
6163
6164 if (peer->hostname)
6165 json_object_string_add(json_peer, "hostname", peer->hostname);
6166
6167 if (peer->conf_if)
6168 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6169 else
6170 json_object_object_add(json_adv_to,
6171 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6172 json_peer);
6173 }
6174 else
6175 {
6176 if (*first)
6177 {
6178 vty_out (vty, "%s", header);
6179 *first = 0;
6180 }
6181
6182 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6183 {
6184 if (peer->conf_if)
6185 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6186 else
6187 vty_out (vty, " %s(%s)", peer->hostname,
6188 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6189 }
6190 else
6191 {
6192 if (peer->conf_if)
6193 vty_out (vty, " %s", peer->conf_if);
6194 else
6195 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6196 }
6197 }
6198 }
6199
6200 static void
6201 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6202 struct bgp_info *binfo, afi_t afi, safi_t safi,
6203 json_object *json_paths)
6204 {
6205 char buf[INET6_ADDRSTRLEN];
6206 char buf1[BUFSIZ];
6207 struct attr *attr;
6208 int sockunion_vty_out (struct vty *, union sockunion *);
6209 #ifdef HAVE_CLOCK_MONOTONIC
6210 time_t tbuf;
6211 #endif
6212 json_object *json_bestpath = NULL;
6213 json_object *json_cluster_list = NULL;
6214 json_object *json_cluster_list_list = NULL;
6215 json_object *json_ext_community = NULL;
6216 json_object *json_last_update = NULL;
6217 json_object *json_nexthop_global = NULL;
6218 json_object *json_nexthop_ll = NULL;
6219 json_object *json_nexthops = NULL;
6220 json_object *json_path = NULL;
6221 json_object *json_peer = NULL;
6222 json_object *json_string = NULL;
6223 json_object *json_adv_to = NULL;
6224 int first = 0;
6225 struct listnode *node, *nnode;
6226 struct peer *peer;
6227 int addpath_capable;
6228 int has_adj;
6229 int first_as;
6230
6231 if (json_paths)
6232 {
6233 json_path = json_object_new_object();
6234 json_peer = json_object_new_object();
6235 json_nexthop_global = json_object_new_object();
6236 }
6237
6238 attr = binfo->attr;
6239
6240 if (attr)
6241 {
6242 /* Line1 display AS-path, Aggregator */
6243 if (attr->aspath)
6244 {
6245 if (json_paths)
6246 {
6247 json_object_lock(attr->aspath->json);
6248 json_object_object_add(json_path, "aspath", attr->aspath->json);
6249 }
6250 else
6251 {
6252 if (attr->aspath->segments)
6253 aspath_print_vty (vty, " %s", attr->aspath, "");
6254 else
6255 vty_out (vty, " Local");
6256 }
6257 }
6258
6259 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6260 {
6261 if (json_paths)
6262 json_object_boolean_true_add(json_path, "removed");
6263 else
6264 vty_out (vty, ", (removed)");
6265 }
6266
6267 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6268 {
6269 if (json_paths)
6270 json_object_boolean_true_add(json_path, "stale");
6271 else
6272 vty_out (vty, ", (stale)");
6273 }
6274
6275 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6276 {
6277 if (json_paths)
6278 {
6279 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6280 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
6281 }
6282 else
6283 {
6284 vty_out (vty, ", (aggregated by %u %s)",
6285 attr->extra->aggregator_as,
6286 inet_ntoa (attr->extra->aggregator_addr));
6287 }
6288 }
6289
6290 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6291 {
6292 if (json_paths)
6293 json_object_boolean_true_add(json_path, "rxedFromRrClient");
6294 else
6295 vty_out (vty, ", (Received from a RR-client)");
6296 }
6297
6298 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6299 {
6300 if (json_paths)
6301 json_object_boolean_true_add(json_path, "rxedFromRsClient");
6302 else
6303 vty_out (vty, ", (Received from a RS-client)");
6304 }
6305
6306 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6307 {
6308 if (json_paths)
6309 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
6310 else
6311 vty_out (vty, ", (history entry)");
6312 }
6313 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6314 {
6315 if (json_paths)
6316 json_object_boolean_true_add(json_path, "dampeningSuppressed");
6317 else
6318 vty_out (vty, ", (suppressed due to dampening)");
6319 }
6320
6321 if (!json_paths)
6322 vty_out (vty, "%s", VTY_NEWLINE);
6323
6324 /* Line2 display Next-hop, Neighbor, Router-id */
6325 /* Display the nexthop */
6326 if (p->family == AF_INET
6327 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6328 {
6329 if (safi == SAFI_MPLS_VPN)
6330 {
6331 if (json_paths)
6332 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6333 else
6334 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6335 }
6336 else
6337 {
6338 if (json_paths)
6339 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6340 else
6341 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6342 }
6343
6344 if (json_paths)
6345 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6346 }
6347 #ifdef HAVE_IPV6
6348 else
6349 {
6350 assert (attr->extra);
6351 if (json_paths)
6352 {
6353 json_object_string_add(json_nexthop_global, "ip",
6354 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6355 buf, INET6_ADDRSTRLEN));
6356 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6357 json_object_string_add(json_nexthop_global, "scope", "global");
6358 }
6359 else
6360 {
6361 vty_out (vty, " %s",
6362 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6363 buf, INET6_ADDRSTRLEN));
6364 }
6365 }
6366 #endif /* HAVE_IPV6 */
6367
6368
6369 /* Display the IGP cost or 'inaccessible' */
6370 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6371 {
6372 if (json_paths)
6373 json_object_boolean_false_add(json_nexthop_global, "accessible");
6374 else
6375 vty_out (vty, " (inaccessible)");
6376 }
6377 else
6378 {
6379 if (binfo->extra && binfo->extra->igpmetric)
6380 {
6381 if (json_paths)
6382 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
6383 else
6384 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
6385 }
6386
6387 /* IGP cost is 0, display this only for json */
6388 else
6389 {
6390 if (json_paths)
6391 json_object_int_add(json_nexthop_global, "metric", 0);
6392 }
6393
6394 if (json_paths)
6395 json_object_boolean_true_add(json_nexthop_global, "accessible");
6396 }
6397
6398 /* Display peer "from" output */
6399 /* This path was originated locally */
6400 if (binfo->peer == bgp->peer_self)
6401 {
6402
6403 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6404 {
6405 if (json_paths)
6406 json_object_string_add(json_peer, "peerId", "0.0.0.0");
6407 else
6408 vty_out (vty, " from 0.0.0.0 ");
6409 }
6410 else
6411 {
6412 if (json_paths)
6413 json_object_string_add(json_peer, "peerId", "::");
6414 else
6415 vty_out (vty, " from :: ");
6416 }
6417
6418 if (json_paths)
6419 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
6420 else
6421 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6422 }
6423
6424 /* We RXed this path from one of our peers */
6425 else
6426 {
6427
6428 if (json_paths)
6429 {
6430 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6431 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6432
6433 if (binfo->peer->hostname)
6434 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
6435
6436 if (binfo->peer->domainname)
6437 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
6438
6439 if (binfo->peer->conf_if)
6440 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
6441 }
6442 else
6443 {
6444 if (binfo->peer->conf_if)
6445 {
6446 if (binfo->peer->hostname &&
6447 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6448 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6449 binfo->peer->conf_if);
6450 else
6451 vty_out (vty, " from %s", binfo->peer->conf_if);
6452 }
6453 else
6454 {
6455 if (binfo->peer->hostname &&
6456 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6457 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6458 binfo->peer->host);
6459 else
6460 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6461 }
6462
6463 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6464 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6465 else
6466 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6467 }
6468 }
6469
6470 if (!json_paths)
6471 vty_out (vty, "%s", VTY_NEWLINE);
6472
6473 #ifdef HAVE_IPV6
6474 /* display the link-local nexthop */
6475 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6476 {
6477 if (json_paths)
6478 {
6479 json_nexthop_ll = json_object_new_object();
6480 json_object_string_add(json_nexthop_ll, "ip",
6481 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6482 buf, INET6_ADDRSTRLEN));
6483 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6484 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6485
6486 json_object_boolean_true_add(json_nexthop_ll, "accessible");
6487 json_object_boolean_true_add(json_nexthop_ll, "used");
6488 }
6489 else
6490 {
6491 vty_out (vty, " (%s) (used)%s",
6492 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6493 buf, INET6_ADDRSTRLEN),
6494 VTY_NEWLINE);
6495 }
6496 }
6497 /* If we do not have a link-local nexthop then we must flag the global as "used" */
6498 else
6499 {
6500 if (json_paths)
6501 json_object_boolean_true_add(json_nexthop_global, "used");
6502 }
6503 #endif /* HAVE_IPV6 */
6504
6505 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
6506 if (json_paths)
6507 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6508 else
6509 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6510
6511 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6512 {
6513 if (json_paths)
6514 json_object_int_add(json_path, "med", attr->med);
6515 else
6516 vty_out (vty, ", metric %u", attr->med);
6517 }
6518
6519 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6520 {
6521 if (json_paths)
6522 json_object_int_add(json_path, "localpref", attr->local_pref);
6523 else
6524 vty_out (vty, ", localpref %u", attr->local_pref);
6525 }
6526 else
6527 {
6528 if (json_paths)
6529 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
6530 else
6531 vty_out (vty, ", localpref %u", bgp->default_local_pref);
6532 }
6533
6534 if (attr->extra && attr->extra->weight != 0)
6535 {
6536 if (json_paths)
6537 json_object_int_add(json_path, "weight", attr->extra->weight);
6538 else
6539 vty_out (vty, ", weight %u", attr->extra->weight);
6540 }
6541
6542 if (attr->extra && attr->extra->tag != 0)
6543 {
6544 if (json_paths)
6545 json_object_int_add(json_path, "tag", attr->extra->tag);
6546 else
6547 vty_out (vty, ", tag %d", attr->extra->tag);
6548 }
6549
6550 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6551 {
6552 if (json_paths)
6553 json_object_boolean_false_add(json_path, "valid");
6554 else
6555 vty_out (vty, ", invalid");
6556 }
6557 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6558 {
6559 if (json_paths)
6560 json_object_boolean_true_add(json_path, "valid");
6561 else
6562 vty_out (vty, ", valid");
6563 }
6564
6565 if (binfo->peer != bgp->peer_self)
6566 {
6567 if (binfo->peer->as == binfo->peer->local_as)
6568 {
6569 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
6570 {
6571 if (json_paths)
6572 json_object_string_add(json_peer, "type", "confed-internal");
6573 else
6574 vty_out (vty, ", confed-internal");
6575 }
6576 else
6577 {
6578 if (json_paths)
6579 json_object_string_add(json_peer, "type", "internal");
6580 else
6581 vty_out (vty, ", internal");
6582 }
6583 }
6584 else
6585 {
6586 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
6587 {
6588 if (json_paths)
6589 json_object_string_add(json_peer, "type", "confed-external");
6590 else
6591 vty_out (vty, ", confed-external");
6592 }
6593 else
6594 {
6595 if (json_paths)
6596 json_object_string_add(json_peer, "type", "external");
6597 else
6598 vty_out (vty, ", external");
6599 }
6600 }
6601 }
6602 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6603 {
6604 if (json_paths)
6605 {
6606 json_object_boolean_true_add(json_path, "aggregated");
6607 json_object_boolean_true_add(json_path, "local");
6608 }
6609 else
6610 {
6611 vty_out (vty, ", aggregated, local");
6612 }
6613 }
6614 else if (binfo->type != ZEBRA_ROUTE_BGP)
6615 {
6616 if (json_paths)
6617 json_object_boolean_true_add(json_path, "sourced");
6618 else
6619 vty_out (vty, ", sourced");
6620 }
6621 else
6622 {
6623 if (json_paths)
6624 {
6625 json_object_boolean_true_add(json_path, "sourced");
6626 json_object_boolean_true_add(json_path, "local");
6627 }
6628 else
6629 {
6630 vty_out (vty, ", sourced, local");
6631 }
6632 }
6633
6634 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6635 {
6636 if (json_paths)
6637 json_object_boolean_true_add(json_path, "atomicAggregate");
6638 else
6639 vty_out (vty, ", atomic-aggregate");
6640 }
6641
6642 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6643 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6644 bgp_info_mpath_count (binfo)))
6645 {
6646 if (json_paths)
6647 json_object_boolean_true_add(json_path, "multipath");
6648 else
6649 vty_out (vty, ", multipath");
6650 }
6651
6652 // Mark the bestpath(s)
6653 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
6654 {
6655 first_as = aspath_get_firstas(attr->aspath);
6656
6657 if (json_paths)
6658 {
6659 if (!json_bestpath)
6660 json_bestpath = json_object_new_object();
6661 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
6662 }
6663 else
6664 {
6665 if (first_as)
6666 vty_out (vty, ", bestpath-from-AS %d", first_as);
6667 else
6668 vty_out (vty, ", bestpath-from-AS Local");
6669 }
6670 }
6671
6672 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6673 {
6674 if (json_paths)
6675 {
6676 if (!json_bestpath)
6677 json_bestpath = json_object_new_object();
6678 json_object_boolean_true_add(json_bestpath, "overall");
6679 }
6680 else
6681 vty_out (vty, ", best");
6682 }
6683
6684 if (json_bestpath)
6685 json_object_object_add(json_path, "bestpath", json_bestpath);
6686
6687 if (!json_paths)
6688 vty_out (vty, "%s", VTY_NEWLINE);
6689
6690 /* Line 4 display Community */
6691 if (attr->community)
6692 {
6693 if (json_paths)
6694 {
6695 json_object_lock(attr->community->json);
6696 json_object_object_add(json_path, "community", attr->community->json);
6697 }
6698 else
6699 {
6700 vty_out (vty, " Community: %s%s", attr->community->str,
6701 VTY_NEWLINE);
6702 }
6703 }
6704
6705 /* Line 5 display Extended-community */
6706 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
6707 {
6708 if (json_paths)
6709 {
6710 json_ext_community = json_object_new_object();
6711 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
6712 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
6713 }
6714 else
6715 {
6716 vty_out (vty, " Extended Community: %s%s",
6717 attr->extra->ecommunity->str, VTY_NEWLINE);
6718 }
6719 }
6720
6721 /* Line 6 display Originator, Cluster-id */
6722 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6723 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6724 {
6725 assert (attr->extra);
6726 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6727 {
6728 if (json_paths)
6729 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
6730 else
6731 vty_out (vty, " Originator: %s",
6732 inet_ntoa (attr->extra->originator_id));
6733 }
6734
6735 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6736 {
6737 int i;
6738
6739 if (json_paths)
6740 {
6741 json_cluster_list = json_object_new_object();
6742 json_cluster_list_list = json_object_new_array();
6743
6744 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6745 {
6746 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
6747 json_object_array_add(json_cluster_list_list, json_string);
6748 }
6749
6750 /* struct cluster_list does not have "str" variable like
6751 * aspath and community do. Add this someday if someone
6752 * asks for it.
6753 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
6754 */
6755 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
6756 json_object_object_add(json_path, "clusterList", json_cluster_list);
6757 }
6758 else
6759 {
6760 vty_out (vty, ", Cluster list: ");
6761
6762 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6763 {
6764 vty_out (vty, "%s ",
6765 inet_ntoa (attr->extra->cluster->list[i]));
6766 }
6767 }
6768 }
6769
6770 if (!json_paths)
6771 vty_out (vty, "%s", VTY_NEWLINE);
6772 }
6773
6774 if (binfo->extra && binfo->extra->damp_info)
6775 bgp_damp_info_vty (vty, binfo, json_path);
6776
6777 /* Line 7 display Addpath IDs */
6778 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
6779 {
6780 if (json_paths)
6781 {
6782 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
6783 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
6784 }
6785 else
6786 {
6787 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
6788 binfo->addpath_rx_id, binfo->addpath_tx_id,
6789 VTY_NEWLINE);
6790 }
6791 }
6792
6793 /* If we used addpath to TX a non-bestpath we need to display
6794 * "Advertised to" on a path-by-path basis */
6795 if (bgp->addpath_tx_used[afi][safi])
6796 {
6797 first = 1;
6798
6799 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6800 {
6801 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
6802 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
6803
6804 if ((addpath_capable && has_adj) ||
6805 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
6806 {
6807 if (json_path && !json_adv_to)
6808 json_adv_to = json_object_new_object();
6809
6810 route_vty_out_advertised_to(vty, peer, &first,
6811 " Advertised to:",
6812 json_adv_to);
6813 }
6814 }
6815
6816 if (json_path)
6817 {
6818 if (json_adv_to)
6819 {
6820 json_object_object_add(json_path, "advertisedTo", json_adv_to);
6821 }
6822 }
6823 else
6824 {
6825 if (!first)
6826 {
6827 vty_out (vty, "%s", VTY_NEWLINE);
6828 }
6829 }
6830 }
6831
6832 /* Line 8 display Uptime */
6833 #ifdef HAVE_CLOCK_MONOTONIC
6834 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
6835 if (json_paths)
6836 {
6837 json_last_update = json_object_new_object();
6838 json_object_int_add(json_last_update, "epoch", tbuf);
6839 json_object_string_add(json_last_update, "string", ctime(&tbuf));
6840 json_object_object_add(json_path, "lastUpdate", json_last_update);
6841 }
6842 else
6843 vty_out (vty, " Last update: %s", ctime(&tbuf));
6844 #else
6845 if (json_paths)
6846 {
6847 json_last_update = json_object_new_object();
6848 json_object_int_add(json_last_update, "epoch", tbuf);
6849 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
6850 json_object_object_add(json_path, "lastUpdate", json_last_update);
6851 }
6852 else
6853 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6854 #endif /* HAVE_CLOCK_MONOTONIC */
6855 }
6856
6857 /* We've constructed the json object for this path, add it to the json
6858 * array of paths
6859 */
6860 if (json_paths)
6861 {
6862 if (json_nexthop_global || json_nexthop_ll)
6863 {
6864 json_nexthops = json_object_new_array();
6865
6866 if (json_nexthop_global)
6867 json_object_array_add(json_nexthops, json_nexthop_global);
6868
6869 if (json_nexthop_ll)
6870 json_object_array_add(json_nexthops, json_nexthop_ll);
6871
6872 json_object_object_add(json_path, "nexthops", json_nexthops);
6873 }
6874
6875 json_object_object_add(json_path, "peer", json_peer);
6876 json_object_array_add(json_paths, json_path);
6877 }
6878 else
6879 vty_out (vty, "%s", VTY_NEWLINE);
6880 }
6881
6882 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
6883 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6884 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6885
6886 enum bgp_show_type
6887 {
6888 bgp_show_type_normal,
6889 bgp_show_type_regexp,
6890 bgp_show_type_prefix_list,
6891 bgp_show_type_filter_list,
6892 bgp_show_type_route_map,
6893 bgp_show_type_neighbor,
6894 bgp_show_type_cidr_only,
6895 bgp_show_type_prefix_longer,
6896 bgp_show_type_community_all,
6897 bgp_show_type_community,
6898 bgp_show_type_community_exact,
6899 bgp_show_type_community_list,
6900 bgp_show_type_community_list_exact,
6901 bgp_show_type_flap_statistics,
6902 bgp_show_type_flap_address,
6903 bgp_show_type_flap_prefix,
6904 bgp_show_type_flap_cidr_only,
6905 bgp_show_type_flap_regexp,
6906 bgp_show_type_flap_filter_list,
6907 bgp_show_type_flap_prefix_list,
6908 bgp_show_type_flap_prefix_longer,
6909 bgp_show_type_flap_route_map,
6910 bgp_show_type_flap_neighbor,
6911 bgp_show_type_dampend_paths,
6912 bgp_show_type_damp_neighbor
6913 };
6914
6915 static int
6916 bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
6917 enum bgp_show_type type, void *output_arg, u_char use_json)
6918 {
6919 struct bgp_info *ri;
6920 struct bgp_node *rn;
6921 int header = 1;
6922 int display;
6923 unsigned long output_count;
6924 struct prefix *p;
6925 char buf[BUFSIZ];
6926 char buf2[BUFSIZ];
6927 json_object *json = NULL;
6928 json_object *json_paths = NULL;
6929 json_object *json_routes = NULL;
6930
6931 if (use_json)
6932 {
6933 json = json_object_new_object();
6934 json_object_int_add(json, "tableVersion", table->version);
6935 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
6936 json_routes = json_object_new_object();
6937 }
6938
6939 /* This is first entry point, so reset total line. */
6940 output_count = 0;
6941
6942 /* Start processing of routes. */
6943 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6944 if (rn->info != NULL)
6945 {
6946 display = 0;
6947
6948 if (use_json)
6949 json_paths = json_object_new_array();
6950 else
6951 json_paths = NULL;
6952
6953 for (ri = rn->info; ri; ri = ri->next)
6954 {
6955 if (type == bgp_show_type_flap_statistics
6956 || type == bgp_show_type_flap_address
6957 || type == bgp_show_type_flap_prefix
6958 || type == bgp_show_type_flap_cidr_only
6959 || type == bgp_show_type_flap_regexp
6960 || type == bgp_show_type_flap_filter_list
6961 || type == bgp_show_type_flap_prefix_list
6962 || type == bgp_show_type_flap_prefix_longer
6963 || type == bgp_show_type_flap_route_map
6964 || type == bgp_show_type_flap_neighbor
6965 || type == bgp_show_type_dampend_paths
6966 || type == bgp_show_type_damp_neighbor)
6967 {
6968 if (!(ri->extra && ri->extra->damp_info))
6969 continue;
6970 }
6971 if (type == bgp_show_type_regexp
6972 || type == bgp_show_type_flap_regexp)
6973 {
6974 regex_t *regex = output_arg;
6975
6976 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6977 continue;
6978 }
6979 if (type == bgp_show_type_prefix_list
6980 || type == bgp_show_type_flap_prefix_list)
6981 {
6982 struct prefix_list *plist = output_arg;
6983
6984 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6985 continue;
6986 }
6987 if (type == bgp_show_type_filter_list
6988 || type == bgp_show_type_flap_filter_list)
6989 {
6990 struct as_list *as_list = output_arg;
6991
6992 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6993 continue;
6994 }
6995 if (type == bgp_show_type_route_map
6996 || type == bgp_show_type_flap_route_map)
6997 {
6998 struct route_map *rmap = output_arg;
6999 struct bgp_info binfo;
7000 struct attr dummy_attr;
7001 struct attr_extra dummy_extra;
7002 int ret;
7003
7004 dummy_attr.extra = &dummy_extra;
7005 bgp_attr_dup (&dummy_attr, ri->attr);
7006
7007 binfo.peer = ri->peer;
7008 binfo.attr = &dummy_attr;
7009
7010 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7011 if (ret == RMAP_DENYMATCH)
7012 continue;
7013 }
7014 if (type == bgp_show_type_neighbor
7015 || type == bgp_show_type_flap_neighbor
7016 || type == bgp_show_type_damp_neighbor)
7017 {
7018 union sockunion *su = output_arg;
7019
7020 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7021 continue;
7022 }
7023 if (type == bgp_show_type_cidr_only
7024 || type == bgp_show_type_flap_cidr_only)
7025 {
7026 u_int32_t destination;
7027
7028 destination = ntohl (rn->p.u.prefix4.s_addr);
7029 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7030 continue;
7031 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7032 continue;
7033 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7034 continue;
7035 }
7036 if (type == bgp_show_type_prefix_longer
7037 || type == bgp_show_type_flap_prefix_longer)
7038 {
7039 struct prefix *p = output_arg;
7040
7041 if (! prefix_match (p, &rn->p))
7042 continue;
7043 }
7044 if (type == bgp_show_type_community_all)
7045 {
7046 if (! ri->attr->community)
7047 continue;
7048 }
7049 if (type == bgp_show_type_community)
7050 {
7051 struct community *com = output_arg;
7052
7053 if (! ri->attr->community ||
7054 ! community_match (ri->attr->community, com))
7055 continue;
7056 }
7057 if (type == bgp_show_type_community_exact)
7058 {
7059 struct community *com = output_arg;
7060
7061 if (! ri->attr->community ||
7062 ! community_cmp (ri->attr->community, com))
7063 continue;
7064 }
7065 if (type == bgp_show_type_community_list)
7066 {
7067 struct community_list *list = output_arg;
7068
7069 if (! community_list_match (ri->attr->community, list))
7070 continue;
7071 }
7072 if (type == bgp_show_type_community_list_exact)
7073 {
7074 struct community_list *list = output_arg;
7075
7076 if (! community_list_exact_match (ri->attr->community, list))
7077 continue;
7078 }
7079 if (type == bgp_show_type_flap_address
7080 || type == bgp_show_type_flap_prefix)
7081 {
7082 struct prefix *p = output_arg;
7083
7084 if (! prefix_match (&rn->p, p))
7085 continue;
7086
7087 if (type == bgp_show_type_flap_prefix)
7088 if (p->prefixlen != rn->p.prefixlen)
7089 continue;
7090 }
7091 if (type == bgp_show_type_dampend_paths
7092 || type == bgp_show_type_damp_neighbor)
7093 {
7094 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7095 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7096 continue;
7097 }
7098
7099 if (!use_json && header)
7100 {
7101 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
7102 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7103 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7104 if (type == bgp_show_type_dampend_paths
7105 || type == bgp_show_type_damp_neighbor)
7106 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7107 else if (type == bgp_show_type_flap_statistics
7108 || type == bgp_show_type_flap_address
7109 || type == bgp_show_type_flap_prefix
7110 || type == bgp_show_type_flap_cidr_only
7111 || type == bgp_show_type_flap_regexp
7112 || type == bgp_show_type_flap_filter_list
7113 || type == bgp_show_type_flap_prefix_list
7114 || type == bgp_show_type_flap_prefix_longer
7115 || type == bgp_show_type_flap_route_map
7116 || type == bgp_show_type_flap_neighbor)
7117 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7118 else
7119 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7120 header = 0;
7121 }
7122
7123 if (type == bgp_show_type_dampend_paths
7124 || type == bgp_show_type_damp_neighbor)
7125 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7126 else if (type == bgp_show_type_flap_statistics
7127 || type == bgp_show_type_flap_address
7128 || type == bgp_show_type_flap_prefix
7129 || type == bgp_show_type_flap_cidr_only
7130 || type == bgp_show_type_flap_regexp
7131 || type == bgp_show_type_flap_filter_list
7132 || type == bgp_show_type_flap_prefix_list
7133 || type == bgp_show_type_flap_prefix_longer
7134 || type == bgp_show_type_flap_route_map
7135 || type == bgp_show_type_flap_neighbor)
7136 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7137 else
7138 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7139 display++;
7140 }
7141
7142 if (display)
7143 {
7144 output_count++;
7145 if (use_json)
7146 {
7147 p = &rn->p;
7148 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7149 json_object_object_add(json_routes, buf2, json_paths);
7150 }
7151 }
7152 }
7153
7154 if (use_json)
7155 {
7156 json_object_object_add(json, "routes", json_routes);
7157 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7158 json_object_free(json);
7159 }
7160 else
7161 {
7162 /* No route is displayed */
7163 if (output_count == 0)
7164 {
7165 if (type == bgp_show_type_normal)
7166 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
7167 }
7168 else
7169 vty_out (vty, "%sTotal number of prefixes %ld%s",
7170 VTY_NEWLINE, output_count, VTY_NEWLINE);
7171 }
7172
7173 return CMD_SUCCESS;
7174 }
7175
7176 static int
7177 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
7178 enum bgp_show_type type, void *output_arg, u_char use_json)
7179 {
7180 struct bgp_table *table;
7181
7182 if (bgp == NULL)
7183 {
7184 bgp = bgp_get_default ();
7185 }
7186
7187 if (bgp == NULL)
7188 {
7189 if (!use_json)
7190 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7191 return CMD_WARNING;
7192 }
7193
7194 table = bgp->rib[afi][safi];
7195
7196 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, use_json);
7197 }
7198
7199 /* Header of detailed BGP route information */
7200 static void
7201 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7202 struct bgp_node *rn,
7203 struct prefix_rd *prd, afi_t afi, safi_t safi,
7204 json_object *json)
7205 {
7206 struct bgp_info *ri;
7207 struct prefix *p;
7208 struct peer *peer;
7209 struct listnode *node, *nnode;
7210 char buf1[INET6_ADDRSTRLEN];
7211 char buf2[INET6_ADDRSTRLEN];
7212 int count = 0;
7213 int best = 0;
7214 int suppress = 0;
7215 int no_export = 0;
7216 int no_advertise = 0;
7217 int local_as = 0;
7218 int first = 1;
7219 json_object *json_adv_to = NULL;
7220
7221 p = &rn->p;
7222
7223 if (json)
7224 {
7225 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7226 json_object_int_add(json, "prefixlen", p->prefixlen);
7227 }
7228 else
7229 {
7230 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7231 (safi == SAFI_MPLS_VPN ?
7232 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7233 safi == SAFI_MPLS_VPN ? ":" : "",
7234 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7235 p->prefixlen, VTY_NEWLINE);
7236 }
7237
7238 for (ri = rn->info; ri; ri = ri->next)
7239 {
7240 count++;
7241 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7242 {
7243 best = count;
7244 if (ri->extra && ri->extra->suppress)
7245 suppress = 1;
7246 if (ri->attr->community != NULL)
7247 {
7248 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7249 no_advertise = 1;
7250 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7251 no_export = 1;
7252 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7253 local_as = 1;
7254 }
7255 }
7256 }
7257
7258 if (!json)
7259 {
7260 vty_out (vty, "Paths: (%d available", count);
7261 if (best)
7262 {
7263 vty_out (vty, ", best #%d", best);
7264 if (safi == SAFI_UNICAST)
7265 vty_out (vty, ", table Default-IP-Routing-Table");
7266 }
7267 else
7268 vty_out (vty, ", no best path");
7269
7270 if (no_advertise)
7271 vty_out (vty, ", not advertised to any peer");
7272 else if (no_export)
7273 vty_out (vty, ", not advertised to EBGP peer");
7274 else if (local_as)
7275 vty_out (vty, ", not advertised outside local AS");
7276
7277 if (suppress)
7278 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7279 vty_out (vty, ")%s", VTY_NEWLINE);
7280 }
7281
7282 /* If we are not using addpath then we can display Advertised to and that will
7283 * show what peers we advertised the bestpath to. If we are using addpath
7284 * though then we must display Advertised to on a path-by-path basis. */
7285 if (!bgp->addpath_tx_used[afi][safi])
7286 {
7287 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7288 {
7289 if (bgp_adj_out_lookup (peer, rn, 0))
7290 {
7291 if (json && !json_adv_to)
7292 json_adv_to = json_object_new_object();
7293
7294 route_vty_out_advertised_to(vty, peer, &first,
7295 " Advertised to non peer-group peers:\n ",
7296 json_adv_to);
7297 }
7298 }
7299
7300 if (json)
7301 {
7302 if (json_adv_to)
7303 {
7304 json_object_object_add(json, "advertisedTo", json_adv_to);
7305 }
7306 }
7307 else
7308 {
7309 if (first)
7310 vty_out (vty, " Not advertised to any peer");
7311 vty_out (vty, "%s", VTY_NEWLINE);
7312 }
7313 }
7314 }
7315
7316 /* Display specified route of BGP table. */
7317 static int
7318 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
7319 struct bgp_table *rib, const char *ip_str,
7320 afi_t afi, safi_t safi, struct prefix_rd *prd,
7321 int prefix_check, enum bgp_path_type pathtype,
7322 u_char use_json)
7323 {
7324 int ret;
7325 int header;
7326 int display = 0;
7327 struct prefix match;
7328 struct bgp_node *rn;
7329 struct bgp_node *rm;
7330 struct bgp_info *ri;
7331 struct bgp_table *table;
7332 json_object *json = NULL;
7333 json_object *json_paths = NULL;
7334
7335 /* Check IP address argument. */
7336 ret = str2prefix (ip_str, &match);
7337 if (! ret)
7338 {
7339 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
7340 return CMD_WARNING;
7341 }
7342
7343 match.family = afi2family (afi);
7344
7345 if (use_json)
7346 {
7347 json = json_object_new_object();
7348 json_paths = json_object_new_array();
7349 }
7350
7351 if (safi == SAFI_MPLS_VPN)
7352 {
7353 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
7354 {
7355 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
7356 continue;
7357
7358 if ((table = rn->info) != NULL)
7359 {
7360 header = 1;
7361
7362 if ((rm = bgp_node_match (table, &match)) != NULL)
7363 {
7364 if (prefix_check && rm->p.prefixlen != match.prefixlen)
7365 {
7366 bgp_unlock_node (rm);
7367 continue;
7368 }
7369
7370 for (ri = rm->info; ri; ri = ri->next)
7371 {
7372 if (header)
7373 {
7374 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
7375 AFI_IP, SAFI_MPLS_VPN, json);
7376
7377 header = 0;
7378 }
7379 display++;
7380
7381 if (pathtype == BGP_PATH_ALL ||
7382 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7383 (pathtype == BGP_PATH_MULTIPATH &&
7384 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7385 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN, json_paths);
7386 }
7387
7388 bgp_unlock_node (rm);
7389 }
7390 }
7391 }
7392 }
7393 else
7394 {
7395 header = 1;
7396
7397 if ((rn = bgp_node_match (rib, &match)) != NULL)
7398 {
7399 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
7400 {
7401 for (ri = rn->info; ri; ri = ri->next)
7402 {
7403 if (header)
7404 {
7405 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
7406 header = 0;
7407 }
7408 display++;
7409
7410 if (pathtype == BGP_PATH_ALL ||
7411 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7412 (pathtype == BGP_PATH_MULTIPATH &&
7413 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7414 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
7415 }
7416 }
7417
7418 bgp_unlock_node (rn);
7419 }
7420 }
7421
7422 if (use_json)
7423 {
7424 if (display)
7425 json_object_object_add(json, "paths", json_paths);
7426
7427 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7428 json_object_free(json);
7429 }
7430 else
7431 {
7432 if (!display)
7433 {
7434 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7435 return CMD_WARNING;
7436 }
7437 }
7438
7439 return CMD_SUCCESS;
7440 }
7441
7442 /* Display specified route of Main RIB */
7443 static int
7444 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
7445 afi_t afi, safi_t safi, struct prefix_rd *prd,
7446 int prefix_check, enum bgp_path_type pathtype,
7447 u_char use_json)
7448 {
7449 struct bgp *bgp;
7450
7451 /* BGP structure lookup. */
7452 if (view_name)
7453 {
7454 bgp = bgp_lookup_by_name (view_name);
7455 if (bgp == NULL)
7456 {
7457 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7458 return CMD_WARNING;
7459 }
7460 }
7461 else
7462 {
7463 bgp = bgp_get_default ();
7464 if (bgp == NULL)
7465 {
7466 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7467 return CMD_WARNING;
7468 }
7469 }
7470
7471 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
7472 afi, safi, prd, prefix_check, pathtype,
7473 use_json);
7474 }
7475
7476 /* BGP route print out function. */
7477 DEFUN (show_ip_bgp,
7478 show_ip_bgp_cmd,
7479 "show ip bgp {json}",
7480 SHOW_STR
7481 IP_STR
7482 BGP_STR
7483 "JavaScript Object Notation\n")
7484 {
7485 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
7486 }
7487
7488 DEFUN (show_ip_bgp_ipv4,
7489 show_ip_bgp_ipv4_cmd,
7490 "show ip bgp ipv4 (unicast|multicast) {json}",
7491 SHOW_STR
7492 IP_STR
7493 BGP_STR
7494 "Address family\n"
7495 "Address Family modifier\n"
7496 "Address Family modifier\n"
7497 "JavaScript Object Notation\n")
7498 {
7499 u_char uj = use_json(argc, argv);
7500
7501 if (strncmp (argv[0], "m", 1) == 0)
7502 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7503 NULL, uj);
7504
7505 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
7506 }
7507
7508 ALIAS (show_ip_bgp_ipv4,
7509 show_bgp_ipv4_safi_cmd,
7510 "show bgp ipv4 (unicast|multicast) {json}",
7511 SHOW_STR
7512 BGP_STR
7513 "Address family\n"
7514 "Address Family modifier\n"
7515 "Address Family modifier\n"
7516 "JavaScript Object Notation\n")
7517
7518 DEFUN (show_ip_bgp_route,
7519 show_ip_bgp_route_cmd,
7520 "show ip bgp A.B.C.D {json}",
7521 SHOW_STR
7522 IP_STR
7523 BGP_STR
7524 "Network in the BGP routing table to display\n"
7525 "JavaScript Object Notation\n")
7526 {
7527 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7528 }
7529
7530 DEFUN (show_ip_bgp_route_pathtype,
7531 show_ip_bgp_route_pathtype_cmd,
7532 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
7533 SHOW_STR
7534 IP_STR
7535 BGP_STR
7536 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7537 "Display only the bestpath\n"
7538 "Display only multipaths\n"
7539 "JavaScript Object Notation\n")
7540 {
7541 u_char uj = use_json(argc, argv);
7542
7543 if (strncmp (argv[1], "b", 1) == 0)
7544 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7545 else
7546 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7547 }
7548
7549 DEFUN (show_bgp_ipv4_safi_route_pathtype,
7550 show_bgp_ipv4_safi_route_pathtype_cmd,
7551 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
7552 SHOW_STR
7553 BGP_STR
7554 "Address family\n"
7555 "Address Family modifier\n"
7556 "Address Family modifier\n"
7557 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7558 "Display only the bestpath\n"
7559 "Display only multipaths\n"
7560 "JavaScript Object Notation\n")
7561 {
7562 u_char uj = use_json(argc, argv);
7563
7564 if (strncmp (argv[0], "m", 1) == 0)
7565 if (strncmp (argv[2], "b", 1) == 0)
7566 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7567 else
7568 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7569 else
7570 if (strncmp (argv[2], "b", 1) == 0)
7571 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7572 else
7573 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7574 }
7575
7576 DEFUN (show_ip_bgp_ipv4_route,
7577 show_ip_bgp_ipv4_route_cmd,
7578 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
7579 SHOW_STR
7580 IP_STR
7581 BGP_STR
7582 "Address family\n"
7583 "Address Family modifier\n"
7584 "Address Family modifier\n"
7585 "Network in the BGP routing table to display\n"
7586 "JavaScript Object Notation\n")
7587 {
7588 u_char uj = use_json(argc, argv);
7589
7590 if (strncmp (argv[0], "m", 1) == 0)
7591 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
7592
7593 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
7594 }
7595
7596 ALIAS (show_ip_bgp_ipv4_route,
7597 show_bgp_ipv4_safi_route_cmd,
7598 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
7599 SHOW_STR
7600 BGP_STR
7601 "Address family\n"
7602 "Address Family modifier\n"
7603 "Address Family modifier\n"
7604 "Network in the BGP routing table to display\n"
7605 "JavaScript Object Notation\n")
7606
7607 DEFUN (show_ip_bgp_vpnv4_all_route,
7608 show_ip_bgp_vpnv4_all_route_cmd,
7609 "show ip bgp vpnv4 all A.B.C.D {json}",
7610 SHOW_STR
7611 IP_STR
7612 BGP_STR
7613 "Display VPNv4 NLRI specific information\n"
7614 "Display information about all VPNv4 NLRIs\n"
7615 "Network in the BGP routing table to display\n"
7616 "JavaScript Object Notation\n")
7617 {
7618 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7619 }
7620
7621
7622 DEFUN (show_ip_bgp_vpnv4_rd_route,
7623 show_ip_bgp_vpnv4_rd_route_cmd,
7624 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
7625 SHOW_STR
7626 IP_STR
7627 BGP_STR
7628 "Display VPNv4 NLRI specific information\n"
7629 "Display information for a route distinguisher\n"
7630 "VPN Route Distinguisher\n"
7631 "Network in the BGP routing table to display\n"
7632 "JavaScript Object Notation\n")
7633 {
7634 int ret;
7635 struct prefix_rd prd;
7636 u_char uj= use_json(argc, argv);
7637
7638 ret = str2prefix_rd (argv[0], &prd);
7639 if (! ret)
7640 {
7641 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7642 return CMD_WARNING;
7643 }
7644 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj);
7645 }
7646
7647 DEFUN (show_ip_bgp_prefix,
7648 show_ip_bgp_prefix_cmd,
7649 "show ip bgp A.B.C.D/M {json}",
7650 SHOW_STR
7651 IP_STR
7652 BGP_STR
7653 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7654 "JavaScript Object Notation\n")
7655 {
7656 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
7657 }
7658
7659 DEFUN (show_ip_bgp_prefix_pathtype,
7660 show_ip_bgp_prefix_pathtype_cmd,
7661 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
7662 SHOW_STR
7663 IP_STR
7664 BGP_STR
7665 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7666 "Display only the bestpath\n"
7667 "Display only multipaths\n"
7668 "JavaScript Object Notation\n")
7669 {
7670 u_char uj = use_json(argc, argv);
7671 if (strncmp (argv[1], "b", 1) == 0)
7672 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
7673 else
7674 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
7675 }
7676
7677 DEFUN (show_ip_bgp_ipv4_prefix,
7678 show_ip_bgp_ipv4_prefix_cmd,
7679 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
7680 SHOW_STR
7681 IP_STR
7682 BGP_STR
7683 "Address family\n"
7684 "Address Family modifier\n"
7685 "Address Family modifier\n"
7686 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7687 "JavaScript Object Notation\n")
7688 {
7689 u_char uj = use_json(argc, argv);
7690
7691 if (strncmp (argv[0], "m", 1) == 0)
7692 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
7693
7694 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
7695 }
7696
7697 ALIAS (show_ip_bgp_ipv4_prefix,
7698 show_bgp_ipv4_safi_prefix_cmd,
7699 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
7700 SHOW_STR
7701 BGP_STR
7702 "Address family\n"
7703 "Address Family modifier\n"
7704 "Address Family modifier\n"
7705 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7706 "JavaScript Object Notation\n")
7707
7708 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7709 show_ip_bgp_ipv4_prefix_pathtype_cmd,
7710 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
7711 SHOW_STR
7712 IP_STR
7713 BGP_STR
7714 "Address family\n"
7715 "Address Family modifier\n"
7716 "Address Family modifier\n"
7717 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7718 "Display only the bestpath\n"
7719 "Display only multipaths\n"
7720 "JavaScript Object Notation\n")
7721 {
7722 u_char uj = use_json(argc, argv);
7723
7724 if (strncmp (argv[0], "m", 1) == 0)
7725 if (strncmp (argv[2], "b", 1) == 0)
7726 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
7727 else
7728 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
7729 else
7730 if (strncmp (argv[2], "b", 1) == 0)
7731 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
7732 else
7733 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
7734 }
7735
7736 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7737 show_bgp_ipv4_safi_prefix_pathtype_cmd,
7738 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
7739 SHOW_STR
7740 BGP_STR
7741 "Address family\n"
7742 "Address Family modifier\n"
7743 "Address Family modifier\n"
7744 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7745 "Display only the bestpath\n"
7746 "Display only multipaths\n"
7747 "JavaScript Object Notation\n")
7748
7749 DEFUN (show_ip_bgp_vpnv4_all_prefix,
7750 show_ip_bgp_vpnv4_all_prefix_cmd,
7751 "show ip bgp vpnv4 all A.B.C.D/M {json}",
7752 SHOW_STR
7753 IP_STR
7754 BGP_STR
7755 "Display VPNv4 NLRI specific information\n"
7756 "Display information about all VPNv4 NLRIs\n"
7757 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7758 "JavaScript Object Notation\n")
7759 {
7760 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
7761 }
7762
7763 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7764 show_ip_bgp_vpnv4_rd_prefix_cmd,
7765 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
7766 SHOW_STR
7767 IP_STR
7768 BGP_STR
7769 "Display VPNv4 NLRI specific information\n"
7770 "Display information for a route distinguisher\n"
7771 "VPN Route Distinguisher\n"
7772 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7773 "JavaScript Object Notation\n")
7774 {
7775 int ret;
7776 struct prefix_rd prd;
7777
7778 ret = str2prefix_rd (argv[0], &prd);
7779 if (! ret)
7780 {
7781 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7782 return CMD_WARNING;
7783 }
7784 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv));
7785 }
7786
7787 DEFUN (show_ip_bgp_view,
7788 show_ip_bgp_view_cmd,
7789 "show ip bgp view WORD {json}",
7790 SHOW_STR
7791 IP_STR
7792 BGP_STR
7793 "BGP view\n"
7794 "View name\n"
7795 "JavaScript Object Notation\n")
7796 {
7797 struct bgp *bgp;
7798
7799 /* BGP structure lookup. */
7800 bgp = bgp_lookup_by_name (argv[0]);
7801 if (bgp == NULL)
7802 {
7803 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7804 return CMD_WARNING;
7805 }
7806
7807 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
7808 }
7809
7810 DEFUN (show_ip_bgp_view_route,
7811 show_ip_bgp_view_route_cmd,
7812 "show ip bgp view WORD A.B.C.D {json}",
7813 SHOW_STR
7814 IP_STR
7815 BGP_STR
7816 "BGP view\n"
7817 "View name\n"
7818 "Network in the BGP routing table to display\n"
7819 "JavaScript Object Notation\n")
7820 {
7821 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7822 }
7823
7824 DEFUN (show_ip_bgp_view_prefix,
7825 show_ip_bgp_view_prefix_cmd,
7826 "show ip bgp view WORD A.B.C.D/M {json}",
7827 SHOW_STR
7828 IP_STR
7829 BGP_STR
7830 "BGP view\n"
7831 "View name\n"
7832 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7833 "JavaScript Object Notation\n")
7834 {
7835 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
7836 }
7837
7838 #ifdef HAVE_IPV6
7839 DEFUN (show_bgp,
7840 show_bgp_cmd,
7841 "show bgp {json}",
7842 SHOW_STR
7843 BGP_STR
7844 "JavaScript Object Notation\n")
7845 {
7846 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7847 NULL, use_json(argc, argv));
7848 }
7849
7850 ALIAS (show_bgp,
7851 show_bgp_ipv6_cmd,
7852 "show bgp ipv6 {json}",
7853 SHOW_STR
7854 BGP_STR
7855 "Address family\n"
7856 "JavaScript Object Notation\n")
7857
7858 DEFUN (show_bgp_ipv6_safi,
7859 show_bgp_ipv6_safi_cmd,
7860 "show bgp ipv6 (unicast|multicast) {json}",
7861 SHOW_STR
7862 BGP_STR
7863 "Address family\n"
7864 "Address Family modifier\n"
7865 "Address Family modifier\n"
7866 "JavaScript Object Notation\n")
7867 {
7868 u_char uj = use_json(argc, argv);
7869 if (strncmp (argv[0], "m", 1) == 0)
7870 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7871 NULL, uj);
7872
7873 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
7874 }
7875
7876 static void
7877 bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
7878 {
7879 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
7880 " next release%sPlese use 'show bgp ipv6' instead%s%s",
7881 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
7882 }
7883
7884 /* old command */
7885 DEFUN (show_ipv6_bgp,
7886 show_ipv6_bgp_cmd,
7887 "show ipv6 bgp {json}",
7888 SHOW_STR
7889 IP_STR
7890 BGP_STR
7891 "JavaScript Object Notation\n")
7892 {
7893 bgp_show_ipv6_bgp_deprecate_warning(vty);
7894 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7895 NULL, use_json(argc, argv));
7896 }
7897
7898 DEFUN (show_bgp_route,
7899 show_bgp_route_cmd,
7900 "show bgp X:X::X:X {json}",
7901 SHOW_STR
7902 BGP_STR
7903 "Network in the BGP routing table to display\n"
7904 "JavaScript Object Notation\n")
7905 {
7906 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7907 }
7908
7909 ALIAS (show_bgp_route,
7910 show_bgp_ipv6_route_cmd,
7911 "show bgp ipv6 X:X::X:X {json}",
7912 SHOW_STR
7913 BGP_STR
7914 "Address family\n"
7915 "Network in the BGP routing table to display\n"
7916 "JavaScript Object Notation\n")
7917
7918 DEFUN (show_bgp_ipv6_safi_route,
7919 show_bgp_ipv6_safi_route_cmd,
7920 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
7921 SHOW_STR
7922 BGP_STR
7923 "Address family\n"
7924 "Address Family modifier\n"
7925 "Address Family modifier\n"
7926 "Network in the BGP routing table to display\n"
7927 "JavaScript Object Notation\n")
7928 {
7929 u_char uj = use_json(argc, argv);
7930 if (strncmp (argv[0], "m", 1) == 0)
7931 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
7932
7933 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
7934 }
7935
7936 DEFUN (show_bgp_route_pathtype,
7937 show_bgp_route_pathtype_cmd,
7938 "show bgp X:X::X:X (bestpath|multipath) {json}",
7939 SHOW_STR
7940 BGP_STR
7941 "Network in the BGP routing table to display\n"
7942 "Display only the bestpath\n"
7943 "Display only multipaths\n"
7944 "JavaScript Object Notation\n")
7945 {
7946 u_char uj = use_json(argc, argv);
7947 if (strncmp (argv[1], "b", 1) == 0)
7948 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7949 else
7950 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7951 }
7952
7953 ALIAS (show_bgp_route_pathtype,
7954 show_bgp_ipv6_route_pathtype_cmd,
7955 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
7956 SHOW_STR
7957 BGP_STR
7958 "Address family\n"
7959 "Network in the BGP routing table to display\n"
7960 "Display only the bestpath\n"
7961 "Display only multipaths\n"
7962 "JavaScript Object Notation\n")
7963
7964 DEFUN (show_bgp_ipv6_safi_route_pathtype,
7965 show_bgp_ipv6_safi_route_pathtype_cmd,
7966 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
7967 SHOW_STR
7968 BGP_STR
7969 "Address family\n"
7970 "Address Family modifier\n"
7971 "Address Family modifier\n"
7972 "Network in the BGP routing table to display\n"
7973 "Display only the bestpath\n"
7974 "Display only multipaths\n"
7975 "JavaScript Object Notation\n")
7976 {
7977 u_char uj = use_json(argc, argv);
7978 if (strncmp (argv[0], "m", 1) == 0)
7979 if (strncmp (argv[2], "b", 1) == 0)
7980 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7981 else
7982 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7983 else
7984 if (strncmp (argv[2], "b", 1) == 0)
7985 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7986 else
7987 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7988 }
7989
7990 /* old command */
7991 DEFUN (show_ipv6_bgp_route,
7992 show_ipv6_bgp_route_cmd,
7993 "show ipv6 bgp X:X::X:X {json}",
7994 SHOW_STR
7995 IP_STR
7996 BGP_STR
7997 "Network in the BGP routing table to display\n"
7998 "JavaScript Object Notation\n")
7999 {
8000 bgp_show_ipv6_bgp_deprecate_warning(vty);
8001 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8002 }
8003
8004 DEFUN (show_bgp_prefix,
8005 show_bgp_prefix_cmd,
8006 "show bgp X:X::X:X/M {json}",
8007 SHOW_STR
8008 BGP_STR
8009 "IPv6 prefix <network>/<length>\n"
8010 "JavaScript Object Notation\n")
8011 {
8012 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8013 }
8014
8015 ALIAS (show_bgp_prefix,
8016 show_bgp_ipv6_prefix_cmd,
8017 "show bgp ipv6 X:X::X:X/M {json}",
8018 SHOW_STR
8019 BGP_STR
8020 "Address family\n"
8021 "IPv6 prefix <network>/<length>\n"
8022 "JavaScript Object Notation\n")
8023
8024 DEFUN (show_bgp_ipv6_safi_prefix,
8025 show_bgp_ipv6_safi_prefix_cmd,
8026 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
8027 SHOW_STR
8028 BGP_STR
8029 "Address family\n"
8030 "Address Family modifier\n"
8031 "Address Family modifier\n"
8032 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8033 "JavaScript Object Notation\n")
8034 {
8035 u_char uj = use_json(argc, argv);
8036 if (strncmp (argv[0], "m", 1) == 0)
8037 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
8038
8039 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
8040 }
8041
8042 DEFUN (show_bgp_prefix_pathtype,
8043 show_bgp_prefix_pathtype_cmd,
8044 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
8045 SHOW_STR
8046 BGP_STR
8047 "IPv6 prefix <network>/<length>\n"
8048 "Display only the bestpath\n"
8049 "Display only multipaths\n"
8050 "JavaScript Object Notation\n")
8051 {
8052 u_char uj = use_json(argc, argv);
8053 if (strncmp (argv[1], "b", 1) == 0)
8054 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8055 else
8056 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8057 }
8058
8059 ALIAS (show_bgp_prefix_pathtype,
8060 show_bgp_ipv6_prefix_pathtype_cmd,
8061 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8062 SHOW_STR
8063 BGP_STR
8064 "Address family\n"
8065 "IPv6 prefix <network>/<length>\n"
8066 "Display only the bestpath\n"
8067 "Display only multipaths\n"
8068 "JavaScript Object Notation\n")
8069
8070 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8071 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8072 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
8073 SHOW_STR
8074 BGP_STR
8075 "Address family\n"
8076 "Address Family modifier\n"
8077 "Address Family modifier\n"
8078 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8079 "Display only the bestpath\n"
8080 "Display only multipaths\n"
8081 "JavaScript Object Notation\n")
8082 {
8083 u_char uj = use_json(argc, argv);
8084 if (strncmp (argv[0], "m", 1) == 0)
8085 if (strncmp (argv[2], "b", 1) == 0)
8086 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8087 else
8088 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8089 else
8090 if (strncmp (argv[2], "b", 1) == 0)
8091 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8092 else
8093 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8094 }
8095
8096 /* old command */
8097 DEFUN (show_ipv6_bgp_prefix,
8098 show_ipv6_bgp_prefix_cmd,
8099 "show ipv6 bgp X:X::X:X/M {json}",
8100 SHOW_STR
8101 IP_STR
8102 BGP_STR
8103 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8104 "JavaScript Object Notation\n")
8105 {
8106 bgp_show_ipv6_bgp_deprecate_warning(vty);
8107 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8108 }
8109
8110 DEFUN (show_bgp_view,
8111 show_bgp_view_cmd,
8112 "show bgp view WORD {json}",
8113 SHOW_STR
8114 BGP_STR
8115 "BGP view\n"
8116 "View name\n"
8117 "JavaScript Object Notation\n")
8118 {
8119 struct bgp *bgp;
8120
8121 /* BGP structure lookup. */
8122 bgp = bgp_lookup_by_name (argv[0]);
8123 if (bgp == NULL)
8124 {
8125 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8126 return CMD_WARNING;
8127 }
8128
8129 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8130 }
8131
8132 ALIAS (show_bgp_view,
8133 show_bgp_view_ipv6_cmd,
8134 "show bgp view WORD ipv6 {json}",
8135 SHOW_STR
8136 BGP_STR
8137 "BGP view\n"
8138 "View name\n"
8139 "Address family\n"
8140 "JavaScript Object Notation\n")
8141
8142 DEFUN (show_bgp_view_route,
8143 show_bgp_view_route_cmd,
8144 "show bgp view WORD X:X::X:X {json}",
8145 SHOW_STR
8146 BGP_STR
8147 "BGP view\n"
8148 "View name\n"
8149 "Network in the BGP routing table to display\n"
8150 "JavaScript Object Notation\n")
8151 {
8152 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8153 }
8154
8155 ALIAS (show_bgp_view_route,
8156 show_bgp_view_ipv6_route_cmd,
8157 "show bgp view WORD ipv6 X:X::X:X {json}",
8158 SHOW_STR
8159 BGP_STR
8160 "BGP view\n"
8161 "View name\n"
8162 "Address family\n"
8163 "Network in the BGP routing table to display\n"
8164 "JavaScript Object Notation\n")
8165
8166 DEFUN (show_bgp_view_prefix,
8167 show_bgp_view_prefix_cmd,
8168 "show bgp view WORD X:X::X:X/M {json}",
8169 SHOW_STR
8170 BGP_STR
8171 "BGP view\n"
8172 "View name\n"
8173 "IPv6 prefix <network>/<length>\n"
8174 "JavaScript Object Notation\n")
8175 {
8176 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8177 }
8178
8179 ALIAS (show_bgp_view_prefix,
8180 show_bgp_view_ipv6_prefix_cmd,
8181 "show bgp view WORD ipv6 X:X::X:X/M {json}",
8182 SHOW_STR
8183 BGP_STR
8184 "BGP view\n"
8185 "View name\n"
8186 "Address family\n"
8187 "IPv6 prefix <network>/<length>\n"
8188 "JavaScript Object Notation\n")
8189
8190 /* old command */
8191 DEFUN (show_ipv6_mbgp,
8192 show_ipv6_mbgp_cmd,
8193 "show ipv6 mbgp {json}",
8194 SHOW_STR
8195 IP_STR
8196 MBGP_STR
8197 "JavaScript Object Notation\n")
8198 {
8199 bgp_show_ipv6_bgp_deprecate_warning(vty);
8200 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8201 NULL, use_json(argc, argv));
8202 }
8203
8204 /* old command */
8205 DEFUN (show_ipv6_mbgp_route,
8206 show_ipv6_mbgp_route_cmd,
8207 "show ipv6 mbgp X:X::X:X {json}",
8208 SHOW_STR
8209 IP_STR
8210 MBGP_STR
8211 "Network in the MBGP routing table to display\n"
8212 "JavaScript Object Notation\n")
8213 {
8214 bgp_show_ipv6_bgp_deprecate_warning(vty);
8215 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8216 }
8217
8218 /* old command */
8219 DEFUN (show_ipv6_mbgp_prefix,
8220 show_ipv6_mbgp_prefix_cmd,
8221 "show ipv6 mbgp X:X::X:X/M {json}",
8222 SHOW_STR
8223 IP_STR
8224 MBGP_STR
8225 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8226 "JavaScript Object Notation\n")
8227 {
8228 bgp_show_ipv6_bgp_deprecate_warning(vty);
8229 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8230 }
8231 #endif
8232
8233
8234 static int
8235 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
8236 safi_t safi, enum bgp_show_type type)
8237 {
8238 int i;
8239 struct buffer *b;
8240 char *regstr;
8241 int first;
8242 regex_t *regex;
8243 int rc;
8244
8245 first = 0;
8246 b = buffer_new (1024);
8247 for (i = 0; i < argc; i++)
8248 {
8249 if (first)
8250 buffer_putc (b, ' ');
8251 else
8252 {
8253 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8254 continue;
8255 first = 1;
8256 }
8257
8258 buffer_putstr (b, argv[i]);
8259 }
8260 buffer_putc (b, '\0');
8261
8262 regstr = buffer_getstr (b);
8263 buffer_free (b);
8264
8265 regex = bgp_regcomp (regstr);
8266 XFREE(MTYPE_TMP, regstr);
8267 if (! regex)
8268 {
8269 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8270 VTY_NEWLINE);
8271 return CMD_WARNING;
8272 }
8273
8274 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
8275 bgp_regex_free (regex);
8276 return rc;
8277 }
8278
8279 DEFUN (show_ip_bgp_regexp,
8280 show_ip_bgp_regexp_cmd,
8281 "show ip bgp regexp .LINE",
8282 SHOW_STR
8283 IP_STR
8284 BGP_STR
8285 "Display routes matching the AS path regular expression\n"
8286 "A regular-expression to match the BGP AS paths\n")
8287 {
8288 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8289 bgp_show_type_regexp);
8290 }
8291
8292 DEFUN (show_ip_bgp_flap_regexp,
8293 show_ip_bgp_flap_regexp_cmd,
8294 "show ip bgp flap-statistics regexp .LINE",
8295 SHOW_STR
8296 IP_STR
8297 BGP_STR
8298 "Display flap statistics of routes\n"
8299 "Display routes matching the AS path regular expression\n"
8300 "A regular-expression to match the BGP AS paths\n")
8301 {
8302 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8303 bgp_show_type_flap_regexp);
8304 }
8305
8306 DEFUN (show_ip_bgp_ipv4_regexp,
8307 show_ip_bgp_ipv4_regexp_cmd,
8308 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8309 SHOW_STR
8310 IP_STR
8311 BGP_STR
8312 "Address family\n"
8313 "Address Family modifier\n"
8314 "Address Family modifier\n"
8315 "Display routes matching the AS path regular expression\n"
8316 "A regular-expression to match the BGP AS paths\n")
8317 {
8318 if (strncmp (argv[0], "m", 1) == 0)
8319 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8320 bgp_show_type_regexp);
8321
8322 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8323 bgp_show_type_regexp);
8324 }
8325
8326 #ifdef HAVE_IPV6
8327 DEFUN (show_bgp_regexp,
8328 show_bgp_regexp_cmd,
8329 "show bgp regexp .LINE",
8330 SHOW_STR
8331 BGP_STR
8332 "Display routes matching the AS path regular expression\n"
8333 "A regular-expression to match the BGP AS paths\n")
8334 {
8335 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8336 bgp_show_type_regexp);
8337 }
8338
8339 ALIAS (show_bgp_regexp,
8340 show_bgp_ipv6_regexp_cmd,
8341 "show bgp ipv6 regexp .LINE",
8342 SHOW_STR
8343 BGP_STR
8344 "Address family\n"
8345 "Display routes matching the AS path regular expression\n"
8346 "A regular-expression to match the BGP AS paths\n")
8347
8348 /* old command */
8349 DEFUN (show_ipv6_bgp_regexp,
8350 show_ipv6_bgp_regexp_cmd,
8351 "show ipv6 bgp regexp .LINE",
8352 SHOW_STR
8353 IP_STR
8354 BGP_STR
8355 "Display routes matching the AS path regular expression\n"
8356 "A regular-expression to match the BGP AS paths\n")
8357 {
8358 bgp_show_ipv6_bgp_deprecate_warning(vty);
8359 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8360 bgp_show_type_regexp);
8361 }
8362
8363 /* old command */
8364 DEFUN (show_ipv6_mbgp_regexp,
8365 show_ipv6_mbgp_regexp_cmd,
8366 "show ipv6 mbgp regexp .LINE",
8367 SHOW_STR
8368 IP_STR
8369 BGP_STR
8370 "Display routes matching the AS path regular expression\n"
8371 "A regular-expression to match the MBGP AS paths\n")
8372 {
8373 bgp_show_ipv6_bgp_deprecate_warning(vty);
8374 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8375 bgp_show_type_regexp);
8376 }
8377 #endif /* HAVE_IPV6 */
8378
8379 static int
8380 bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
8381 safi_t safi, enum bgp_show_type type)
8382 {
8383 struct prefix_list *plist;
8384
8385 plist = prefix_list_lookup (afi, prefix_list_str);
8386 if (plist == NULL)
8387 {
8388 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8389 prefix_list_str, VTY_NEWLINE);
8390 return CMD_WARNING;
8391 }
8392
8393 return bgp_show (vty, NULL, afi, safi, type, plist, 0);
8394 }
8395
8396 DEFUN (show_ip_bgp_prefix_list,
8397 show_ip_bgp_prefix_list_cmd,
8398 "show ip bgp prefix-list WORD",
8399 SHOW_STR
8400 IP_STR
8401 BGP_STR
8402 "Display routes conforming to the prefix-list\n"
8403 "IP prefix-list name\n")
8404 {
8405 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8406 bgp_show_type_prefix_list);
8407 }
8408
8409 DEFUN (show_ip_bgp_flap_prefix_list,
8410 show_ip_bgp_flap_prefix_list_cmd,
8411 "show ip bgp flap-statistics prefix-list WORD",
8412 SHOW_STR
8413 IP_STR
8414 BGP_STR
8415 "Display flap statistics of routes\n"
8416 "Display routes conforming to the prefix-list\n"
8417 "IP prefix-list name\n")
8418 {
8419 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8420 bgp_show_type_flap_prefix_list);
8421 }
8422
8423 DEFUN (show_ip_bgp_ipv4_prefix_list,
8424 show_ip_bgp_ipv4_prefix_list_cmd,
8425 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8426 SHOW_STR
8427 IP_STR
8428 BGP_STR
8429 "Address family\n"
8430 "Address Family modifier\n"
8431 "Address Family modifier\n"
8432 "Display routes conforming to the prefix-list\n"
8433 "IP prefix-list name\n")
8434 {
8435 if (strncmp (argv[0], "m", 1) == 0)
8436 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8437 bgp_show_type_prefix_list);
8438
8439 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8440 bgp_show_type_prefix_list);
8441 }
8442
8443 #ifdef HAVE_IPV6
8444 DEFUN (show_bgp_prefix_list,
8445 show_bgp_prefix_list_cmd,
8446 "show bgp prefix-list WORD",
8447 SHOW_STR
8448 BGP_STR
8449 "Display routes conforming to the prefix-list\n"
8450 "IPv6 prefix-list name\n")
8451 {
8452 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8453 bgp_show_type_prefix_list);
8454 }
8455
8456 ALIAS (show_bgp_prefix_list,
8457 show_bgp_ipv6_prefix_list_cmd,
8458 "show bgp ipv6 prefix-list WORD",
8459 SHOW_STR
8460 BGP_STR
8461 "Address family\n"
8462 "Display routes conforming to the prefix-list\n"
8463 "IPv6 prefix-list name\n")
8464
8465 /* old command */
8466 DEFUN (show_ipv6_bgp_prefix_list,
8467 show_ipv6_bgp_prefix_list_cmd,
8468 "show ipv6 bgp prefix-list WORD",
8469 SHOW_STR
8470 IPV6_STR
8471 BGP_STR
8472 "Display routes matching the prefix-list\n"
8473 "IPv6 prefix-list name\n")
8474 {
8475 bgp_show_ipv6_bgp_deprecate_warning(vty);
8476 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8477 bgp_show_type_prefix_list);
8478 }
8479
8480 /* old command */
8481 DEFUN (show_ipv6_mbgp_prefix_list,
8482 show_ipv6_mbgp_prefix_list_cmd,
8483 "show ipv6 mbgp prefix-list WORD",
8484 SHOW_STR
8485 IPV6_STR
8486 MBGP_STR
8487 "Display routes matching the prefix-list\n"
8488 "IPv6 prefix-list name\n")
8489 {
8490 bgp_show_ipv6_bgp_deprecate_warning(vty);
8491 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8492 bgp_show_type_prefix_list);
8493 }
8494 #endif /* HAVE_IPV6 */
8495
8496 static int
8497 bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
8498 safi_t safi, enum bgp_show_type type)
8499 {
8500 struct as_list *as_list;
8501
8502 as_list = as_list_lookup (filter);
8503 if (as_list == NULL)
8504 {
8505 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8506 return CMD_WARNING;
8507 }
8508
8509 return bgp_show (vty, NULL, afi, safi, type, as_list, 0);
8510 }
8511
8512 DEFUN (show_ip_bgp_filter_list,
8513 show_ip_bgp_filter_list_cmd,
8514 "show ip bgp filter-list WORD",
8515 SHOW_STR
8516 IP_STR
8517 BGP_STR
8518 "Display routes conforming to the filter-list\n"
8519 "Regular expression access list name\n")
8520 {
8521 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8522 bgp_show_type_filter_list);
8523 }
8524
8525 DEFUN (show_ip_bgp_flap_filter_list,
8526 show_ip_bgp_flap_filter_list_cmd,
8527 "show ip bgp flap-statistics filter-list WORD",
8528 SHOW_STR
8529 IP_STR
8530 BGP_STR
8531 "Display flap statistics of routes\n"
8532 "Display routes conforming to the filter-list\n"
8533 "Regular expression access list name\n")
8534 {
8535 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8536 bgp_show_type_flap_filter_list);
8537 }
8538
8539 DEFUN (show_ip_bgp_ipv4_filter_list,
8540 show_ip_bgp_ipv4_filter_list_cmd,
8541 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8542 SHOW_STR
8543 IP_STR
8544 BGP_STR
8545 "Address family\n"
8546 "Address Family modifier\n"
8547 "Address Family modifier\n"
8548 "Display routes conforming to the filter-list\n"
8549 "Regular expression access list name\n")
8550 {
8551 if (strncmp (argv[0], "m", 1) == 0)
8552 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8553 bgp_show_type_filter_list);
8554
8555 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8556 bgp_show_type_filter_list);
8557 }
8558
8559 #ifdef HAVE_IPV6
8560 DEFUN (show_bgp_filter_list,
8561 show_bgp_filter_list_cmd,
8562 "show bgp filter-list WORD",
8563 SHOW_STR
8564 BGP_STR
8565 "Display routes conforming to the filter-list\n"
8566 "Regular expression access list name\n")
8567 {
8568 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8569 bgp_show_type_filter_list);
8570 }
8571
8572 ALIAS (show_bgp_filter_list,
8573 show_bgp_ipv6_filter_list_cmd,
8574 "show bgp ipv6 filter-list WORD",
8575 SHOW_STR
8576 BGP_STR
8577 "Address family\n"
8578 "Display routes conforming to the filter-list\n"
8579 "Regular expression access list name\n")
8580
8581 /* old command */
8582 DEFUN (show_ipv6_bgp_filter_list,
8583 show_ipv6_bgp_filter_list_cmd,
8584 "show ipv6 bgp filter-list WORD",
8585 SHOW_STR
8586 IPV6_STR
8587 BGP_STR
8588 "Display routes conforming to the filter-list\n"
8589 "Regular expression access list name\n")
8590 {
8591 bgp_show_ipv6_bgp_deprecate_warning(vty);
8592 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8593 bgp_show_type_filter_list);
8594 }
8595
8596 /* old command */
8597 DEFUN (show_ipv6_mbgp_filter_list,
8598 show_ipv6_mbgp_filter_list_cmd,
8599 "show ipv6 mbgp filter-list WORD",
8600 SHOW_STR
8601 IPV6_STR
8602 MBGP_STR
8603 "Display routes conforming to the filter-list\n"
8604 "Regular expression access list name\n")
8605 {
8606 bgp_show_ipv6_bgp_deprecate_warning(vty);
8607 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8608 bgp_show_type_filter_list);
8609 }
8610 #endif /* HAVE_IPV6 */
8611
8612 static int
8613 bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
8614 safi_t safi, enum bgp_show_type type)
8615 {
8616 struct route_map *rmap;
8617
8618 rmap = route_map_lookup_by_name (rmap_str);
8619 if (! rmap)
8620 {
8621 vty_out (vty, "%% %s is not a valid route-map name%s",
8622 rmap_str, VTY_NEWLINE);
8623 return CMD_WARNING;
8624 }
8625
8626 return bgp_show (vty, NULL, afi, safi, type, rmap, 0);
8627 }
8628
8629 DEFUN (show_ip_bgp_route_map,
8630 show_ip_bgp_route_map_cmd,
8631 "show ip bgp route-map WORD",
8632 SHOW_STR
8633 IP_STR
8634 BGP_STR
8635 "Display routes matching the route-map\n"
8636 "A route-map to match on\n")
8637 {
8638 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8639 bgp_show_type_route_map);
8640 }
8641
8642 DEFUN (show_ip_bgp_flap_route_map,
8643 show_ip_bgp_flap_route_map_cmd,
8644 "show ip bgp flap-statistics route-map WORD",
8645 SHOW_STR
8646 IP_STR
8647 BGP_STR
8648 "Display flap statistics of routes\n"
8649 "Display routes matching the route-map\n"
8650 "A route-map to match on\n")
8651 {
8652 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8653 bgp_show_type_flap_route_map);
8654 }
8655
8656 DEFUN (show_ip_bgp_ipv4_route_map,
8657 show_ip_bgp_ipv4_route_map_cmd,
8658 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8659 SHOW_STR
8660 IP_STR
8661 BGP_STR
8662 "Address family\n"
8663 "Address Family modifier\n"
8664 "Address Family modifier\n"
8665 "Display routes matching the route-map\n"
8666 "A route-map to match on\n")
8667 {
8668 if (strncmp (argv[0], "m", 1) == 0)
8669 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8670 bgp_show_type_route_map);
8671
8672 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8673 bgp_show_type_route_map);
8674 }
8675
8676 DEFUN (show_bgp_route_map,
8677 show_bgp_route_map_cmd,
8678 "show bgp route-map WORD",
8679 SHOW_STR
8680 BGP_STR
8681 "Display routes matching the route-map\n"
8682 "A route-map to match on\n")
8683 {
8684 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8685 bgp_show_type_route_map);
8686 }
8687
8688 ALIAS (show_bgp_route_map,
8689 show_bgp_ipv6_route_map_cmd,
8690 "show bgp ipv6 route-map WORD",
8691 SHOW_STR
8692 BGP_STR
8693 "Address family\n"
8694 "Display routes matching the route-map\n"
8695 "A route-map to match on\n")
8696
8697 DEFUN (show_ip_bgp_cidr_only,
8698 show_ip_bgp_cidr_only_cmd,
8699 "show ip bgp cidr-only",
8700 SHOW_STR
8701 IP_STR
8702 BGP_STR
8703 "Display only routes with non-natural netmasks\n")
8704 {
8705 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8706 bgp_show_type_cidr_only, NULL, 0);
8707 }
8708
8709 DEFUN (show_ip_bgp_flap_cidr_only,
8710 show_ip_bgp_flap_cidr_only_cmd,
8711 "show ip bgp flap-statistics cidr-only",
8712 SHOW_STR
8713 IP_STR
8714 BGP_STR
8715 "Display flap statistics of routes\n"
8716 "Display only routes with non-natural netmasks\n")
8717 {
8718 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8719 bgp_show_type_flap_cidr_only, NULL, 0);
8720 }
8721
8722 DEFUN (show_ip_bgp_ipv4_cidr_only,
8723 show_ip_bgp_ipv4_cidr_only_cmd,
8724 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8725 SHOW_STR
8726 IP_STR
8727 BGP_STR
8728 "Address family\n"
8729 "Address Family modifier\n"
8730 "Address Family modifier\n"
8731 "Display only routes with non-natural netmasks\n")
8732 {
8733 if (strncmp (argv[0], "m", 1) == 0)
8734 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8735 bgp_show_type_cidr_only, NULL, 0);
8736
8737 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8738 bgp_show_type_cidr_only, NULL, 0);
8739 }
8740
8741 DEFUN (show_ip_bgp_community_all,
8742 show_ip_bgp_community_all_cmd,
8743 "show ip bgp community",
8744 SHOW_STR
8745 IP_STR
8746 BGP_STR
8747 "Display routes matching the communities\n")
8748 {
8749 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8750 bgp_show_type_community_all, NULL, 0);
8751 }
8752
8753 DEFUN (show_ip_bgp_ipv4_community_all,
8754 show_ip_bgp_ipv4_community_all_cmd,
8755 "show ip bgp ipv4 (unicast|multicast) community",
8756 SHOW_STR
8757 IP_STR
8758 BGP_STR
8759 "Address family\n"
8760 "Address Family modifier\n"
8761 "Address Family modifier\n"
8762 "Display routes matching the communities\n")
8763 {
8764 if (strncmp (argv[0], "m", 1) == 0)
8765 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8766 bgp_show_type_community_all, NULL, 0);
8767
8768 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8769 bgp_show_type_community_all, NULL, 0);
8770 }
8771
8772 #ifdef HAVE_IPV6
8773 DEFUN (show_bgp_community_all,
8774 show_bgp_community_all_cmd,
8775 "show bgp community",
8776 SHOW_STR
8777 BGP_STR
8778 "Display routes matching the communities\n")
8779 {
8780 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8781 bgp_show_type_community_all, NULL, 0);
8782 }
8783
8784 ALIAS (show_bgp_community_all,
8785 show_bgp_ipv6_community_all_cmd,
8786 "show bgp ipv6 community",
8787 SHOW_STR
8788 BGP_STR
8789 "Address family\n"
8790 "Display routes matching the communities\n")
8791
8792 /* old command */
8793 DEFUN (show_ipv6_bgp_community_all,
8794 show_ipv6_bgp_community_all_cmd,
8795 "show ipv6 bgp community",
8796 SHOW_STR
8797 IPV6_STR
8798 BGP_STR
8799 "Display routes matching the communities\n")
8800 {
8801 bgp_show_ipv6_bgp_deprecate_warning(vty);
8802 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8803 bgp_show_type_community_all, NULL, 0);
8804 }
8805
8806 /* old command */
8807 DEFUN (show_ipv6_mbgp_community_all,
8808 show_ipv6_mbgp_community_all_cmd,
8809 "show ipv6 mbgp community",
8810 SHOW_STR
8811 IPV6_STR
8812 MBGP_STR
8813 "Display routes matching the communities\n")
8814 {
8815 bgp_show_ipv6_bgp_deprecate_warning(vty);
8816 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
8817 bgp_show_type_community_all, NULL, 0);
8818 }
8819 #endif /* HAVE_IPV6 */
8820
8821 static int
8822 bgp_show_community (struct vty *vty, const char *view_name, int argc,
8823 const char **argv, int exact, afi_t afi, safi_t safi)
8824 {
8825 struct community *com;
8826 struct buffer *b;
8827 struct bgp *bgp;
8828 int i;
8829 char *str;
8830 int first = 0;
8831
8832 /* BGP structure lookup */
8833 if (view_name)
8834 {
8835 bgp = bgp_lookup_by_name (view_name);
8836 if (bgp == NULL)
8837 {
8838 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8839 return CMD_WARNING;
8840 }
8841 }
8842 else
8843 {
8844 bgp = bgp_get_default ();
8845 if (bgp == NULL)
8846 {
8847 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8848 return CMD_WARNING;
8849 }
8850 }
8851
8852 b = buffer_new (1024);
8853 for (i = 0; i < argc; i++)
8854 {
8855 if (first)
8856 buffer_putc (b, ' ');
8857 else
8858 {
8859 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8860 continue;
8861 first = 1;
8862 }
8863
8864 buffer_putstr (b, argv[i]);
8865 }
8866 buffer_putc (b, '\0');
8867
8868 str = buffer_getstr (b);
8869 buffer_free (b);
8870
8871 com = community_str2com (str);
8872 XFREE (MTYPE_TMP, str);
8873 if (! com)
8874 {
8875 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
8876 return CMD_WARNING;
8877 }
8878
8879 return bgp_show (vty, bgp, afi, safi,
8880 (exact ? bgp_show_type_community_exact :
8881 bgp_show_type_community), com, 0);
8882 }
8883
8884 DEFUN (show_ip_bgp_community,
8885 show_ip_bgp_community_cmd,
8886 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
8887 SHOW_STR
8888 IP_STR
8889 BGP_STR
8890 "Display routes matching the communities\n"
8891 "community number\n"
8892 "Do not send outside local AS (well-known community)\n"
8893 "Do not advertise to any peer (well-known community)\n"
8894 "Do not export to next AS (well-known community)\n")
8895 {
8896 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
8897 }
8898
8899 ALIAS (show_ip_bgp_community,
8900 show_ip_bgp_community2_cmd,
8901 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8902 SHOW_STR
8903 IP_STR
8904 BGP_STR
8905 "Display routes matching the communities\n"
8906 "community number\n"
8907 "Do not send outside local AS (well-known community)\n"
8908 "Do not advertise to any peer (well-known community)\n"
8909 "Do not export to next AS (well-known community)\n"
8910 "community number\n"
8911 "Do not send outside local AS (well-known community)\n"
8912 "Do not advertise to any peer (well-known community)\n"
8913 "Do not export to next AS (well-known community)\n")
8914
8915 ALIAS (show_ip_bgp_community,
8916 show_ip_bgp_community3_cmd,
8917 "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)",
8918 SHOW_STR
8919 IP_STR
8920 BGP_STR
8921 "Display routes matching the communities\n"
8922 "community number\n"
8923 "Do not send outside local AS (well-known community)\n"
8924 "Do not advertise to any peer (well-known community)\n"
8925 "Do not export to next AS (well-known community)\n"
8926 "community number\n"
8927 "Do not send outside local AS (well-known community)\n"
8928 "Do not advertise to any peer (well-known community)\n"
8929 "Do not export to next AS (well-known community)\n"
8930 "community number\n"
8931 "Do not send outside local AS (well-known community)\n"
8932 "Do not advertise to any peer (well-known community)\n"
8933 "Do not export to next AS (well-known community)\n")
8934
8935 ALIAS (show_ip_bgp_community,
8936 show_ip_bgp_community4_cmd,
8937 "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)",
8938 SHOW_STR
8939 IP_STR
8940 BGP_STR
8941 "Display routes matching the communities\n"
8942 "community number\n"
8943 "Do not send outside local AS (well-known community)\n"
8944 "Do not advertise to any peer (well-known community)\n"
8945 "Do not export to next AS (well-known community)\n"
8946 "community number\n"
8947 "Do not send outside local AS (well-known community)\n"
8948 "Do not advertise to any peer (well-known community)\n"
8949 "Do not export to next AS (well-known community)\n"
8950 "community number\n"
8951 "Do not send outside local AS (well-known community)\n"
8952 "Do not advertise to any peer (well-known community)\n"
8953 "Do not export to next AS (well-known community)\n"
8954 "community number\n"
8955 "Do not send outside local AS (well-known community)\n"
8956 "Do not advertise to any peer (well-known community)\n"
8957 "Do not export to next AS (well-known community)\n")
8958
8959 DEFUN (show_ip_bgp_ipv4_community,
8960 show_ip_bgp_ipv4_community_cmd,
8961 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8962 SHOW_STR
8963 IP_STR
8964 BGP_STR
8965 "Address family\n"
8966 "Address Family modifier\n"
8967 "Address Family modifier\n"
8968 "Display routes matching the communities\n"
8969 "community number\n"
8970 "Do not send outside local AS (well-known community)\n"
8971 "Do not advertise to any peer (well-known community)\n"
8972 "Do not export to next AS (well-known community)\n")
8973 {
8974 if (strncmp (argv[0], "m", 1) == 0)
8975 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
8976
8977 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
8978 }
8979
8980 ALIAS (show_ip_bgp_ipv4_community,
8981 show_ip_bgp_ipv4_community2_cmd,
8982 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8983 SHOW_STR
8984 IP_STR
8985 BGP_STR
8986 "Address family\n"
8987 "Address Family modifier\n"
8988 "Address Family modifier\n"
8989 "Display routes matching the communities\n"
8990 "community number\n"
8991 "Do not send outside local AS (well-known community)\n"
8992 "Do not advertise to any peer (well-known community)\n"
8993 "Do not export to next AS (well-known community)\n"
8994 "community number\n"
8995 "Do not send outside local AS (well-known community)\n"
8996 "Do not advertise to any peer (well-known community)\n"
8997 "Do not export to next AS (well-known community)\n")
8998
8999 ALIAS (show_ip_bgp_ipv4_community,
9000 show_ip_bgp_ipv4_community3_cmd,
9001 "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)",
9002 SHOW_STR
9003 IP_STR
9004 BGP_STR
9005 "Address family\n"
9006 "Address Family modifier\n"
9007 "Address Family modifier\n"
9008 "Display routes matching the communities\n"
9009 "community number\n"
9010 "Do not send outside local AS (well-known community)\n"
9011 "Do not advertise to any peer (well-known community)\n"
9012 "Do not export to next AS (well-known community)\n"
9013 "community number\n"
9014 "Do not send outside local AS (well-known community)\n"
9015 "Do not advertise to any peer (well-known community)\n"
9016 "Do not export to next AS (well-known community)\n"
9017 "community number\n"
9018 "Do not send outside local AS (well-known community)\n"
9019 "Do not advertise to any peer (well-known community)\n"
9020 "Do not export to next AS (well-known community)\n")
9021
9022 ALIAS (show_ip_bgp_ipv4_community,
9023 show_ip_bgp_ipv4_community4_cmd,
9024 "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)",
9025 SHOW_STR
9026 IP_STR
9027 BGP_STR
9028 "Address family\n"
9029 "Address Family modifier\n"
9030 "Address Family modifier\n"
9031 "Display routes matching the communities\n"
9032 "community number\n"
9033 "Do not send outside local AS (well-known community)\n"
9034 "Do not advertise to any peer (well-known community)\n"
9035 "Do not export to next AS (well-known community)\n"
9036 "community number\n"
9037 "Do not send outside local AS (well-known community)\n"
9038 "Do not advertise to any peer (well-known community)\n"
9039 "Do not export to next AS (well-known community)\n"
9040 "community number\n"
9041 "Do not send outside local AS (well-known community)\n"
9042 "Do not advertise to any peer (well-known community)\n"
9043 "Do not export to next AS (well-known community)\n"
9044 "community number\n"
9045 "Do not send outside local AS (well-known community)\n"
9046 "Do not advertise to any peer (well-known community)\n"
9047 "Do not export to next AS (well-known community)\n")
9048
9049 DEFUN (show_bgp_view_afi_safi_community_all,
9050 show_bgp_view_afi_safi_community_all_cmd,
9051 #ifdef HAVE_IPV6
9052 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
9053 #else
9054 "show bgp view WORD ipv4 (unicast|multicast) community",
9055 #endif
9056 SHOW_STR
9057 BGP_STR
9058 "BGP view\n"
9059 "View name\n"
9060 "Address family\n"
9061 #ifdef HAVE_IPV6
9062 "Address family\n"
9063 #endif
9064 "Address Family modifier\n"
9065 "Address Family modifier\n"
9066 "Display routes matching the communities\n")
9067 {
9068 int afi;
9069 int safi;
9070 struct bgp *bgp;
9071
9072 /* BGP structure lookup. */
9073 bgp = bgp_lookup_by_name (argv[0]);
9074 if (bgp == NULL)
9075 {
9076 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9077 return CMD_WARNING;
9078 }
9079
9080 #ifdef HAVE_IPV6
9081 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9082 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9083 #else
9084 afi = AFI_IP;
9085 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9086 #endif
9087 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
9088 }
9089
9090 DEFUN (show_bgp_view_afi_safi_community,
9091 show_bgp_view_afi_safi_community_cmd,
9092 #ifdef HAVE_IPV6
9093 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9094 #else
9095 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9096 #endif
9097 SHOW_STR
9098 BGP_STR
9099 "BGP view\n"
9100 "View name\n"
9101 "Address family\n"
9102 #ifdef HAVE_IPV6
9103 "Address family\n"
9104 #endif
9105 "Address family modifier\n"
9106 "Address family modifier\n"
9107 "Display routes matching the communities\n"
9108 "community number\n"
9109 "Do not send outside local AS (well-known community)\n"
9110 "Do not advertise to any peer (well-known community)\n"
9111 "Do not export to next AS (well-known community)\n")
9112 {
9113 int afi;
9114 int safi;
9115
9116 #ifdef HAVE_IPV6
9117 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9118 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9119 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
9120 #else
9121 afi = AFI_IP;
9122 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9123 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
9124 #endif
9125 }
9126
9127 ALIAS (show_bgp_view_afi_safi_community,
9128 show_bgp_view_afi_safi_community2_cmd,
9129 #ifdef HAVE_IPV6
9130 "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)",
9131 #else
9132 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9133 #endif
9134 SHOW_STR
9135 BGP_STR
9136 "BGP view\n"
9137 "View name\n"
9138 "Address family\n"
9139 #ifdef HAVE_IPV6
9140 "Address family\n"
9141 #endif
9142 "Address family modifier\n"
9143 "Address family modifier\n"
9144 "Display routes matching the communities\n"
9145 "community number\n"
9146 "Do not send outside local AS (well-known community)\n"
9147 "Do not advertise to any peer (well-known community)\n"
9148 "Do not export to next AS (well-known community)\n"
9149 "community number\n"
9150 "Do not send outside local AS (well-known community)\n"
9151 "Do not advertise to any peer (well-known community)\n"
9152 "Do not export to next AS (well-known community)\n")
9153
9154 ALIAS (show_bgp_view_afi_safi_community,
9155 show_bgp_view_afi_safi_community3_cmd,
9156 #ifdef HAVE_IPV6
9157 "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)",
9158 #else
9159 "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)",
9160 #endif
9161 SHOW_STR
9162 BGP_STR
9163 "BGP view\n"
9164 "View name\n"
9165 "Address family\n"
9166 #ifdef HAVE_IPV6
9167 "Address family\n"
9168 #endif
9169 "Address family modifier\n"
9170 "Address family modifier\n"
9171 "Display routes matching the communities\n"
9172 "community number\n"
9173 "Do not send outside local AS (well-known community)\n"
9174 "Do not advertise to any peer (well-known community)\n"
9175 "Do not export to next AS (well-known community)\n"
9176 "community number\n"
9177 "Do not send outside local AS (well-known community)\n"
9178 "Do not advertise to any peer (well-known community)\n"
9179 "Do not export to next AS (well-known community)\n"
9180 "community number\n"
9181 "Do not send outside local AS (well-known community)\n"
9182 "Do not advertise to any peer (well-known community)\n"
9183 "Do not export to next AS (well-known community)\n")
9184
9185 ALIAS (show_bgp_view_afi_safi_community,
9186 show_bgp_view_afi_safi_community4_cmd,
9187 #ifdef HAVE_IPV6
9188 "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)",
9189 #else
9190 "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)",
9191 #endif
9192 SHOW_STR
9193 BGP_STR
9194 "BGP view\n"
9195 "View name\n"
9196 "Address family\n"
9197 #ifdef HAVE_IPV6
9198 "Address family\n"
9199 #endif
9200 "Address family modifier\n"
9201 "Address family modifier\n"
9202 "Display routes matching the communities\n"
9203 "community number\n"
9204 "Do not send outside local AS (well-known community)\n"
9205 "Do not advertise to any peer (well-known community)\n"
9206 "Do not export to next AS (well-known community)\n"
9207 "community number\n"
9208 "Do not send outside local AS (well-known community)\n"
9209 "Do not advertise to any peer (well-known community)\n"
9210 "Do not export to next AS (well-known community)\n"
9211 "community number\n"
9212 "Do not send outside local AS (well-known community)\n"
9213 "Do not advertise to any peer (well-known community)\n"
9214 "Do not export to next AS (well-known community)\n"
9215 "community number\n"
9216 "Do not send outside local AS (well-known community)\n"
9217 "Do not advertise to any peer (well-known community)\n"
9218 "Do not export to next AS (well-known community)\n")
9219
9220 DEFUN (show_ip_bgp_community_exact,
9221 show_ip_bgp_community_exact_cmd,
9222 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9223 SHOW_STR
9224 IP_STR
9225 BGP_STR
9226 "Display routes matching the communities\n"
9227 "community number\n"
9228 "Do not send outside local AS (well-known community)\n"
9229 "Do not advertise to any peer (well-known community)\n"
9230 "Do not export to next AS (well-known community)\n"
9231 "Exact match of the communities")
9232 {
9233 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9234 }
9235
9236 ALIAS (show_ip_bgp_community_exact,
9237 show_ip_bgp_community2_exact_cmd,
9238 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9239 SHOW_STR
9240 IP_STR
9241 BGP_STR
9242 "Display routes matching the communities\n"
9243 "community number\n"
9244 "Do not send outside local AS (well-known community)\n"
9245 "Do not advertise to any peer (well-known community)\n"
9246 "Do not export to next AS (well-known community)\n"
9247 "community number\n"
9248 "Do not send outside local AS (well-known community)\n"
9249 "Do not advertise to any peer (well-known community)\n"
9250 "Do not export to next AS (well-known community)\n"
9251 "Exact match of the communities")
9252
9253 ALIAS (show_ip_bgp_community_exact,
9254 show_ip_bgp_community3_exact_cmd,
9255 "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",
9256 SHOW_STR
9257 IP_STR
9258 BGP_STR
9259 "Display routes matching the communities\n"
9260 "community number\n"
9261 "Do not send outside local AS (well-known community)\n"
9262 "Do not advertise to any peer (well-known community)\n"
9263 "Do not export to next AS (well-known community)\n"
9264 "community number\n"
9265 "Do not send outside local AS (well-known community)\n"
9266 "Do not advertise to any peer (well-known community)\n"
9267 "Do not export to next AS (well-known community)\n"
9268 "community number\n"
9269 "Do not send outside local AS (well-known community)\n"
9270 "Do not advertise to any peer (well-known community)\n"
9271 "Do not export to next AS (well-known community)\n"
9272 "Exact match of the communities")
9273
9274 ALIAS (show_ip_bgp_community_exact,
9275 show_ip_bgp_community4_exact_cmd,
9276 "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",
9277 SHOW_STR
9278 IP_STR
9279 BGP_STR
9280 "Display routes matching the communities\n"
9281 "community number\n"
9282 "Do not send outside local AS (well-known community)\n"
9283 "Do not advertise to any peer (well-known community)\n"
9284 "Do not export to next AS (well-known community)\n"
9285 "community number\n"
9286 "Do not send outside local AS (well-known community)\n"
9287 "Do not advertise to any peer (well-known community)\n"
9288 "Do not export to next AS (well-known community)\n"
9289 "community number\n"
9290 "Do not send outside local AS (well-known community)\n"
9291 "Do not advertise to any peer (well-known community)\n"
9292 "Do not export to next AS (well-known community)\n"
9293 "community number\n"
9294 "Do not send outside local AS (well-known community)\n"
9295 "Do not advertise to any peer (well-known community)\n"
9296 "Do not export to next AS (well-known community)\n"
9297 "Exact match of the communities")
9298
9299 DEFUN (show_ip_bgp_ipv4_community_exact,
9300 show_ip_bgp_ipv4_community_exact_cmd,
9301 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9302 SHOW_STR
9303 IP_STR
9304 BGP_STR
9305 "Address family\n"
9306 "Address Family modifier\n"
9307 "Address Family modifier\n"
9308 "Display routes matching the communities\n"
9309 "community number\n"
9310 "Do not send outside local AS (well-known community)\n"
9311 "Do not advertise to any peer (well-known community)\n"
9312 "Do not export to next AS (well-known community)\n"
9313 "Exact match of the communities")
9314 {
9315 if (strncmp (argv[0], "m", 1) == 0)
9316 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9317
9318 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9319 }
9320
9321 ALIAS (show_ip_bgp_ipv4_community_exact,
9322 show_ip_bgp_ipv4_community2_exact_cmd,
9323 "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",
9324 SHOW_STR
9325 IP_STR
9326 BGP_STR
9327 "Address family\n"
9328 "Address Family modifier\n"
9329 "Address Family modifier\n"
9330 "Display routes matching the communities\n"
9331 "community number\n"
9332 "Do not send outside local AS (well-known community)\n"
9333 "Do not advertise to any peer (well-known community)\n"
9334 "Do not export to next AS (well-known community)\n"
9335 "community number\n"
9336 "Do not send outside local AS (well-known community)\n"
9337 "Do not advertise to any peer (well-known community)\n"
9338 "Do not export to next AS (well-known community)\n"
9339 "Exact match of the communities")
9340
9341 ALIAS (show_ip_bgp_ipv4_community_exact,
9342 show_ip_bgp_ipv4_community3_exact_cmd,
9343 "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",
9344 SHOW_STR
9345 IP_STR
9346 BGP_STR
9347 "Address family\n"
9348 "Address Family modifier\n"
9349 "Address Family modifier\n"
9350 "Display routes matching the communities\n"
9351 "community number\n"
9352 "Do not send outside local AS (well-known community)\n"
9353 "Do not advertise to any peer (well-known community)\n"
9354 "Do not export to next AS (well-known community)\n"
9355 "community number\n"
9356 "Do not send outside local AS (well-known community)\n"
9357 "Do not advertise to any peer (well-known community)\n"
9358 "Do not export to next AS (well-known community)\n"
9359 "community number\n"
9360 "Do not send outside local AS (well-known community)\n"
9361 "Do not advertise to any peer (well-known community)\n"
9362 "Do not export to next AS (well-known community)\n"
9363 "Exact match of the communities")
9364
9365 ALIAS (show_ip_bgp_ipv4_community_exact,
9366 show_ip_bgp_ipv4_community4_exact_cmd,
9367 "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",
9368 SHOW_STR
9369 IP_STR
9370 BGP_STR
9371 "Address family\n"
9372 "Address Family modifier\n"
9373 "Address Family modifier\n"
9374 "Display routes matching the communities\n"
9375 "community number\n"
9376 "Do not send outside local AS (well-known community)\n"
9377 "Do not advertise to any peer (well-known community)\n"
9378 "Do not export to next AS (well-known community)\n"
9379 "community number\n"
9380 "Do not send outside local AS (well-known community)\n"
9381 "Do not advertise to any peer (well-known community)\n"
9382 "Do not export to next AS (well-known community)\n"
9383 "community number\n"
9384 "Do not send outside local AS (well-known community)\n"
9385 "Do not advertise to any peer (well-known community)\n"
9386 "Do not export to next AS (well-known community)\n"
9387 "community number\n"
9388 "Do not send outside local AS (well-known community)\n"
9389 "Do not advertise to any peer (well-known community)\n"
9390 "Do not export to next AS (well-known community)\n"
9391 "Exact match of the communities")
9392
9393 #ifdef HAVE_IPV6
9394 DEFUN (show_bgp_community,
9395 show_bgp_community_cmd,
9396 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9397 SHOW_STR
9398 BGP_STR
9399 "Display routes matching the communities\n"
9400 "community number\n"
9401 "Do not send outside local AS (well-known community)\n"
9402 "Do not advertise to any peer (well-known community)\n"
9403 "Do not export to next AS (well-known community)\n")
9404 {
9405 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9406 }
9407
9408 ALIAS (show_bgp_community,
9409 show_bgp_ipv6_community_cmd,
9410 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9411 SHOW_STR
9412 BGP_STR
9413 "Address family\n"
9414 "Display routes matching the communities\n"
9415 "community number\n"
9416 "Do not send outside local AS (well-known community)\n"
9417 "Do not advertise to any peer (well-known community)\n"
9418 "Do not export to next AS (well-known community)\n")
9419
9420 ALIAS (show_bgp_community,
9421 show_bgp_community2_cmd,
9422 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9423 SHOW_STR
9424 BGP_STR
9425 "Display routes matching the communities\n"
9426 "community number\n"
9427 "Do not send outside local AS (well-known community)\n"
9428 "Do not advertise to any peer (well-known community)\n"
9429 "Do not export to next AS (well-known community)\n"
9430 "community number\n"
9431 "Do not send outside local AS (well-known community)\n"
9432 "Do not advertise to any peer (well-known community)\n"
9433 "Do not export to next AS (well-known community)\n")
9434
9435 ALIAS (show_bgp_community,
9436 show_bgp_ipv6_community2_cmd,
9437 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9438 SHOW_STR
9439 BGP_STR
9440 "Address family\n"
9441 "Display routes matching the communities\n"
9442 "community number\n"
9443 "Do not send outside local AS (well-known community)\n"
9444 "Do not advertise to any peer (well-known community)\n"
9445 "Do not export to next AS (well-known community)\n"
9446 "community number\n"
9447 "Do not send outside local AS (well-known community)\n"
9448 "Do not advertise to any peer (well-known community)\n"
9449 "Do not export to next AS (well-known community)\n")
9450
9451 ALIAS (show_bgp_community,
9452 show_bgp_community3_cmd,
9453 "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)",
9454 SHOW_STR
9455 BGP_STR
9456 "Display routes matching the communities\n"
9457 "community number\n"
9458 "Do not send outside local AS (well-known community)\n"
9459 "Do not advertise to any peer (well-known community)\n"
9460 "Do not export to next AS (well-known community)\n"
9461 "community number\n"
9462 "Do not send outside local AS (well-known community)\n"
9463 "Do not advertise to any peer (well-known community)\n"
9464 "Do not export to next AS (well-known community)\n"
9465 "community number\n"
9466 "Do not send outside local AS (well-known community)\n"
9467 "Do not advertise to any peer (well-known community)\n"
9468 "Do not export to next AS (well-known community)\n")
9469
9470 ALIAS (show_bgp_community,
9471 show_bgp_ipv6_community3_cmd,
9472 "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)",
9473 SHOW_STR
9474 BGP_STR
9475 "Address family\n"
9476 "Display routes matching the communities\n"
9477 "community number\n"
9478 "Do not send outside local AS (well-known community)\n"
9479 "Do not advertise to any peer (well-known community)\n"
9480 "Do not export to next AS (well-known community)\n"
9481 "community number\n"
9482 "Do not send outside local AS (well-known community)\n"
9483 "Do not advertise to any peer (well-known community)\n"
9484 "Do not export to next AS (well-known community)\n"
9485 "community number\n"
9486 "Do not send outside local AS (well-known community)\n"
9487 "Do not advertise to any peer (well-known community)\n"
9488 "Do not export to next AS (well-known community)\n")
9489
9490 ALIAS (show_bgp_community,
9491 show_bgp_community4_cmd,
9492 "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)",
9493 SHOW_STR
9494 BGP_STR
9495 "Display routes matching the communities\n"
9496 "community number\n"
9497 "Do not send outside local AS (well-known community)\n"
9498 "Do not advertise to any peer (well-known community)\n"
9499 "Do not export to next AS (well-known community)\n"
9500 "community number\n"
9501 "Do not send outside local AS (well-known community)\n"
9502 "Do not advertise to any peer (well-known community)\n"
9503 "Do not export to next AS (well-known community)\n"
9504 "community number\n"
9505 "Do not send outside local AS (well-known community)\n"
9506 "Do not advertise to any peer (well-known community)\n"
9507 "Do not export to next AS (well-known community)\n"
9508 "community number\n"
9509 "Do not send outside local AS (well-known community)\n"
9510 "Do not advertise to any peer (well-known community)\n"
9511 "Do not export to next AS (well-known community)\n")
9512
9513 ALIAS (show_bgp_community,
9514 show_bgp_ipv6_community4_cmd,
9515 "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)",
9516 SHOW_STR
9517 BGP_STR
9518 "Address family\n"
9519 "Display routes matching the communities\n"
9520 "community number\n"
9521 "Do not send outside local AS (well-known community)\n"
9522 "Do not advertise to any peer (well-known community)\n"
9523 "Do not export to next AS (well-known community)\n"
9524 "community number\n"
9525 "Do not send outside local AS (well-known community)\n"
9526 "Do not advertise to any peer (well-known community)\n"
9527 "Do not export to next AS (well-known community)\n"
9528 "community number\n"
9529 "Do not send outside local AS (well-known community)\n"
9530 "Do not advertise to any peer (well-known community)\n"
9531 "Do not export to next AS (well-known community)\n"
9532 "community number\n"
9533 "Do not send outside local AS (well-known community)\n"
9534 "Do not advertise to any peer (well-known community)\n"
9535 "Do not export to next AS (well-known community)\n")
9536
9537 /* old command */
9538 DEFUN (show_ipv6_bgp_community,
9539 show_ipv6_bgp_community_cmd,
9540 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9541 SHOW_STR
9542 IPV6_STR
9543 BGP_STR
9544 "Display routes matching the communities\n"
9545 "community number\n"
9546 "Do not send outside local AS (well-known community)\n"
9547 "Do not advertise to any peer (well-known community)\n"
9548 "Do not export to next AS (well-known community)\n")
9549 {
9550 bgp_show_ipv6_bgp_deprecate_warning(vty);
9551 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9552 }
9553
9554 /* old command */
9555 ALIAS (show_ipv6_bgp_community,
9556 show_ipv6_bgp_community2_cmd,
9557 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9558 SHOW_STR
9559 IPV6_STR
9560 BGP_STR
9561 "Display routes matching the communities\n"
9562 "community number\n"
9563 "Do not send outside local AS (well-known community)\n"
9564 "Do not advertise to any peer (well-known community)\n"
9565 "Do not export to next AS (well-known community)\n"
9566 "community number\n"
9567 "Do not send outside local AS (well-known community)\n"
9568 "Do not advertise to any peer (well-known community)\n"
9569 "Do not export to next AS (well-known community)\n")
9570
9571 /* old command */
9572 ALIAS (show_ipv6_bgp_community,
9573 show_ipv6_bgp_community3_cmd,
9574 "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)",
9575 SHOW_STR
9576 IPV6_STR
9577 BGP_STR
9578 "Display routes matching the communities\n"
9579 "community number\n"
9580 "Do not send outside local AS (well-known community)\n"
9581 "Do not advertise to any peer (well-known community)\n"
9582 "Do not export to next AS (well-known community)\n"
9583 "community number\n"
9584 "Do not send outside local AS (well-known community)\n"
9585 "Do not advertise to any peer (well-known community)\n"
9586 "Do not export to next AS (well-known community)\n"
9587 "community number\n"
9588 "Do not send outside local AS (well-known community)\n"
9589 "Do not advertise to any peer (well-known community)\n"
9590 "Do not export to next AS (well-known community)\n")
9591
9592 /* old command */
9593 ALIAS (show_ipv6_bgp_community,
9594 show_ipv6_bgp_community4_cmd,
9595 "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)",
9596 SHOW_STR
9597 IPV6_STR
9598 BGP_STR
9599 "Display routes matching the communities\n"
9600 "community number\n"
9601 "Do not send outside local AS (well-known community)\n"
9602 "Do not advertise to any peer (well-known community)\n"
9603 "Do not export to next AS (well-known community)\n"
9604 "community number\n"
9605 "Do not send outside local AS (well-known community)\n"
9606 "Do not advertise to any peer (well-known community)\n"
9607 "Do not export to next AS (well-known community)\n"
9608 "community number\n"
9609 "Do not send outside local AS (well-known community)\n"
9610 "Do not advertise to any peer (well-known community)\n"
9611 "Do not export to next AS (well-known community)\n"
9612 "community number\n"
9613 "Do not send outside local AS (well-known community)\n"
9614 "Do not advertise to any peer (well-known community)\n"
9615 "Do not export to next AS (well-known community)\n")
9616
9617 DEFUN (show_bgp_community_exact,
9618 show_bgp_community_exact_cmd,
9619 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9620 SHOW_STR
9621 BGP_STR
9622 "Display routes matching the communities\n"
9623 "community number\n"
9624 "Do not send outside local AS (well-known community)\n"
9625 "Do not advertise to any peer (well-known community)\n"
9626 "Do not export to next AS (well-known community)\n"
9627 "Exact match of the communities")
9628 {
9629 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9630 }
9631
9632 ALIAS (show_bgp_community_exact,
9633 show_bgp_ipv6_community_exact_cmd,
9634 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9635 SHOW_STR
9636 BGP_STR
9637 "Address family\n"
9638 "Display routes matching the communities\n"
9639 "community number\n"
9640 "Do not send outside local AS (well-known community)\n"
9641 "Do not advertise to any peer (well-known community)\n"
9642 "Do not export to next AS (well-known community)\n"
9643 "Exact match of the communities")
9644
9645 ALIAS (show_bgp_community_exact,
9646 show_bgp_community2_exact_cmd,
9647 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9648 SHOW_STR
9649 BGP_STR
9650 "Display routes matching the communities\n"
9651 "community number\n"
9652 "Do not send outside local AS (well-known community)\n"
9653 "Do not advertise to any peer (well-known community)\n"
9654 "Do not export to next AS (well-known community)\n"
9655 "community number\n"
9656 "Do not send outside local AS (well-known community)\n"
9657 "Do not advertise to any peer (well-known community)\n"
9658 "Do not export to next AS (well-known community)\n"
9659 "Exact match of the communities")
9660
9661 ALIAS (show_bgp_community_exact,
9662 show_bgp_ipv6_community2_exact_cmd,
9663 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9664 SHOW_STR
9665 BGP_STR
9666 "Address family\n"
9667 "Display routes matching the communities\n"
9668 "community number\n"
9669 "Do not send outside local AS (well-known community)\n"
9670 "Do not advertise to any peer (well-known community)\n"
9671 "Do not export to next AS (well-known community)\n"
9672 "community number\n"
9673 "Do not send outside local AS (well-known community)\n"
9674 "Do not advertise to any peer (well-known community)\n"
9675 "Do not export to next AS (well-known community)\n"
9676 "Exact match of the communities")
9677
9678 ALIAS (show_bgp_community_exact,
9679 show_bgp_community3_exact_cmd,
9680 "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",
9681 SHOW_STR
9682 BGP_STR
9683 "Display routes matching the communities\n"
9684 "community number\n"
9685 "Do not send outside local AS (well-known community)\n"
9686 "Do not advertise to any peer (well-known community)\n"
9687 "Do not export to next AS (well-known community)\n"
9688 "community number\n"
9689 "Do not send outside local AS (well-known community)\n"
9690 "Do not advertise to any peer (well-known community)\n"
9691 "Do not export to next AS (well-known community)\n"
9692 "community number\n"
9693 "Do not send outside local AS (well-known community)\n"
9694 "Do not advertise to any peer (well-known community)\n"
9695 "Do not export to next AS (well-known community)\n"
9696 "Exact match of the communities")
9697
9698 ALIAS (show_bgp_community_exact,
9699 show_bgp_ipv6_community3_exact_cmd,
9700 "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",
9701 SHOW_STR
9702 BGP_STR
9703 "Address family\n"
9704 "Display routes matching the communities\n"
9705 "community number\n"
9706 "Do not send outside local AS (well-known community)\n"
9707 "Do not advertise to any peer (well-known community)\n"
9708 "Do not export to next AS (well-known community)\n"
9709 "community number\n"
9710 "Do not send outside local AS (well-known community)\n"
9711 "Do not advertise to any peer (well-known community)\n"
9712 "Do not export to next AS (well-known community)\n"
9713 "community number\n"
9714 "Do not send outside local AS (well-known community)\n"
9715 "Do not advertise to any peer (well-known community)\n"
9716 "Do not export to next AS (well-known community)\n"
9717 "Exact match of the communities")
9718
9719 ALIAS (show_bgp_community_exact,
9720 show_bgp_community4_exact_cmd,
9721 "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",
9722 SHOW_STR
9723 BGP_STR
9724 "Display routes matching the communities\n"
9725 "community number\n"
9726 "Do not send outside local AS (well-known community)\n"
9727 "Do not advertise to any peer (well-known community)\n"
9728 "Do not export to next AS (well-known community)\n"
9729 "community number\n"
9730 "Do not send outside local AS (well-known community)\n"
9731 "Do not advertise to any peer (well-known community)\n"
9732 "Do not export to next AS (well-known community)\n"
9733 "community number\n"
9734 "Do not send outside local AS (well-known community)\n"
9735 "Do not advertise to any peer (well-known community)\n"
9736 "Do not export to next AS (well-known community)\n"
9737 "community number\n"
9738 "Do not send outside local AS (well-known community)\n"
9739 "Do not advertise to any peer (well-known community)\n"
9740 "Do not export to next AS (well-known community)\n"
9741 "Exact match of the communities")
9742
9743 ALIAS (show_bgp_community_exact,
9744 show_bgp_ipv6_community4_exact_cmd,
9745 "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",
9746 SHOW_STR
9747 BGP_STR
9748 "Address family\n"
9749 "Display routes matching the communities\n"
9750 "community number\n"
9751 "Do not send outside local AS (well-known community)\n"
9752 "Do not advertise to any peer (well-known community)\n"
9753 "Do not export to next AS (well-known community)\n"
9754 "community number\n"
9755 "Do not send outside local AS (well-known community)\n"
9756 "Do not advertise to any peer (well-known community)\n"
9757 "Do not export to next AS (well-known community)\n"
9758 "community number\n"
9759 "Do not send outside local AS (well-known community)\n"
9760 "Do not advertise to any peer (well-known community)\n"
9761 "Do not export to next AS (well-known community)\n"
9762 "community number\n"
9763 "Do not send outside local AS (well-known community)\n"
9764 "Do not advertise to any peer (well-known community)\n"
9765 "Do not export to next AS (well-known community)\n"
9766 "Exact match of the communities")
9767
9768 /* old command */
9769 DEFUN (show_ipv6_bgp_community_exact,
9770 show_ipv6_bgp_community_exact_cmd,
9771 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9772 SHOW_STR
9773 IPV6_STR
9774 BGP_STR
9775 "Display routes matching the communities\n"
9776 "community number\n"
9777 "Do not send outside local AS (well-known community)\n"
9778 "Do not advertise to any peer (well-known community)\n"
9779 "Do not export to next AS (well-known community)\n"
9780 "Exact match of the communities")
9781 {
9782 bgp_show_ipv6_bgp_deprecate_warning(vty);
9783 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9784 }
9785
9786 /* old command */
9787 ALIAS (show_ipv6_bgp_community_exact,
9788 show_ipv6_bgp_community2_exact_cmd,
9789 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9790 SHOW_STR
9791 IPV6_STR
9792 BGP_STR
9793 "Display routes matching the communities\n"
9794 "community number\n"
9795 "Do not send outside local AS (well-known community)\n"
9796 "Do not advertise to any peer (well-known community)\n"
9797 "Do not export to next AS (well-known community)\n"
9798 "community number\n"
9799 "Do not send outside local AS (well-known community)\n"
9800 "Do not advertise to any peer (well-known community)\n"
9801 "Do not export to next AS (well-known community)\n"
9802 "Exact match of the communities")
9803
9804 /* old command */
9805 ALIAS (show_ipv6_bgp_community_exact,
9806 show_ipv6_bgp_community3_exact_cmd,
9807 "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",
9808 SHOW_STR
9809 IPV6_STR
9810 BGP_STR
9811 "Display routes matching the communities\n"
9812 "community number\n"
9813 "Do not send outside local AS (well-known community)\n"
9814 "Do not advertise to any peer (well-known community)\n"
9815 "Do not export to next AS (well-known community)\n"
9816 "community number\n"
9817 "Do not send outside local AS (well-known community)\n"
9818 "Do not advertise to any peer (well-known community)\n"
9819 "Do not export to next AS (well-known community)\n"
9820 "community number\n"
9821 "Do not send outside local AS (well-known community)\n"
9822 "Do not advertise to any peer (well-known community)\n"
9823 "Do not export to next AS (well-known community)\n"
9824 "Exact match of the communities")
9825
9826 /* old command */
9827 ALIAS (show_ipv6_bgp_community_exact,
9828 show_ipv6_bgp_community4_exact_cmd,
9829 "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",
9830 SHOW_STR
9831 IPV6_STR
9832 BGP_STR
9833 "Display routes matching the communities\n"
9834 "community number\n"
9835 "Do not send outside local AS (well-known community)\n"
9836 "Do not advertise to any peer (well-known community)\n"
9837 "Do not export to next AS (well-known community)\n"
9838 "community number\n"
9839 "Do not send outside local AS (well-known community)\n"
9840 "Do not advertise to any peer (well-known community)\n"
9841 "Do not export to next AS (well-known community)\n"
9842 "community number\n"
9843 "Do not send outside local AS (well-known community)\n"
9844 "Do not advertise to any peer (well-known community)\n"
9845 "Do not export to next AS (well-known community)\n"
9846 "community number\n"
9847 "Do not send outside local AS (well-known community)\n"
9848 "Do not advertise to any peer (well-known community)\n"
9849 "Do not export to next AS (well-known community)\n"
9850 "Exact match of the communities")
9851
9852 /* old command */
9853 DEFUN (show_ipv6_mbgp_community,
9854 show_ipv6_mbgp_community_cmd,
9855 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
9856 SHOW_STR
9857 IPV6_STR
9858 MBGP_STR
9859 "Display routes matching the communities\n"
9860 "community number\n"
9861 "Do not send outside local AS (well-known community)\n"
9862 "Do not advertise to any peer (well-known community)\n"
9863 "Do not export to next AS (well-known community)\n")
9864 {
9865 bgp_show_ipv6_bgp_deprecate_warning(vty);
9866 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
9867 }
9868
9869 /* old command */
9870 ALIAS (show_ipv6_mbgp_community,
9871 show_ipv6_mbgp_community2_cmd,
9872 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9873 SHOW_STR
9874 IPV6_STR
9875 MBGP_STR
9876 "Display routes matching the communities\n"
9877 "community number\n"
9878 "Do not send outside local AS (well-known community)\n"
9879 "Do not advertise to any peer (well-known community)\n"
9880 "Do not export to next AS (well-known community)\n"
9881 "community number\n"
9882 "Do not send outside local AS (well-known community)\n"
9883 "Do not advertise to any peer (well-known community)\n"
9884 "Do not export to next AS (well-known community)\n")
9885
9886 /* old command */
9887 ALIAS (show_ipv6_mbgp_community,
9888 show_ipv6_mbgp_community3_cmd,
9889 "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)",
9890 SHOW_STR
9891 IPV6_STR
9892 MBGP_STR
9893 "Display routes matching the communities\n"
9894 "community number\n"
9895 "Do not send outside local AS (well-known community)\n"
9896 "Do not advertise to any peer (well-known community)\n"
9897 "Do not export to next AS (well-known community)\n"
9898 "community number\n"
9899 "Do not send outside local AS (well-known community)\n"
9900 "Do not advertise to any peer (well-known community)\n"
9901 "Do not export to next AS (well-known community)\n"
9902 "community number\n"
9903 "Do not send outside local AS (well-known community)\n"
9904 "Do not advertise to any peer (well-known community)\n"
9905 "Do not export to next AS (well-known community)\n")
9906
9907 /* old command */
9908 ALIAS (show_ipv6_mbgp_community,
9909 show_ipv6_mbgp_community4_cmd,
9910 "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)",
9911 SHOW_STR
9912 IPV6_STR
9913 MBGP_STR
9914 "Display routes matching the communities\n"
9915 "community number\n"
9916 "Do not send outside local AS (well-known community)\n"
9917 "Do not advertise to any peer (well-known community)\n"
9918 "Do not export to next AS (well-known community)\n"
9919 "community number\n"
9920 "Do not send outside local AS (well-known community)\n"
9921 "Do not advertise to any peer (well-known community)\n"
9922 "Do not export to next AS (well-known community)\n"
9923 "community number\n"
9924 "Do not send outside local AS (well-known community)\n"
9925 "Do not advertise to any peer (well-known community)\n"
9926 "Do not export to next AS (well-known community)\n"
9927 "community number\n"
9928 "Do not send outside local AS (well-known community)\n"
9929 "Do not advertise to any peer (well-known community)\n"
9930 "Do not export to next AS (well-known community)\n")
9931
9932 /* old command */
9933 DEFUN (show_ipv6_mbgp_community_exact,
9934 show_ipv6_mbgp_community_exact_cmd,
9935 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9936 SHOW_STR
9937 IPV6_STR
9938 MBGP_STR
9939 "Display routes matching the communities\n"
9940 "community number\n"
9941 "Do not send outside local AS (well-known community)\n"
9942 "Do not advertise to any peer (well-known community)\n"
9943 "Do not export to next AS (well-known community)\n"
9944 "Exact match of the communities")
9945 {
9946 bgp_show_ipv6_bgp_deprecate_warning(vty);
9947 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
9948 }
9949
9950 /* old command */
9951 ALIAS (show_ipv6_mbgp_community_exact,
9952 show_ipv6_mbgp_community2_exact_cmd,
9953 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9954 SHOW_STR
9955 IPV6_STR
9956 MBGP_STR
9957 "Display routes matching the communities\n"
9958 "community number\n"
9959 "Do not send outside local AS (well-known community)\n"
9960 "Do not advertise to any peer (well-known community)\n"
9961 "Do not export to next AS (well-known community)\n"
9962 "community number\n"
9963 "Do not send outside local AS (well-known community)\n"
9964 "Do not advertise to any peer (well-known community)\n"
9965 "Do not export to next AS (well-known community)\n"
9966 "Exact match of the communities")
9967
9968 /* old command */
9969 ALIAS (show_ipv6_mbgp_community_exact,
9970 show_ipv6_mbgp_community3_exact_cmd,
9971 "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",
9972 SHOW_STR
9973 IPV6_STR
9974 MBGP_STR
9975 "Display routes matching the communities\n"
9976 "community number\n"
9977 "Do not send outside local AS (well-known community)\n"
9978 "Do not advertise to any peer (well-known community)\n"
9979 "Do not export to next AS (well-known community)\n"
9980 "community number\n"
9981 "Do not send outside local AS (well-known community)\n"
9982 "Do not advertise to any peer (well-known community)\n"
9983 "Do not export to next AS (well-known community)\n"
9984 "community number\n"
9985 "Do not send outside local AS (well-known community)\n"
9986 "Do not advertise to any peer (well-known community)\n"
9987 "Do not export to next AS (well-known community)\n"
9988 "Exact match of the communities")
9989
9990 /* old command */
9991 ALIAS (show_ipv6_mbgp_community_exact,
9992 show_ipv6_mbgp_community4_exact_cmd,
9993 "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",
9994 SHOW_STR
9995 IPV6_STR
9996 MBGP_STR
9997 "Display routes matching the communities\n"
9998 "community number\n"
9999 "Do not send outside local AS (well-known community)\n"
10000 "Do not advertise to any peer (well-known community)\n"
10001 "Do not export to next AS (well-known community)\n"
10002 "community number\n"
10003 "Do not send outside local AS (well-known community)\n"
10004 "Do not advertise to any peer (well-known community)\n"
10005 "Do not export to next AS (well-known community)\n"
10006 "community number\n"
10007 "Do not send outside local AS (well-known community)\n"
10008 "Do not advertise to any peer (well-known community)\n"
10009 "Do not export to next AS (well-known community)\n"
10010 "community number\n"
10011 "Do not send outside local AS (well-known community)\n"
10012 "Do not advertise to any peer (well-known community)\n"
10013 "Do not export to next AS (well-known community)\n"
10014 "Exact match of the communities")
10015 #endif /* HAVE_IPV6 */
10016
10017 static int
10018 bgp_show_community_list (struct vty *vty, const char *com, int exact,
10019 afi_t afi, safi_t safi)
10020 {
10021 struct community_list *list;
10022
10023 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
10024 if (list == NULL)
10025 {
10026 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10027 VTY_NEWLINE);
10028 return CMD_WARNING;
10029 }
10030
10031 return bgp_show (vty, NULL, afi, safi,
10032 (exact ? bgp_show_type_community_list_exact :
10033 bgp_show_type_community_list), list, 0);
10034 }
10035
10036 DEFUN (show_ip_bgp_community_list,
10037 show_ip_bgp_community_list_cmd,
10038 "show ip bgp community-list (<1-500>|WORD)",
10039 SHOW_STR
10040 IP_STR
10041 BGP_STR
10042 "Display routes matching the community-list\n"
10043 "community-list number\n"
10044 "community-list name\n")
10045 {
10046 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
10047 }
10048
10049 DEFUN (show_ip_bgp_ipv4_community_list,
10050 show_ip_bgp_ipv4_community_list_cmd,
10051 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
10052 SHOW_STR
10053 IP_STR
10054 BGP_STR
10055 "Address family\n"
10056 "Address Family modifier\n"
10057 "Address Family modifier\n"
10058 "Display routes matching the community-list\n"
10059 "community-list number\n"
10060 "community-list name\n")
10061 {
10062 if (strncmp (argv[0], "m", 1) == 0)
10063 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10064
10065 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
10066 }
10067
10068 DEFUN (show_ip_bgp_community_list_exact,
10069 show_ip_bgp_community_list_exact_cmd,
10070 "show ip bgp community-list (<1-500>|WORD) exact-match",
10071 SHOW_STR
10072 IP_STR
10073 BGP_STR
10074 "Display routes matching the community-list\n"
10075 "community-list number\n"
10076 "community-list name\n"
10077 "Exact match of the communities\n")
10078 {
10079 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
10080 }
10081
10082 DEFUN (show_ip_bgp_ipv4_community_list_exact,
10083 show_ip_bgp_ipv4_community_list_exact_cmd,
10084 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
10085 SHOW_STR
10086 IP_STR
10087 BGP_STR
10088 "Address family\n"
10089 "Address Family modifier\n"
10090 "Address Family modifier\n"
10091 "Display routes matching the community-list\n"
10092 "community-list number\n"
10093 "community-list name\n"
10094 "Exact match of the communities\n")
10095 {
10096 if (strncmp (argv[0], "m", 1) == 0)
10097 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10098
10099 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
10100 }
10101
10102 #ifdef HAVE_IPV6
10103 DEFUN (show_bgp_community_list,
10104 show_bgp_community_list_cmd,
10105 "show bgp community-list (<1-500>|WORD)",
10106 SHOW_STR
10107 BGP_STR
10108 "Display routes matching the community-list\n"
10109 "community-list number\n"
10110 "community-list name\n")
10111 {
10112 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10113 }
10114
10115 ALIAS (show_bgp_community_list,
10116 show_bgp_ipv6_community_list_cmd,
10117 "show bgp ipv6 community-list (<1-500>|WORD)",
10118 SHOW_STR
10119 BGP_STR
10120 "Address family\n"
10121 "Display routes matching the community-list\n"
10122 "community-list number\n"
10123 "community-list name\n")
10124
10125 /* old command */
10126 DEFUN (show_ipv6_bgp_community_list,
10127 show_ipv6_bgp_community_list_cmd,
10128 "show ipv6 bgp community-list WORD",
10129 SHOW_STR
10130 IPV6_STR
10131 BGP_STR
10132 "Display routes matching the community-list\n"
10133 "community-list name\n")
10134 {
10135 bgp_show_ipv6_bgp_deprecate_warning(vty);
10136 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10137 }
10138
10139 /* old command */
10140 DEFUN (show_ipv6_mbgp_community_list,
10141 show_ipv6_mbgp_community_list_cmd,
10142 "show ipv6 mbgp community-list WORD",
10143 SHOW_STR
10144 IPV6_STR
10145 MBGP_STR
10146 "Display routes matching the community-list\n"
10147 "community-list name\n")
10148 {
10149 bgp_show_ipv6_bgp_deprecate_warning(vty);
10150 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10151 }
10152
10153 DEFUN (show_bgp_community_list_exact,
10154 show_bgp_community_list_exact_cmd,
10155 "show bgp community-list (<1-500>|WORD) exact-match",
10156 SHOW_STR
10157 BGP_STR
10158 "Display routes matching the community-list\n"
10159 "community-list number\n"
10160 "community-list name\n"
10161 "Exact match of the communities\n")
10162 {
10163 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10164 }
10165
10166 ALIAS (show_bgp_community_list_exact,
10167 show_bgp_ipv6_community_list_exact_cmd,
10168 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
10169 SHOW_STR
10170 BGP_STR
10171 "Address family\n"
10172 "Display routes matching the community-list\n"
10173 "community-list number\n"
10174 "community-list name\n"
10175 "Exact match of the communities\n")
10176
10177 /* old command */
10178 DEFUN (show_ipv6_bgp_community_list_exact,
10179 show_ipv6_bgp_community_list_exact_cmd,
10180 "show ipv6 bgp community-list WORD exact-match",
10181 SHOW_STR
10182 IPV6_STR
10183 BGP_STR
10184 "Display routes matching the community-list\n"
10185 "community-list name\n"
10186 "Exact match of the communities\n")
10187 {
10188 bgp_show_ipv6_bgp_deprecate_warning(vty);
10189 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10190 }
10191
10192 /* old command */
10193 DEFUN (show_ipv6_mbgp_community_list_exact,
10194 show_ipv6_mbgp_community_list_exact_cmd,
10195 "show ipv6 mbgp community-list WORD exact-match",
10196 SHOW_STR
10197 IPV6_STR
10198 MBGP_STR
10199 "Display routes matching the community-list\n"
10200 "community-list name\n"
10201 "Exact match of the communities\n")
10202 {
10203 bgp_show_ipv6_bgp_deprecate_warning(vty);
10204 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
10205 }
10206 #endif /* HAVE_IPV6 */
10207
10208 static int
10209 bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
10210 safi_t safi, enum bgp_show_type type)
10211 {
10212 int ret;
10213 struct prefix *p;
10214
10215 p = prefix_new();
10216
10217 ret = str2prefix (prefix, p);
10218 if (! ret)
10219 {
10220 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
10221 return CMD_WARNING;
10222 }
10223
10224 ret = bgp_show (vty, NULL, afi, safi, type, p, 0);
10225 prefix_free(p);
10226 return ret;
10227 }
10228
10229 DEFUN (show_ip_bgp_prefix_longer,
10230 show_ip_bgp_prefix_longer_cmd,
10231 "show ip bgp A.B.C.D/M longer-prefixes",
10232 SHOW_STR
10233 IP_STR
10234 BGP_STR
10235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10236 "Display route and more specific routes\n")
10237 {
10238 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10239 bgp_show_type_prefix_longer);
10240 }
10241
10242 DEFUN (show_ip_bgp_flap_prefix_longer,
10243 show_ip_bgp_flap_prefix_longer_cmd,
10244 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
10245 SHOW_STR
10246 IP_STR
10247 BGP_STR
10248 "Display flap statistics of routes\n"
10249 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10250 "Display route and more specific routes\n")
10251 {
10252 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10253 bgp_show_type_flap_prefix_longer);
10254 }
10255
10256 DEFUN (show_ip_bgp_ipv4_prefix_longer,
10257 show_ip_bgp_ipv4_prefix_longer_cmd,
10258 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
10259 SHOW_STR
10260 IP_STR
10261 BGP_STR
10262 "Address family\n"
10263 "Address Family modifier\n"
10264 "Address Family modifier\n"
10265 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10266 "Display route and more specific routes\n")
10267 {
10268 if (strncmp (argv[0], "m", 1) == 0)
10269 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
10270 bgp_show_type_prefix_longer);
10271
10272 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
10273 bgp_show_type_prefix_longer);
10274 }
10275
10276 DEFUN (show_ip_bgp_flap_address,
10277 show_ip_bgp_flap_address_cmd,
10278 "show ip bgp flap-statistics A.B.C.D",
10279 SHOW_STR
10280 IP_STR
10281 BGP_STR
10282 "Display flap statistics of routes\n"
10283 "Network in the BGP routing table to display\n")
10284 {
10285 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10286 bgp_show_type_flap_address);
10287 }
10288
10289 DEFUN (show_ip_bgp_flap_prefix,
10290 show_ip_bgp_flap_prefix_cmd,
10291 "show ip bgp flap-statistics A.B.C.D/M",
10292 SHOW_STR
10293 IP_STR
10294 BGP_STR
10295 "Display flap statistics of routes\n"
10296 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10297 {
10298 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
10299 bgp_show_type_flap_prefix);
10300 }
10301 #ifdef HAVE_IPV6
10302 DEFUN (show_bgp_prefix_longer,
10303 show_bgp_prefix_longer_cmd,
10304 "show bgp X:X::X:X/M longer-prefixes",
10305 SHOW_STR
10306 BGP_STR
10307 "IPv6 prefix <network>/<length>\n"
10308 "Display route and more specific routes\n")
10309 {
10310 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
10311 bgp_show_type_prefix_longer);
10312 }
10313
10314 ALIAS (show_bgp_prefix_longer,
10315 show_bgp_ipv6_prefix_longer_cmd,
10316 "show bgp ipv6 X:X::X:X/M longer-prefixes",
10317 SHOW_STR
10318 BGP_STR
10319 "Address family\n"
10320 "IPv6 prefix <network>/<length>\n"
10321 "Display route and more specific routes\n")
10322
10323 /* old command */
10324 DEFUN (show_ipv6_bgp_prefix_longer,
10325 show_ipv6_bgp_prefix_longer_cmd,
10326 "show ipv6 bgp X:X::X:X/M longer-prefixes",
10327 SHOW_STR
10328 IPV6_STR
10329 BGP_STR
10330 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
10331 "Display route and more specific routes\n")
10332 {
10333 bgp_show_ipv6_bgp_deprecate_warning(vty);
10334 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
10335 bgp_show_type_prefix_longer);
10336 }
10337
10338 /* old command */
10339 DEFUN (show_ipv6_mbgp_prefix_longer,
10340 show_ipv6_mbgp_prefix_longer_cmd,
10341 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
10342 SHOW_STR
10343 IPV6_STR
10344 MBGP_STR
10345 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
10346 "Display route and more specific routes\n")
10347 {
10348 bgp_show_ipv6_bgp_deprecate_warning(vty);
10349 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
10350 bgp_show_type_prefix_longer);
10351 }
10352 #endif /* HAVE_IPV6 */
10353
10354 static struct peer *
10355 peer_lookup_in_view (struct vty *vty, const char *view_name,
10356 const char *ip_str, u_char use_json)
10357 {
10358 int ret;
10359 struct bgp *bgp;
10360 struct peer *peer;
10361 union sockunion su;
10362
10363 /* BGP structure lookup. */
10364 if (view_name)
10365 {
10366 bgp = bgp_lookup_by_name (view_name);
10367 if (! bgp)
10368 {
10369 if (use_json)
10370 {
10371 json_object *json_no = NULL;
10372 json_no = json_object_new_object();
10373 json_object_string_add(json_no, "warning", "Can't find BGP view");
10374 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10375 json_object_free(json_no);
10376 }
10377 else
10378 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10379 return NULL;
10380 }
10381 }
10382 else
10383 {
10384 bgp = bgp_get_default ();
10385 if (! bgp)
10386 {
10387 if (use_json)
10388 {
10389 json_object *json_no = NULL;
10390 json_no = json_object_new_object();
10391 json_object_string_add(json_no, "warning", "No BGP process configured");
10392 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10393 json_object_free(json_no);
10394 }
10395 else
10396 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10397 return NULL;
10398 }
10399 }
10400
10401 /* Get peer sockunion. */
10402 ret = str2sockunion (ip_str, &su);
10403 if (ret < 0)
10404 {
10405 peer = peer_lookup_by_conf_if (bgp, ip_str);
10406 if (!peer)
10407 {
10408 peer = peer_lookup_by_hostname(bgp, ip_str);
10409
10410 if (!peer)
10411 {
10412 if (use_json)
10413 {
10414 json_object *json_no = NULL;
10415 json_no = json_object_new_object();
10416 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
10417 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10418 json_object_free(json_no);
10419 }
10420 else
10421 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
10422 return NULL;
10423 }
10424 }
10425 return peer;
10426 }
10427
10428 /* Peer structure lookup. */
10429 peer = peer_lookup (bgp, &su);
10430 if (! peer)
10431 {
10432 if (use_json)
10433 {
10434 json_object *json_no = NULL;
10435 json_no = json_object_new_object();
10436 json_object_string_add(json_no, "warning","No such neighbor");
10437 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10438 json_object_free(json_no);
10439 }
10440 else
10441 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
10442 return NULL;
10443 }
10444
10445 return peer;
10446 }
10447
10448 enum bgp_stats
10449 {
10450 BGP_STATS_MAXBITLEN = 0,
10451 BGP_STATS_RIB,
10452 BGP_STATS_PREFIXES,
10453 BGP_STATS_TOTPLEN,
10454 BGP_STATS_UNAGGREGATEABLE,
10455 BGP_STATS_MAX_AGGREGATEABLE,
10456 BGP_STATS_AGGREGATES,
10457 BGP_STATS_SPACE,
10458 BGP_STATS_ASPATH_COUNT,
10459 BGP_STATS_ASPATH_MAXHOPS,
10460 BGP_STATS_ASPATH_TOTHOPS,
10461 BGP_STATS_ASPATH_MAXSIZE,
10462 BGP_STATS_ASPATH_TOTSIZE,
10463 BGP_STATS_ASN_HIGHEST,
10464 BGP_STATS_MAX,
10465 };
10466
10467 static const char *table_stats_strs[] =
10468 {
10469 [BGP_STATS_PREFIXES] = "Total Prefixes",
10470 [BGP_STATS_TOTPLEN] = "Average prefix length",
10471 [BGP_STATS_RIB] = "Total Advertisements",
10472 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
10473 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
10474 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
10475 [BGP_STATS_SPACE] = "Address space advertised",
10476 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
10477 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
10478 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
10479 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
10480 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
10481 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
10482 [BGP_STATS_MAX] = NULL,
10483 };
10484
10485 struct bgp_table_stats
10486 {
10487 struct bgp_table *table;
10488 unsigned long long counts[BGP_STATS_MAX];
10489 };
10490
10491 #if 0
10492 #define TALLY_SIGFIG 100000
10493 static unsigned long
10494 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
10495 {
10496 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
10497 unsigned long res = (newtot * TALLY_SIGFIG) / count;
10498 unsigned long ret = newtot / count;
10499
10500 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
10501 return ret + 1;
10502 else
10503 return ret;
10504 }
10505 #endif
10506
10507 static int
10508 bgp_table_stats_walker (struct thread *t)
10509 {
10510 struct bgp_node *rn;
10511 struct bgp_node *top;
10512 struct bgp_table_stats *ts = THREAD_ARG (t);
10513 unsigned int space = 0;
10514
10515 if (!(top = bgp_table_top (ts->table)))
10516 return 0;
10517
10518 switch (top->p.family)
10519 {
10520 case AF_INET:
10521 space = IPV4_MAX_BITLEN;
10522 break;
10523 case AF_INET6:
10524 space = IPV6_MAX_BITLEN;
10525 break;
10526 }
10527
10528 ts->counts[BGP_STATS_MAXBITLEN] = space;
10529
10530 for (rn = top; rn; rn = bgp_route_next (rn))
10531 {
10532 struct bgp_info *ri;
10533 struct bgp_node *prn = bgp_node_parent_nolock (rn);
10534 unsigned int rinum = 0;
10535
10536 if (rn == top)
10537 continue;
10538
10539 if (!rn->info)
10540 continue;
10541
10542 ts->counts[BGP_STATS_PREFIXES]++;
10543 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
10544
10545 #if 0
10546 ts->counts[BGP_STATS_AVGPLEN]
10547 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
10548 ts->counts[BGP_STATS_AVGPLEN],
10549 rn->p.prefixlen);
10550 #endif
10551
10552 /* check if the prefix is included by any other announcements */
10553 while (prn && !prn->info)
10554 prn = bgp_node_parent_nolock (prn);
10555
10556 if (prn == NULL || prn == top)
10557 {
10558 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
10559 /* announced address space */
10560 if (space)
10561 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
10562 }
10563 else if (prn->info)
10564 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
10565
10566 for (ri = rn->info; ri; ri = ri->next)
10567 {
10568 rinum++;
10569 ts->counts[BGP_STATS_RIB]++;
10570
10571 if (ri->attr &&
10572 (CHECK_FLAG (ri->attr->flag,
10573 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
10574 ts->counts[BGP_STATS_AGGREGATES]++;
10575
10576 /* as-path stats */
10577 if (ri->attr && ri->attr->aspath)
10578 {
10579 unsigned int hops = aspath_count_hops (ri->attr->aspath);
10580 unsigned int size = aspath_size (ri->attr->aspath);
10581 as_t highest = aspath_highest (ri->attr->aspath);
10582
10583 ts->counts[BGP_STATS_ASPATH_COUNT]++;
10584
10585 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
10586 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
10587
10588 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
10589 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
10590
10591 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
10592 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
10593 #if 0
10594 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
10595 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
10596 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
10597 hops);
10598 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
10599 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
10600 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
10601 size);
10602 #endif
10603 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
10604 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
10605 }
10606 }
10607 }
10608 return 0;
10609 }
10610
10611 static int
10612 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
10613 {
10614 struct bgp_table_stats ts;
10615 unsigned int i;
10616
10617 if (!bgp->rib[afi][safi])
10618 {
10619 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
10620 return CMD_WARNING;
10621 }
10622
10623 memset (&ts, 0, sizeof (ts));
10624 ts.table = bgp->rib[afi][safi];
10625 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
10626
10627 vty_out (vty, "BGP %s RIB statistics%s%s",
10628 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
10629
10630 for (i = 0; i < BGP_STATS_MAX; i++)
10631 {
10632 if (!table_stats_strs[i])
10633 continue;
10634
10635 switch (i)
10636 {
10637 #if 0
10638 case BGP_STATS_ASPATH_AVGHOPS:
10639 case BGP_STATS_ASPATH_AVGSIZE:
10640 case BGP_STATS_AVGPLEN:
10641 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10642 vty_out (vty, "%12.2f",
10643 (float)ts.counts[i] / (float)TALLY_SIGFIG);
10644 break;
10645 #endif
10646 case BGP_STATS_ASPATH_TOTHOPS:
10647 case BGP_STATS_ASPATH_TOTSIZE:
10648 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10649 vty_out (vty, "%12.2f",
10650 ts.counts[i] ?
10651 (float)ts.counts[i] /
10652 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
10653 : 0);
10654 break;
10655 case BGP_STATS_TOTPLEN:
10656 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10657 vty_out (vty, "%12.2f",
10658 ts.counts[i] ?
10659 (float)ts.counts[i] /
10660 (float)ts.counts[BGP_STATS_PREFIXES]
10661 : 0);
10662 break;
10663 case BGP_STATS_SPACE:
10664 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10665 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
10666 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
10667 break;
10668 vty_out (vty, "%30s: ", "%% announced ");
10669 vty_out (vty, "%12.2f%s",
10670 100 * (float)ts.counts[BGP_STATS_SPACE] /
10671 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
10672 VTY_NEWLINE);
10673 vty_out (vty, "%30s: ", "/8 equivalent ");
10674 vty_out (vty, "%12.2f%s",
10675 (float)ts.counts[BGP_STATS_SPACE] /
10676 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
10677 VTY_NEWLINE);
10678 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
10679 break;
10680 vty_out (vty, "%30s: ", "/24 equivalent ");
10681 vty_out (vty, "%12.2f",
10682 (float)ts.counts[BGP_STATS_SPACE] /
10683 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
10684 break;
10685 default:
10686 vty_out (vty, "%-30s: ", table_stats_strs[i]);
10687 vty_out (vty, "%12llu", ts.counts[i]);
10688 }
10689
10690 vty_out (vty, "%s", VTY_NEWLINE);
10691 }
10692 return CMD_SUCCESS;
10693 }
10694
10695 static int
10696 bgp_table_stats_vty (struct vty *vty, const char *name,
10697 const char *afi_str, const char *safi_str)
10698 {
10699 struct bgp *bgp;
10700 afi_t afi;
10701 safi_t safi;
10702
10703 if (name)
10704 bgp = bgp_lookup_by_name (name);
10705 else
10706 bgp = bgp_get_default ();
10707
10708 if (!bgp)
10709 {
10710 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
10711 return CMD_WARNING;
10712 }
10713 if (strncmp (afi_str, "ipv", 3) == 0)
10714 {
10715 if (strncmp (afi_str, "ipv4", 4) == 0)
10716 afi = AFI_IP;
10717 else if (strncmp (afi_str, "ipv6", 4) == 0)
10718 afi = AFI_IP6;
10719 else
10720 {
10721 vty_out (vty, "%% Invalid address family %s%s",
10722 afi_str, VTY_NEWLINE);
10723 return CMD_WARNING;
10724 }
10725 if (strncmp (safi_str, "m", 1) == 0)
10726 safi = SAFI_MULTICAST;
10727 else if (strncmp (safi_str, "u", 1) == 0)
10728 safi = SAFI_UNICAST;
10729 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
10730 safi = SAFI_MPLS_LABELED_VPN;
10731 else
10732 {
10733 vty_out (vty, "%% Invalid subsequent address family %s%s",
10734 safi_str, VTY_NEWLINE);
10735 return CMD_WARNING;
10736 }
10737 }
10738 else
10739 {
10740 vty_out (vty, "%% Invalid address family %s%s",
10741 afi_str, VTY_NEWLINE);
10742 return CMD_WARNING;
10743 }
10744
10745 return bgp_table_stats (vty, bgp, afi, safi);
10746 }
10747
10748 DEFUN (show_bgp_statistics,
10749 show_bgp_statistics_cmd,
10750 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
10751 SHOW_STR
10752 BGP_STR
10753 "Address family\n"
10754 "Address family\n"
10755 "Address Family modifier\n"
10756 "Address Family modifier\n"
10757 "BGP RIB advertisement statistics\n")
10758 {
10759 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
10760 }
10761
10762 ALIAS (show_bgp_statistics,
10763 show_bgp_statistics_vpnv4_cmd,
10764 "show bgp (ipv4) (vpnv4) statistics",
10765 SHOW_STR
10766 BGP_STR
10767 "Address family\n"
10768 "Address Family modifier\n"
10769 "BGP RIB advertisement statistics\n")
10770
10771 DEFUN (show_bgp_statistics_view,
10772 show_bgp_statistics_view_cmd,
10773 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
10774 SHOW_STR
10775 BGP_STR
10776 "BGP view\n"
10777 "Address family\n"
10778 "Address family\n"
10779 "Address Family modifier\n"
10780 "Address Family modifier\n"
10781 "BGP RIB advertisement statistics\n")
10782 {
10783 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
10784 }
10785
10786 ALIAS (show_bgp_statistics_view,
10787 show_bgp_statistics_view_vpnv4_cmd,
10788 "show bgp view WORD (ipv4) (vpnv4) statistics",
10789 SHOW_STR
10790 BGP_STR
10791 "BGP view\n"
10792 "Address family\n"
10793 "Address Family modifier\n"
10794 "BGP RIB advertisement statistics\n")
10795
10796 enum bgp_pcounts
10797 {
10798 PCOUNT_ADJ_IN = 0,
10799 PCOUNT_DAMPED,
10800 PCOUNT_REMOVED,
10801 PCOUNT_HISTORY,
10802 PCOUNT_STALE,
10803 PCOUNT_VALID,
10804 PCOUNT_ALL,
10805 PCOUNT_COUNTED,
10806 PCOUNT_PFCNT, /* the figure we display to users */
10807 PCOUNT_MAX,
10808 };
10809
10810 static const char *pcount_strs[] =
10811 {
10812 [PCOUNT_ADJ_IN] = "Adj-in",
10813 [PCOUNT_DAMPED] = "Damped",
10814 [PCOUNT_REMOVED] = "Removed",
10815 [PCOUNT_HISTORY] = "History",
10816 [PCOUNT_STALE] = "Stale",
10817 [PCOUNT_VALID] = "Valid",
10818 [PCOUNT_ALL] = "All RIB",
10819 [PCOUNT_COUNTED] = "PfxCt counted",
10820 [PCOUNT_PFCNT] = "Useable",
10821 [PCOUNT_MAX] = NULL,
10822 };
10823
10824 struct peer_pcounts
10825 {
10826 unsigned int count[PCOUNT_MAX];
10827 const struct peer *peer;
10828 const struct bgp_table *table;
10829 };
10830
10831 static int
10832 bgp_peer_count_walker (struct thread *t)
10833 {
10834 struct bgp_node *rn;
10835 struct peer_pcounts *pc = THREAD_ARG (t);
10836 const struct peer *peer = pc->peer;
10837
10838 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
10839 {
10840 struct bgp_adj_in *ain;
10841 struct bgp_info *ri;
10842
10843 for (ain = rn->adj_in; ain; ain = ain->next)
10844 if (ain->peer == peer)
10845 pc->count[PCOUNT_ADJ_IN]++;
10846
10847 for (ri = rn->info; ri; ri = ri->next)
10848 {
10849 char buf[SU_ADDRSTRLEN];
10850
10851 if (ri->peer != peer)
10852 continue;
10853
10854 pc->count[PCOUNT_ALL]++;
10855
10856 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
10857 pc->count[PCOUNT_DAMPED]++;
10858 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
10859 pc->count[PCOUNT_HISTORY]++;
10860 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
10861 pc->count[PCOUNT_REMOVED]++;
10862 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
10863 pc->count[PCOUNT_STALE]++;
10864 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
10865 pc->count[PCOUNT_VALID]++;
10866 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
10867 pc->count[PCOUNT_PFCNT]++;
10868
10869 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
10870 {
10871 pc->count[PCOUNT_COUNTED]++;
10872 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
10873 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
10874 peer->host,
10875 inet_ntop(rn->p.family, &rn->p.u.prefix,
10876 buf, SU_ADDRSTRLEN),
10877 rn->p.prefixlen,
10878 ri->flags);
10879 }
10880 else
10881 {
10882 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
10883 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
10884 peer->host,
10885 inet_ntop(rn->p.family, &rn->p.u.prefix,
10886 buf, SU_ADDRSTRLEN),
10887 rn->p.prefixlen,
10888 ri->flags);
10889 }
10890 }
10891 }
10892 return 0;
10893 }
10894
10895 static int
10896 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
10897 {
10898 struct peer_pcounts pcounts = { .peer = peer };
10899 unsigned int i;
10900 json_object *json = NULL;
10901 json_object *json_loop = NULL;
10902
10903 if (use_json)
10904 {
10905 json = json_object_new_object();
10906 json_loop = json_object_new_object();
10907 }
10908
10909 if (!peer || !peer->bgp || !peer->afc[afi][safi]
10910 || !peer->bgp->rib[afi][safi])
10911 {
10912 if (use_json)
10913 {
10914 json_object_string_add(json, "warning", "No such neighbor or address family");
10915 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
10916 json_object_free(json);
10917 }
10918 else
10919 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10920
10921 return CMD_WARNING;
10922 }
10923
10924 memset (&pcounts, 0, sizeof(pcounts));
10925 pcounts.peer = peer;
10926 pcounts.table = peer->bgp->rib[afi][safi];
10927
10928 /* in-place call via thread subsystem so as to record execution time
10929 * * stats for the thread-walk (i.e. ensure this can't be blamed on
10930 * * on just vty_read()).
10931 * */
10932 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
10933
10934 if (use_json)
10935 {
10936 json_object_string_add(json, "prefixCountsFor", peer->host);
10937 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
10938 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
10939
10940 for (i = 0; i < PCOUNT_MAX; i++)
10941 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
10942
10943 json_object_object_add(json, "ribTableWalkCounters", json_loop);
10944
10945 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
10946 {
10947 json_object_string_add(json, "pfxctDriftFor", peer->host);
10948 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
10949 }
10950 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
10951 json_object_free(json);
10952 }
10953 else
10954 {
10955
10956 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
10957 {
10958 vty_out (vty, "Prefix counts for %s/%s, %s%s",
10959 peer->hostname, peer->host, afi_safi_print (afi, safi),
10960 VTY_NEWLINE);
10961 }
10962 else
10963 {
10964 vty_out (vty, "Prefix counts for %s, %s%s",
10965 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
10966 }
10967
10968 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
10969 vty_out (vty, "%sCounts from RIB table walk:%s%s",
10970 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
10971
10972 for (i = 0; i < PCOUNT_MAX; i++)
10973 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
10974
10975 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
10976 {
10977 vty_out (vty, "%s [pcount] PfxCt drift!%s",
10978 peer->host, VTY_NEWLINE);
10979 vty_out (vty, "Please report this bug, with the above command output%s",
10980 VTY_NEWLINE);
10981 }
10982 }
10983
10984 return CMD_SUCCESS;
10985 }
10986
10987 DEFUN (show_ip_bgp_neighbor_prefix_counts,
10988 show_ip_bgp_neighbor_prefix_counts_cmd,
10989 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
10990 SHOW_STR
10991 IP_STR
10992 BGP_STR
10993 "Detailed information on TCP and BGP neighbor connections\n"
10994 "Neighbor to display information about\n"
10995 "Neighbor to display information about\n"
10996 "Neighbor on bgp configured interface\n"
10997 "Display detailed prefix count information\n"
10998 "JavaScript Object Notation\n")
10999 {
11000 struct peer *peer;
11001 u_char uj = use_json(argc, argv);
11002
11003 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11004 if (! peer)
11005 return CMD_WARNING;
11006
11007 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11008 }
11009
11010 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
11011 show_bgp_ipv6_neighbor_prefix_counts_cmd,
11012 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11013 SHOW_STR
11014 BGP_STR
11015 "Address family\n"
11016 "Detailed information on TCP and BGP neighbor connections\n"
11017 "Neighbor to display information about\n"
11018 "Neighbor to display information about\n"
11019 "Neighbor on bgp configured interface\n"
11020 "Display detailed prefix count information\n"
11021 "JavaScript Object Notation\n")
11022 {
11023 struct peer *peer;
11024 u_char uj = use_json(argc, argv);
11025
11026 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11027 if (! peer)
11028 return CMD_WARNING;
11029
11030 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
11031 }
11032
11033 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
11034 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
11035 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11036 SHOW_STR
11037 IP_STR
11038 BGP_STR
11039 "Address family\n"
11040 "Address Family modifier\n"
11041 "Address Family modifier\n"
11042 "Detailed information on TCP and BGP neighbor connections\n"
11043 "Neighbor to display information about\n"
11044 "Neighbor to display information about\n"
11045 "Neighbor on bgp configured interface\n"
11046 "Display detailed prefix count information\n"
11047 "JavaScript Object Notation\n")
11048 {
11049 struct peer *peer;
11050 u_char uj = use_json(argc, argv);
11051
11052 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
11053 if (! peer)
11054 return CMD_WARNING;
11055
11056 if (strncmp (argv[0], "m", 1) == 0)
11057 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj);
11058
11059 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11060 }
11061
11062 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
11063 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
11064 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11065 SHOW_STR
11066 IP_STR
11067 BGP_STR
11068 "Address family\n"
11069 "Address Family modifier\n"
11070 "Address Family modifier\n"
11071 "Detailed information on TCP and BGP neighbor connections\n"
11072 "Neighbor to display information about\n"
11073 "Neighbor to display information about\n"
11074 "Neighbor on bgp configured interface\n"
11075 "Display detailed prefix count information\n"
11076 "JavaScript Object Notation\n")
11077 {
11078 struct peer *peer;
11079 u_char uj = use_json(argc, argv);
11080
11081 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11082 if (! peer)
11083 return CMD_WARNING;
11084
11085 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
11086 }
11087
11088 static void
11089 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
11090 int in, const char *rmap_name, u_char use_json, json_object *json)
11091 {
11092 struct bgp_table *table;
11093 struct bgp_adj_in *ain;
11094 struct bgp_adj_out *adj;
11095 unsigned long output_count;
11096 unsigned long filtered_count;
11097 struct bgp_node *rn;
11098 int header1 = 1;
11099 struct bgp *bgp;
11100 int header2 = 1;
11101 struct attr attr;
11102 struct attr_extra extra;
11103 int ret;
11104 struct update_subgroup *subgrp;
11105 json_object *json_scode = NULL;
11106 json_object *json_ocode = NULL;
11107 json_object *json_ar = NULL;
11108 struct peer_af *paf;
11109
11110 if (use_json)
11111 {
11112 json_scode = json_object_new_object();
11113 json_ocode = json_object_new_object();
11114 json_ar = json_object_new_object();
11115
11116 json_object_string_add(json_scode, "suppressed", "s");
11117 json_object_string_add(json_scode, "damped", "d");
11118 json_object_string_add(json_scode, "history", "h");
11119 json_object_string_add(json_scode, "valid", "*");
11120 json_object_string_add(json_scode, "best", ">");
11121 json_object_string_add(json_scode, "multipath", "=");
11122 json_object_string_add(json_scode, "internal", "i");
11123 json_object_string_add(json_scode, "ribFailure", "r");
11124 json_object_string_add(json_scode, "stale", "S");
11125 json_object_string_add(json_scode, "removed", "R");
11126
11127 json_object_string_add(json_ocode, "igp", "i");
11128 json_object_string_add(json_ocode, "egp", "e");
11129 json_object_string_add(json_ocode, "incomplete", "?");
11130 }
11131
11132 bgp = peer->bgp;
11133
11134 if (! bgp)
11135 {
11136 if (use_json)
11137 {
11138 json_object_string_add(json, "alert", "no BGP");
11139 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11140 json_object_free(json);
11141 }
11142 else
11143 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
11144 return;
11145 }
11146
11147 table = bgp->rib[afi][safi];
11148
11149 output_count = filtered_count = 0;
11150 subgrp = peer_subgroup(peer, afi, safi);
11151
11152 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
11153 {
11154 if (use_json)
11155 {
11156 json_object_int_add(json, "bgpTableVersion", table->version);
11157 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11158 json_object_object_add(json, "bgpStatusCodes", json_scode);
11159 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11160 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
11161 }
11162 else
11163 {
11164 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
11165 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11166 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11167
11168 vty_out (vty, "Originating default network 0.0.0.0%s%s",
11169 VTY_NEWLINE, VTY_NEWLINE);
11170 }
11171 header1 = 0;
11172 }
11173
11174 attr.extra = &extra;
11175 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11176 {
11177 if (in)
11178 {
11179 for (ain = rn->adj_in; ain; ain = ain->next)
11180 {
11181 if (ain->peer == peer)
11182 {
11183 if (header1)
11184 {
11185 if (use_json)
11186 {
11187 json_object_int_add(json, "bgpTableVersion", 0);
11188 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11189 json_object_object_add(json, "bgpStatusCodes", json_scode);
11190 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11191 }
11192 else
11193 {
11194 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
11195 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11196 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11197 }
11198 header1 = 0;
11199 }
11200 if (header2)
11201 {
11202 if (!use_json)
11203 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
11204 header2 = 0;
11205 }
11206 if (ain->attr)
11207 {
11208 bgp_attr_dup(&attr, ain->attr);
11209 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
11210 {
11211 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
11212 output_count++;
11213 }
11214 else
11215 filtered_count++;
11216 }
11217 }
11218 }
11219 }
11220 else
11221 {
11222 for (adj = rn->adj_out; adj; adj = adj->next)
11223 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
11224 if (paf->peer == peer)
11225 {
11226 if (header1)
11227 {
11228 if (use_json)
11229 {
11230 json_object_int_add(json, "bgpTableVersion", table->version);
11231 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11232 json_object_object_add(json, "bgpStatusCodes", json_scode);
11233 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11234 }
11235 else
11236 {
11237 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
11238 inet_ntoa (bgp->router_id), VTY_NEWLINE);
11239 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11240 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11241 }
11242 header1 = 0;
11243 }
11244
11245 if (header2)
11246 {
11247 if (!use_json)
11248 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
11249 header2 = 0;
11250 }
11251
11252 if (adj->attr)
11253 {
11254 bgp_attr_dup(&attr, adj->attr);
11255 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
11256 if (ret != RMAP_DENY)
11257 {
11258 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
11259 output_count++;
11260 }
11261 else
11262 filtered_count++;
11263 }
11264 }
11265 }
11266 }
11267 if (use_json)
11268 json_object_object_add(json, "advertisedRoutes", json_ar);
11269
11270 if (output_count != 0)
11271 {
11272 if (use_json)
11273 json_object_int_add(json, "totalPrefixCounter", output_count);
11274 else
11275 vty_out (vty, "%sTotal number of prefixes %ld%s",
11276 VTY_NEWLINE, output_count, VTY_NEWLINE);
11277 }
11278 if (use_json)
11279 {
11280 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11281 json_object_free(json);
11282 }
11283
11284 }
11285
11286 static int
11287 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
11288 int in, const char *rmap_name, u_char use_json)
11289 {
11290 json_object *json = NULL;
11291
11292 if (use_json)
11293 json = json_object_new_object();
11294
11295 if (!peer || !peer->afc[afi][safi])
11296 {
11297 if (use_json)
11298 {
11299 json_object_string_add(json, "warning", "No such neighbor or address family");
11300 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11301 json_object_free(json);
11302 }
11303 else
11304 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11305
11306 return CMD_WARNING;
11307 }
11308
11309 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11310 {
11311 if (use_json)
11312 {
11313 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
11314 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11315 json_object_free(json);
11316 }
11317 else
11318 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
11319
11320 return CMD_WARNING;
11321 }
11322
11323 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
11324
11325 return CMD_SUCCESS;
11326 }
11327
11328 DEFUN (show_ip_bgp_view_neighbor_advertised_route,
11329 show_ip_bgp_view_neighbor_advertised_route_cmd,
11330 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11331 SHOW_STR
11332 IP_STR
11333 BGP_STR
11334 "BGP view\n"
11335 "View name\n"
11336 "Detailed information on TCP and BGP neighbor connections\n"
11337 "Neighbor to display information about\n"
11338 "Neighbor to display information about\n"
11339 "Display the routes advertised to a BGP neighbor\n"
11340 "JavaScript Object Notation\n")
11341 {
11342 struct peer *peer;
11343 u_char uj = use_json(argc, argv);
11344
11345 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
11346 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
11347 else
11348 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11349
11350 if (! peer)
11351 return CMD_WARNING;
11352
11353 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
11354 }
11355
11356 DEFUN (show_ip_bgp_neighbor_advertised_route,
11357 show_ip_bgp_neighbor_advertised_route_cmd,
11358 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11359 SHOW_STR
11360 IP_STR
11361 BGP_STR
11362 "Detailed information on TCP and BGP neighbor connections\n"
11363 "Neighbor to display information about\n"
11364 "Neighbor to display information about\n"
11365 "Neighbor on bgp configured interface\n"
11366 "Display the routes advertised to a BGP neighbor\n"
11367 "JavaScript Object Notation\n")
11368
11369 {
11370 struct peer *peer;
11371 const char *rmap_name = NULL;
11372 u_char uj = use_json(argc, argv);
11373
11374 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11375
11376 if (! peer)
11377 return CMD_WARNING;
11378
11379 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
11380 || (argc == 3))
11381 rmap_name = argv[1];
11382
11383 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
11384 }
11385
11386 ALIAS (show_ip_bgp_neighbor_advertised_route,
11387 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
11388 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
11389 SHOW_STR
11390 IP_STR
11391 BGP_STR
11392 "Detailed information on TCP and BGP neighbor connections\n"
11393 "Neighbor to display information about\n"
11394 "Neighbor to display information about\n"
11395 "Neighbor on bgp configured interface\n"
11396 "Display the routes advertised to a BGP neighbor\n"
11397 "JavaScript Object Notation\n")
11398
11399 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
11400 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
11401 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11402 SHOW_STR
11403 IP_STR
11404 BGP_STR
11405 "Address family\n"
11406 "Address Family modifier\n"
11407 "Address Family modifier\n"
11408 "Detailed information on TCP and BGP neighbor connections\n"
11409 "Neighbor to display information about\n"
11410 "Neighbor to display information about\n"
11411 "Neighbor on bgp configured interface\n"
11412 "Display the routes advertised to a BGP neighbor\n"
11413 "JavaScript Object Notation\n")
11414 {
11415 struct peer *peer;
11416 const char *rmap_name = NULL;
11417 u_char uj = use_json(argc, argv);
11418
11419 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
11420 if (! peer)
11421 return CMD_WARNING;
11422
11423 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
11424 rmap_name = argv[2];
11425
11426 if (strncmp (argv[0], "m", 1) == 0)
11427 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj);
11428 else
11429 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
11430 }
11431
11432 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
11433 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
11434 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
11435 SHOW_STR
11436 IP_STR
11437 BGP_STR
11438 "Address family\n"
11439 "Address Family modifier\n"
11440 "Address Family modifier\n"
11441 "Detailed information on TCP and BGP neighbor connections\n"
11442 "Neighbor to display information about\n"
11443 "Neighbor to display information about\n"
11444 "Neighbor on bgp configured interface\n"
11445 "Display the routes advertised to a BGP neighbor\n"
11446 "Route-map to control what is displayed\n"
11447 "JavaScript Object Notation\n")
11448
11449 #ifdef HAVE_IPV6
11450 DEFUN (show_bgp_view_neighbor_advertised_route,
11451 show_bgp_view_neighbor_advertised_route_cmd,
11452 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11453 SHOW_STR
11454 BGP_STR
11455 "BGP view\n"
11456 "View name\n"
11457 "Detailed information on TCP and BGP neighbor connections\n"
11458 "Neighbor to display information about\n"
11459 "Neighbor to display information about\n"
11460 "Neighbor on bgp configured interface\n"
11461 "Display the routes advertised to a BGP neighbor\n"
11462 "JavaScript Object Notation\n")
11463 {
11464 struct peer *peer;
11465 u_char uj = use_json(argc, argv);
11466
11467 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
11468 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
11469 else
11470 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11471
11472 if (! peer)
11473 return CMD_WARNING;
11474
11475 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
11476 }
11477
11478 ALIAS (show_bgp_view_neighbor_advertised_route,
11479 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
11480 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11481 SHOW_STR
11482 BGP_STR
11483 "BGP view\n"
11484 "View name\n"
11485 "Address family\n"
11486 "Detailed information on TCP and BGP neighbor connections\n"
11487 "Neighbor to display information about\n"
11488 "Neighbor to display information about\n"
11489 "Neighbor on bgp configured interface\n"
11490 "Display the routes advertised to a BGP neighbor\n"
11491 "JavaScript Object Notation\n")
11492
11493 DEFUN (show_bgp_neighbor_advertised_route,
11494 show_bgp_neighbor_advertised_route_cmd,
11495 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11496 SHOW_STR
11497 BGP_STR
11498 "Detailed information on TCP and BGP neighbor connections\n"
11499 "Neighbor to display information about\n"
11500 "Neighbor to display information about\n"
11501 "Neighbor on bgp configured interface\n"
11502 "Display the routes advertised to a BGP neighbor\n"
11503 "JavaScript Object Notation\n")
11504
11505 {
11506 struct peer *peer;
11507 const char *rmap_name = NULL;
11508 u_char uj = use_json(argc, argv);
11509
11510 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11511
11512 if (!peer)
11513 return CMD_WARNING;
11514
11515 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
11516 rmap_name = argv[1];
11517
11518 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
11519 }
11520
11521 ALIAS (show_bgp_neighbor_advertised_route,
11522 show_bgp_ipv6_neighbor_advertised_route_cmd,
11523 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11524 SHOW_STR
11525 BGP_STR
11526 "Address family\n"
11527 "Detailed information on TCP and BGP neighbor connections\n"
11528 "Neighbor to display information about\n"
11529 "Neighbor to display information about\n"
11530 "Neighbor on bgp configured interface\n"
11531 "Display the routes advertised to a BGP neighbor\n"
11532 "JavaScript Object Notation\n")
11533
11534 /* old command */
11535 ALIAS (show_bgp_neighbor_advertised_route,
11536 ipv6_bgp_neighbor_advertised_route_cmd,
11537 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11538 SHOW_STR
11539 IPV6_STR
11540 BGP_STR
11541 "Detailed information on TCP and BGP neighbor connections\n"
11542 "Neighbor to display information about\n"
11543 "Neighbor to display information about\n"
11544 "Neighbor on bgp configured interface\n"
11545 "Display the routes advertised to a BGP neighbor\n"
11546 "JavaScript Object Notation\n")
11547
11548 /* old command */
11549 DEFUN (ipv6_mbgp_neighbor_advertised_route,
11550 ipv6_mbgp_neighbor_advertised_route_cmd,
11551 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11552 SHOW_STR
11553 IPV6_STR
11554 MBGP_STR
11555 "Detailed information on TCP and BGP neighbor connections\n"
11556 "Neighbor to display information about\n"
11557 "Neighbor to display information about\n"
11558 "Neighbor on bgp configured interface\n"
11559 "Neighbor on bgp configured interface\n"
11560 "Display the routes advertised to a BGP neighbor\n"
11561 "JavaScript Object Notation\n")
11562 {
11563 struct peer *peer;
11564 u_char uj = use_json(argc, argv);
11565
11566 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11567 if (! peer)
11568 return CMD_WARNING;
11569
11570 bgp_show_ipv6_bgp_deprecate_warning(vty);
11571 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
11572 }
11573 #endif /* HAVE_IPV6 */
11574
11575 DEFUN (show_bgp_view_neighbor_received_routes,
11576 show_bgp_view_neighbor_received_routes_cmd,
11577 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
11578 SHOW_STR
11579 BGP_STR
11580 "BGP view\n"
11581 "View name\n"
11582 "Detailed information on TCP and BGP neighbor connections\n"
11583 "Neighbor to display information about\n"
11584 "Neighbor to display information about\n"
11585 "Neighbor on bgp configured interface\n"
11586 "Display the received routes from neighbor\n"
11587 "JavaScript Object Notation\n")
11588 {
11589 struct peer *peer;
11590 u_char uj = use_json(argc, argv);
11591
11592 if (uj)
11593 {
11594 if (argc == 3)
11595 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
11596 else
11597 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11598 }
11599 else
11600 {
11601 if (argc == 2)
11602 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
11603 else
11604 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11605 }
11606
11607 if (! peer)
11608 return CMD_WARNING;
11609
11610 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
11611 }
11612
11613 DEFUN (show_ip_bgp_view_neighbor_received_routes,
11614 show_ip_bgp_view_neighbor_received_routes_cmd,
11615 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
11616 SHOW_STR
11617 IP_STR
11618 BGP_STR
11619 "BGP view\n"
11620 "View name\n"
11621 "Detailed information on TCP and BGP neighbor connections\n"
11622 "Neighbor to display information about\n"
11623 "Neighbor to display information about\n"
11624 "Neighbor on bgp configured interface\n"
11625 "Display the received routes from neighbor\n"
11626 "JavaScript Object Notation\n")
11627 {
11628 struct peer *peer;
11629 u_char uj = use_json(argc, argv);
11630
11631 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
11632 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
11633 else
11634 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11635
11636 if (! peer)
11637 return CMD_WARNING;
11638
11639 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
11640 }
11641
11642 ALIAS (show_bgp_view_neighbor_received_routes,
11643 show_bgp_view_ipv6_neighbor_received_routes_cmd,
11644 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
11645 SHOW_STR
11646 BGP_STR
11647 "BGP view\n"
11648 "View name\n"
11649 "Address family\n"
11650 "Detailed information on TCP and BGP neighbor connections\n"
11651 "Neighbor to display information about\n"
11652 "Neighbor to display information about\n"
11653 "Neighbor on bgp configured interface\n"
11654 "Display the received routes from neighbor\n"
11655 "JavaScript Object Notation\n")
11656
11657 DEFUN (show_ip_bgp_neighbor_received_routes,
11658 show_ip_bgp_neighbor_received_routes_cmd,
11659 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
11660 SHOW_STR
11661 IP_STR
11662 BGP_STR
11663 "Detailed information on TCP and BGP neighbor connections\n"
11664 "Neighbor to display information about\n"
11665 "Neighbor to display information about\n"
11666 "Neighbor on bgp configured interface\n"
11667 "Display the received routes from neighbor\n"
11668 "JavaScript Object Notation\n")
11669
11670 {
11671 struct peer *peer;
11672 const char *rmap_name = NULL;
11673 u_char uj = use_json(argc, argv);
11674
11675 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11676
11677 if (! peer)
11678 return CMD_WARNING;
11679
11680 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
11681 rmap_name = argv[1];
11682
11683 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
11684 }
11685
11686 ALIAS (show_ip_bgp_neighbor_received_routes,
11687 show_ip_bgp_neighbor_received_routes_rmap_cmd,
11688 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
11689 SHOW_STR
11690 IP_STR
11691 BGP_STR
11692 "Detailed information on TCP and BGP neighbor connections\n"
11693 "Neighbor to display information about\n"
11694 "Neighbor to display information about\n"
11695 "Neighbor on bgp configured interface\n"
11696 "Display the received routes from neighbor\n"
11697 "JavaScript Object Notation\n")
11698
11699 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
11700 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
11701 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
11702 SHOW_STR
11703 IP_STR
11704 BGP_STR
11705 "Address family\n"
11706 "Address Family modifier\n"
11707 "Address Family modifier\n"
11708 "Detailed information on TCP and BGP neighbor connections\n"
11709 "Neighbor to display information about\n"
11710 "Neighbor to display information about\n"
11711 "Neighbor on bgp configured interface\n"
11712 "Display the received routes from neighbor\n"
11713 "JavaScript Object Notation\n")
11714 {
11715 struct peer *peer;
11716 const char *rmap_name = NULL;
11717 u_char uj = use_json(argc, argv);
11718
11719 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
11720 if (! peer)
11721 return CMD_WARNING;
11722
11723 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
11724 rmap_name = argv[2];
11725
11726 if (strncmp (argv[0], "m", 1) == 0)
11727 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj);
11728 else
11729 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
11730 }
11731
11732 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
11733 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
11734 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
11735 SHOW_STR
11736 IP_STR
11737 BGP_STR
11738 "Address family\n"
11739 "Address Family modifier\n"
11740 "Address Family modifier\n"
11741 "Detailed information on TCP and BGP neighbor connections\n"
11742 "Neighbor to display information about\n"
11743 "Neighbor to display information about\n"
11744 "Neighbor on bgp configured interface\n"
11745 "Display the received routes from neighbor\n"
11746 "JavaScript Object Notation\n")
11747
11748 DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
11749 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
11750 #ifdef HAVE_IPV6
11751 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
11752 #else
11753 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
11754 #endif
11755 SHOW_STR
11756 BGP_STR
11757 "BGP view\n"
11758 "View name\n"
11759 "Address family\n"
11760 #ifdef HAVE_IPV6
11761 "Address family\n"
11762 #endif
11763 "Address family modifier\n"
11764 "Address family modifier\n"
11765 "Detailed information on TCP and BGP neighbor connections\n"
11766 "Neighbor to display information about\n"
11767 "Neighbor to display information about\n"
11768 "Neighbor on bgp configured interface\n"
11769 "Display the advertised routes to neighbor\n"
11770 "Display the received routes from neighbor\n"
11771 "JavaScript Object Notation\n")
11772 {
11773 int afi;
11774 int safi;
11775 int in;
11776 struct peer *peer;
11777 u_char uj = use_json(argc, argv);
11778
11779 peer = peer_lookup_in_view (vty, argv[0], argv[3], uj);
11780
11781 if (! peer)
11782 return CMD_WARNING;
11783
11784 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
11785 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11786 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
11787
11788 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
11789 }
11790
11791 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
11792 show_ip_bgp_neighbor_received_prefix_filter_cmd,
11793 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
11794 SHOW_STR
11795 IP_STR
11796 BGP_STR
11797 "Detailed information on TCP and BGP neighbor connections\n"
11798 "Neighbor to display information about\n"
11799 "Neighbor to display information about\n"
11800 "Neighbor on bgp configured interface\n"
11801 "Display information received from a BGP neighbor\n"
11802 "Display the prefixlist filter\n"
11803 "JavaScript Object Notation\n")
11804 {
11805 char name[BUFSIZ];
11806 union sockunion su;
11807 struct peer *peer;
11808 int count, ret;
11809 u_char uj = use_json(argc, argv);
11810
11811 ret = str2sockunion (argv[0], &su);
11812 if (ret < 0)
11813 {
11814 peer = peer_lookup_by_conf_if (NULL, argv[0]);
11815 if (! peer)
11816 {
11817 if (uj)
11818 {
11819 json_object *json_no = NULL;
11820 json_object *json_sub = NULL;
11821 json_no = json_object_new_object();
11822 json_sub = json_object_new_object();
11823 json_object_string_add(json_no, "warning", "Malformed address or name");
11824 json_object_string_add(json_sub, "warningCause", argv[0]);
11825 json_object_object_add(json_no, "detail", json_sub);
11826 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11827 json_object_free(json_no);
11828 }
11829 else
11830 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
11831 return CMD_WARNING;
11832 }
11833 }
11834 else
11835 {
11836 peer = peer_lookup (NULL, &su);
11837 if (! peer)
11838 {
11839 if (uj)
11840 {
11841 json_object *json_no = NULL;
11842 json_no = json_object_new_object();
11843 json_object_string_add(json_no, "warning", "Peer not found");
11844 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11845 json_object_free(json_no);
11846 }
11847 else
11848 vty_out (vty, "No peer%s", VTY_NEWLINE);
11849 return CMD_WARNING;
11850 }
11851 }
11852
11853 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
11854 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
11855 if (count)
11856 {
11857 if (!uj)
11858 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
11859 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
11860 }
11861 else
11862 {
11863 if (uj)
11864 {
11865 json_object *json_no = NULL;
11866 json_no = json_object_new_object();
11867 json_object_boolean_true_add(json_no, "noFuntionalOutput");
11868 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11869 json_object_free(json_no);
11870 }
11871 else
11872 vty_out (vty, "No functional output%s", VTY_NEWLINE);
11873 }
11874
11875 return CMD_SUCCESS;
11876 }
11877
11878 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
11879 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
11880 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
11881 SHOW_STR
11882 IP_STR
11883 BGP_STR
11884 "Address family\n"
11885 "Address Family modifier\n"
11886 "Address Family modifier\n"
11887 "Detailed information on TCP and BGP neighbor connections\n"
11888 "Neighbor to display information about\n"
11889 "Neighbor to display information about\n"
11890 "Neighbor on bgp configured interface\n"
11891 "Display information received from a BGP neighbor\n"
11892 "Display the prefixlist filter\n"
11893 "JavaScript Object Notation\n")
11894 {
11895 char name[BUFSIZ];
11896 union sockunion su;
11897 struct peer *peer;
11898 int count, ret;
11899 u_char uj = use_json(argc, argv);
11900
11901 ret = str2sockunion (argv[1], &su);
11902 if (ret < 0)
11903 {
11904 peer = peer_lookup_by_conf_if (NULL, argv[1]);
11905 if (! peer)
11906 {
11907 if (uj)
11908 {
11909 json_object *json_no = NULL;
11910 json_object *json_sub = NULL;
11911 json_no = json_object_new_object();
11912 json_sub = json_object_new_object();
11913 json_object_string_add(json_no, "warning", "Malformed address or name");
11914 json_object_string_add(json_sub, "warningCause", argv[1]);
11915 json_object_object_add(json_no, "detail", json_sub);
11916 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11917 json_object_free(json_no);
11918 }
11919 else
11920 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
11921 return CMD_WARNING;
11922 }
11923 }
11924 else
11925 {
11926 peer = peer_lookup (NULL, &su);
11927 if (! peer)
11928 {
11929 if (uj)
11930 {
11931 json_object *json_no = NULL;
11932 json_no = json_object_new_object();
11933 json_object_string_add(json_no, "warning", "Peer not found");
11934 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11935 json_object_free(json_no);
11936 }
11937 else
11938 vty_out (vty, "No peer%s", VTY_NEWLINE);
11939 return CMD_WARNING;
11940 }
11941 }
11942
11943 if (strncmp (argv[0], "m", 1) == 0)
11944 {
11945 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
11946 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
11947 if (count)
11948 {
11949 if (!uj)
11950 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
11951 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
11952 }
11953 else
11954 {
11955 if (uj)
11956 {
11957 json_object *json_no = NULL;
11958 json_no = json_object_new_object();
11959 json_object_boolean_true_add(json_no, "noFuntionalOutput");
11960 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11961 json_object_free(json_no);
11962 }
11963 else
11964 vty_out (vty, "No functional output%s", VTY_NEWLINE);
11965 }
11966 }
11967 else
11968 {
11969 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
11970 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
11971 if (count)
11972 {
11973 if (!uj)
11974 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
11975 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
11976 }
11977 else
11978 {
11979 if (uj)
11980 {
11981 json_object *json_no = NULL;
11982 json_no = json_object_new_object();
11983 json_object_boolean_true_add(json_no, "noFuntionalOutput");
11984 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11985 json_object_free(json_no);
11986 }
11987 else
11988 vty_out (vty, "No functional output%s", VTY_NEWLINE);
11989 }
11990 }
11991
11992 return CMD_SUCCESS;
11993 }
11994 #ifdef HAVE_IPV6
11995 ALIAS (show_bgp_view_neighbor_received_routes,
11996 show_bgp_neighbor_received_routes_cmd,
11997 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
11998 SHOW_STR
11999 BGP_STR
12000 "Detailed information on TCP and BGP neighbor connections\n"
12001 "Neighbor to display information about\n"
12002 "Neighbor to display information about\n"
12003 "Neighbor on bgp configured interface\n"
12004 "Display the received routes from neighbor\n"
12005 "JavaScript Object Notation\n")
12006
12007 ALIAS (show_bgp_view_neighbor_received_routes,
12008 show_bgp_ipv6_neighbor_received_routes_cmd,
12009 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12010 SHOW_STR
12011 BGP_STR
12012 "Address family\n"
12013 "Detailed information on TCP and BGP neighbor connections\n"
12014 "Neighbor to display information about\n"
12015 "Neighbor to display information about\n"
12016 "Neighbor on bgp configured interface\n"
12017 "Display the received routes from neighbor\n"
12018 "JavaScript Object Notation\n")
12019
12020 DEFUN (show_bgp_neighbor_received_prefix_filter,
12021 show_bgp_neighbor_received_prefix_filter_cmd,
12022 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12023 SHOW_STR
12024 BGP_STR
12025 "Detailed information on TCP and BGP neighbor connections\n"
12026 "Neighbor to display information about\n"
12027 "Neighbor to display information about\n"
12028 "Neighbor on bgp configured interface\n"
12029 "Display information received from a BGP neighbor\n"
12030 "Display the prefixlist filter\n"
12031 "JavaScript Object Notation\n")
12032 {
12033 char name[BUFSIZ];
12034 union sockunion su;
12035 struct peer *peer;
12036 int count, ret;
12037 u_char uj = use_json(argc, argv);
12038
12039 ret = str2sockunion (argv[0], &su);
12040 if (ret < 0)
12041 {
12042 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12043 if (! peer)
12044 {
12045 if (uj)
12046 {
12047 json_object *json_no = NULL;
12048 json_object *json_sub = NULL;
12049 json_no = json_object_new_object();
12050 json_sub = json_object_new_object();
12051 json_object_string_add(json_no, "warning", "Malformed address or name");
12052 json_object_string_add(json_sub, "warningCause", argv[0]);
12053 json_object_object_add(json_no, "detail", json_sub);
12054 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12055 json_object_free(json_no);
12056 }
12057 else
12058 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12059 return CMD_WARNING;
12060 }
12061 }
12062 else
12063 {
12064 peer = peer_lookup (NULL, &su);
12065 if (! peer)
12066 {
12067 if (uj)
12068 {
12069 json_object *json_no = NULL;
12070 json_no = json_object_new_object();
12071 json_object_string_add(json_no, "warning", "No Peer");
12072 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12073 json_object_free(json_no);
12074 }
12075 else
12076 vty_out (vty, "No peer%s", VTY_NEWLINE);
12077 return CMD_WARNING;
12078 }
12079 }
12080
12081 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12082 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
12083 if (count)
12084 {
12085 if (!uj)
12086 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12087 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
12088 }
12089 else
12090 {
12091 if (uj)
12092 {
12093 json_object *json_no = NULL;
12094 json_no = json_object_new_object();
12095 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12096 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12097 json_object_free(json_no);
12098 }
12099 else
12100 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12101 }
12102
12103 return CMD_SUCCESS;
12104 }
12105
12106 ALIAS (show_bgp_neighbor_received_prefix_filter,
12107 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
12108 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12109 SHOW_STR
12110 BGP_STR
12111 "Address family\n"
12112 "Detailed information on TCP and BGP neighbor connections\n"
12113 "Neighbor to display information about\n"
12114 "Neighbor to display information about\n"
12115 "Neighbor on bgp configured interface\n"
12116 "Display information received from a BGP neighbor\n"
12117 "Display the prefixlist filter\n"
12118 "JavaScript Object Notation\n")
12119
12120 /* old command */
12121 ALIAS (show_bgp_view_neighbor_received_routes,
12122 ipv6_bgp_neighbor_received_routes_cmd,
12123 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12124 SHOW_STR
12125 IPV6_STR
12126 BGP_STR
12127 "Detailed information on TCP and BGP neighbor connections\n"
12128 "Neighbor to display information about\n"
12129 "Neighbor to display information about\n"
12130 "Neighbor on bgp configured interface\n"
12131 "Display the received routes from neighbor\n"
12132 "JavaScript Object Notation\n")
12133
12134 /* old command */
12135 DEFUN (ipv6_mbgp_neighbor_received_routes,
12136 ipv6_mbgp_neighbor_received_routes_cmd,
12137 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12138 SHOW_STR
12139 IPV6_STR
12140 MBGP_STR
12141 "Detailed information on TCP and BGP neighbor connections\n"
12142 "Neighbor to display information about\n"
12143 "Neighbor to display information about\n"
12144 "Neighbor on bgp configured interface\n"
12145 "Display the received routes from neighbor\n"
12146 "JavaScript Object Notation\n")
12147 {
12148 struct peer *peer;
12149 u_char uj = use_json(argc, argv);
12150
12151 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12152 if (! peer)
12153 return CMD_WARNING;
12154
12155 bgp_show_ipv6_bgp_deprecate_warning(vty);
12156 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
12157 }
12158
12159 DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12160 show_bgp_view_neighbor_received_prefix_filter_cmd,
12161 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12162 SHOW_STR
12163 BGP_STR
12164 "BGP view\n"
12165 "View name\n"
12166 "Detailed information on TCP and BGP neighbor connections\n"
12167 "Neighbor to display information about\n"
12168 "Neighbor to display information about\n"
12169 "Neighbor on bgp configured interface\n"
12170 "Display information received from a BGP neighbor\n"
12171 "Display the prefixlist filter\n"
12172 "JavaScript Object Notation\n")
12173 {
12174 char name[BUFSIZ];
12175 union sockunion su;
12176 struct peer *peer;
12177 struct bgp *bgp;
12178 int count, ret;
12179 u_char uj = use_json(argc, argv);
12180
12181 /* BGP structure lookup. */
12182 bgp = bgp_lookup_by_name (argv[0]);
12183 if (bgp == NULL)
12184 {
12185 if (uj)
12186 {
12187 json_object *json_no = NULL;
12188 json_no = json_object_new_object();
12189 json_object_string_add(json_no, "warning", "Can't find BGP view");
12190 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12191 json_object_free(json_no);
12192 }
12193 else
12194 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12195 return CMD_WARNING;
12196 }
12197
12198 ret = str2sockunion (argv[1], &su);
12199 if (ret < 0)
12200 {
12201 peer = peer_lookup_by_conf_if (bgp, argv[1]);
12202 if (! peer)
12203 {
12204 if (uj)
12205 {
12206 json_object *json_no = NULL;
12207 json_object *json_sub = NULL;
12208 json_no = json_object_new_object();
12209 json_sub = json_object_new_object();
12210 json_object_string_add(json_no, "warning", "Malformed address or name");
12211 json_object_string_add(json_sub, "warningCause", argv[1]);
12212 json_object_object_add(json_no, "detail", json_sub);
12213 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12214 json_object_free(json_no);
12215 }
12216 else
12217 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12218 return CMD_WARNING;
12219 }
12220 }
12221 else
12222 {
12223 peer = peer_lookup (bgp, &su);
12224 if (! peer)
12225 {
12226 if (uj)
12227 {
12228 json_object *json_no = NULL;
12229 json_no = json_object_new_object();
12230 json_object_boolean_true_add(json_no, "noPeer");
12231 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12232 json_object_free(json_no);
12233 }
12234 else
12235 vty_out (vty, "No peer%s", VTY_NEWLINE);
12236 return CMD_WARNING;
12237 }
12238
12239 }
12240
12241 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12242 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
12243 if (count)
12244 {
12245 if (!uj)
12246 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12247 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
12248 }
12249
12250 return CMD_SUCCESS;
12251 }
12252 ALIAS (show_bgp_view_neighbor_received_prefix_filter,
12253 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
12254 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12255 SHOW_STR
12256 BGP_STR
12257 "BGP view\n"
12258 "View name\n"
12259 "Address family\n"
12260 "Detailed information on TCP and BGP neighbor connections\n"
12261 "Neighbor to display information about\n"
12262 "Neighbor to display information about\n"
12263 "Neighbor on bgp configured interface\n"
12264 "Display information received from a BGP neighbor\n"
12265 "Display the prefixlist filter\n"
12266 "JavaScript Object NOtation\n")
12267 #endif /* HAVE_IPV6 */
12268
12269 static int
12270 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
12271 safi_t safi, enum bgp_show_type type, u_char use_json)
12272 {
12273 if (! peer || ! peer->afc[afi][safi])
12274 {
12275 if (use_json)
12276 {
12277 json_object *json_no = NULL;
12278 json_no = json_object_new_object();
12279 json_object_string_add(json_no, "warning", "No such neighbor or address family");
12280 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12281 json_object_free(json_no);
12282 }
12283 else
12284 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12285 return CMD_WARNING;
12286 }
12287
12288 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
12289 }
12290
12291 DEFUN (show_ip_bgp_neighbor_routes,
12292 show_ip_bgp_neighbor_routes_cmd,
12293 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12294 SHOW_STR
12295 IP_STR
12296 BGP_STR
12297 "Detailed information on TCP and BGP neighbor connections\n"
12298 "Neighbor to display information about\n"
12299 "Neighbor to display information about\n"
12300 "Neighbor on bgp configured interface\n"
12301 "Display routes learned from neighbor\n"
12302 "JavaScript Object Notation\n")
12303 {
12304 struct peer *peer;
12305 u_char uj = use_json(argc, argv);
12306
12307 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12308 if (! peer)
12309 return CMD_WARNING;
12310
12311 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12312 bgp_show_type_neighbor, uj);
12313 }
12314
12315 DEFUN (show_ip_bgp_neighbor_flap,
12316 show_ip_bgp_neighbor_flap_cmd,
12317 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
12318 SHOW_STR
12319 IP_STR
12320 BGP_STR
12321 "Detailed information on TCP and BGP neighbor connections\n"
12322 "Neighbor to display information about\n"
12323 "Neighbor to display information about\n"
12324 "Neighbor on bgp configured interface\n"
12325 "Display flap statistics of the routes learned from neighbor\n"
12326 "JavaScript Object Notation\n")
12327 {
12328 struct peer *peer;
12329 u_char uj = use_json(argc, argv);
12330
12331 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12332 if (! peer)
12333 return CMD_WARNING;
12334
12335 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12336 bgp_show_type_flap_neighbor, uj);
12337 }
12338
12339 DEFUN (show_ip_bgp_neighbor_damp,
12340 show_ip_bgp_neighbor_damp_cmd,
12341 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
12342 SHOW_STR
12343 IP_STR
12344 BGP_STR
12345 "Detailed information on TCP and BGP neighbor connections\n"
12346 "Neighbor to display information about\n"
12347 "Neighbor to display information about\n"
12348 "Neighbor on bgp configured interface\n"
12349 "Display the dampened routes received from neighbor\n"
12350 "JavaScript Object Notation\n")
12351 {
12352 struct peer *peer;
12353 u_char uj = use_json(argc, argv);
12354
12355 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12356 if (! peer)
12357 return CMD_WARNING;
12358
12359 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12360 bgp_show_type_damp_neighbor, uj);
12361 }
12362
12363 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
12364 show_ip_bgp_ipv4_neighbor_routes_cmd,
12365 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12366 SHOW_STR
12367 IP_STR
12368 BGP_STR
12369 "Address family\n"
12370 "Address Family modifier\n"
12371 "Address Family modifier\n"
12372 "Detailed information on TCP and BGP neighbor connections\n"
12373 "Neighbor to display information about\n"
12374 "Neighbor to display information about\n"
12375 "Neighbor on bgp configured interface\n"
12376 "Display routes learned from neighbor\n"
12377 "JavaScript Object Notation\n")
12378 {
12379 struct peer *peer;
12380 u_char uj = use_json(argc, argv);
12381
12382 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12383 if (! peer)
12384 return CMD_WARNING;
12385
12386 if (strncmp (argv[0], "m", 1) == 0)
12387 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
12388 bgp_show_type_neighbor, uj);
12389
12390 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12391 bgp_show_type_neighbor, uj);
12392 }
12393
12394 #ifdef HAVE_IPV6
12395 DEFUN (show_bgp_view_neighbor_routes,
12396 show_bgp_view_neighbor_routes_cmd,
12397 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12398 SHOW_STR
12399 BGP_STR
12400 "BGP view\n"
12401 "View name\n"
12402 "Detailed information on TCP and BGP neighbor connections\n"
12403 "Neighbor to display information about\n"
12404 "Neighbor to display information about\n"
12405 "Neighbor on bgp configured interface\n"
12406 "Display routes learned from neighbor\n"
12407 "JavaScript Object Notation\n")
12408 {
12409 struct peer *peer;
12410 u_char uj = use_json(argc, argv);
12411
12412 if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
12413 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12414 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
12415 else
12416 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12417
12418 if (! peer)
12419 return CMD_WARNING;
12420
12421 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12422 bgp_show_type_neighbor, uj);
12423 }
12424
12425 ALIAS (show_bgp_view_neighbor_routes,
12426 show_bgp_view_ipv6_neighbor_routes_cmd,
12427 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12428 SHOW_STR
12429 BGP_STR
12430 "BGP view\n"
12431 "View name\n"
12432 "Address family\n"
12433 "Detailed information on TCP and BGP neighbor connections\n"
12434 "Neighbor to display information about\n"
12435 "Neighbor to display information about\n"
12436 "Neighbor on bgp configured interface\n"
12437 "Display routes learned from neighbor\n"
12438 "JavaScript Object Notation\n")
12439
12440 DEFUN (show_bgp_view_neighbor_damp,
12441 show_bgp_view_neighbor_damp_cmd,
12442 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
12443 SHOW_STR
12444 BGP_STR
12445 "BGP view\n"
12446 "View name\n"
12447 "Detailed information on TCP and BGP neighbor connections\n"
12448 "Neighbor to display information about\n"
12449 "Neighbor to display information about\n"
12450 "Neighbor on bgp configured interface\n"
12451 "Display the dampened routes received from neighbor\n"
12452 "JavaScript Object Notation\n")
12453 {
12454 struct peer *peer;
12455 u_char uj = use_json(argc, argv);
12456
12457 if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
12458 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12459 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
12460 else
12461 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12462
12463 if (! peer)
12464 return CMD_WARNING;
12465
12466 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12467 bgp_show_type_damp_neighbor, uj);
12468 }
12469
12470 ALIAS (show_bgp_view_neighbor_damp,
12471 show_bgp_view_ipv6_neighbor_damp_cmd,
12472 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
12473 SHOW_STR
12474 BGP_STR
12475 "BGP view\n"
12476 "View name\n"
12477 "Address family\n"
12478 "Detailed information on TCP and BGP neighbor connections\n"
12479 "Neighbor to display information about\n"
12480 "Neighbor to display information about\n"
12481 "Neighbor on bgp configured interface\n"
12482 "Display the dampened routes received from neighbor\n"
12483 "JavaScript Object Notation\n")
12484
12485 DEFUN (show_bgp_view_neighbor_flap,
12486 show_bgp_view_neighbor_flap_cmd,
12487 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
12488 SHOW_STR
12489 BGP_STR
12490 "BGP view\n"
12491 "View name\n"
12492 "Detailed information on TCP and BGP neighbor connections\n"
12493 "Neighbor to display information about\n"
12494 "Neighbor to display information about\n"
12495 "Neighbor on bgp configured interface\n"
12496 "Display flap statistics of the routes learned from neighbor\n"
12497 "JavaScript Object Notation\n")
12498 {
12499 struct peer *peer;
12500 u_char uj = use_json(argc, argv);
12501
12502 if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
12503 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12504 peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
12505 else
12506 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12507
12508 if (! peer)
12509 return CMD_WARNING;
12510
12511 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12512 bgp_show_type_flap_neighbor, uj);
12513 }
12514
12515 ALIAS (show_bgp_view_neighbor_flap,
12516 show_bgp_view_ipv6_neighbor_flap_cmd,
12517 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
12518 SHOW_STR
12519 BGP_STR
12520 "BGP view\n"
12521 "View name\n"
12522 "Address family\n"
12523 "Detailed information on TCP and BGP neighbor connections\n"
12524 "Neighbor to display information about\n"
12525 "Neighbor to display information about\n"
12526 "Neighbor on bgp configured interface\n"
12527 "Display flap statistics of the routes learned from neighbor\n"
12528 "JavaScript Object Notation\n")
12529
12530 ALIAS (show_bgp_view_neighbor_routes,
12531 show_bgp_neighbor_routes_cmd,
12532 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12533 SHOW_STR
12534 BGP_STR
12535 "Detailed information on TCP and BGP neighbor connections\n"
12536 "Neighbor to display information about\n"
12537 "Neighbor to display information about\n"
12538 "Neighbor on bgp configured interface\n"
12539 "Display routes learned from neighbor\n"
12540 "JavaScript Object Notation\n")
12541
12542
12543 ALIAS (show_bgp_view_neighbor_routes,
12544 show_bgp_ipv6_neighbor_routes_cmd,
12545 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12546 SHOW_STR
12547 BGP_STR
12548 "Address family\n"
12549 "Detailed information on TCP and BGP neighbor connections\n"
12550 "Neighbor to display information about\n"
12551 "Neighbor to display information about\n"
12552 "Neighbor on bgp configured interface\n"
12553 "Display routes learned from neighbor\n"
12554 "JavaScript Object Notation\n")
12555
12556 /* old command */
12557 ALIAS (show_bgp_view_neighbor_routes,
12558 ipv6_bgp_neighbor_routes_cmd,
12559 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12560 SHOW_STR
12561 IPV6_STR
12562 BGP_STR
12563 "Detailed information on TCP and BGP neighbor connections\n"
12564 "Neighbor to display information about\n"
12565 "Neighbor to display information about\n"
12566 "Neighbor on bgp configured interface\n"
12567 "Display routes learned from neighbor\n"
12568 "JavaScript Object Notation\n")
12569
12570 /* old command */
12571 DEFUN (ipv6_mbgp_neighbor_routes,
12572 ipv6_mbgp_neighbor_routes_cmd,
12573 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12574 SHOW_STR
12575 IPV6_STR
12576 MBGP_STR
12577 "Detailed information on TCP and BGP neighbor connections\n"
12578 "Neighbor to display information about\n"
12579 "Neighbor to display information about\n"
12580 "Neighbor on bgp configured interface\n"
12581 "Display routes learned from neighbor\n"
12582 "JavaScript Object Notation\n")
12583 {
12584 struct peer *peer;
12585 u_char uj = use_json(argc, argv);
12586
12587 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12588 if (! peer)
12589 return CMD_WARNING;
12590
12591 bgp_show_ipv6_bgp_deprecate_warning(vty);
12592 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
12593 bgp_show_type_neighbor, uj);
12594 }
12595
12596 ALIAS (show_bgp_view_neighbor_flap,
12597 show_bgp_neighbor_flap_cmd,
12598 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
12599 SHOW_STR
12600 BGP_STR
12601 "Detailed information on TCP and BGP neighbor connections\n"
12602 "Neighbor to display information about\n"
12603 "Neighbor to display information about\n"
12604 "Neighbor on bgp configured interface\n"
12605 "Display flap statistics of the routes learned from neighbor\n"
12606 "JavaScript Object Notation\n")
12607
12608 ALIAS (show_bgp_view_neighbor_flap,
12609 show_bgp_ipv6_neighbor_flap_cmd,
12610 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
12611 SHOW_STR
12612 BGP_STR
12613 "Address family\n"
12614 "Detailed information on TCP and BGP neighbor connections\n"
12615 "Neighbor to display information about\n"
12616 "Neighbor to display information about\n"
12617 "Neighbor on bgp configured interface\n"
12618 "Display flap statistics of the routes learned from neighbor\n"
12619 "JavaScript Object Notation\n")
12620
12621 ALIAS (show_bgp_view_neighbor_damp,
12622 show_bgp_neighbor_damp_cmd,
12623 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
12624 SHOW_STR
12625 BGP_STR
12626 "Detailed information on TCP and BGP neighbor connections\n"
12627 "Neighbor to display information about\n"
12628 "Neighbor to display information about\n"
12629 "Neighbor on bgp configured interface\n"
12630 "Display the dampened routes received from neighbor\n"
12631 "JavaScript Object Notation\n")
12632
12633 ALIAS (show_bgp_view_neighbor_damp,
12634 show_bgp_ipv6_neighbor_damp_cmd,
12635 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
12636 SHOW_STR
12637 BGP_STR
12638 "Address family\n"
12639 "Detailed information on TCP and BGP neighbor connections\n"
12640 "Neighbor to display information about\n"
12641 "Neighbor to display information about\n"
12642 "Neighbor on bgp configured interface\n"
12643 "Display the dampened routes received from neighbor\n"
12644 "JavaScript Object Notation\n")
12645
12646 #endif /* HAVE_IPV6 */
12647
12648 struct bgp_table *bgp_distance_table;
12649
12650 struct bgp_distance
12651 {
12652 /* Distance value for the IP source prefix. */
12653 u_char distance;
12654
12655 /* Name of the access-list to be matched. */
12656 char *access_list;
12657 };
12658
12659 static struct bgp_distance *
12660 bgp_distance_new (void)
12661 {
12662 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
12663 }
12664
12665 static void
12666 bgp_distance_free (struct bgp_distance *bdistance)
12667 {
12668 XFREE (MTYPE_BGP_DISTANCE, bdistance);
12669 }
12670
12671 static int
12672 bgp_distance_set (struct vty *vty, const char *distance_str,
12673 const char *ip_str, const char *access_list_str)
12674 {
12675 int ret;
12676 struct prefix_ipv4 p;
12677 u_char distance;
12678 struct bgp_node *rn;
12679 struct bgp_distance *bdistance;
12680
12681 ret = str2prefix_ipv4 (ip_str, &p);
12682 if (ret == 0)
12683 {
12684 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12685 return CMD_WARNING;
12686 }
12687
12688 distance = atoi (distance_str);
12689
12690 /* Get BGP distance node. */
12691 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
12692 if (rn->info)
12693 {
12694 bdistance = rn->info;
12695 bgp_unlock_node (rn);
12696 }
12697 else
12698 {
12699 bdistance = bgp_distance_new ();
12700 rn->info = bdistance;
12701 }
12702
12703 /* Set distance value. */
12704 bdistance->distance = distance;
12705
12706 /* Reset access-list configuration. */
12707 if (bdistance->access_list)
12708 {
12709 XFREE(MTYPE_AS_LIST, bdistance->access_list);
12710 bdistance->access_list = NULL;
12711 }
12712 if (access_list_str)
12713 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
12714
12715 return CMD_SUCCESS;
12716 }
12717
12718 static int
12719 bgp_distance_unset (struct vty *vty, const char *distance_str,
12720 const char *ip_str, const char *access_list_str)
12721 {
12722 int ret;
12723 struct prefix_ipv4 p;
12724 struct bgp_node *rn;
12725 struct bgp_distance *bdistance;
12726
12727 ret = str2prefix_ipv4 (ip_str, &p);
12728 if (ret == 0)
12729 {
12730 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12731 return CMD_WARNING;
12732 }
12733
12734 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
12735 if (! rn)
12736 {
12737 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
12738 return CMD_WARNING;
12739 }
12740
12741 bdistance = rn->info;
12742
12743 if (bdistance->access_list)
12744 XFREE(MTYPE_AS_LIST, bdistance->access_list);
12745 bgp_distance_free (bdistance);
12746
12747 rn->info = NULL;
12748 bgp_unlock_node (rn);
12749 bgp_unlock_node (rn);
12750
12751 return CMD_SUCCESS;
12752 }
12753
12754 /* Apply BGP information to distance method. */
12755 u_char
12756 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
12757 {
12758 struct bgp_node *rn;
12759 struct prefix_ipv4 q;
12760 struct peer *peer;
12761 struct bgp_distance *bdistance;
12762 struct access_list *alist;
12763 struct bgp_static *bgp_static;
12764
12765 if (! bgp)
12766 return 0;
12767
12768 if (p->family != AF_INET)
12769 return 0;
12770
12771 peer = rinfo->peer;
12772
12773 if (peer->su.sa.sa_family != AF_INET)
12774 return 0;
12775
12776 memset (&q, 0, sizeof (struct prefix_ipv4));
12777 q.family = AF_INET;
12778 q.prefix = peer->su.sin.sin_addr;
12779 q.prefixlen = IPV4_MAX_BITLEN;
12780
12781 /* Check source address. */
12782 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
12783 if (rn)
12784 {
12785 bdistance = rn->info;
12786 bgp_unlock_node (rn);
12787
12788 if (bdistance->access_list)
12789 {
12790 alist = access_list_lookup (AFI_IP, bdistance->access_list);
12791 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
12792 return bdistance->distance;
12793 }
12794 else
12795 return bdistance->distance;
12796 }
12797
12798 /* Backdoor check. */
12799 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
12800 if (rn)
12801 {
12802 bgp_static = rn->info;
12803 bgp_unlock_node (rn);
12804
12805 if (bgp_static->backdoor)
12806 {
12807 if (bgp->distance_local)
12808 return bgp->distance_local;
12809 else
12810 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12811 }
12812 }
12813
12814 if (peer->sort == BGP_PEER_EBGP)
12815 {
12816 if (bgp->distance_ebgp)
12817 return bgp->distance_ebgp;
12818 return ZEBRA_EBGP_DISTANCE_DEFAULT;
12819 }
12820 else
12821 {
12822 if (bgp->distance_ibgp)
12823 return bgp->distance_ibgp;
12824 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12825 }
12826 }
12827
12828 DEFUN (bgp_distance,
12829 bgp_distance_cmd,
12830 "distance bgp <1-255> <1-255> <1-255>",
12831 "Define an administrative distance\n"
12832 "BGP distance\n"
12833 "Distance for routes external to the AS\n"
12834 "Distance for routes internal to the AS\n"
12835 "Distance for local routes\n")
12836 {
12837 struct bgp *bgp;
12838
12839 bgp = vty->index;
12840
12841 bgp->distance_ebgp = atoi (argv[0]);
12842 bgp->distance_ibgp = atoi (argv[1]);
12843 bgp->distance_local = atoi (argv[2]);
12844 return CMD_SUCCESS;
12845 }
12846
12847 DEFUN (no_bgp_distance,
12848 no_bgp_distance_cmd,
12849 "no distance bgp <1-255> <1-255> <1-255>",
12850 NO_STR
12851 "Define an administrative distance\n"
12852 "BGP distance\n"
12853 "Distance for routes external to the AS\n"
12854 "Distance for routes internal to the AS\n"
12855 "Distance for local routes\n")
12856 {
12857 struct bgp *bgp;
12858
12859 bgp = vty->index;
12860
12861 bgp->distance_ebgp= 0;
12862 bgp->distance_ibgp = 0;
12863 bgp->distance_local = 0;
12864 return CMD_SUCCESS;
12865 }
12866
12867 ALIAS (no_bgp_distance,
12868 no_bgp_distance2_cmd,
12869 "no distance bgp",
12870 NO_STR
12871 "Define an administrative distance\n"
12872 "BGP distance\n")
12873
12874 DEFUN (bgp_distance_source,
12875 bgp_distance_source_cmd,
12876 "distance <1-255> A.B.C.D/M",
12877 "Define an administrative distance\n"
12878 "Administrative distance\n"
12879 "IP source prefix\n")
12880 {
12881 bgp_distance_set (vty, argv[0], argv[1], NULL);
12882 return CMD_SUCCESS;
12883 }
12884
12885 DEFUN (no_bgp_distance_source,
12886 no_bgp_distance_source_cmd,
12887 "no distance <1-255> A.B.C.D/M",
12888 NO_STR
12889 "Define an administrative distance\n"
12890 "Administrative distance\n"
12891 "IP source prefix\n")
12892 {
12893 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12894 return CMD_SUCCESS;
12895 }
12896
12897 DEFUN (bgp_distance_source_access_list,
12898 bgp_distance_source_access_list_cmd,
12899 "distance <1-255> A.B.C.D/M WORD",
12900 "Define an administrative distance\n"
12901 "Administrative distance\n"
12902 "IP source prefix\n"
12903 "Access list name\n")
12904 {
12905 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12906 return CMD_SUCCESS;
12907 }
12908
12909 DEFUN (no_bgp_distance_source_access_list,
12910 no_bgp_distance_source_access_list_cmd,
12911 "no distance <1-255> A.B.C.D/M WORD",
12912 NO_STR
12913 "Define an administrative distance\n"
12914 "Administrative distance\n"
12915 "IP source prefix\n"
12916 "Access list name\n")
12917 {
12918 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12919 return CMD_SUCCESS;
12920 }
12921
12922 DEFUN (bgp_damp_set,
12923 bgp_damp_set_cmd,
12924 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12925 "BGP Specific commands\n"
12926 "Enable route-flap dampening\n"
12927 "Half-life time for the penalty\n"
12928 "Value to start reusing a route\n"
12929 "Value to start suppressing a route\n"
12930 "Maximum duration to suppress a stable route\n")
12931 {
12932 struct bgp *bgp;
12933 int half = DEFAULT_HALF_LIFE * 60;
12934 int reuse = DEFAULT_REUSE;
12935 int suppress = DEFAULT_SUPPRESS;
12936 int max = 4 * half;
12937
12938 if (argc == 4)
12939 {
12940 half = atoi (argv[0]) * 60;
12941 reuse = atoi (argv[1]);
12942 suppress = atoi (argv[2]);
12943 max = atoi (argv[3]) * 60;
12944 }
12945 else if (argc == 1)
12946 {
12947 half = atoi (argv[0]) * 60;
12948 max = 4 * half;
12949 }
12950
12951 bgp = vty->index;
12952 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12953 half, reuse, suppress, max);
12954 }
12955
12956 ALIAS (bgp_damp_set,
12957 bgp_damp_set2_cmd,
12958 "bgp dampening <1-45>",
12959 "BGP Specific commands\n"
12960 "Enable route-flap dampening\n"
12961 "Half-life time for the penalty\n")
12962
12963 ALIAS (bgp_damp_set,
12964 bgp_damp_set3_cmd,
12965 "bgp dampening",
12966 "BGP Specific commands\n"
12967 "Enable route-flap dampening\n")
12968
12969 DEFUN (bgp_damp_unset,
12970 bgp_damp_unset_cmd,
12971 "no bgp dampening",
12972 NO_STR
12973 "BGP Specific commands\n"
12974 "Enable route-flap dampening\n")
12975 {
12976 struct bgp *bgp;
12977
12978 bgp = vty->index;
12979 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12980 }
12981
12982 ALIAS (bgp_damp_unset,
12983 bgp_damp_unset2_cmd,
12984 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12985 NO_STR
12986 "BGP Specific commands\n"
12987 "Enable route-flap dampening\n"
12988 "Half-life time for the penalty\n"
12989 "Value to start reusing a route\n"
12990 "Value to start suppressing a route\n"
12991 "Maximum duration to suppress a stable route\n")
12992
12993 DEFUN (show_ip_bgp_dampened_paths,
12994 show_ip_bgp_dampened_paths_cmd,
12995 "show ip bgp dampened-paths",
12996 SHOW_STR
12997 IP_STR
12998 BGP_STR
12999 "Display paths suppressed due to dampening\n")
13000 {
13001 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
13002 NULL, 0);
13003 }
13004
13005 DEFUN (show_ip_bgp_flap_statistics,
13006 show_ip_bgp_flap_statistics_cmd,
13007 "show ip bgp flap-statistics",
13008 SHOW_STR
13009 IP_STR
13010 BGP_STR
13011 "Display flap statistics of routes\n")
13012 {
13013 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
13014 bgp_show_type_flap_statistics, NULL, 0);
13015 }
13016
13017 /* Display specified route of BGP table. */
13018 static int
13019 bgp_clear_damp_route (struct vty *vty, const char *view_name,
13020 const char *ip_str, afi_t afi, safi_t safi,
13021 struct prefix_rd *prd, int prefix_check)
13022 {
13023 int ret;
13024 struct prefix match;
13025 struct bgp_node *rn;
13026 struct bgp_node *rm;
13027 struct bgp_info *ri;
13028 struct bgp_info *ri_temp;
13029 struct bgp *bgp;
13030 struct bgp_table *table;
13031
13032 /* BGP structure lookup. */
13033 if (view_name)
13034 {
13035 bgp = bgp_lookup_by_name (view_name);
13036 if (bgp == NULL)
13037 {
13038 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
13039 return CMD_WARNING;
13040 }
13041 }
13042 else
13043 {
13044 bgp = bgp_get_default ();
13045 if (bgp == NULL)
13046 {
13047 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
13048 return CMD_WARNING;
13049 }
13050 }
13051
13052 /* Check IP address argument. */
13053 ret = str2prefix (ip_str, &match);
13054 if (! ret)
13055 {
13056 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
13057 return CMD_WARNING;
13058 }
13059
13060 match.family = afi2family (afi);
13061
13062 if (safi == SAFI_MPLS_VPN)
13063 {
13064 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
13065 {
13066 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
13067 continue;
13068
13069 if ((table = rn->info) != NULL)
13070 if ((rm = bgp_node_match (table, &match)) != NULL)
13071 {
13072 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
13073 {
13074 ri = rm->info;
13075 while (ri)
13076 {
13077 if (ri->extra && ri->extra->damp_info)
13078 {
13079 ri_temp = ri->next;
13080 bgp_damp_info_free (ri->extra->damp_info, 1);
13081 ri = ri_temp;
13082 }
13083 else
13084 ri = ri->next;
13085 }
13086 }
13087
13088 bgp_unlock_node (rm);
13089 }
13090 }
13091 }
13092 else
13093 {
13094 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
13095 {
13096 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
13097 {
13098 ri = rn->info;
13099 while (ri)
13100 {
13101 if (ri->extra && ri->extra->damp_info)
13102 {
13103 ri_temp = ri->next;
13104 bgp_damp_info_free (ri->extra->damp_info, 1);
13105 ri = ri_temp;
13106 }
13107 else
13108 ri = ri->next;
13109 }
13110 }
13111
13112 bgp_unlock_node (rn);
13113 }
13114 }
13115
13116 return CMD_SUCCESS;
13117 }
13118
13119 DEFUN (clear_ip_bgp_dampening,
13120 clear_ip_bgp_dampening_cmd,
13121 "clear ip bgp dampening",
13122 CLEAR_STR
13123 IP_STR
13124 BGP_STR
13125 "Clear route flap dampening information\n")
13126 {
13127 bgp_damp_info_clean ();
13128 return CMD_SUCCESS;
13129 }
13130
13131 DEFUN (clear_ip_bgp_dampening_prefix,
13132 clear_ip_bgp_dampening_prefix_cmd,
13133 "clear ip bgp dampening A.B.C.D/M",
13134 CLEAR_STR
13135 IP_STR
13136 BGP_STR
13137 "Clear route flap dampening information\n"
13138 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13139 {
13140 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13141 SAFI_UNICAST, NULL, 1);
13142 }
13143
13144 DEFUN (clear_ip_bgp_dampening_address,
13145 clear_ip_bgp_dampening_address_cmd,
13146 "clear ip bgp dampening A.B.C.D",
13147 CLEAR_STR
13148 IP_STR
13149 BGP_STR
13150 "Clear route flap dampening information\n"
13151 "Network to clear damping information\n")
13152 {
13153 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13154 SAFI_UNICAST, NULL, 0);
13155 }
13156
13157 DEFUN (clear_ip_bgp_dampening_address_mask,
13158 clear_ip_bgp_dampening_address_mask_cmd,
13159 "clear ip bgp dampening A.B.C.D A.B.C.D",
13160 CLEAR_STR
13161 IP_STR
13162 BGP_STR
13163 "Clear route flap dampening information\n"
13164 "Network to clear damping information\n"
13165 "Network mask\n")
13166 {
13167 int ret;
13168 char prefix_str[BUFSIZ];
13169
13170 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
13171 if (! ret)
13172 {
13173 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
13174 return CMD_WARNING;
13175 }
13176
13177 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
13178 SAFI_UNICAST, NULL, 0);
13179 }
13180
13181 static int
13182 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
13183 afi_t afi, safi_t safi, int *write)
13184 {
13185 struct bgp_node *prn;
13186 struct bgp_node *rn;
13187 struct bgp_table *table;
13188 struct prefix *p;
13189 struct prefix_rd *prd;
13190 struct bgp_static *bgp_static;
13191 u_int32_t label;
13192 char buf[SU_ADDRSTRLEN];
13193 char rdbuf[RD_ADDRSTRLEN];
13194
13195 /* Network configuration. */
13196 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
13197 if ((table = prn->info) != NULL)
13198 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
13199 if ((bgp_static = rn->info) != NULL)
13200 {
13201 p = &rn->p;
13202 prd = (struct prefix_rd *) &prn->p;
13203
13204 /* "address-family" display. */
13205 bgp_config_write_family_header (vty, afi, safi, write);
13206
13207 /* "network" configuration display. */
13208 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
13209 label = decode_label (bgp_static->tag);
13210
13211 vty_out (vty, " network %s/%d rd %s tag %d",
13212 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13213 p->prefixlen,
13214 rdbuf, label);
13215 vty_out (vty, "%s", VTY_NEWLINE);
13216 }
13217 return 0;
13218 }
13219
13220 /* Configuration of static route announcement and aggregate
13221 information. */
13222 int
13223 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
13224 afi_t afi, safi_t safi, int *write)
13225 {
13226 struct bgp_node *rn;
13227 struct prefix *p;
13228 struct bgp_static *bgp_static;
13229 struct bgp_aggregate *bgp_aggregate;
13230 char buf[SU_ADDRSTRLEN];
13231
13232 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
13233 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
13234
13235 /* Network configuration. */
13236 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
13237 if ((bgp_static = rn->info) != NULL)
13238 {
13239 p = &rn->p;
13240
13241 /* "address-family" display. */
13242 bgp_config_write_family_header (vty, afi, safi, write);
13243
13244 /* "network" configuration display. */
13245 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13246 {
13247 u_int32_t destination;
13248 struct in_addr netmask;
13249
13250 destination = ntohl (p->u.prefix4.s_addr);
13251 masklen2ip (p->prefixlen, &netmask);
13252 vty_out (vty, " network %s",
13253 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
13254
13255 if ((IN_CLASSC (destination) && p->prefixlen == 24)
13256 || (IN_CLASSB (destination) && p->prefixlen == 16)
13257 || (IN_CLASSA (destination) && p->prefixlen == 8)
13258 || p->u.prefix4.s_addr == 0)
13259 {
13260 /* Natural mask is not display. */
13261 }
13262 else
13263 vty_out (vty, " mask %s", inet_ntoa (netmask));
13264 }
13265 else
13266 {
13267 vty_out (vty, " network %s/%d",
13268 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13269 p->prefixlen);
13270 }
13271
13272 if (bgp_static->rmap.name)
13273 vty_out (vty, " route-map %s", bgp_static->rmap.name);
13274 else
13275 {
13276 if (bgp_static->backdoor)
13277 vty_out (vty, " backdoor");
13278 }
13279
13280 vty_out (vty, "%s", VTY_NEWLINE);
13281 }
13282
13283 /* Aggregate-address configuration. */
13284 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
13285 if ((bgp_aggregate = rn->info) != NULL)
13286 {
13287 p = &rn->p;
13288
13289 /* "address-family" display. */
13290 bgp_config_write_family_header (vty, afi, safi, write);
13291
13292 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13293 {
13294 struct in_addr netmask;
13295
13296 masklen2ip (p->prefixlen, &netmask);
13297 vty_out (vty, " aggregate-address %s %s",
13298 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13299 inet_ntoa (netmask));
13300 }
13301 else
13302 {
13303 vty_out (vty, " aggregate-address %s/%d",
13304 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13305 p->prefixlen);
13306 }
13307
13308 if (bgp_aggregate->as_set)
13309 vty_out (vty, " as-set");
13310
13311 if (bgp_aggregate->summary_only)
13312 vty_out (vty, " summary-only");
13313
13314 vty_out (vty, "%s", VTY_NEWLINE);
13315 }
13316
13317 return 0;
13318 }
13319
13320 int
13321 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
13322 {
13323 struct bgp_node *rn;
13324 struct bgp_distance *bdistance;
13325
13326 /* Distance configuration. */
13327 if (bgp->distance_ebgp
13328 && bgp->distance_ibgp
13329 && bgp->distance_local
13330 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
13331 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
13332 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
13333 vty_out (vty, " distance bgp %d %d %d%s",
13334 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
13335 VTY_NEWLINE);
13336
13337 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
13338 if ((bdistance = rn->info) != NULL)
13339 {
13340 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
13341 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
13342 bdistance->access_list ? bdistance->access_list : "",
13343 VTY_NEWLINE);
13344 }
13345
13346 return 0;
13347 }
13348
13349 /* Allocate routing table structure and install commands. */
13350 void
13351 bgp_route_init (void)
13352 {
13353 /* Init BGP distance table. */
13354 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
13355
13356 /* IPv4 BGP commands. */
13357 install_element (BGP_NODE, &bgp_table_map_cmd);
13358 install_element (BGP_NODE, &bgp_network_cmd);
13359 install_element (BGP_NODE, &bgp_network_mask_cmd);
13360 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
13361 install_element (BGP_NODE, &bgp_network_route_map_cmd);
13362 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
13363 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
13364 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
13365 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
13366 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
13367 install_element (BGP_NODE, &no_bgp_table_map_cmd);
13368 install_element (BGP_NODE, &no_bgp_network_cmd);
13369 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
13370 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
13371 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
13372 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
13373 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13374 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
13375 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
13376 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
13377
13378 install_element (BGP_NODE, &aggregate_address_cmd);
13379 install_element (BGP_NODE, &aggregate_address_mask_cmd);
13380 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
13381 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
13382 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
13383 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
13384 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
13385 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
13386 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
13387 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
13388 install_element (BGP_NODE, &no_aggregate_address_cmd);
13389 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
13390 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
13391 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
13392 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
13393 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
13394 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
13395 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
13396 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13397 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13398
13399 /* IPv4 unicast configuration. */
13400 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
13401 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
13402 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
13403 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
13404 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
13405 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
13406 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
13407 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
13408 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
13409 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
13410 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
13411 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
13412 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
13413 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13414
13415 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
13416 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
13417 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
13418 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
13419 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
13420 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
13421 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
13422 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
13423 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
13424 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
13425 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
13426 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
13427 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
13428 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
13429 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
13430 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
13431 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
13432 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
13433 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13434 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13435
13436 /* IPv4 multicast configuration. */
13437 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
13438 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
13439 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
13440 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
13441 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
13442 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
13443 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
13444 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
13445 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
13446 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
13447 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
13448 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
13449 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
13450 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13451 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
13452 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
13453 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
13454 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
13455 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
13456 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
13457 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
13458 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
13459 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
13460 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
13461 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
13462 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
13463 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
13464 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
13465 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
13466 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
13467 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
13468 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
13469 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13470 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13471
13472 install_element (VIEW_NODE, &show_ip_bgp_cmd);
13473 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
13474 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
13475 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
13476 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
13477 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
13478 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
13479 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
13480 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
13481 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13482 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
13483 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
13484 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13485 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
13486 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
13487 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
13488 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13489 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13490 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
13491 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
13492 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
13493 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
13494 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
13495 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
13496 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
13497 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
13498 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
13499 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
13500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
13501 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
13502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
13503 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
13504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
13505 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
13506 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
13507 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
13508 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
13509 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
13510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
13511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
13512 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
13513 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13514 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
13515 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
13516 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
13517 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
13518 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
13519 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
13520 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
13521 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
13522 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13524 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13526 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
13527 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
13528 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
13529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
13530 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
13531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
13532 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
13533 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
13534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
13535 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
13536 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
13537 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
13538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
13539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
13540 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
13541 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
13542 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
13543 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
13544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
13545 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
13546 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
13547 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
13548 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
13549 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
13550 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
13551 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
13552 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
13553 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
13554 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
13555 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
13556 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
13557 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13558 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
13559
13560 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
13561 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
13562 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
13563 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
13564 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
13565 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
13566 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13567 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
13568 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
13569 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13570 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
13571 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
13572 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
13573 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13574 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13575 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
13576 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
13577 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
13578 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
13579 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
13580 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
13581 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
13582 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
13583 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
13584 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
13585 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13586 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
13587 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
13588 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
13589 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
13590 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
13591 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
13592 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
13593 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
13594 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13595 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13596 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13597 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13598
13599 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
13600 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
13601 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
13602 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
13603 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
13604 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
13605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
13606 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
13607 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
13608 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13609 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
13610 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
13611 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13612 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
13613 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
13614 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
13615 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13616 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13617 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
13618 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
13619 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
13620 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
13621 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
13622 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
13623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
13624 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
13625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
13626 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
13627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
13628 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
13629 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
13630 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
13631 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
13632 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
13633 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
13634 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
13635 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
13636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
13637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
13638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
13639 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
13640 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13641 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
13642 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
13643 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
13644 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
13645 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
13646 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
13647 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
13648 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
13649 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13652 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13653 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
13654 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
13655 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
13656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
13657 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
13658 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
13659 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
13660 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
13661 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
13662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
13663 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
13664 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
13665 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
13666 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
13667 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
13668 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
13669 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
13670 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
13671 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
13672 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
13673 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
13674 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
13675 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
13676 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
13677 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
13678 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
13679 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
13680 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
13681 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
13682 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
13683 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
13684 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13685 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
13686
13687 /* BGP dampening clear commands */
13688 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
13689 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
13690 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
13691 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
13692
13693 /* prefix count */
13694 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
13695 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
13696 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
13697 #ifdef HAVE_IPV6
13698 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
13699
13700 /* New config IPv6 BGP commands. */
13701 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
13702 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
13703 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
13704 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
13705 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
13706 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
13707
13708 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
13709 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
13710 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
13711 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
13712
13713 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
13714 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
13715
13716 /* Old config IPv6 BGP commands. */
13717 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
13718 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
13719
13720 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
13721 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
13722 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
13723 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
13724
13725 install_element (VIEW_NODE, &show_bgp_cmd);
13726 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
13727 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
13728 install_element (VIEW_NODE, &show_bgp_route_cmd);
13729 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
13730 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
13731 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
13732 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
13733 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
13734 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
13735 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
13736 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
13737 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
13738 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
13739 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
13740 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
13741 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
13742 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
13743 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
13744 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
13745 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
13746 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
13747 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
13748 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
13749 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
13750 install_element (VIEW_NODE, &show_bgp_community_cmd);
13751 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
13752 install_element (VIEW_NODE, &show_bgp_community2_cmd);
13753 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
13754 install_element (VIEW_NODE, &show_bgp_community3_cmd);
13755 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
13756 install_element (VIEW_NODE, &show_bgp_community4_cmd);
13757 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
13758 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
13759 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
13760 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
13761 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
13762 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
13763 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
13764 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
13765 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
13766 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
13767 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
13768 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
13769 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13770 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
13771 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13772 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
13773 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13774 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
13775 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13776 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
13777 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13778 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13779 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
13780 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
13781 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13782 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
13783 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
13784 install_element (VIEW_NODE, &show_bgp_view_cmd);
13785 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
13786 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
13787 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
13788 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
13789 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
13790 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13791 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13792 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13793 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13794 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
13795 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13796 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13797 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13798 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
13799 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13800 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
13801 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
13802
13803 /* Restricted:
13804 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
13805 */
13806 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
13807 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
13808 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
13809 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
13810 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
13811 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
13812 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
13813 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
13814 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
13815 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
13816 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
13817 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
13818 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
13819 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
13820 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
13821 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
13822 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
13823 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
13824 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
13825 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
13826 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
13827 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
13828 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
13829 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
13830 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
13831 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
13832 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
13833 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
13834 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
13835 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
13836 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
13837 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
13838 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13839 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13840
13841 install_element (ENABLE_NODE, &show_bgp_cmd);
13842 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
13843 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
13844 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13845 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
13846 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
13847 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
13848 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
13849 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
13850 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
13851 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
13852 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
13853 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
13854 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
13855 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
13856 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13857 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13858 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13859 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13860 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13861 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13862 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13863 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13864 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13865 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13866 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13867 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13868 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13869 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13870 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13871 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13872 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13873 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13874 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13875 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13876 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13877 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13878 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13879 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13880 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13881 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13882 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13883 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13884 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13885 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13886 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13887 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13888 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13889 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13890 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13891 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13892 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13893 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13894 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13895 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
13896 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13897 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13898 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13899 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
13900 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13901 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13902 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13903 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13904 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13905 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13906 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13907 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13908 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13909 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13910 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
13911 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13912 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13913 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13914 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13915 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13916 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13917 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
13918
13919 /* Statistics */
13920 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
13921 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
13922 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
13923 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
13924
13925 /* old command */
13926 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13927 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13928 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13929 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13930 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13931 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13932 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13933 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13934 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13935 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13936 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13937 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13938 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13939 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13940 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13941 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13942 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13943 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13944 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13945 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13946 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13947 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13948 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13949 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13950 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13951 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13952 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13953 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13954 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13955 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13956 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13957 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13958 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13959 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13960 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13961 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13962
13963 /* old command */
13964 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13965 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13966 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13967 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13968 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13969 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13970 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13971 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13972 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13973 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13974 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13975 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13976 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13977 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13978 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13979 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13980 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13981 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13982 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13983 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13984 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13985 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13986 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13987 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13988 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13989 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13990 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13991 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13992 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13993 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13994 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13995 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13996 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13997 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13998 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13999 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14000
14001 /* old command */
14002 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14003 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14004 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14005 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14006
14007 /* old command */
14008 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14009 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14010 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14011 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14012
14013 /* old command */
14014 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
14015 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
14016 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14017 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14018 #endif /* HAVE_IPV6 */
14019
14020 install_element (BGP_NODE, &bgp_distance_cmd);
14021 install_element (BGP_NODE, &no_bgp_distance_cmd);
14022 install_element (BGP_NODE, &no_bgp_distance2_cmd);
14023 install_element (BGP_NODE, &bgp_distance_source_cmd);
14024 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
14025 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
14026 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
14027
14028 install_element (BGP_NODE, &bgp_damp_set_cmd);
14029 install_element (BGP_NODE, &bgp_damp_set2_cmd);
14030 install_element (BGP_NODE, &bgp_damp_set3_cmd);
14031 install_element (BGP_NODE, &bgp_damp_unset_cmd);
14032 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
14033 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
14034 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
14035 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
14036 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
14037 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
14038 }
14039
14040 void
14041 bgp_route_finish (void)
14042 {
14043 bgp_table_unlock (bgp_distance_table);
14044 bgp_distance_table = NULL;
14045 }