]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
bgpd: Display interface next-hop for "show ip bgp" with unnumbered
[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 #include "bgpd/bgp_vty.h"
64
65 /* Extern from bgp_dump.c */
66 extern const char *bgp_origin_str[];
67 extern const char *bgp_origin_long_str[];
68
69 struct bgp_node *
70 bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
71 struct prefix_rd *prd)
72 {
73 struct bgp_node *rn;
74 struct bgp_node *prn = NULL;
75
76 assert (table);
77 if (!table)
78 return NULL;
79
80 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
81 {
82 prn = bgp_node_get (table, (struct prefix *) prd);
83
84 if (prn->info == NULL)
85 prn->info = bgp_table_init (afi, safi);
86 else
87 bgp_unlock_node (prn);
88 table = prn->info;
89 }
90
91 rn = bgp_node_get (table, p);
92
93 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
94 rn->prn = prn;
95
96 return rn;
97 }
98
99 /* Allocate bgp_info_extra */
100 static struct bgp_info_extra *
101 bgp_info_extra_new (void)
102 {
103 struct bgp_info_extra *new;
104 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
105 return new;
106 }
107
108 static void
109 bgp_info_extra_free (struct bgp_info_extra **extra)
110 {
111 if (extra && *extra)
112 {
113 if ((*extra)->damp_info)
114 bgp_damp_info_free ((*extra)->damp_info, 0);
115
116 (*extra)->damp_info = NULL;
117
118 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
119
120 *extra = NULL;
121 }
122 }
123
124 /* Get bgp_info extra information for the given bgp_info, lazy allocated
125 * if required.
126 */
127 struct bgp_info_extra *
128 bgp_info_extra_get (struct bgp_info *ri)
129 {
130 if (!ri->extra)
131 ri->extra = bgp_info_extra_new();
132 return ri->extra;
133 }
134
135 /* Free bgp route information. */
136 static void
137 bgp_info_free (struct bgp_info *binfo)
138 {
139 if (binfo->attr)
140 bgp_attr_unintern (&binfo->attr);
141
142 bgp_unlink_nexthop(binfo);
143 bgp_info_extra_free (&binfo->extra);
144 bgp_info_mpath_free (&binfo->mpath);
145
146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
148 XFREE (MTYPE_BGP_ROUTE, binfo);
149 }
150
151 struct bgp_info *
152 bgp_info_lock (struct bgp_info *binfo)
153 {
154 binfo->lock++;
155 return binfo;
156 }
157
158 struct bgp_info *
159 bgp_info_unlock (struct bgp_info *binfo)
160 {
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166 #if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169 #endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174 #if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180 #endif
181
182 return binfo;
183 }
184
185 void
186 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187 {
188 struct bgp_info *top;
189
190 top = rn->info;
191
192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
201 }
202
203 /* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205 static void
206 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
207 {
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
214
215 bgp_info_mpath_dequeue (ri);
216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
218 }
219
220 void
221 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222 {
223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226 }
227
228 /* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231 static void
232 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233 {
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237 }
238
239 /* Adjust pcount as required */
240 static void
241 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242 {
243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
246 assert (ri && ri->peer && ri->peer->bgp);
247
248 table = bgp_node_table (rn);
249
250 if (ri->peer == ri->peer->bgp->peer_self)
251 return;
252
253 if (!BGP_INFO_COUNTABLE (ri)
254 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
255 {
256
257 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
258
259 /* slight hack, but more robust against errors. */
260 if (ri->peer->pcount[table->afi][table->safi])
261 ri->peer->pcount[table->afi][table->safi]--;
262 else
263 {
264 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
265 __func__, ri->peer->host);
266 zlog_backtrace (LOG_WARNING);
267 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
268 }
269 }
270 else if (BGP_INFO_COUNTABLE (ri)
271 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
272 {
273 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
274 ri->peer->pcount[table->afi][table->safi]++;
275 }
276 }
277
278
279 /* Set/unset bgp_info flags, adjusting any other state as needed.
280 * This is here primarily to keep prefix-count in check.
281 */
282 void
283 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
284 {
285 SET_FLAG (ri->flags, flag);
286
287 /* early bath if we know it's not a flag that changes countability state */
288 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
289 return;
290
291 bgp_pcount_adjust (rn, ri);
292 }
293
294 void
295 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
296 {
297 UNSET_FLAG (ri->flags, flag);
298
299 /* early bath if we know it's not a flag that changes countability state */
300 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
301 return;
302
303 bgp_pcount_adjust (rn, ri);
304 }
305
306 /* Get MED value. If MED value is missing and "bgp bestpath
307 missing-as-worst" is specified, treat it as the worst value. */
308 static u_int32_t
309 bgp_med_value (struct attr *attr, struct bgp *bgp)
310 {
311 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
312 return attr->med;
313 else
314 {
315 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
316 return BGP_MED_MAX;
317 else
318 return 0;
319 }
320 }
321
322 void
323 bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf)
324 {
325 if (ri->addpath_rx_id)
326 sprintf(buf, "path %s (addpath rxid %d)", ri->peer->host, ri->addpath_rx_id);
327 else
328 sprintf(buf, "path %s", ri->peer->host);
329 }
330
331 /* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
332 static int
333 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
334 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
335 char *pfx_buf)
336 {
337 struct attr *newattr, *existattr;
338 struct attr_extra *newattre, *existattre;
339 bgp_peer_sort_t new_sort;
340 bgp_peer_sort_t exist_sort;
341 u_int32_t new_pref;
342 u_int32_t exist_pref;
343 u_int32_t new_med;
344 u_int32_t exist_med;
345 u_int32_t new_weight;
346 u_int32_t exist_weight;
347 uint32_t newm, existm;
348 struct in_addr new_id;
349 struct in_addr exist_id;
350 int new_cluster;
351 int exist_cluster;
352 int internal_as_route;
353 int confed_as_route;
354 int ret;
355 char new_buf[PATH_ADDPATH_STR_BUFFER];
356 char exist_buf[PATH_ADDPATH_STR_BUFFER];
357
358 *paths_eq = 0;
359
360 /* 0. Null check. */
361 if (new == NULL)
362 {
363 if (debug)
364 zlog_debug("%s: new is NULL", pfx_buf);
365 return 0;
366 }
367
368 if (debug)
369 bgp_info_path_with_addpath_rx_str (new, new_buf);
370
371 if (exist == NULL)
372 {
373 if (debug)
374 zlog_debug("%s: %s is the initial bestpath", pfx_buf, new_buf);
375 return 1;
376 }
377
378 if (debug)
379 {
380 bgp_info_path_with_addpath_rx_str (exist, exist_buf);
381 zlog_debug("%s: Comparing %s flags 0x%x with %s flags 0x%x",
382 pfx_buf, new_buf, new->flags, exist_buf, exist->flags);
383 }
384
385 newattr = new->attr;
386 existattr = exist->attr;
387 newattre = newattr->extra;
388 existattre = existattr->extra;
389
390 /* 1. Weight check. */
391 new_weight = exist_weight = 0;
392
393 if (newattre)
394 new_weight = newattre->weight;
395 if (existattre)
396 exist_weight = existattre->weight;
397
398 if (new_weight > exist_weight)
399 {
400 if (debug)
401 zlog_debug("%s: %s wins over %s due to weight %d > %d",
402 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
403 return 1;
404 }
405
406 if (new_weight < exist_weight)
407 {
408 if (debug)
409 zlog_debug("%s: %s loses to %s due to weight %d < %d",
410 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
411 return 0;
412 }
413
414 /* 2. Local preference check. */
415 new_pref = exist_pref = bgp->default_local_pref;
416
417 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
418 new_pref = newattr->local_pref;
419 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
420 exist_pref = existattr->local_pref;
421
422 if (new_pref > exist_pref)
423 {
424 if (debug)
425 zlog_debug("%s: %s wins over %s due to localpref %d > %d",
426 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
427 return 1;
428 }
429
430 if (new_pref < exist_pref)
431 {
432 if (debug)
433 zlog_debug("%s: %s loses to %s due to localpref %d < %d",
434 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
435 return 0;
436 }
437
438 /* 3. Local route check. We prefer:
439 * - BGP_ROUTE_STATIC
440 * - BGP_ROUTE_AGGREGATE
441 * - BGP_ROUTE_REDISTRIBUTE
442 */
443 if (! (new->sub_type == BGP_ROUTE_NORMAL))
444 {
445 if (debug)
446 zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type",
447 pfx_buf, new_buf, exist_buf);
448 return 1;
449 }
450
451 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
452 {
453 if (debug)
454 zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type",
455 pfx_buf, new_buf, exist_buf);
456 return 0;
457 }
458
459 /* 4. AS path length check. */
460 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
461 {
462 int exist_hops = aspath_count_hops (existattr->aspath);
463 int exist_confeds = aspath_count_confeds (existattr->aspath);
464
465 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
466 {
467 int aspath_hops;
468
469 aspath_hops = aspath_count_hops (newattr->aspath);
470 aspath_hops += aspath_count_confeds (newattr->aspath);
471
472 if ( aspath_hops < (exist_hops + exist_confeds))
473 {
474 if (debug)
475 zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
476 pfx_buf, new_buf, exist_buf,
477 aspath_hops, (exist_hops + exist_confeds));
478 return 1;
479 }
480
481 if ( aspath_hops > (exist_hops + exist_confeds))
482 {
483 if (debug)
484 zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
485 pfx_buf, new_buf, exist_buf,
486 aspath_hops, (exist_hops + exist_confeds));
487 return 0;
488 }
489 }
490 else
491 {
492 int newhops = aspath_count_hops (newattr->aspath);
493
494 if (newhops < exist_hops)
495 {
496 if (debug)
497 zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d",
498 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
499 return 1;
500 }
501
502 if (newhops > exist_hops)
503 {
504 if (debug)
505 zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d",
506 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
507 return 0;
508 }
509 }
510 }
511
512 /* 5. Origin check. */
513 if (newattr->origin < existattr->origin)
514 {
515 if (debug)
516 zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
517 pfx_buf, new_buf, exist_buf,
518 bgp_origin_long_str[newattr->origin],
519 bgp_origin_long_str[existattr->origin]);
520 return 1;
521 }
522
523 if (newattr->origin > existattr->origin)
524 {
525 if (debug)
526 zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
527 pfx_buf, new_buf, exist_buf,
528 bgp_origin_long_str[newattr->origin],
529 bgp_origin_long_str[existattr->origin]);
530 return 0;
531 }
532
533 /* 6. MED check. */
534 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
535 && aspath_count_hops (existattr->aspath) == 0);
536 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
537 && aspath_count_confeds (existattr->aspath) > 0
538 && aspath_count_hops (newattr->aspath) == 0
539 && aspath_count_hops (existattr->aspath) == 0);
540
541 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
542 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
543 && confed_as_route)
544 || aspath_cmp_left (newattr->aspath, existattr->aspath)
545 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
546 || internal_as_route)
547 {
548 new_med = bgp_med_value (new->attr, bgp);
549 exist_med = bgp_med_value (exist->attr, bgp);
550
551 if (new_med < exist_med)
552 {
553 if (debug)
554 zlog_debug("%s: %s wins over %s due to MED %d < %d",
555 pfx_buf, new_buf, exist_buf, new_med, exist_med);
556 return 1;
557 }
558
559 if (new_med > exist_med)
560 {
561 if (debug)
562 zlog_debug("%s: %s loses to %s due to MED %d > %d",
563 pfx_buf, new_buf, exist_buf, new_med, exist_med);
564 return 0;
565 }
566 }
567
568 /* 7. Peer type check. */
569 new_sort = new->peer->sort;
570 exist_sort = exist->peer->sort;
571
572 if (new_sort == BGP_PEER_EBGP
573 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
574 {
575 if (debug)
576 zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer",
577 pfx_buf, new_buf, exist_buf);
578 return 1;
579 }
580
581 if (exist_sort == BGP_PEER_EBGP
582 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
583 {
584 if (debug)
585 zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer",
586 pfx_buf, new_buf, exist_buf);
587 return 0;
588 }
589
590 /* 8. IGP metric check. */
591 newm = existm = 0;
592
593 if (new->extra)
594 newm = new->extra->igpmetric;
595 if (exist->extra)
596 existm = exist->extra->igpmetric;
597
598 if (newm < existm)
599 {
600 if (debug)
601 zlog_debug("%s: %s wins over %s due to IGP metric %d < %d",
602 pfx_buf, new_buf, exist_buf, newm, existm);
603 ret = 1;
604 }
605
606 if (newm > existm)
607 {
608 if (debug)
609 zlog_debug("%s: %s loses to %s due to IGP metric %d > %d",
610 pfx_buf, new_buf, exist_buf, newm, existm);
611 ret = 0;
612 }
613
614 /* 9. Same IGP metric. Compare the cluster list length as
615 representative of IGP hops metric. Rewrite the metric value
616 pair (newm, existm) with the cluster list length. Prefer the
617 path with smaller cluster list length. */
618 if (newm == existm)
619 {
620 if (peer_sort (new->peer) == BGP_PEER_IBGP
621 && peer_sort (exist->peer) == BGP_PEER_IBGP
622 && CHECK_FLAG (mpath_cfg->ibgp_flags,
623 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
624 {
625 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
626 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
627
628 if (newm < existm)
629 {
630 if (debug)
631 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
632 pfx_buf, new_buf, exist_buf, newm, existm);
633 ret = 1;
634 }
635
636 if (newm > existm)
637 {
638 if (debug)
639 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
640 pfx_buf, new_buf, exist_buf, newm, existm);
641 ret = 0;
642 }
643 }
644 }
645
646 /* 10. confed-external vs. confed-internal */
647 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
648 {
649 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
650 {
651 if (debug)
652 zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer",
653 pfx_buf, new_buf, exist_buf);
654 return 1;
655 }
656
657 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
658 {
659 if (debug)
660 zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer",
661 pfx_buf, new_buf, exist_buf);
662 return 0;
663 }
664 }
665
666 /* 11. Maximum path check. */
667 if (newm == existm)
668 {
669 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
670 {
671
672 /*
673 * For the two paths, all comparison steps till IGP metric
674 * have succeeded - including AS_PATH hop count. Since 'bgp
675 * bestpath as-path multipath-relax' knob is on, we don't need
676 * an exact match of AS_PATH. Thus, mark the paths are equal.
677 * That will trigger both these paths to get into the multipath
678 * array.
679 */
680 *paths_eq = 1;
681
682 if (debug)
683 zlog_debug("%s: %s and %s are equal via multipath-relax",
684 pfx_buf, new_buf, exist_buf);
685 }
686 else if (new->peer->sort == BGP_PEER_IBGP)
687 {
688 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
689 {
690 *paths_eq = 1;
691
692 if (debug)
693 zlog_debug("%s: %s and %s are equal via matching aspaths",
694 pfx_buf, new_buf, exist_buf);
695 }
696 }
697 else if (new->peer->as == exist->peer->as)
698 {
699 *paths_eq = 1;
700
701 if (debug)
702 zlog_debug("%s: %s and %s are equal via same remote-as",
703 pfx_buf, new_buf, exist_buf);
704 }
705 }
706 else
707 {
708 /*
709 * TODO: If unequal cost ibgp multipath is enabled we can
710 * mark the paths as equal here instead of returning
711 */
712 if (debug)
713 {
714 if (ret == 1)
715 zlog_debug("%s: %s wins over %s after IGP metric comparison",
716 pfx_buf, new_buf, exist_buf);
717 else
718 zlog_debug("%s: %s loses to %s after IGP metric comparison",
719 pfx_buf, new_buf, exist_buf);
720 }
721 return ret;
722 }
723
724 /* 12. If both paths are external, prefer the path that was received
725 first (the oldest one). This step minimizes route-flap, since a
726 newer path won't displace an older one, even if it was the
727 preferred route based on the additional decision criteria below. */
728 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
729 && new_sort == BGP_PEER_EBGP
730 && exist_sort == BGP_PEER_EBGP)
731 {
732 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
733 {
734 if (debug)
735 zlog_debug("%s: %s wins over %s due to oldest external",
736 pfx_buf, new_buf, exist_buf);
737 return 1;
738 }
739
740 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
741 {
742 if (debug)
743 zlog_debug("%s: %s loses to %s due to oldest external",
744 pfx_buf, new_buf, exist_buf);
745 return 0;
746 }
747 }
748
749 /* 13. Router-ID comparision. */
750 /* If one of the paths is "stale", the corresponding peer router-id will
751 * be 0 and would always win over the other path. If originator id is
752 * used for the comparision, it will decide which path is better.
753 */
754 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
755 new_id.s_addr = newattre->originator_id.s_addr;
756 else
757 new_id.s_addr = new->peer->remote_id.s_addr;
758 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
759 exist_id.s_addr = existattre->originator_id.s_addr;
760 else
761 exist_id.s_addr = exist->peer->remote_id.s_addr;
762
763 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
764 {
765 if (debug)
766 zlog_debug("%s: %s wins over %s due to Router-ID comparison",
767 pfx_buf, new_buf, exist_buf);
768 return 1;
769 }
770
771 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
772 {
773 if (debug)
774 zlog_debug("%s: %s loses to %s due to Router-ID comparison",
775 pfx_buf, new_buf, exist_buf);
776 return 0;
777 }
778
779 /* 14. Cluster length comparision. */
780 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
781 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
782
783 if (new_cluster < exist_cluster)
784 {
785 if (debug)
786 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
787 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
788 return 1;
789 }
790
791 if (new_cluster > exist_cluster)
792 {
793 if (debug)
794 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
795 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
796 return 0;
797 }
798
799 /* 15. Neighbor address comparision. */
800 /* Do this only if neither path is "stale" as stale paths do not have
801 * valid peer information (as the connection may or may not be up).
802 */
803 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
804 {
805 if (debug)
806 zlog_debug("%s: %s wins over %s due to latter path being STALE",
807 pfx_buf, new_buf, exist_buf);
808 return 1;
809 }
810
811 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
812 {
813 if (debug)
814 zlog_debug("%s: %s loses to %s due to former path being STALE",
815 pfx_buf, new_buf, exist_buf);
816 return 0;
817 }
818
819 /* locally configured routes to advertise do not have su_remote */
820 if (new->peer->su_remote == NULL)
821 return 0;
822 if (exist->peer->su_remote == NULL)
823 return 1;
824
825 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
826
827 if (ret == 1)
828 {
829 if (debug)
830 zlog_debug("%s: %s loses to %s due to Neighor IP comparison",
831 pfx_buf, new_buf, exist_buf);
832 return 0;
833 }
834
835 if (ret == -1)
836 {
837 if (debug)
838 zlog_debug("%s: %s wins over %s due to Neighor IP comparison",
839 pfx_buf, new_buf, exist_buf);
840 return 1;
841 }
842
843 if (debug)
844 zlog_debug("%s: %s wins over %s due to nothing left to compare",
845 pfx_buf, new_buf, exist_buf);
846
847 return 1;
848 }
849
850 static enum filter_type
851 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
852 afi_t afi, safi_t safi)
853 {
854 struct bgp_filter *filter;
855
856 filter = &peer->filter[afi][safi];
857
858 #define FILTER_EXIST_WARN(F,f,filter) \
859 if (BGP_DEBUG (update, UPDATE_IN) \
860 && !(F ## _IN (filter))) \
861 zlog_warn ("%s: Could not find configured input %s-list %s!", \
862 peer->host, #f, F ## _IN_NAME(filter));
863
864 if (DISTRIBUTE_IN_NAME (filter)) {
865 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
866
867 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
868 return FILTER_DENY;
869 }
870
871 if (PREFIX_LIST_IN_NAME (filter)) {
872 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
873
874 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
875 return FILTER_DENY;
876 }
877
878 if (FILTER_LIST_IN_NAME (filter)) {
879 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
880
881 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
882 return FILTER_DENY;
883 }
884
885 return FILTER_PERMIT;
886 #undef FILTER_EXIST_WARN
887 }
888
889 static enum filter_type
890 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
891 afi_t afi, safi_t safi)
892 {
893 struct bgp_filter *filter;
894
895 filter = &peer->filter[afi][safi];
896
897 #define FILTER_EXIST_WARN(F,f,filter) \
898 if (BGP_DEBUG (update, UPDATE_OUT) \
899 && !(F ## _OUT (filter))) \
900 zlog_warn ("%s: Could not find configured output %s-list %s!", \
901 peer->host, #f, F ## _OUT_NAME(filter));
902
903 if (DISTRIBUTE_OUT_NAME (filter)) {
904 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
905
906 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
907 return FILTER_DENY;
908 }
909
910 if (PREFIX_LIST_OUT_NAME (filter)) {
911 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
912
913 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
914 return FILTER_DENY;
915 }
916
917 if (FILTER_LIST_OUT_NAME (filter)) {
918 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
919
920 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
921 return FILTER_DENY;
922 }
923
924 return FILTER_PERMIT;
925 #undef FILTER_EXIST_WARN
926 }
927
928 /* If community attribute includes no_export then return 1. */
929 static int
930 bgp_community_filter (struct peer *peer, struct attr *attr)
931 {
932 if (attr->community)
933 {
934 /* NO_ADVERTISE check. */
935 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
936 return 1;
937
938 /* NO_EXPORT check. */
939 if (peer->sort == BGP_PEER_EBGP &&
940 community_include (attr->community, COMMUNITY_NO_EXPORT))
941 return 1;
942
943 /* NO_EXPORT_SUBCONFED check. */
944 if (peer->sort == BGP_PEER_EBGP
945 || peer->sort == BGP_PEER_CONFED)
946 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
947 return 1;
948 }
949 return 0;
950 }
951
952 /* Route reflection loop check. */
953 static int
954 bgp_cluster_filter (struct peer *peer, struct attr *attr)
955 {
956 struct in_addr cluster_id;
957
958 if (attr->extra && attr->extra->cluster)
959 {
960 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
961 cluster_id = peer->bgp->cluster_id;
962 else
963 cluster_id = peer->bgp->router_id;
964
965 if (cluster_loop_check (attr->extra->cluster, cluster_id))
966 return 1;
967 }
968 return 0;
969 }
970
971 static int
972 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
973 afi_t afi, safi_t safi, const char *rmap_name)
974 {
975 struct bgp_filter *filter;
976 struct bgp_info info;
977 route_map_result_t ret;
978 struct route_map *rmap = NULL;
979
980 filter = &peer->filter[afi][safi];
981
982 /* Apply default weight value. */
983 if (peer->weight)
984 (bgp_attr_extra_get (attr))->weight = peer->weight;
985
986 if (rmap_name)
987 {
988 rmap = route_map_lookup_by_name(rmap_name);
989
990 if (rmap == NULL)
991 return RMAP_DENY;
992 }
993 else
994 {
995 if (ROUTE_MAP_IN_NAME(filter))
996 {
997 rmap = ROUTE_MAP_IN (filter);
998
999 if (rmap == NULL)
1000 return RMAP_DENY;
1001 }
1002 }
1003
1004 /* Route map apply. */
1005 if (rmap)
1006 {
1007 /* Duplicate current value to new strucutre for modification. */
1008 info.peer = peer;
1009 info.attr = attr;
1010
1011 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
1012
1013 /* Apply BGP route map to the attribute. */
1014 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1015
1016 peer->rmap_type = 0;
1017
1018 if (ret == RMAP_DENYMATCH)
1019 {
1020 /* Free newly generated AS path and community by route-map. */
1021 bgp_attr_flush (attr);
1022 return RMAP_DENY;
1023 }
1024 }
1025 return RMAP_PERMIT;
1026 }
1027
1028 static int
1029 bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1030 afi_t afi, safi_t safi, const char *rmap_name)
1031 {
1032 struct bgp_filter *filter;
1033 struct bgp_info info;
1034 route_map_result_t ret;
1035 struct route_map *rmap = NULL;
1036
1037 filter = &peer->filter[afi][safi];
1038
1039 /* Apply default weight value. */
1040 if (peer->weight)
1041 (bgp_attr_extra_get (attr))->weight = peer->weight;
1042
1043 if (rmap_name)
1044 {
1045 rmap = route_map_lookup_by_name(rmap_name);
1046
1047 if (rmap == NULL)
1048 return RMAP_DENY;
1049 }
1050 else
1051 {
1052 if (ROUTE_MAP_OUT_NAME(filter))
1053 {
1054 rmap = ROUTE_MAP_OUT (filter);
1055
1056 if (rmap == NULL)
1057 return RMAP_DENY;
1058 }
1059 }
1060
1061 /* Route map apply. */
1062 if (rmap)
1063 {
1064 /* Duplicate current value to new strucutre for modification. */
1065 info.peer = peer;
1066 info.attr = attr;
1067
1068 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1069
1070 /* Apply BGP route map to the attribute. */
1071 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1072
1073 peer->rmap_type = 0;
1074
1075 if (ret == RMAP_DENYMATCH)
1076 /* caller has multiple error paths with bgp_attr_flush() */
1077 return RMAP_DENY;
1078 }
1079 return RMAP_PERMIT;
1080 }
1081
1082 /* If this is an EBGP peer with remove-private-AS */
1083 static void
1084 bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1085 struct peer *peer, struct attr *attr)
1086 {
1087 if (peer->sort == BGP_PEER_EBGP &&
1088 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1089 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1090 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1091 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
1092 {
1093 // Take action on the entire aspath
1094 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1095 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
1096 {
1097 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
1098 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1099
1100 // The entire aspath consists of private ASNs so create an empty aspath
1101 else if (aspath_private_as_check (attr->aspath))
1102 attr->aspath = aspath_empty_get ();
1103
1104 // There are some public and some private ASNs, remove the private ASNs
1105 else
1106 attr->aspath = aspath_remove_private_asns (attr->aspath);
1107 }
1108
1109 // 'all' was not specified so the entire aspath must be private ASNs
1110 // for us to do anything
1111 else if (aspath_private_as_check (attr->aspath))
1112 {
1113 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1114 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1115 else
1116 attr->aspath = aspath_empty_get ();
1117 }
1118 }
1119 }
1120
1121 /* If this is an EBGP peer with as-override */
1122 static void
1123 bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1124 struct peer *peer, struct attr *attr)
1125 {
1126 if (peer->sort == BGP_PEER_EBGP &&
1127 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1128 {
1129 if (aspath_single_asn_check (attr->aspath, peer->as))
1130 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1131 }
1132 }
1133
1134 static void
1135 subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1136 {
1137 if (family == AF_INET)
1138 attr->nexthop.s_addr = 0;
1139 #ifdef HAVE_IPV6
1140 if (family == AF_INET6)
1141 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1142 #endif
1143 }
1144
1145 int
1146 subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1147 struct prefix *p, struct attr *attr)
1148 {
1149 struct bgp_filter *filter;
1150 struct peer *from;
1151 struct peer *peer;
1152 struct peer *onlypeer;
1153 struct bgp *bgp;
1154 struct attr *riattr;
1155 struct peer_af *paf;
1156 char buf[SU_ADDRSTRLEN];
1157 int ret;
1158 int transparent;
1159 int reflect;
1160 afi_t afi;
1161 safi_t safi;
1162
1163 if (DISABLE_BGP_ANNOUNCE)
1164 return 0;
1165
1166 afi = SUBGRP_AFI(subgrp);
1167 safi = SUBGRP_SAFI(subgrp);
1168 peer = SUBGRP_PEER(subgrp);
1169 onlypeer = NULL;
1170 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1171 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1172
1173 from = ri->peer;
1174 filter = &peer->filter[afi][safi];
1175 bgp = SUBGRP_INST(subgrp);
1176 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1177
1178 /* With addpath we may be asked to TX all kinds of paths so make sure
1179 * ri is valid */
1180 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1181 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1182 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1183 {
1184 return 0;
1185 }
1186
1187 /* If this is not the bestpath then check to see if there is an enabled addpath
1188 * feature that requires us to advertise it */
1189 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1190 {
1191 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1192 {
1193 return 0;
1194 }
1195 }
1196
1197 /* Aggregate-address suppress check. */
1198 if (ri->extra && ri->extra->suppress)
1199 if (! UNSUPPRESS_MAP_NAME (filter))
1200 {
1201 return 0;
1202 }
1203
1204 /* Do not send back route to sender. */
1205 if (onlypeer && from == onlypeer)
1206 {
1207 return 0;
1208 }
1209
1210 /* Do not send the default route in the BGP table if the neighbor is
1211 * configured for default-originate */
1212 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1213 {
1214 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1215 return 0;
1216 #ifdef HAVE_IPV6
1217 else if (p->family == AF_INET6 && p->prefixlen == 0)
1218 return 0;
1219 #endif /* HAVE_IPV6 */
1220 }
1221
1222 /* Transparency check. */
1223 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1224 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1225 transparent = 1;
1226 else
1227 transparent = 0;
1228
1229 /* If community is not disabled check the no-export and local. */
1230 if (! transparent && bgp_community_filter (peer, riattr))
1231 {
1232 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1233 zlog_debug ("subgrpannouncecheck: community filter check fail");
1234 return 0;
1235 }
1236
1237 /* If the attribute has originator-id and it is same as remote
1238 peer's id. */
1239 if (onlypeer &&
1240 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1241 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1242 {
1243 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1244 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1245 "remote router-id",
1246 onlypeer->host,
1247 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1248 p->prefixlen);
1249 return 0;
1250 }
1251
1252 /* ORF prefix-list filter check */
1253 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1254 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1255 || CHECK_FLAG (peer->af_cap[afi][safi],
1256 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1257 if (peer->orf_plist[afi][safi])
1258 {
1259 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1260 {
1261 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1262 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1263 peer->host,
1264 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1265 p->prefixlen);
1266 return 0;
1267 }
1268 }
1269
1270 /* Output filter check. */
1271 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1272 {
1273 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1274 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1275 peer->host,
1276 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1277 p->prefixlen);
1278 return 0;
1279 }
1280
1281 #ifdef BGP_SEND_ASPATH_CHECK
1282 /* AS path loop check. */
1283 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1284 {
1285 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1286 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1287 "that is part of AS path.",
1288 onlypeer->host, onlypeer->as);
1289 return 0;
1290 }
1291 #endif /* BGP_SEND_ASPATH_CHECK */
1292
1293 /* If we're a CONFED we need to loop check the CONFED ID too */
1294 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1295 {
1296 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1297 {
1298 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1299 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1300 " is AS path.",
1301 peer->host,
1302 bgp->confed_id);
1303 return 0;
1304 }
1305 }
1306
1307 /* Route-Reflect check. */
1308 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1309 reflect = 1;
1310 else
1311 reflect = 0;
1312
1313 /* IBGP reflection check. */
1314 if (reflect)
1315 {
1316 /* A route from a Client peer. */
1317 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1318 {
1319 /* Reflect to all the Non-Client peers and also to the
1320 Client peers other than the originator. Originator check
1321 is already done. So there is noting to do. */
1322 /* no bgp client-to-client reflection check. */
1323 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1324 if (CHECK_FLAG (peer->af_flags[afi][safi],
1325 PEER_FLAG_REFLECTOR_CLIENT))
1326 return 0;
1327 }
1328 else
1329 {
1330 /* A route from a Non-client peer. Reflect to all other
1331 clients. */
1332 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1333 PEER_FLAG_REFLECTOR_CLIENT))
1334 return 0;
1335 }
1336 }
1337
1338 /* For modify attribute, copy it to temporary structure. */
1339 bgp_attr_dup (attr, riattr);
1340
1341 /* If local-preference is not set. */
1342 if ((peer->sort == BGP_PEER_IBGP
1343 || peer->sort == BGP_PEER_CONFED)
1344 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1345 {
1346 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1347 attr->local_pref = bgp->default_local_pref;
1348 }
1349
1350 /* If originator-id is not set and the route is to be reflected,
1351 set the originator id */
1352 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1353 {
1354 attr->extra = bgp_attr_extra_get(attr);
1355 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1356 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1357 }
1358
1359 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1360 if (peer->sort == BGP_PEER_EBGP
1361 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1362 {
1363 if (from != bgp->peer_self && ! transparent
1364 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1365 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1366 }
1367
1368 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1369 * in announce check, only certain flags and length (or number of nexthops
1370 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1371 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1372 * Typically, the source nexthop in the attribute is preserved but in the
1373 * scenarios where we know it will always be overwritten, we reset the
1374 * nexthop to "0" in an attempt to achieve better Update packing. An
1375 * example of this is when a prefix from each of 2 IBGP peers needs to be
1376 * announced to an EBGP peer (and they have the same attributes barring
1377 * their nexthop).
1378 */
1379 if (reflect)
1380 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1381
1382 #ifdef HAVE_IPV6
1383 #define NEXTHOP_IS_V6 (\
1384 (safi != SAFI_ENCAP && \
1385 (p->family == AF_INET6 || peer_cap_enhe(peer))) || \
1386 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
1387
1388 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1389 * the peer (group) is configured to receive link-local nexthop unchanged
1390 * and it is available in the prefix OR we're not reflecting the route and
1391 * the peer (group) to whom we're going to announce is on a shared network
1392 * and this is either a self-originated route or the peer is EBGP.
1393 */
1394 if (NEXTHOP_IS_V6)
1395 {
1396 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
1397 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1398 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1399 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1400 (!reflect && peer->shared_network &&
1401 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
1402 {
1403 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
1404 }
1405
1406 /* Clear off link-local nexthop in source, whenever it is not needed to
1407 * ensure more prefixes share the same attribute for announcement.
1408 */
1409 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1410 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1411 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1412 }
1413 #endif /* HAVE_IPV6 */
1414
1415 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1416 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1417
1418 /* Route map & unsuppress-map apply. */
1419 if (ROUTE_MAP_OUT_NAME (filter)
1420 || (ri->extra && ri->extra->suppress) )
1421 {
1422 struct bgp_info info;
1423 struct attr dummy_attr;
1424 struct attr_extra dummy_extra;
1425
1426 dummy_attr.extra = &dummy_extra;
1427
1428 info.peer = peer;
1429 info.attr = attr;
1430 /* don't confuse inbound and outbound setting */
1431 RESET_FLAG(attr->rmap_change_flags);
1432
1433 /*
1434 * The route reflector is not allowed to modify the attributes
1435 * of the reflected IBGP routes unless explicitly allowed.
1436 */
1437 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1438 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1439 {
1440 bgp_attr_dup (&dummy_attr, attr);
1441 info.attr = &dummy_attr;
1442 }
1443
1444 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1445
1446 if (ri->extra && ri->extra->suppress)
1447 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1448 else
1449 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1450
1451 peer->rmap_type = 0;
1452
1453 if (ret == RMAP_DENYMATCH)
1454 {
1455 bgp_attr_flush (attr);
1456 return 0;
1457 }
1458 }
1459
1460 /* After route-map has been applied, we check to see if the nexthop to
1461 * be carried in the attribute (that is used for the announcement) can
1462 * be cleared off or not. We do this in all cases where we would be
1463 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1464 * the global nexthop here; the link-local nexthop would have been cleared
1465 * already, and if not, it is required by the update formation code.
1466 * Also see earlier comments in this function.
1467 */
1468 /*
1469 * If route-map has performed some operation on the nexthop or the peer
1470 * configuration says to pass it unchanged, we cannot reset the nexthop
1471 * here, so only attempt to do it if these aren't true. Note that the
1472 * route-map handler itself might have cleared the nexthop, if for example,
1473 * it is configured as 'peer-address'.
1474 */
1475 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1476 riattr->rmap_change_flags) &&
1477 !transparent &&
1478 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
1479 {
1480 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
1481 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1482 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
1483 {
1484 if (!reflect ||
1485 CHECK_FLAG (peer->af_flags[afi][safi],
1486 PEER_FLAG_FORCE_NEXTHOP_SELF))
1487 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1488 AF_INET6 : p->family), attr);
1489 }
1490 else if (peer->sort == BGP_PEER_EBGP)
1491 {
1492 /* Can also reset the nexthop if announcing to EBGP, but only if
1493 * no peer in the subgroup is on a shared subnet.
1494 * Note: 3rd party nexthop currently implemented for IPv4 only.
1495 */
1496 SUBGRP_FOREACH_PEER (subgrp, paf)
1497 {
1498 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1499 break;
1500 }
1501 if (!paf)
1502 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
1503 }
1504 /* If IPv6/MP and nexthop does not have any override and happens to
1505 * be a link-local address, reset it so that we don't pass along the
1506 * source's link-local IPv6 address to recipients who may not be on
1507 * the same interface.
1508 */
1509 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1510 {
1511 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1512 subgroup_announce_reset_nhop (AF_INET6, attr);
1513 }
1514 }
1515
1516 return 1;
1517 }
1518
1519 struct bgp_info_pair
1520 {
1521 struct bgp_info *old;
1522 struct bgp_info *new;
1523 };
1524
1525 static void
1526 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1527 struct bgp_maxpaths_cfg *mpath_cfg,
1528 struct bgp_info_pair *result)
1529 {
1530 struct bgp_info *new_select;
1531 struct bgp_info *old_select;
1532 struct bgp_info *ri;
1533 struct bgp_info *ri1;
1534 struct bgp_info *ri2;
1535 struct bgp_info *nextri = NULL;
1536 int paths_eq, do_mpath, debug;
1537 struct list mp_list;
1538 char pfx_buf[PREFIX2STR_BUFFER];
1539 char path_buf[PATH_ADDPATH_STR_BUFFER];
1540
1541 bgp_mp_list_init (&mp_list);
1542 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
1543
1544 debug = bgp_debug_bestpath(&rn->p);
1545
1546 if (debug)
1547 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1548
1549 /* bgp deterministic-med */
1550 new_select = NULL;
1551 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1552 {
1553
1554 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1555 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1556 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1557
1558 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1559 {
1560 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1561 continue;
1562 if (BGP_INFO_HOLDDOWN (ri1))
1563 continue;
1564 if (ri1->peer && ri1->peer != bgp->peer_self)
1565 if (ri1->peer->status != Established)
1566 continue;
1567
1568 new_select = ri1;
1569 if (ri1->next)
1570 {
1571 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1572 {
1573 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1574 continue;
1575 if (BGP_INFO_HOLDDOWN (ri2))
1576 continue;
1577 if (ri2->peer &&
1578 ri2->peer != bgp->peer_self &&
1579 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1580 if (ri2->peer->status != Established)
1581 continue;
1582
1583 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1584 || aspath_cmp_left_confed (ri1->attr->aspath,
1585 ri2->attr->aspath))
1586 {
1587 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1588 mpath_cfg, debug, pfx_buf))
1589 {
1590 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1591 new_select = ri2;
1592 }
1593
1594 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1595 }
1596 }
1597 }
1598 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1599 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1600
1601 if (debug)
1602 {
1603 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1604 zlog_debug("%s: %s is the bestpath from AS %d",
1605 pfx_buf, path_buf, aspath_get_firstas(new_select->attr->aspath));
1606 }
1607 }
1608 }
1609
1610 /* Check old selected route and new selected route. */
1611 old_select = NULL;
1612 new_select = NULL;
1613 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1614 {
1615 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1616 old_select = ri;
1617
1618 if (BGP_INFO_HOLDDOWN (ri))
1619 {
1620 /* reap REMOVED routes, if needs be
1621 * selected route must stay for a while longer though
1622 */
1623 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1624 && (ri != old_select))
1625 bgp_info_reap (rn, ri);
1626
1627 continue;
1628 }
1629
1630 if (ri->peer &&
1631 ri->peer != bgp->peer_self &&
1632 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1633 if (ri->peer->status != Established)
1634 continue;
1635
1636 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1637 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1638 {
1639 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1640 continue;
1641 }
1642
1643 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1644
1645 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
1646 {
1647 new_select = ri;
1648 }
1649 }
1650
1651 /* Now that we know which path is the bestpath see if any of the other paths
1652 * qualify as multipaths
1653 */
1654 if (debug)
1655 {
1656 if (new_select)
1657 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1658 else
1659 sprintf (path_buf, "NONE");
1660 zlog_debug("%s: After path selection, newbest is %s oldbest was %s",
1661 pfx_buf, path_buf,
1662 old_select ? old_select->peer->host : "NONE");
1663 }
1664
1665 if (do_mpath && new_select)
1666 {
1667 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1668 {
1669
1670 if (debug)
1671 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1672
1673 if (ri == new_select)
1674 {
1675 if (debug)
1676 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1677 pfx_buf, path_buf);
1678 bgp_mp_list_add (&mp_list, ri);
1679 continue;
1680 }
1681
1682 if (BGP_INFO_HOLDDOWN (ri))
1683 continue;
1684
1685 if (ri->peer &&
1686 ri->peer != bgp->peer_self &&
1687 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1688 if (ri->peer->status != Established)
1689 continue;
1690
1691 if (!bgp_info_nexthop_cmp (ri, new_select))
1692 {
1693 if (debug)
1694 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1695 pfx_buf, path_buf);
1696 continue;
1697 }
1698
1699 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
1700
1701 if (paths_eq)
1702 {
1703 if (debug)
1704 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1705 pfx_buf, path_buf);
1706 bgp_mp_list_add (&mp_list, ri);
1707 }
1708 }
1709 }
1710
1711 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1712 bgp_info_mpath_aggregate_update (new_select, old_select);
1713 bgp_mp_list_clear (&mp_list);
1714
1715 result->old = old_select;
1716 result->new = new_select;
1717
1718 return;
1719 }
1720
1721 /*
1722 * A new route/change in bestpath of an existing route. Evaluate the path
1723 * for advertisement to the subgroup.
1724 */
1725 int
1726 subgroup_process_announce_selected (struct update_subgroup *subgrp,
1727 struct bgp_info *selected,
1728 struct bgp_node *rn,
1729 u_int32_t addpath_tx_id)
1730 {
1731 struct prefix *p;
1732 struct peer *onlypeer;
1733 struct attr attr;
1734 struct attr_extra extra;
1735 afi_t afi;
1736 safi_t safi;
1737
1738 p = &rn->p;
1739 afi = SUBGRP_AFI(subgrp);
1740 safi = SUBGRP_SAFI(subgrp);
1741 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1742 (SUBGRP_PFIRST(subgrp))->peer : NULL);
1743
1744 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1745 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1746 PEER_STATUS_ORF_WAIT_REFRESH))
1747 return 0;
1748
1749 /* It's initialized in bgp_announce_check() */
1750 attr.extra = &extra;
1751
1752 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1753 if (selected)
1754 {
1755 if (subgroup_announce_check(selected, subgrp, p, &attr))
1756 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1757 else
1758 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1759 }
1760
1761 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1762 else
1763 {
1764 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
1765 }
1766
1767 return 0;
1768 }
1769
1770 /*
1771 * Clear IGP changed flag and attribute changed flag for a route (all paths).
1772 * This is called at the end of route processing.
1773 */
1774 static void
1775 bgp_zebra_clear_route_change_flags (struct bgp_node *rn)
1776 {
1777 struct bgp_info *ri;
1778
1779 for (ri = rn->info; ri; ri = ri->next)
1780 {
1781 if (BGP_INFO_HOLDDOWN (ri))
1782 continue;
1783 UNSET_FLAG (ri->flags, BGP_INFO_IGP_CHANGED);
1784 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1785 }
1786 }
1787
1788 /*
1789 * Has the route changed from the RIB's perspective? This is invoked only
1790 * if the route selection returns the same best route as earlier - to
1791 * determine if we need to update zebra or not.
1792 */
1793 static int
1794 bgp_zebra_has_route_changed (struct bgp_node *rn, struct bgp_info *selected)
1795 {
1796 struct bgp_info *mpinfo;
1797
1798 /* If this is multipath, check all selected paths for any nexthop change or
1799 * attribute change. Some attribute changes (e.g., community) aren't of
1800 * relevance to the RIB, but we'll update zebra to ensure we handle the
1801 * case of BGP nexthop change. This is the behavior when the best path has
1802 * an attribute change anyway.
1803 */
1804 if (CHECK_FLAG (selected->flags, BGP_INFO_IGP_CHANGED) ||
1805 CHECK_FLAG (selected->flags, BGP_INFO_MULTIPATH_CHG))
1806 return 1;
1807
1808 /* If this is multipath, check all selected paths for any nexthop change */
1809 for (mpinfo = bgp_info_mpath_first (selected); mpinfo;
1810 mpinfo = bgp_info_mpath_next (mpinfo))
1811 {
1812 if (CHECK_FLAG (mpinfo->flags, BGP_INFO_IGP_CHANGED)
1813 || CHECK_FLAG (mpinfo->flags, BGP_INFO_ATTR_CHANGED))
1814 return 1;
1815 }
1816
1817 /* Nothing has changed from the RIB's perspective. */
1818 return 0;
1819 }
1820
1821 struct bgp_process_queue
1822 {
1823 struct bgp *bgp;
1824 struct bgp_node *rn;
1825 afi_t afi;
1826 safi_t safi;
1827 };
1828
1829 static wq_item_status
1830 bgp_process_main (struct work_queue *wq, void *data)
1831 {
1832 struct bgp_process_queue *pq = data;
1833 struct bgp *bgp = pq->bgp;
1834 struct bgp_node *rn = pq->rn;
1835 afi_t afi = pq->afi;
1836 safi_t safi = pq->safi;
1837 struct prefix *p = &rn->p;
1838 struct bgp_info *new_select;
1839 struct bgp_info *old_select;
1840 struct bgp_info_pair old_and_new;
1841
1842 /* Is it end of initial update? (after startup) */
1843 if (!rn)
1844 {
1845 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1846 sizeof(bgp->update_delay_zebra_resume_time));
1847
1848 bgp->main_zebra_update_hold = 0;
1849 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1850 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1851 {
1852 bgp_zebra_announce_table(bgp, afi, safi);
1853 }
1854 bgp->main_peers_update_hold = 0;
1855
1856 bgp_start_routeadv(bgp);
1857 return WQ_SUCCESS;
1858 }
1859
1860 /* Best path selection. */
1861 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1862 old_select = old_and_new.old;
1863 new_select = old_and_new.new;
1864
1865 /* Nothing to do. */
1866 if (old_select && old_select == new_select &&
1867 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1868 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1869 !bgp->addpath_tx_used[afi][safi])
1870 {
1871 if (bgp_zebra_has_route_changed (rn, old_select))
1872 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1873
1874 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1875 bgp_zebra_clear_route_change_flags (rn);
1876 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1877 return WQ_SUCCESS;
1878 }
1879
1880 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1881 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1882
1883 /* bestpath has changed; bump version */
1884 if (old_select || new_select)
1885 {
1886 bgp_bump_version(rn);
1887
1888 if (!bgp->t_rmap_def_originate_eval)
1889 {
1890 bgp_lock (bgp);
1891 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
1892 update_group_refresh_default_originate_route_map,
1893 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1894 }
1895 }
1896
1897 if (old_select)
1898 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1899 if (new_select)
1900 {
1901 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1902 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1903 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1904 }
1905
1906 group_announce_route(bgp, afi, safi, rn, new_select);
1907
1908 /* FIB update. */
1909 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) &&
1910 (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) &&
1911 !bgp_option_check (BGP_OPT_NO_FIB))
1912 {
1913 if (new_select
1914 && new_select->type == ZEBRA_ROUTE_BGP
1915 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1916 new_select->sub_type == BGP_ROUTE_AGGREGATE))
1917 bgp_zebra_announce (p, new_select, bgp, afi, safi);
1918 else
1919 {
1920 /* Withdraw the route from the kernel. */
1921 if (old_select
1922 && old_select->type == ZEBRA_ROUTE_BGP
1923 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
1924 old_select->sub_type == BGP_ROUTE_AGGREGATE))
1925 bgp_zebra_withdraw (p, old_select, safi);
1926 }
1927 }
1928
1929 /* Clear any route change flags. */
1930 bgp_zebra_clear_route_change_flags (rn);
1931
1932 /* Reap old select bgp_info, if it has been removed */
1933 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1934 bgp_info_reap (rn, old_select);
1935
1936 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1937 return WQ_SUCCESS;
1938 }
1939
1940 static void
1941 bgp_processq_del (struct work_queue *wq, void *data)
1942 {
1943 struct bgp_process_queue *pq = data;
1944 struct bgp_table *table;
1945
1946 bgp_unlock (pq->bgp);
1947 if (pq->rn)
1948 {
1949 table = bgp_node_table (pq->rn);
1950 bgp_unlock_node (pq->rn);
1951 bgp_table_unlock (table);
1952 }
1953 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1954 }
1955
1956 void
1957 bgp_process_queue_init (void)
1958 {
1959 if (!bm->process_main_queue)
1960 {
1961 bm->process_main_queue
1962 = work_queue_new (bm->master, "process_main_queue");
1963
1964 if ( !bm->process_main_queue)
1965 {
1966 zlog_err ("%s: Failed to allocate work queue", __func__);
1967 exit (1);
1968 }
1969 }
1970
1971 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1972 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1973 bm->process_main_queue->spec.max_retries = 0;
1974 bm->process_main_queue->spec.hold = 50;
1975 /* Use a higher yield value of 50ms for main queue processing */
1976 bm->process_main_queue->spec.yield = 50 * 1000L;
1977 }
1978
1979 void
1980 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1981 {
1982 struct bgp_process_queue *pqnode;
1983
1984 /* already scheduled for processing? */
1985 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1986 return;
1987
1988 if (bm->process_main_queue == NULL)
1989 bgp_process_queue_init ();
1990
1991 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1992 sizeof (struct bgp_process_queue));
1993 if (!pqnode)
1994 return;
1995
1996 /* all unlocked in bgp_processq_del */
1997 bgp_table_lock (bgp_node_table (rn));
1998 pqnode->rn = bgp_lock_node (rn);
1999 pqnode->bgp = bgp;
2000 bgp_lock (bgp);
2001 pqnode->afi = afi;
2002 pqnode->safi = safi;
2003 work_queue_add (bm->process_main_queue, pqnode);
2004 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2005 return;
2006 }
2007
2008 void
2009 bgp_add_eoiu_mark (struct bgp *bgp)
2010 {
2011 struct bgp_process_queue *pqnode;
2012
2013 if (bm->process_main_queue == NULL)
2014 bgp_process_queue_init ();
2015
2016 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2017 sizeof (struct bgp_process_queue));
2018 if (!pqnode)
2019 return;
2020
2021 pqnode->rn = NULL;
2022 pqnode->bgp = bgp;
2023 bgp_lock (bgp);
2024 work_queue_add (bm->process_main_queue, pqnode);
2025 }
2026
2027 static int
2028 bgp_maximum_prefix_restart_timer (struct thread *thread)
2029 {
2030 struct peer *peer;
2031
2032 peer = THREAD_ARG (thread);
2033 peer->t_pmax_restart = NULL;
2034
2035 if (bgp_debug_neighbor_events(peer))
2036 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2037 peer->host);
2038
2039 peer_clear (peer, NULL);
2040
2041 return 0;
2042 }
2043
2044 int
2045 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2046 safi_t safi, int always)
2047 {
2048 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2049 return 0;
2050
2051 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
2052 {
2053 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2054 && ! always)
2055 return 0;
2056
2057 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2058 "limit %ld", afi_safi_print (afi, safi), peer->host,
2059 peer->pcount[afi][safi], peer->pmax[afi][safi]);
2060 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2061
2062 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2063 return 0;
2064
2065 {
2066 u_int8_t ndata[7];
2067
2068 if (safi == SAFI_MPLS_VPN)
2069 safi = SAFI_MPLS_LABELED_VPN;
2070
2071 ndata[0] = (afi >> 8);
2072 ndata[1] = afi;
2073 ndata[2] = safi;
2074 ndata[3] = (peer->pmax[afi][safi] >> 24);
2075 ndata[4] = (peer->pmax[afi][safi] >> 16);
2076 ndata[5] = (peer->pmax[afi][safi] >> 8);
2077 ndata[6] = (peer->pmax[afi][safi]);
2078
2079 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2080 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2081 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2082 }
2083
2084 /* Dynamic peers will just close their connection. */
2085 if (peer_dynamic_neighbor (peer))
2086 return 1;
2087
2088 /* restart timer start */
2089 if (peer->pmax_restart[afi][safi])
2090 {
2091 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2092
2093 if (bgp_debug_neighbor_events(peer))
2094 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2095 peer->host, peer->v_pmax_restart);
2096
2097 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2098 peer->v_pmax_restart);
2099 }
2100
2101 return 1;
2102 }
2103 else
2104 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2105
2106 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2107 {
2108 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2109 && ! always)
2110 return 0;
2111
2112 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2113 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2114 peer->pmax[afi][safi]);
2115 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2116 }
2117 else
2118 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2119 return 0;
2120 }
2121
2122 /* Unconditionally remove the route from the RIB, without taking
2123 * damping into consideration (eg, because the session went down)
2124 */
2125 static void
2126 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2127 afi_t afi, safi_t safi)
2128 {
2129 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2130
2131 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2132 bgp_info_delete (rn, ri); /* keep historical info */
2133
2134 bgp_process (peer->bgp, rn, afi, safi);
2135 }
2136
2137 static void
2138 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2139 afi_t afi, safi_t safi)
2140 {
2141 int status = BGP_DAMP_NONE;
2142
2143 /* apply dampening, if result is suppressed, we'll be retaining
2144 * the bgp_info in the RIB for historical reference.
2145 */
2146 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2147 && peer->sort == BGP_PEER_EBGP)
2148 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2149 == BGP_DAMP_SUPPRESSED)
2150 {
2151 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2152 return;
2153 }
2154
2155 bgp_rib_remove (rn, ri, peer, afi, safi);
2156 }
2157
2158 static struct bgp_info *
2159 info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
2160 struct bgp_node *rn)
2161 {
2162 struct bgp_info *new;
2163
2164 /* Make new BGP info. */
2165 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2166 new->type = type;
2167 new->instance = instance;
2168 new->sub_type = sub_type;
2169 new->peer = peer;
2170 new->attr = attr;
2171 new->uptime = bgp_clock ();
2172 new->net = rn;
2173 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
2174 return new;
2175 }
2176
2177 static void
2178 bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
2179 {
2180 if (addpath_id)
2181 sprintf(buf, " with addpath ID %d", addpath_id);
2182 }
2183
2184
2185 /* Check if received nexthop is valid or not. */
2186 static int
2187 bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
2188 {
2189 struct attr_extra *attre = attr->extra;
2190 int ret = 0;
2191
2192 /* Only validated for unicast and multicast currently. */
2193 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2194 return 0;
2195
2196 /* If NEXT_HOP is present, validate it. */
2197 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2198 {
2199 if (attr->nexthop.s_addr == 0 ||
2200 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2201 bgp_nexthop_self (bgp, attr))
2202 ret = 1;
2203 }
2204
2205 /* If MP_NEXTHOP is present, validate it. */
2206 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2207 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2208 * it is not an IPv6 link-local address.
2209 */
2210 if (attre && attre->mp_nexthop_len)
2211 {
2212 switch (attre->mp_nexthop_len)
2213 {
2214 case BGP_ATTR_NHLEN_IPV4:
2215 case BGP_ATTR_NHLEN_VPNV4:
2216 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2217 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2218 break;
2219
2220 #ifdef HAVE_IPV6
2221 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2222 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2223 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2224 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2225 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2226 break;
2227 #endif /* HAVE_IPV6 */
2228
2229 default:
2230 ret = 1;
2231 break;
2232 }
2233 }
2234
2235 return ret;
2236 }
2237
2238 int
2239 bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2240 struct attr *attr, afi_t afi, safi_t safi, int type,
2241 int sub_type, struct prefix_rd *prd, u_char *tag,
2242 int soft_reconfig)
2243 {
2244 int ret;
2245 int aspath_loop_count = 0;
2246 struct bgp_node *rn;
2247 struct bgp *bgp;
2248 struct attr new_attr;
2249 struct attr_extra new_extra;
2250 struct attr *attr_new;
2251 struct bgp_info *ri;
2252 struct bgp_info *new;
2253 const char *reason;
2254 char buf[SU_ADDRSTRLEN];
2255 char buf2[30];
2256 int connected = 0;
2257
2258 bgp = peer->bgp;
2259 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2260
2261 /* When peer's soft reconfiguration enabled. Record input packet in
2262 Adj-RIBs-In. */
2263 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2264 && peer != bgp->peer_self)
2265 bgp_adj_in_set (rn, peer, attr, addpath_id);
2266
2267 /* Check previously received route. */
2268 for (ri = rn->info; ri; ri = ri->next)
2269 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2270 ri->addpath_rx_id == addpath_id)
2271 break;
2272
2273 /* AS path local-as loop check. */
2274 if (peer->change_local_as)
2275 {
2276 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2277 aspath_loop_count = 1;
2278
2279 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2280 {
2281 reason = "as-path contains our own AS;";
2282 goto filtered;
2283 }
2284 }
2285
2286 /* AS path loop check. */
2287 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2288 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2289 && aspath_loop_check(attr->aspath, bgp->confed_id)
2290 > peer->allowas_in[afi][safi]))
2291 {
2292 reason = "as-path contains our own AS;";
2293 goto filtered;
2294 }
2295
2296 /* Route reflector originator ID check. */
2297 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2298 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2299 {
2300 reason = "originator is us;";
2301 goto filtered;
2302 }
2303
2304 /* Route reflector cluster ID check. */
2305 if (bgp_cluster_filter (peer, attr))
2306 {
2307 reason = "reflected from the same cluster;";
2308 goto filtered;
2309 }
2310
2311 /* Apply incoming filter. */
2312 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2313 {
2314 reason = "filter;";
2315 goto filtered;
2316 }
2317
2318 new_attr.extra = &new_extra;
2319 bgp_attr_dup (&new_attr, attr);
2320
2321 /* Apply incoming route-map.
2322 * NB: new_attr may now contain newly allocated values from route-map "set"
2323 * commands, so we need bgp_attr_flush in the error paths, until we intern
2324 * the attr (which takes over the memory references) */
2325 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2326 {
2327 reason = "route-map;";
2328 bgp_attr_flush (&new_attr);
2329 goto filtered;
2330 }
2331
2332 /* next hop check. */
2333 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
2334 {
2335 reason = "martian or self next-hop;";
2336 bgp_attr_flush (&new_attr);
2337 goto filtered;
2338 }
2339
2340 attr_new = bgp_attr_intern (&new_attr);
2341
2342 /* If the update is implicit withdraw. */
2343 if (ri)
2344 {
2345 ri->uptime = bgp_clock ();
2346
2347 /* Same attribute comes in. */
2348 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2349 && attrhash_cmp (ri->attr, attr_new))
2350 {
2351 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2352 && peer->sort == BGP_PEER_EBGP
2353 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2354 {
2355 if (bgp_debug_update(peer, p, NULL, 1))
2356 {
2357 bgp_info_addpath_rx_str(addpath_id, buf2);
2358 zlog_debug ("%s rcvd %s/%d%s",
2359 peer->host,
2360 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2361 p->prefixlen, buf2);
2362 }
2363
2364 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2365 {
2366 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2367 bgp_process (bgp, rn, afi, safi);
2368 }
2369 }
2370 else /* Duplicate - odd */
2371 {
2372 if (bgp_debug_update(peer, p, NULL, 1))
2373 {
2374 if (!peer->rcvd_attr_printed)
2375 {
2376 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2377 peer->rcvd_attr_printed = 1;
2378 }
2379
2380 bgp_info_addpath_rx_str(addpath_id, buf2);
2381 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
2382 peer->host,
2383 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2384 p->prefixlen, buf2);
2385 }
2386
2387 /* graceful restart STALE flag unset. */
2388 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2389 {
2390 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2391 bgp_process (bgp, rn, afi, safi);
2392 }
2393 }
2394
2395 bgp_unlock_node (rn);
2396 bgp_attr_unintern (&attr_new);
2397
2398 return 0;
2399 }
2400
2401 /* Withdraw/Announce before we fully processed the withdraw */
2402 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2403 {
2404 if (bgp_debug_update(peer, p, NULL, 1))
2405 {
2406 bgp_info_addpath_rx_str(addpath_id, buf2);
2407 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2408 peer->host,
2409 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2410 p->prefixlen, buf2);
2411 }
2412 bgp_info_restore (rn, ri);
2413 }
2414
2415 /* Received Logging. */
2416 if (bgp_debug_update(peer, p, NULL, 1))
2417 {
2418 bgp_info_addpath_rx_str(addpath_id, buf2);
2419 zlog_debug ("%s rcvd %s/%d%s",
2420 peer->host,
2421 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2422 p->prefixlen, buf2);
2423 }
2424
2425 /* graceful restart STALE flag unset. */
2426 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2427 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2428
2429 /* The attribute is changed. */
2430 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2431
2432 /* implicit withdraw, decrement aggregate and pcount here.
2433 * only if update is accepted, they'll increment below.
2434 */
2435 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2436
2437 /* Update bgp route dampening information. */
2438 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2439 && peer->sort == BGP_PEER_EBGP)
2440 {
2441 /* This is implicit withdraw so we should update dampening
2442 information. */
2443 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2444 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2445 }
2446
2447 /* Update to new attribute. */
2448 bgp_attr_unintern (&ri->attr);
2449 ri->attr = attr_new;
2450
2451 /* Update MPLS tag. */
2452 if (safi == SAFI_MPLS_VPN)
2453 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2454
2455 /* Update bgp route dampening information. */
2456 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2457 && peer->sort == BGP_PEER_EBGP)
2458 {
2459 /* Now we do normal update dampening. */
2460 ret = bgp_damp_update (ri, rn, afi, safi);
2461 if (ret == BGP_DAMP_SUPPRESSED)
2462 {
2463 bgp_unlock_node (rn);
2464 return 0;
2465 }
2466 }
2467
2468 /* Nexthop reachability check. */
2469 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2470 {
2471 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2472 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2473 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2474 connected = 1;
2475 else
2476 connected = 0;
2477
2478 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
2479 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2480 else
2481 {
2482 if (BGP_DEBUG(nht, NHT))
2483 {
2484 char buf1[INET6_ADDRSTRLEN];
2485 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2486 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2487 }
2488 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2489 }
2490 }
2491 else
2492 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2493
2494 /* Process change. */
2495 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2496
2497 bgp_process (bgp, rn, afi, safi);
2498 bgp_unlock_node (rn);
2499
2500 return 0;
2501 } // End of implicit withdraw
2502
2503 /* Received Logging. */
2504 if (bgp_debug_update(peer, p, NULL, 1))
2505 {
2506 if (!peer->rcvd_attr_printed)
2507 {
2508 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2509 peer->rcvd_attr_printed = 1;
2510 }
2511
2512 bgp_info_addpath_rx_str(addpath_id, buf2);
2513 zlog_debug ("%s rcvd %s/%d%s",
2514 peer->host,
2515 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2516 p->prefixlen, buf2);
2517 }
2518
2519 /* Make new BGP info. */
2520 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2521
2522 /* Update MPLS tag. */
2523 if (safi == SAFI_MPLS_VPN)
2524 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2525
2526 /* Nexthop reachability check. */
2527 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2528 {
2529 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2530 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2531 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2532 connected = 1;
2533 else
2534 connected = 0;
2535
2536 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
2537 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2538 else
2539 {
2540 if (BGP_DEBUG(nht, NHT))
2541 {
2542 char buf1[INET6_ADDRSTRLEN];
2543 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2544 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2545 }
2546 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2547 }
2548 }
2549 else
2550 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2551
2552 /* Addpath ID */
2553 new->addpath_rx_id = addpath_id;
2554
2555 /* Increment prefix */
2556 bgp_aggregate_increment (bgp, p, new, afi, safi);
2557
2558 /* Register new BGP information. */
2559 bgp_info_add (rn, new);
2560
2561 /* route_node_get lock */
2562 bgp_unlock_node (rn);
2563
2564 /* If maximum prefix count is configured and current prefix
2565 count exeed it. */
2566 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2567 return -1;
2568
2569 /* Process change. */
2570 bgp_process (bgp, rn, afi, safi);
2571
2572 return 0;
2573
2574 /* This BGP update is filtered. Log the reason then update BGP
2575 entry. */
2576 filtered:
2577 if (bgp_debug_update(peer, p, NULL, 1))
2578 {
2579 if (!peer->rcvd_attr_printed)
2580 {
2581 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2582 peer->rcvd_attr_printed = 1;
2583 }
2584
2585 bgp_info_addpath_rx_str(addpath_id, buf2);
2586 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
2587 peer->host,
2588 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2589 p->prefixlen, buf2, reason);
2590 }
2591
2592 if (ri)
2593 bgp_rib_remove (rn, ri, peer, afi, safi);
2594
2595 bgp_unlock_node (rn);
2596
2597 return 0;
2598 }
2599
2600 int
2601 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2602 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2603 struct prefix_rd *prd, u_char *tag)
2604 {
2605 struct bgp *bgp;
2606 char buf[SU_ADDRSTRLEN];
2607 char buf2[30];
2608 struct bgp_node *rn;
2609 struct bgp_info *ri;
2610
2611 bgp = peer->bgp;
2612
2613 /* Lookup node. */
2614 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2615
2616 /* If peer is soft reconfiguration enabled. Record input packet for
2617 * further calculation.
2618 *
2619 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2620 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2621 * the iteration over all RS clients.
2622 * Since we need to remove the entry from adj_in anyway, do that first and
2623 * if there was no entry, we don't need to do anything more.
2624 */
2625 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2626 && peer != bgp->peer_self)
2627 if (!bgp_adj_in_unset (rn, peer, addpath_id))
2628 {
2629 if (bgp_debug_update (peer, p, NULL, 1))
2630 zlog_debug ("%s withdrawing route %s/%d "
2631 "not in adj-in", peer->host,
2632 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2633 p->prefixlen);
2634 bgp_unlock_node (rn);
2635 return 0;
2636 }
2637
2638 /* Lookup withdrawn route. */
2639 for (ri = rn->info; ri; ri = ri->next)
2640 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2641 ri->addpath_rx_id == addpath_id)
2642 break;
2643
2644 /* Logging. */
2645 if (bgp_debug_update(peer, p, NULL, 1))
2646 {
2647 bgp_info_addpath_rx_str(addpath_id, buf2);
2648 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2649 peer->host,
2650 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2651 p->prefixlen, buf2);
2652 }
2653
2654 /* Withdraw specified route from routing table. */
2655 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2656 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2657 else if (bgp_debug_update(peer, p, NULL, 1))
2658 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2659 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2660 p->prefixlen);
2661
2662 /* Unlock bgp_node_get() lock. */
2663 bgp_unlock_node (rn);
2664
2665 return 0;
2666 }
2667
2668 void
2669 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2670 {
2671 struct update_subgroup *subgrp;
2672 subgrp = peer_subgroup(peer, afi, safi);
2673 subgroup_default_originate(subgrp, withdraw);
2674 }
2675
2676
2677 /*
2678 * bgp_stop_announce_route_timer
2679 */
2680 void
2681 bgp_stop_announce_route_timer (struct peer_af *paf)
2682 {
2683 if (!paf->t_announce_route)
2684 return;
2685
2686 THREAD_TIMER_OFF (paf->t_announce_route);
2687 }
2688
2689 /*
2690 * bgp_announce_route_timer_expired
2691 *
2692 * Callback that is invoked when the route announcement timer for a
2693 * peer_af expires.
2694 */
2695 static int
2696 bgp_announce_route_timer_expired (struct thread *t)
2697 {
2698 struct peer_af *paf;
2699 struct peer *peer;
2700
2701 paf = THREAD_ARG (t);
2702 peer = paf->peer;
2703
2704 assert (paf->t_announce_route);
2705 paf->t_announce_route = NULL;
2706
2707 if (peer->status != Established)
2708 return 0;
2709
2710 if (!peer->afc_nego[paf->afi][paf->safi])
2711 return 0;
2712
2713 peer_af_announce_route (paf, 1);
2714 return 0;
2715 }
2716
2717 /*
2718 * bgp_announce_route
2719 *
2720 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2721 */
2722 void
2723 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2724 {
2725 struct peer_af *paf;
2726 struct update_subgroup *subgrp;
2727
2728 paf = peer_af_find (peer, afi, safi);
2729 if (!paf)
2730 return;
2731 subgrp = PAF_SUBGRP(paf);
2732
2733 /*
2734 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2735 * or a refresh has already been triggered.
2736 */
2737 if (!subgrp || paf->t_announce_route)
2738 return;
2739
2740 /*
2741 * Start a timer to stagger/delay the announce. This serves
2742 * two purposes - announcement can potentially be combined for
2743 * multiple peers and the announcement doesn't happen in the
2744 * vty context.
2745 */
2746 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
2747 bgp_announce_route_timer_expired, paf,
2748 (subgrp->peer_count == 1) ?
2749 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2750 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2751 }
2752
2753 /*
2754 * Announce routes from all AF tables to a peer.
2755 *
2756 * This should ONLY be called when there is a need to refresh the
2757 * routes to the peer based on a policy change for this peer alone
2758 * or a route refresh request received from the peer.
2759 * The operation will result in splitting the peer from its existing
2760 * subgroups and putting it in new subgroups.
2761 */
2762 void
2763 bgp_announce_route_all (struct peer *peer)
2764 {
2765 afi_t afi;
2766 safi_t safi;
2767
2768 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2769 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2770 bgp_announce_route (peer, afi, safi);
2771 }
2772
2773 static void
2774 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2775 struct bgp_table *table, struct prefix_rd *prd)
2776 {
2777 int ret;
2778 struct bgp_node *rn;
2779 struct bgp_adj_in *ain;
2780
2781 if (! table)
2782 table = peer->bgp->rib[afi][safi];
2783
2784 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2785 for (ain = rn->adj_in; ain; ain = ain->next)
2786 {
2787 if (ain->peer == peer)
2788 {
2789 struct bgp_info *ri = rn->info;
2790 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2791
2792 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
2793 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2794 prd, tag, 1);
2795
2796 if (ret < 0)
2797 {
2798 bgp_unlock_node (rn);
2799 return;
2800 }
2801 }
2802 }
2803 }
2804
2805 void
2806 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2807 {
2808 struct bgp_node *rn;
2809 struct bgp_table *table;
2810
2811 if (peer->status != Established)
2812 return;
2813
2814 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
2815 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
2816 else
2817 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2818 rn = bgp_route_next (rn))
2819 if ((table = rn->info) != NULL)
2820 {
2821 struct prefix_rd prd;
2822 prd.family = AF_UNSPEC;
2823 prd.prefixlen = 64;
2824 memcpy(&prd.val, rn->p.u.val, 8);
2825
2826 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2827 }
2828 }
2829
2830
2831 struct bgp_clear_node_queue
2832 {
2833 struct bgp_node *rn;
2834 };
2835
2836 static wq_item_status
2837 bgp_clear_route_node (struct work_queue *wq, void *data)
2838 {
2839 struct bgp_clear_node_queue *cnq = data;
2840 struct bgp_node *rn = cnq->rn;
2841 struct peer *peer = wq->spec.data;
2842 struct bgp_info *ri;
2843 afi_t afi = bgp_node_table (rn)->afi;
2844 safi_t safi = bgp_node_table (rn)->safi;
2845
2846 assert (rn && peer);
2847
2848 /* It is possible that we have multiple paths for a prefix from a peer
2849 * if that peer is using AddPath.
2850 */
2851 for (ri = rn->info; ri; ri = ri->next)
2852 if (ri->peer == peer)
2853 {
2854 /* graceful restart STALE flag set. */
2855 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2856 && peer->nsf[afi][safi]
2857 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2858 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2859 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
2860 else
2861 bgp_rib_remove (rn, ri, peer, afi, safi);
2862 }
2863 return WQ_SUCCESS;
2864 }
2865
2866 static void
2867 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
2868 {
2869 struct bgp_clear_node_queue *cnq = data;
2870 struct bgp_node *rn = cnq->rn;
2871 struct bgp_table *table = bgp_node_table (rn);
2872
2873 bgp_unlock_node (rn);
2874 bgp_table_unlock (table);
2875 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
2876 }
2877
2878 static void
2879 bgp_clear_node_complete (struct work_queue *wq)
2880 {
2881 struct peer *peer = wq->spec.data;
2882
2883 /* Tickle FSM to start moving again */
2884 BGP_EVENT_ADD (peer, Clearing_Completed);
2885
2886 peer_unlock (peer); /* bgp_clear_route */
2887 }
2888
2889 static void
2890 bgp_clear_node_queue_init (struct peer *peer)
2891 {
2892 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
2893
2894 snprintf (wname, sizeof(wname), "clear %s", peer->host);
2895 #undef CLEAR_QUEUE_NAME_LEN
2896
2897 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
2898 {
2899 zlog_err ("%s: Failed to allocate work queue", __func__);
2900 exit (1);
2901 }
2902 peer->clear_node_queue->spec.hold = 10;
2903 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2904 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2905 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2906 peer->clear_node_queue->spec.max_retries = 0;
2907
2908 /* we only 'lock' this peer reference when the queue is actually active */
2909 peer->clear_node_queue->spec.data = peer;
2910 }
2911
2912 static void
2913 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2914 struct bgp_table *table)
2915 {
2916 struct bgp_node *rn;
2917
2918
2919 if (! table)
2920 table = peer->bgp->rib[afi][safi];
2921
2922 /* If still no table => afi/safi isn't configured at all or smth. */
2923 if (! table)
2924 return;
2925
2926 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2927 {
2928 struct bgp_info *ri;
2929 struct bgp_adj_in *ain;
2930 struct bgp_adj_in *ain_next;
2931
2932 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2933 * queued for every clearing peer, regardless of whether it is
2934 * relevant to the peer at hand.
2935 *
2936 * Overview: There are 3 different indices which need to be
2937 * scrubbed, potentially, when a peer is removed:
2938 *
2939 * 1 peer's routes visible via the RIB (ie accepted routes)
2940 * 2 peer's routes visible by the (optional) peer's adj-in index
2941 * 3 other routes visible by the peer's adj-out index
2942 *
2943 * 3 there is no hurry in scrubbing, once the struct peer is
2944 * removed from bgp->peer, we could just GC such deleted peer's
2945 * adj-outs at our leisure.
2946 *
2947 * 1 and 2 must be 'scrubbed' in some way, at least made
2948 * invisible via RIB index before peer session is allowed to be
2949 * brought back up. So one needs to know when such a 'search' is
2950 * complete.
2951 *
2952 * Ideally:
2953 *
2954 * - there'd be a single global queue or a single RIB walker
2955 * - rather than tracking which route_nodes still need to be
2956 * examined on a peer basis, we'd track which peers still
2957 * aren't cleared
2958 *
2959 * Given that our per-peer prefix-counts now should be reliable,
2960 * this may actually be achievable. It doesn't seem to be a huge
2961 * problem at this time,
2962 *
2963 * It is possible that we have multiple paths for a prefix from a peer
2964 * if that peer is using AddPath.
2965 */
2966 ain = rn->adj_in;
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 for (ri = rn->info; ri; ri = ri->next)
2981 if (ri->peer == peer)
2982 {
2983 struct bgp_clear_node_queue *cnq;
2984
2985 /* both unlocked in bgp_clear_node_queue_del */
2986 bgp_table_lock (bgp_node_table (rn));
2987 bgp_lock_node (rn);
2988 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2989 sizeof (struct bgp_clear_node_queue));
2990 cnq->rn = rn;
2991 work_queue_add (peer->clear_node_queue, cnq);
2992 break;
2993 }
2994 }
2995 return;
2996 }
2997
2998 void
2999 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
3000 {
3001 struct bgp_node *rn;
3002 struct bgp_table *table;
3003
3004 if (peer->clear_node_queue == NULL)
3005 bgp_clear_node_queue_init (peer);
3006
3007 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3008 * Idle until it receives a Clearing_Completed event. This protects
3009 * against peers which flap faster than we can we clear, which could
3010 * lead to:
3011 *
3012 * a) race with routes from the new session being installed before
3013 * clear_route_node visits the node (to delete the route of that
3014 * peer)
3015 * b) resource exhaustion, clear_route_node likely leads to an entry
3016 * on the process_main queue. Fast-flapping could cause that queue
3017 * to grow and grow.
3018 */
3019
3020 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3021 * the unlock will happen upon work-queue completion; other wise, the
3022 * unlock happens at the end of this function.
3023 */
3024 if (!peer->clear_node_queue->thread)
3025 peer_lock (peer);
3026
3027 if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP)
3028 bgp_clear_route_table (peer, afi, safi, NULL);
3029 else
3030 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3031 rn = bgp_route_next (rn))
3032 if ((table = rn->info) != NULL)
3033 bgp_clear_route_table (peer, afi, safi, table);
3034
3035 /* unlock if no nodes got added to the clear-node-queue. */
3036 if (!peer->clear_node_queue->thread)
3037 peer_unlock (peer);
3038
3039 }
3040
3041 void
3042 bgp_clear_route_all (struct peer *peer)
3043 {
3044 afi_t afi;
3045 safi_t safi;
3046
3047 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3048 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3049 bgp_clear_route (peer, afi, safi);
3050 }
3051
3052 void
3053 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3054 {
3055 struct bgp_table *table;
3056 struct bgp_node *rn;
3057 struct bgp_adj_in *ain;
3058 struct bgp_adj_in *ain_next;
3059
3060 table = peer->bgp->rib[afi][safi];
3061
3062 /* It is possible that we have multiple paths for a prefix from a peer
3063 * if that peer is using AddPath.
3064 */
3065 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3066 {
3067 ain = rn->adj_in;
3068
3069 while (ain)
3070 {
3071 ain_next = ain->next;
3072
3073 if (ain->peer == peer)
3074 {
3075 bgp_adj_in_remove (rn, ain);
3076 bgp_unlock_node (rn);
3077 }
3078
3079 ain = ain_next;
3080 }
3081 }
3082 }
3083
3084 void
3085 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3086 {
3087 struct bgp_node *rn;
3088 struct bgp_info *ri;
3089 struct bgp_table *table;
3090
3091 table = peer->bgp->rib[afi][safi];
3092
3093 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3094 {
3095 for (ri = rn->info; ri; ri = ri->next)
3096 if (ri->peer == peer)
3097 {
3098 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3099 bgp_rib_remove (rn, ri, peer, afi, safi);
3100 break;
3101 }
3102 }
3103 }
3104
3105 static void
3106 bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3107 {
3108 struct bgp_node *rn;
3109 struct bgp_info *ri;
3110 struct bgp_info *next;
3111
3112 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3113 for (ri = rn->info; ri; ri = next)
3114 {
3115 next = ri->next;
3116 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3117 && ri->type == ZEBRA_ROUTE_BGP
3118 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3119 ri->sub_type == BGP_ROUTE_AGGREGATE))
3120 bgp_zebra_withdraw (&rn->p, ri, safi);
3121 }
3122 }
3123
3124 /* Delete all kernel routes. */
3125 void
3126 bgp_cleanup_routes (void)
3127 {
3128 struct bgp *bgp;
3129 struct listnode *node, *nnode;
3130 afi_t afi;
3131
3132 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
3133 {
3134 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3135 {
3136 struct bgp_node *rn;
3137
3138 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
3139
3140 /*
3141 * VPN and ENCAP tables are two-level (RD is top level)
3142 */
3143 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3144 rn = bgp_route_next (rn))
3145 {
3146 if (rn->info)
3147 {
3148 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3149 bgp_table_finish ((struct bgp_table **)&(rn->info));
3150 rn->info = NULL;
3151 bgp_unlock_node(rn);
3152 }
3153 }
3154
3155 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3156 rn = bgp_route_next (rn))
3157 {
3158 if (rn->info)
3159 {
3160 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3161 bgp_table_finish ((struct bgp_table **)&(rn->info));
3162 rn->info = NULL;
3163 bgp_unlock_node(rn);
3164 }
3165 }
3166 }
3167 }
3168 }
3169
3170 void
3171 bgp_reset (void)
3172 {
3173 vty_reset ();
3174 bgp_zclient_reset ();
3175 access_list_reset ();
3176 prefix_list_reset ();
3177 }
3178
3179 static int
3180 bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3181 {
3182 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3183 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3184 }
3185
3186 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3187 value. */
3188 int
3189 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3190 {
3191 u_char *pnt;
3192 u_char *lim;
3193 struct prefix p;
3194 int psize;
3195 int ret;
3196 afi_t afi;
3197 safi_t safi;
3198 int addpath_encoded;
3199 u_int32_t addpath_id;
3200
3201 /* Check peer status. */
3202 if (peer->status != Established)
3203 return 0;
3204
3205 pnt = packet->nlri;
3206 lim = pnt + packet->length;
3207 afi = packet->afi;
3208 safi = packet->safi;
3209 addpath_id = 0;
3210 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3211
3212 for (; pnt < lim; pnt += psize)
3213 {
3214 /* Clear prefix structure. */
3215 memset (&p, 0, sizeof (struct prefix));
3216
3217 if (addpath_encoded)
3218 {
3219
3220 /* When packet overflow occurs return immediately. */
3221 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3222 return -1;
3223
3224 addpath_id = ntohl(*((uint32_t*) pnt));
3225 pnt += BGP_ADDPATH_ID_LEN;
3226 }
3227
3228 /* Fetch prefix length. */
3229 p.prefixlen = *pnt++;
3230 p.family = afi2family (afi);
3231
3232 /* Already checked in nlri_sanity_check(). We do double check
3233 here. */
3234 if ((afi == AFI_IP && p.prefixlen > 32)
3235 || (afi == AFI_IP6 && p.prefixlen > 128))
3236 return -1;
3237
3238 /* Packet size overflow check. */
3239 psize = PSIZE (p.prefixlen);
3240
3241 /* When packet overflow occur return immediately. */
3242 if (pnt + psize > lim)
3243 return -1;
3244
3245 /* Fetch prefix from NLRI packet. */
3246 memcpy (&p.u.prefix, pnt, psize);
3247
3248 /* Check address. */
3249 if (afi == AFI_IP && safi == SAFI_UNICAST)
3250 {
3251 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3252 {
3253 /*
3254 * From draft-ietf-idr-bgp4-22, Section 6.3:
3255 * If a BGP router receives an UPDATE message with a
3256 * semantically incorrect NLRI field, in which a prefix is
3257 * semantically incorrect (eg. an unexpected multicast IP
3258 * address), it should ignore the prefix.
3259 */
3260 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3261 inet_ntoa (p.u.prefix4));
3262
3263 return -1;
3264 }
3265 }
3266
3267 #ifdef HAVE_IPV6
3268 /* Check address. */
3269 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3270 {
3271 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3272 {
3273 char buf[BUFSIZ];
3274
3275 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3276 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3277
3278 continue;
3279 }
3280 }
3281 #endif /* HAVE_IPV6 */
3282
3283 /* Normal process. */
3284 if (attr)
3285 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3286 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3287 else
3288 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3289 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3290
3291 /* Address family configuration mismatch or maximum-prefix count
3292 overflow. */
3293 if (ret < 0)
3294 return -1;
3295 }
3296
3297 /* Packet length consistency check. */
3298 if (pnt != lim)
3299 return -1;
3300
3301 return 0;
3302 }
3303
3304 /* NLRI encode syntax check routine. */
3305 int
3306 bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
3307 bgp_size_t length, int *numpfx)
3308 {
3309 u_char *end;
3310 u_char prefixlen;
3311 int psize;
3312 int addpath_encoded;
3313
3314 *numpfx = 0;
3315 end = pnt + length;
3316 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3317
3318 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3319 syntactic validity. If the field is syntactically incorrect,
3320 then the Error Subcode is set to Invalid Network Field. */
3321
3322 while (pnt < end)
3323 {
3324 int badlength;
3325
3326 /* If the NLRI is encoded using addpath then the first 4 bytes are
3327 * the addpath ID. */
3328 if (addpath_encoded)
3329 {
3330 if (pnt + BGP_ADDPATH_ID_LEN > end)
3331 {
3332 zlog_err ("%s [Error] Update packet error"
3333 " (prefix data addpath overflow)",
3334 peer->host);
3335 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3336 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3337 return -1;
3338 }
3339 pnt += BGP_ADDPATH_ID_LEN;
3340 }
3341
3342 prefixlen = *pnt++;
3343
3344 /* Prefix length check. */
3345 badlength = 0;
3346 if (safi == SAFI_ENCAP) {
3347 if (prefixlen > 128)
3348 badlength = 1;
3349 } else {
3350 if ((afi == AFI_IP && prefixlen > 32) ||
3351 (afi == AFI_IP6 && prefixlen > 128)) {
3352
3353 badlength = 1;
3354 }
3355 }
3356 if (badlength)
3357 {
3358 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
3359 peer->host, prefixlen);
3360 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3361 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3362 return -1;
3363 }
3364
3365 /* Packet size overflow check. */
3366 psize = PSIZE (prefixlen);
3367
3368 if (pnt + psize > end)
3369 {
3370 zlog_err ("%s [Error] Update packet error"
3371 " (prefix data overflow prefix size is %d)",
3372 peer->host, psize);
3373 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3374 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3375 return -1;
3376 }
3377
3378 pnt += psize;
3379 (*numpfx)++;
3380 }
3381
3382 /* Packet length consistency check. */
3383 if (pnt != end)
3384 {
3385 zlog_err ("%s [Error] Update packet error"
3386 " (prefix length mismatch with total length)",
3387 peer->host);
3388 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3389 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3390 return -1;
3391 }
3392 return 0;
3393 }
3394
3395 static struct bgp_static *
3396 bgp_static_new (void)
3397 {
3398 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3399 }
3400
3401 static void
3402 bgp_static_free (struct bgp_static *bgp_static)
3403 {
3404 if (bgp_static->rmap.name)
3405 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3406 XFREE (MTYPE_BGP_STATIC, bgp_static);
3407 }
3408
3409 static void
3410 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3411 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3412 {
3413 struct bgp_node *rn;
3414 struct bgp_info *ri;
3415 struct bgp_info *new;
3416 struct bgp_info info;
3417 struct attr attr;
3418 struct attr *attr_new;
3419 int ret;
3420
3421 assert (bgp_static);
3422 if (!bgp_static)
3423 return;
3424
3425 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3426
3427 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3428
3429 attr.nexthop = bgp_static->igpnexthop;
3430 attr.med = bgp_static->igpmetric;
3431 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3432
3433 if (bgp_static->atomic)
3434 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3435
3436 /* Apply route-map. */
3437 if (bgp_static->rmap.name)
3438 {
3439 struct attr attr_tmp = attr;
3440 info.peer = bgp->peer_self;
3441 info.attr = &attr_tmp;
3442
3443 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3444
3445 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3446
3447 bgp->peer_self->rmap_type = 0;
3448
3449 if (ret == RMAP_DENYMATCH)
3450 {
3451 /* Free uninterned attribute. */
3452 bgp_attr_flush (&attr_tmp);
3453
3454 /* Unintern original. */
3455 aspath_unintern (&attr.aspath);
3456 bgp_attr_extra_free (&attr);
3457 bgp_static_withdraw (bgp, p, afi, safi);
3458 return;
3459 }
3460 attr_new = bgp_attr_intern (&attr_tmp);
3461 }
3462 else
3463 attr_new = bgp_attr_intern (&attr);
3464
3465 for (ri = rn->info; ri; ri = ri->next)
3466 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3467 && ri->sub_type == BGP_ROUTE_STATIC)
3468 break;
3469
3470 if (ri)
3471 {
3472 if (attrhash_cmp (ri->attr, attr_new) &&
3473 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3474 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
3475 {
3476 bgp_unlock_node (rn);
3477 bgp_attr_unintern (&attr_new);
3478 aspath_unintern (&attr.aspath);
3479 bgp_attr_extra_free (&attr);
3480 return;
3481 }
3482 else
3483 {
3484 /* The attribute is changed. */
3485 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3486
3487 /* Rewrite BGP route information. */
3488 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3489 bgp_info_restore(rn, ri);
3490 else
3491 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3492 bgp_attr_unintern (&ri->attr);
3493 ri->attr = attr_new;
3494 ri->uptime = bgp_clock ();
3495
3496 /* Nexthop reachability check. */
3497 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3498 {
3499 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
3500 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3501 else
3502 {
3503 if (BGP_DEBUG(nht, NHT))
3504 {
3505 char buf1[INET6_ADDRSTRLEN];
3506 inet_ntop(p->family, &p->u.prefix, buf1,
3507 INET6_ADDRSTRLEN);
3508 zlog_debug("%s(%s): Route not in table, not advertising",
3509 __FUNCTION__, buf1);
3510 }
3511 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3512 }
3513 }
3514 else
3515 {
3516 /* Delete the NHT structure if any, if we're toggling between
3517 * enabling/disabling import check. We deregister the route
3518 * from NHT to avoid overloading NHT and the process interaction
3519 */
3520 bgp_unlink_nexthop(ri);
3521 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3522 }
3523 /* Process change. */
3524 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3525 bgp_process (bgp, rn, afi, safi);
3526 bgp_unlock_node (rn);
3527 aspath_unintern (&attr.aspath);
3528 bgp_attr_extra_free (&attr);
3529 return;
3530 }
3531 }
3532
3533 /* Make new BGP info. */
3534 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3535 rn);
3536 /* Nexthop reachability check. */
3537 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3538 {
3539 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
3540 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3541 else
3542 {
3543 if (BGP_DEBUG(nht, NHT))
3544 {
3545 char buf1[INET6_ADDRSTRLEN];
3546 inet_ntop(p->family, &p->u.prefix, buf1,
3547 INET6_ADDRSTRLEN);
3548 zlog_debug("%s(%s): Route not in table, not advertising",
3549 __FUNCTION__, buf1);
3550 }
3551 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3552 }
3553 }
3554 else
3555 {
3556 /* Delete the NHT structure if any, if we're toggling between
3557 * enabling/disabling import check. We deregister the route
3558 * from NHT to avoid overloading NHT and the process interaction
3559 */
3560 bgp_unlink_nexthop(new);
3561
3562 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3563 }
3564
3565 /* Aggregate address increment. */
3566 bgp_aggregate_increment (bgp, p, new, afi, safi);
3567
3568 /* Register new BGP information. */
3569 bgp_info_add (rn, new);
3570
3571 /* route_node_get lock */
3572 bgp_unlock_node (rn);
3573
3574 /* Process change. */
3575 bgp_process (bgp, rn, afi, safi);
3576
3577 /* Unintern original. */
3578 aspath_unintern (&attr.aspath);
3579 bgp_attr_extra_free (&attr);
3580 }
3581
3582 void
3583 bgp_static_update (struct bgp *bgp, struct prefix *p,
3584 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3585 {
3586 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3587 }
3588
3589 void
3590 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3591 safi_t safi)
3592 {
3593 struct bgp_node *rn;
3594 struct bgp_info *ri;
3595
3596 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3597
3598 /* Check selected route and self inserted route. */
3599 for (ri = rn->info; ri; ri = ri->next)
3600 if (ri->peer == bgp->peer_self
3601 && ri->type == ZEBRA_ROUTE_BGP
3602 && ri->sub_type == BGP_ROUTE_STATIC)
3603 break;
3604
3605 /* Withdraw static BGP route from routing table. */
3606 if (ri)
3607 {
3608 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3609 bgp_unlink_nexthop(ri);
3610 bgp_info_delete (rn, ri);
3611 bgp_process (bgp, rn, afi, safi);
3612 }
3613
3614 /* Unlock bgp_node_lookup. */
3615 bgp_unlock_node (rn);
3616 }
3617
3618 /*
3619 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3620 */
3621 static void
3622 bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3623 safi_t safi, struct prefix_rd *prd, u_char *tag)
3624 {
3625 struct bgp_node *rn;
3626 struct bgp_info *ri;
3627
3628 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3629
3630 /* Check selected route and self inserted route. */
3631 for (ri = rn->info; ri; ri = ri->next)
3632 if (ri->peer == bgp->peer_self
3633 && ri->type == ZEBRA_ROUTE_BGP
3634 && ri->sub_type == BGP_ROUTE_STATIC)
3635 break;
3636
3637 /* Withdraw static BGP route from routing table. */
3638 if (ri)
3639 {
3640 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3641 bgp_info_delete (rn, ri);
3642 bgp_process (bgp, rn, afi, safi);
3643 }
3644
3645 /* Unlock bgp_node_lookup. */
3646 bgp_unlock_node (rn);
3647 }
3648
3649 static void
3650 bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3651 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3652 {
3653 struct bgp_node *rn;
3654 struct bgp_info *new;
3655 struct attr *attr_new;
3656 struct attr attr = { 0 };
3657 struct bgp_info *ri;
3658
3659 assert (bgp_static);
3660
3661 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3662
3663 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3664
3665 attr.nexthop = bgp_static->igpnexthop;
3666 attr.med = bgp_static->igpmetric;
3667 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3668
3669 /* Apply route-map. */
3670 if (bgp_static->rmap.name)
3671 {
3672 struct attr attr_tmp = attr;
3673 struct bgp_info info;
3674 int ret;
3675
3676 info.peer = bgp->peer_self;
3677 info.attr = &attr_tmp;
3678
3679 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3680
3681 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3682
3683 bgp->peer_self->rmap_type = 0;
3684
3685 if (ret == RMAP_DENYMATCH)
3686 {
3687 /* Free uninterned attribute. */
3688 bgp_attr_flush (&attr_tmp);
3689
3690 /* Unintern original. */
3691 aspath_unintern (&attr.aspath);
3692 bgp_attr_extra_free (&attr);
3693 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3694 bgp_static->tag);
3695 return;
3696 }
3697
3698 attr_new = bgp_attr_intern (&attr_tmp);
3699 }
3700 else
3701 {
3702 attr_new = bgp_attr_intern (&attr);
3703 }
3704
3705 for (ri = rn->info; ri; ri = ri->next)
3706 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3707 && ri->sub_type == BGP_ROUTE_STATIC)
3708 break;
3709
3710 if (ri)
3711 {
3712 if (attrhash_cmp (ri->attr, attr_new) &&
3713 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3714 {
3715 bgp_unlock_node (rn);
3716 bgp_attr_unintern (&attr_new);
3717 aspath_unintern (&attr.aspath);
3718 bgp_attr_extra_free (&attr);
3719 return;
3720 }
3721 else
3722 {
3723 /* The attribute is changed. */
3724 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3725
3726 /* Rewrite BGP route information. */
3727 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3728 bgp_info_restore(rn, ri);
3729 else
3730 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3731 bgp_attr_unintern (&ri->attr);
3732 ri->attr = attr_new;
3733 ri->uptime = bgp_clock ();
3734
3735 /* Process change. */
3736 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3737 bgp_process (bgp, rn, afi, safi);
3738 bgp_unlock_node (rn);
3739 aspath_unintern (&attr.aspath);
3740 bgp_attr_extra_free (&attr);
3741 return;
3742 }
3743 }
3744
3745
3746 /* Make new BGP info. */
3747 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3748 rn);
3749 SET_FLAG (new->flags, BGP_INFO_VALID);
3750 new->extra = bgp_info_extra_new();
3751 memcpy (new->extra->tag, bgp_static->tag, 3);
3752
3753 /* Aggregate address increment. */
3754 bgp_aggregate_increment (bgp, p, new, afi, safi);
3755
3756 /* Register new BGP information. */
3757 bgp_info_add (rn, new);
3758
3759 /* route_node_get lock */
3760 bgp_unlock_node (rn);
3761
3762 /* Process change. */
3763 bgp_process (bgp, rn, afi, safi);
3764
3765 /* Unintern original. */
3766 aspath_unintern (&attr.aspath);
3767 bgp_attr_extra_free (&attr);
3768 }
3769
3770 /* Configure static BGP network. When user don't run zebra, static
3771 route should be installed as valid. */
3772 static int
3773 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3774 afi_t afi, safi_t safi, const char *rmap, int backdoor)
3775 {
3776 int ret;
3777 struct prefix p;
3778 struct bgp_static *bgp_static;
3779 struct bgp_node *rn;
3780 u_char need_update = 0;
3781
3782 /* Convert IP prefix string to struct prefix. */
3783 ret = str2prefix (ip_str, &p);
3784 if (! ret)
3785 {
3786 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3787 return CMD_WARNING;
3788 }
3789 #ifdef HAVE_IPV6
3790 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3791 {
3792 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3793 VTY_NEWLINE);
3794 return CMD_WARNING;
3795 }
3796 #endif /* HAVE_IPV6 */
3797
3798 apply_mask (&p);
3799
3800 /* Set BGP static route configuration. */
3801 rn = bgp_node_get (bgp->route[afi][safi], &p);
3802
3803 if (rn->info)
3804 {
3805 /* Configuration change. */
3806 bgp_static = rn->info;
3807
3808 /* Check previous routes are installed into BGP. */
3809 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3810 need_update = 1;
3811
3812 bgp_static->backdoor = backdoor;
3813
3814 if (rmap)
3815 {
3816 if (bgp_static->rmap.name)
3817 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3818 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
3819 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3820 }
3821 else
3822 {
3823 if (bgp_static->rmap.name)
3824 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3825 bgp_static->rmap.name = NULL;
3826 bgp_static->rmap.map = NULL;
3827 bgp_static->valid = 0;
3828 }
3829 bgp_unlock_node (rn);
3830 }
3831 else
3832 {
3833 /* New configuration. */
3834 bgp_static = bgp_static_new ();
3835 bgp_static->backdoor = backdoor;
3836 bgp_static->valid = 0;
3837 bgp_static->igpmetric = 0;
3838 bgp_static->igpnexthop.s_addr = 0;
3839
3840 if (rmap)
3841 {
3842 if (bgp_static->rmap.name)
3843 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3844 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
3845 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3846 }
3847 rn->info = bgp_static;
3848 }
3849
3850 bgp_static->valid = 1;
3851 if (need_update)
3852 bgp_static_withdraw (bgp, &p, afi, safi);
3853
3854 if (! bgp_static->backdoor)
3855 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3856
3857 return CMD_SUCCESS;
3858 }
3859
3860 /* Configure static BGP network. */
3861 static int
3862 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
3863 afi_t afi, safi_t safi)
3864 {
3865 int ret;
3866 struct prefix p;
3867 struct bgp_static *bgp_static;
3868 struct bgp_node *rn;
3869
3870 /* Convert IP prefix string to struct prefix. */
3871 ret = str2prefix (ip_str, &p);
3872 if (! ret)
3873 {
3874 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3875 return CMD_WARNING;
3876 }
3877 #ifdef HAVE_IPV6
3878 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3879 {
3880 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3881 VTY_NEWLINE);
3882 return CMD_WARNING;
3883 }
3884 #endif /* HAVE_IPV6 */
3885
3886 apply_mask (&p);
3887
3888 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3889 if (! rn)
3890 {
3891 vty_out (vty, "%% Can't find specified static route configuration.%s",
3892 VTY_NEWLINE);
3893 return CMD_WARNING;
3894 }
3895
3896 bgp_static = rn->info;
3897
3898 /* Update BGP RIB. */
3899 if (! bgp_static->backdoor)
3900 bgp_static_withdraw (bgp, &p, afi, safi);
3901
3902 /* Clear configuration. */
3903 bgp_static_free (bgp_static);
3904 rn->info = NULL;
3905 bgp_unlock_node (rn);
3906 bgp_unlock_node (rn);
3907
3908 return CMD_SUCCESS;
3909 }
3910
3911 void
3912 bgp_static_add (struct bgp *bgp)
3913 {
3914 afi_t afi;
3915 safi_t safi;
3916 struct bgp_node *rn;
3917 struct bgp_node *rm;
3918 struct bgp_table *table;
3919 struct bgp_static *bgp_static;
3920
3921 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3922 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3923 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3924 if (rn->info != NULL)
3925 {
3926 if (safi == SAFI_MPLS_VPN)
3927 {
3928 table = rn->info;
3929
3930 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3931 {
3932 bgp_static = rn->info;
3933 bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
3934 }
3935 }
3936 else
3937 {
3938 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
3939 }
3940 }
3941 }
3942
3943 /* Called from bgp_delete(). Delete all static routes from the BGP
3944 instance. */
3945 void
3946 bgp_static_delete (struct bgp *bgp)
3947 {
3948 afi_t afi;
3949 safi_t safi;
3950 struct bgp_node *rn;
3951 struct bgp_node *rm;
3952 struct bgp_table *table;
3953 struct bgp_static *bgp_static;
3954
3955 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3956 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3957 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3958 if (rn->info != NULL)
3959 {
3960 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
3961 {
3962 table = rn->info;
3963
3964 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3965 {
3966 bgp_static = rn->info;
3967 bgp_static_withdraw_safi (bgp, &rm->p,
3968 AFI_IP, safi,
3969 (struct prefix_rd *)&rn->p,
3970 bgp_static->tag);
3971 bgp_static_free (bgp_static);
3972 rn->info = NULL;
3973 bgp_unlock_node (rn);
3974 }
3975 }
3976 else
3977 {
3978 bgp_static = rn->info;
3979 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3980 bgp_static_free (bgp_static);
3981 rn->info = NULL;
3982 bgp_unlock_node (rn);
3983 }
3984 }
3985 }
3986
3987 void
3988 bgp_static_redo_import_check (struct bgp *bgp)
3989 {
3990 afi_t afi;
3991 safi_t safi;
3992 struct bgp_node *rn;
3993 struct bgp_static *bgp_static;
3994
3995 /* Use this flag to force reprocessing of the route */
3996 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3997 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3998 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3999 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4000 if (rn->info != NULL)
4001 {
4002 bgp_static = rn->info;
4003 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
4004 }
4005 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4006 }
4007
4008 static void
4009 bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
4010 {
4011 struct bgp_table *table;
4012 struct bgp_node *rn;
4013 struct bgp_info *ri;
4014
4015 table = bgp->rib[afi][safi];
4016 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4017 {
4018 for (ri = rn->info; ri; ri = ri->next)
4019 {
4020 if (ri->peer == bgp->peer_self &&
4021 ((ri->type == ZEBRA_ROUTE_BGP &&
4022 ri->sub_type == BGP_ROUTE_STATIC) ||
4023 (ri->type != ZEBRA_ROUTE_BGP &&
4024 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
4025 {
4026 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
4027 bgp_unlink_nexthop(ri);
4028 bgp_info_delete (rn, ri);
4029 bgp_process (bgp, rn, afi, safi);
4030 }
4031 }
4032 }
4033 }
4034
4035 /*
4036 * Purge all networks and redistributed routes from routing table.
4037 * Invoked upon the instance going down.
4038 */
4039 void
4040 bgp_purge_static_redist_routes (struct bgp *bgp)
4041 {
4042 afi_t afi;
4043 safi_t safi;
4044
4045 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4046 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4047 bgp_purge_af_static_redist_routes (bgp, afi, safi);
4048 }
4049
4050 /*
4051 * gpz 110624
4052 * Currently this is used to set static routes for VPN and ENCAP.
4053 * I think it can probably be factored with bgp_static_set.
4054 */
4055 int
4056 bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4057 const char *rd_str, const char *tag_str,
4058 const char *rmap_str)
4059 {
4060 int ret;
4061 struct prefix p;
4062 struct prefix_rd prd;
4063 struct bgp *bgp;
4064 struct bgp_node *prn;
4065 struct bgp_node *rn;
4066 struct bgp_table *table;
4067 struct bgp_static *bgp_static;
4068 u_char tag[3];
4069
4070 bgp = vty->index;
4071
4072 ret = str2prefix (ip_str, &p);
4073 if (! ret)
4074 {
4075 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4076 return CMD_WARNING;
4077 }
4078 apply_mask (&p);
4079
4080 ret = str2prefix_rd (rd_str, &prd);
4081 if (! ret)
4082 {
4083 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4084 return CMD_WARNING;
4085 }
4086
4087 ret = str2tag (tag_str, tag);
4088 if (! ret)
4089 {
4090 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4091 return CMD_WARNING;
4092 }
4093
4094 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4095 (struct prefix *)&prd);
4096 if (prn->info == NULL)
4097 prn->info = bgp_table_init (AFI_IP, safi);
4098 else
4099 bgp_unlock_node (prn);
4100 table = prn->info;
4101
4102 rn = bgp_node_get (table, &p);
4103
4104 if (rn->info)
4105 {
4106 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4107 bgp_unlock_node (rn);
4108 }
4109 else
4110 {
4111 /* New configuration. */
4112 bgp_static = bgp_static_new ();
4113 bgp_static->backdoor = 0;
4114 bgp_static->valid = 0;
4115 bgp_static->igpmetric = 0;
4116 bgp_static->igpnexthop.s_addr = 0;
4117 memcpy(bgp_static->tag, tag, 3);
4118 bgp_static->prd = prd;
4119
4120 if (rmap_str)
4121 {
4122 if (bgp_static->rmap.name)
4123 free (bgp_static->rmap.name);
4124 bgp_static->rmap.name = strdup (rmap_str);
4125 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4126 }
4127 rn->info = bgp_static;
4128
4129 bgp_static->valid = 1;
4130 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
4131 }
4132
4133 return CMD_SUCCESS;
4134 }
4135
4136 /* Configure static BGP network. */
4137 int
4138 bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4139 const char *rd_str, const char *tag_str)
4140 {
4141 int ret;
4142 struct bgp *bgp;
4143 struct prefix p;
4144 struct prefix_rd prd;
4145 struct bgp_node *prn;
4146 struct bgp_node *rn;
4147 struct bgp_table *table;
4148 struct bgp_static *bgp_static;
4149 u_char tag[3];
4150
4151 bgp = vty->index;
4152
4153 /* Convert IP prefix string to struct prefix. */
4154 ret = str2prefix (ip_str, &p);
4155 if (! ret)
4156 {
4157 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4158 return CMD_WARNING;
4159 }
4160 apply_mask (&p);
4161
4162 ret = str2prefix_rd (rd_str, &prd);
4163 if (! ret)
4164 {
4165 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4166 return CMD_WARNING;
4167 }
4168
4169 ret = str2tag (tag_str, tag);
4170 if (! ret)
4171 {
4172 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4173 return CMD_WARNING;
4174 }
4175
4176 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4177 (struct prefix *)&prd);
4178 if (prn->info == NULL)
4179 prn->info = bgp_table_init (AFI_IP, safi);
4180 else
4181 bgp_unlock_node (prn);
4182 table = prn->info;
4183
4184 rn = bgp_node_lookup (table, &p);
4185
4186 if (rn)
4187 {
4188 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
4189
4190 bgp_static = rn->info;
4191 bgp_static_free (bgp_static);
4192 rn->info = NULL;
4193 bgp_unlock_node (rn);
4194 bgp_unlock_node (rn);
4195 }
4196 else
4197 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4198
4199 return CMD_SUCCESS;
4200 }
4201
4202 static int
4203 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4204 const char *rmap_name)
4205 {
4206 struct bgp_rmap *rmap;
4207
4208 rmap = &bgp->table_map[afi][safi];
4209 if (rmap_name)
4210 {
4211 if (rmap->name)
4212 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4213 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
4214 rmap->map = route_map_lookup_by_name (rmap_name);
4215 }
4216 else
4217 {
4218 if (rmap->name)
4219 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4220 rmap->name = NULL;
4221 rmap->map = NULL;
4222 }
4223
4224 bgp_zebra_announce_table(bgp, afi, safi);
4225
4226 return CMD_SUCCESS;
4227 }
4228
4229 static int
4230 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4231 const char *rmap_name)
4232 {
4233 struct bgp_rmap *rmap;
4234
4235 rmap = &bgp->table_map[afi][safi];
4236 if (rmap->name)
4237 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4238 rmap->name = NULL;
4239 rmap->map = NULL;
4240
4241 bgp_zebra_announce_table(bgp, afi, safi);
4242
4243 return CMD_SUCCESS;
4244 }
4245
4246 int
4247 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4248 safi_t safi, int *write)
4249 {
4250 if (bgp->table_map[afi][safi].name)
4251 {
4252 bgp_config_write_family_header (vty, afi, safi, write);
4253 vty_out (vty, " table-map %s%s",
4254 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4255 }
4256
4257 return 0;
4258 }
4259
4260
4261 DEFUN (bgp_table_map,
4262 bgp_table_map_cmd,
4263 "table-map WORD",
4264 "BGP table to RIB route download filter\n"
4265 "Name of the route map\n")
4266 {
4267 return bgp_table_map_set (vty, vty->index,
4268 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4269 }
4270 DEFUN (no_bgp_table_map,
4271 no_bgp_table_map_cmd,
4272 "no table-map WORD",
4273 "BGP table to RIB route download filter\n"
4274 "Name of the route map\n")
4275 {
4276 return bgp_table_map_unset (vty, vty->index,
4277 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4278 }
4279
4280 DEFUN (bgp_network,
4281 bgp_network_cmd,
4282 "network A.B.C.D/M",
4283 "Specify a network to announce via BGP\n"
4284 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4285 {
4286 return bgp_static_set (vty, vty->index, argv[0],
4287 AFI_IP, bgp_node_safi (vty), NULL, 0);
4288 }
4289
4290 DEFUN (bgp_network_route_map,
4291 bgp_network_route_map_cmd,
4292 "network A.B.C.D/M route-map WORD",
4293 "Specify a network to announce via BGP\n"
4294 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4295 "Route-map to modify the attributes\n"
4296 "Name of the route map\n")
4297 {
4298 return bgp_static_set (vty, vty->index, argv[0],
4299 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4300 }
4301
4302 DEFUN (bgp_network_backdoor,
4303 bgp_network_backdoor_cmd,
4304 "network A.B.C.D/M backdoor",
4305 "Specify a network to announce via BGP\n"
4306 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4307 "Specify a BGP backdoor route\n")
4308 {
4309 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4310 NULL, 1);
4311 }
4312
4313 DEFUN (bgp_network_mask,
4314 bgp_network_mask_cmd,
4315 "network A.B.C.D mask A.B.C.D",
4316 "Specify a network to announce via BGP\n"
4317 "Network number\n"
4318 "Network mask\n"
4319 "Network mask\n")
4320 {
4321 int ret;
4322 char prefix_str[BUFSIZ];
4323
4324 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4325 if (! ret)
4326 {
4327 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4328 return CMD_WARNING;
4329 }
4330
4331 return bgp_static_set (vty, vty->index, prefix_str,
4332 AFI_IP, bgp_node_safi (vty), NULL, 0);
4333 }
4334
4335 DEFUN (bgp_network_mask_route_map,
4336 bgp_network_mask_route_map_cmd,
4337 "network A.B.C.D mask A.B.C.D route-map WORD",
4338 "Specify a network to announce via BGP\n"
4339 "Network number\n"
4340 "Network mask\n"
4341 "Network mask\n"
4342 "Route-map to modify the attributes\n"
4343 "Name of the route map\n")
4344 {
4345 int ret;
4346 char prefix_str[BUFSIZ];
4347
4348 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4349 if (! ret)
4350 {
4351 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4352 return CMD_WARNING;
4353 }
4354
4355 return bgp_static_set (vty, vty->index, prefix_str,
4356 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4357 }
4358
4359 DEFUN (bgp_network_mask_backdoor,
4360 bgp_network_mask_backdoor_cmd,
4361 "network A.B.C.D mask A.B.C.D backdoor",
4362 "Specify a network to announce via BGP\n"
4363 "Network number\n"
4364 "Network mask\n"
4365 "Network mask\n"
4366 "Specify a BGP backdoor route\n")
4367 {
4368 int ret;
4369 char prefix_str[BUFSIZ];
4370
4371 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4372 if (! ret)
4373 {
4374 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4375 return CMD_WARNING;
4376 }
4377
4378 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4379 NULL, 1);
4380 }
4381
4382 DEFUN (bgp_network_mask_natural,
4383 bgp_network_mask_natural_cmd,
4384 "network A.B.C.D",
4385 "Specify a network to announce via BGP\n"
4386 "Network number\n")
4387 {
4388 int ret;
4389 char prefix_str[BUFSIZ];
4390
4391 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4392 if (! ret)
4393 {
4394 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4395 return CMD_WARNING;
4396 }
4397
4398 return bgp_static_set (vty, vty->index, prefix_str,
4399 AFI_IP, bgp_node_safi (vty), NULL, 0);
4400 }
4401
4402 DEFUN (bgp_network_mask_natural_route_map,
4403 bgp_network_mask_natural_route_map_cmd,
4404 "network A.B.C.D route-map WORD",
4405 "Specify a network to announce via BGP\n"
4406 "Network number\n"
4407 "Route-map to modify the attributes\n"
4408 "Name of the route map\n")
4409 {
4410 int ret;
4411 char prefix_str[BUFSIZ];
4412
4413 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4414 if (! ret)
4415 {
4416 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4417 return CMD_WARNING;
4418 }
4419
4420 return bgp_static_set (vty, vty->index, prefix_str,
4421 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4422 }
4423
4424 DEFUN (bgp_network_mask_natural_backdoor,
4425 bgp_network_mask_natural_backdoor_cmd,
4426 "network A.B.C.D backdoor",
4427 "Specify a network to announce via BGP\n"
4428 "Network number\n"
4429 "Specify a BGP backdoor route\n")
4430 {
4431 int ret;
4432 char prefix_str[BUFSIZ];
4433
4434 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4435 if (! ret)
4436 {
4437 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4438 return CMD_WARNING;
4439 }
4440
4441 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4442 NULL, 1);
4443 }
4444
4445 DEFUN (no_bgp_network,
4446 no_bgp_network_cmd,
4447 "no network A.B.C.D/M",
4448 NO_STR
4449 "Specify a network to announce via BGP\n"
4450 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4451 {
4452 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4453 bgp_node_safi (vty));
4454 }
4455
4456 ALIAS (no_bgp_network,
4457 no_bgp_network_route_map_cmd,
4458 "no network A.B.C.D/M route-map WORD",
4459 NO_STR
4460 "Specify a network to announce via BGP\n"
4461 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4462 "Route-map to modify the attributes\n"
4463 "Name of the route map\n")
4464
4465 ALIAS (no_bgp_network,
4466 no_bgp_network_backdoor_cmd,
4467 "no network A.B.C.D/M backdoor",
4468 NO_STR
4469 "Specify a network to announce via BGP\n"
4470 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4471 "Specify a BGP backdoor route\n")
4472
4473 DEFUN (no_bgp_network_mask,
4474 no_bgp_network_mask_cmd,
4475 "no network A.B.C.D mask A.B.C.D",
4476 NO_STR
4477 "Specify a network to announce via BGP\n"
4478 "Network number\n"
4479 "Network mask\n"
4480 "Network mask\n")
4481 {
4482 int ret;
4483 char prefix_str[BUFSIZ];
4484
4485 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4486 if (! ret)
4487 {
4488 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4489 return CMD_WARNING;
4490 }
4491
4492 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4493 bgp_node_safi (vty));
4494 }
4495
4496 ALIAS (no_bgp_network_mask,
4497 no_bgp_network_mask_route_map_cmd,
4498 "no network A.B.C.D mask A.B.C.D route-map WORD",
4499 NO_STR
4500 "Specify a network to announce via BGP\n"
4501 "Network number\n"
4502 "Network mask\n"
4503 "Network mask\n"
4504 "Route-map to modify the attributes\n"
4505 "Name of the route map\n")
4506
4507 ALIAS (no_bgp_network_mask,
4508 no_bgp_network_mask_backdoor_cmd,
4509 "no network A.B.C.D mask A.B.C.D backdoor",
4510 NO_STR
4511 "Specify a network to announce via BGP\n"
4512 "Network number\n"
4513 "Network mask\n"
4514 "Network mask\n"
4515 "Specify a BGP backdoor route\n")
4516
4517 DEFUN (no_bgp_network_mask_natural,
4518 no_bgp_network_mask_natural_cmd,
4519 "no network A.B.C.D",
4520 NO_STR
4521 "Specify a network to announce via BGP\n"
4522 "Network number\n")
4523 {
4524 int ret;
4525 char prefix_str[BUFSIZ];
4526
4527 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4528 if (! ret)
4529 {
4530 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4531 return CMD_WARNING;
4532 }
4533
4534 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4535 bgp_node_safi (vty));
4536 }
4537
4538 ALIAS (no_bgp_network_mask_natural,
4539 no_bgp_network_mask_natural_route_map_cmd,
4540 "no network A.B.C.D route-map WORD",
4541 NO_STR
4542 "Specify a network to announce via BGP\n"
4543 "Network number\n"
4544 "Route-map to modify the attributes\n"
4545 "Name of the route map\n")
4546
4547 ALIAS (no_bgp_network_mask_natural,
4548 no_bgp_network_mask_natural_backdoor_cmd,
4549 "no network A.B.C.D backdoor",
4550 NO_STR
4551 "Specify a network to announce via BGP\n"
4552 "Network number\n"
4553 "Specify a BGP backdoor route\n")
4554
4555 #ifdef HAVE_IPV6
4556 DEFUN (ipv6_bgp_network,
4557 ipv6_bgp_network_cmd,
4558 "network X:X::X:X/M",
4559 "Specify a network to announce via BGP\n"
4560 "IPv6 prefix <network>/<length>\n")
4561 {
4562 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4563 NULL, 0);
4564 }
4565
4566 DEFUN (ipv6_bgp_network_route_map,
4567 ipv6_bgp_network_route_map_cmd,
4568 "network X:X::X:X/M route-map WORD",
4569 "Specify a network to announce via BGP\n"
4570 "IPv6 prefix <network>/<length>\n"
4571 "Route-map to modify the attributes\n"
4572 "Name of the route map\n")
4573 {
4574 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4575 bgp_node_safi (vty), argv[1], 0);
4576 }
4577
4578 DEFUN (no_ipv6_bgp_network,
4579 no_ipv6_bgp_network_cmd,
4580 "no network X:X::X:X/M",
4581 NO_STR
4582 "Specify a network to announce via BGP\n"
4583 "IPv6 prefix <network>/<length>\n")
4584 {
4585 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4586 }
4587
4588 ALIAS (no_ipv6_bgp_network,
4589 no_ipv6_bgp_network_route_map_cmd,
4590 "no network X:X::X:X/M route-map WORD",
4591 NO_STR
4592 "Specify a network to announce via BGP\n"
4593 "IPv6 prefix <network>/<length>\n"
4594 "Route-map to modify the attributes\n"
4595 "Name of the route map\n")
4596
4597 ALIAS (ipv6_bgp_network,
4598 old_ipv6_bgp_network_cmd,
4599 "ipv6 bgp network X:X::X:X/M",
4600 IPV6_STR
4601 BGP_STR
4602 "Specify a network to announce via BGP\n"
4603 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4604
4605 ALIAS (no_ipv6_bgp_network,
4606 old_no_ipv6_bgp_network_cmd,
4607 "no ipv6 bgp network X:X::X:X/M",
4608 NO_STR
4609 IPV6_STR
4610 BGP_STR
4611 "Specify a network to announce via BGP\n"
4612 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4613 #endif /* HAVE_IPV6 */
4614
4615 /* Aggreagete address:
4616
4617 advertise-map Set condition to advertise attribute
4618 as-set Generate AS set path information
4619 attribute-map Set attributes of aggregate
4620 route-map Set parameters of aggregate
4621 summary-only Filter more specific routes from updates
4622 suppress-map Conditionally filter more specific routes from updates
4623 <cr>
4624 */
4625 struct bgp_aggregate
4626 {
4627 /* Summary-only flag. */
4628 u_char summary_only;
4629
4630 /* AS set generation. */
4631 u_char as_set;
4632
4633 /* Route-map for aggregated route. */
4634 struct route_map *map;
4635
4636 /* Suppress-count. */
4637 unsigned long count;
4638
4639 /* SAFI configuration. */
4640 safi_t safi;
4641 };
4642
4643 static struct bgp_aggregate *
4644 bgp_aggregate_new (void)
4645 {
4646 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4647 }
4648
4649 static void
4650 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4651 {
4652 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4653 }
4654
4655 /* Update an aggregate as routes are added/removed from the BGP table */
4656 static void
4657 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4658 afi_t afi, safi_t safi, struct bgp_info *del,
4659 struct bgp_aggregate *aggregate)
4660 {
4661 struct bgp_table *table;
4662 struct bgp_node *top;
4663 struct bgp_node *rn;
4664 u_char origin;
4665 struct aspath *aspath = NULL;
4666 struct aspath *asmerge = NULL;
4667 struct community *community = NULL;
4668 struct community *commerge = NULL;
4669 #if defined(AGGREGATE_NEXTHOP_CHECK)
4670 struct in_addr nexthop;
4671 u_int32_t med = 0;
4672 #endif
4673 struct bgp_info *ri;
4674 struct bgp_info *new;
4675 int first = 1;
4676 unsigned long match = 0;
4677 u_char atomic_aggregate = 0;
4678
4679 /* Record adding route's nexthop and med. */
4680 if (rinew)
4681 {
4682 #if defined(AGGREGATE_NEXTHOP_CHECK)
4683 nexthop = rinew->attr->nexthop;
4684 med = rinew->attr->med;
4685 #endif
4686 }
4687
4688 /* ORIGIN attribute: If at least one route among routes that are
4689 aggregated has ORIGIN with the value INCOMPLETE, then the
4690 aggregated route must have the ORIGIN attribute with the value
4691 INCOMPLETE. Otherwise, if at least one route among routes that
4692 are aggregated has ORIGIN with the value EGP, then the aggregated
4693 route must have the origin attribute with the value EGP. In all
4694 other case the value of the ORIGIN attribute of the aggregated
4695 route is INTERNAL. */
4696 origin = BGP_ORIGIN_IGP;
4697
4698 table = bgp->rib[afi][safi];
4699
4700 top = bgp_node_get (table, p);
4701 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4702 if (rn->p.prefixlen > p->prefixlen)
4703 {
4704 match = 0;
4705
4706 for (ri = rn->info; ri; ri = ri->next)
4707 {
4708 if (BGP_INFO_HOLDDOWN (ri))
4709 continue;
4710
4711 if (del && ri == del)
4712 continue;
4713
4714 if (! rinew && first)
4715 {
4716 #if defined(AGGREGATE_NEXTHOP_CHECK)
4717 nexthop = ri->attr->nexthop;
4718 med = ri->attr->med;
4719 #endif
4720 first = 0;
4721 }
4722
4723 #ifdef AGGREGATE_NEXTHOP_CHECK
4724 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4725 || ri->attr->med != med)
4726 {
4727 if (aspath)
4728 aspath_free (aspath);
4729 if (community)
4730 community_free (community);
4731 bgp_unlock_node (rn);
4732 bgp_unlock_node (top);
4733 return;
4734 }
4735 #endif /* AGGREGATE_NEXTHOP_CHECK */
4736
4737 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4738 atomic_aggregate = 1;
4739
4740 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4741 {
4742 if (aggregate->summary_only)
4743 {
4744 (bgp_info_extra_get (ri))->suppress++;
4745 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4746 match++;
4747 }
4748
4749 aggregate->count++;
4750
4751 if (origin < ri->attr->origin)
4752 origin = ri->attr->origin;
4753
4754 if (aggregate->as_set)
4755 {
4756 if (aspath)
4757 {
4758 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4759 aspath_free (aspath);
4760 aspath = asmerge;
4761 }
4762 else
4763 aspath = aspath_dup (ri->attr->aspath);
4764
4765 if (ri->attr->community)
4766 {
4767 if (community)
4768 {
4769 commerge = community_merge (community,
4770 ri->attr->community);
4771 community = community_uniq_sort (commerge);
4772 community_free (commerge);
4773 }
4774 else
4775 community = community_dup (ri->attr->community);
4776 }
4777 }
4778 }
4779 }
4780 if (match)
4781 bgp_process (bgp, rn, afi, safi);
4782 }
4783 bgp_unlock_node (top);
4784
4785 if (rinew)
4786 {
4787 aggregate->count++;
4788
4789 if (aggregate->summary_only)
4790 (bgp_info_extra_get (rinew))->suppress++;
4791
4792 if (origin < rinew->attr->origin)
4793 origin = rinew->attr->origin;
4794
4795 if (aggregate->as_set)
4796 {
4797 if (aspath)
4798 {
4799 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4800 aspath_free (aspath);
4801 aspath = asmerge;
4802 }
4803 else
4804 aspath = aspath_dup (rinew->attr->aspath);
4805
4806 if (rinew->attr->community)
4807 {
4808 if (community)
4809 {
4810 commerge = community_merge (community,
4811 rinew->attr->community);
4812 community = community_uniq_sort (commerge);
4813 community_free (commerge);
4814 }
4815 else
4816 community = community_dup (rinew->attr->community);
4817 }
4818 }
4819 }
4820
4821 if (aggregate->count > 0)
4822 {
4823 rn = bgp_node_get (table, p);
4824 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
4825 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4826 aggregate->as_set,
4827 atomic_aggregate), rn);
4828 SET_FLAG (new->flags, BGP_INFO_VALID);
4829
4830 bgp_info_add (rn, new);
4831 bgp_unlock_node (rn);
4832 bgp_process (bgp, rn, afi, safi);
4833 }
4834 else
4835 {
4836 if (aspath)
4837 aspath_free (aspath);
4838 if (community)
4839 community_free (community);
4840 }
4841 }
4842
4843 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4844 struct bgp_aggregate *);
4845
4846 void
4847 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4848 struct bgp_info *ri, afi_t afi, safi_t safi)
4849 {
4850 struct bgp_node *child;
4851 struct bgp_node *rn;
4852 struct bgp_aggregate *aggregate;
4853 struct bgp_table *table;
4854
4855 /* MPLS-VPN aggregation is not yet supported. */
4856 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
4857 return;
4858
4859 table = bgp->aggregate[afi][safi];
4860
4861 /* No aggregates configured. */
4862 if (bgp_table_top_nolock (table) == NULL)
4863 return;
4864
4865 if (p->prefixlen == 0)
4866 return;
4867
4868 if (BGP_INFO_HOLDDOWN (ri))
4869 return;
4870
4871 child = bgp_node_get (table, p);
4872
4873 /* Aggregate address configuration check. */
4874 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
4875 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4876 {
4877 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4878 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
4879 }
4880 bgp_unlock_node (child);
4881 }
4882
4883 void
4884 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4885 struct bgp_info *del, afi_t afi, safi_t safi)
4886 {
4887 struct bgp_node *child;
4888 struct bgp_node *rn;
4889 struct bgp_aggregate *aggregate;
4890 struct bgp_table *table;
4891
4892 /* MPLS-VPN aggregation is not yet supported. */
4893 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
4894 return;
4895
4896 table = bgp->aggregate[afi][safi];
4897
4898 /* No aggregates configured. */
4899 if (bgp_table_top_nolock (table) == NULL)
4900 return;
4901
4902 if (p->prefixlen == 0)
4903 return;
4904
4905 child = bgp_node_get (table, p);
4906
4907 /* Aggregate address configuration check. */
4908 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
4909 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4910 {
4911 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4912 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
4913 }
4914 bgp_unlock_node (child);
4915 }
4916
4917 /* Called via bgp_aggregate_set when the user configures aggregate-address */
4918 static void
4919 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4920 struct bgp_aggregate *aggregate)
4921 {
4922 struct bgp_table *table;
4923 struct bgp_node *top;
4924 struct bgp_node *rn;
4925 struct bgp_info *new;
4926 struct bgp_info *ri;
4927 unsigned long match;
4928 u_char origin = BGP_ORIGIN_IGP;
4929 struct aspath *aspath = NULL;
4930 struct aspath *asmerge = NULL;
4931 struct community *community = NULL;
4932 struct community *commerge = NULL;
4933 u_char atomic_aggregate = 0;
4934
4935 table = bgp->rib[afi][safi];
4936
4937 /* Sanity check. */
4938 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4939 return;
4940 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4941 return;
4942
4943 /* If routes exists below this node, generate aggregate routes. */
4944 top = bgp_node_get (table, p);
4945 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4946 if (rn->p.prefixlen > p->prefixlen)
4947 {
4948 match = 0;
4949
4950 for (ri = rn->info; ri; ri = ri->next)
4951 {
4952 if (BGP_INFO_HOLDDOWN (ri))
4953 continue;
4954
4955 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4956 atomic_aggregate = 1;
4957
4958 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4959 {
4960 /* summary-only aggregate route suppress aggregated
4961 route announcement. */
4962 if (aggregate->summary_only)
4963 {
4964 (bgp_info_extra_get (ri))->suppress++;
4965 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4966 match++;
4967 }
4968
4969 /* If at least one route among routes that are aggregated has
4970 * ORIGIN with the value INCOMPLETE, then the aggregated route
4971 * MUST have the ORIGIN attribute with the value INCOMPLETE.
4972 * Otherwise, if at least one route among routes that are
4973 * aggregated has ORIGIN with the value EGP, then the aggregated
4974 * route MUST have the ORIGIN attribute with the value EGP.
4975 */
4976 if (origin < ri->attr->origin)
4977 origin = ri->attr->origin;
4978
4979 /* as-set aggregate route generate origin, as path,
4980 community aggregation. */
4981 if (aggregate->as_set)
4982 {
4983 if (aspath)
4984 {
4985 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4986 aspath_free (aspath);
4987 aspath = asmerge;
4988 }
4989 else
4990 aspath = aspath_dup (ri->attr->aspath);
4991
4992 if (ri->attr->community)
4993 {
4994 if (community)
4995 {
4996 commerge = community_merge (community,
4997 ri->attr->community);
4998 community = community_uniq_sort (commerge);
4999 community_free (commerge);
5000 }
5001 else
5002 community = community_dup (ri->attr->community);
5003 }
5004 }
5005 aggregate->count++;
5006 }
5007 }
5008
5009 /* If this node is suppressed, process the change. */
5010 if (match)
5011 bgp_process (bgp, rn, afi, safi);
5012 }
5013 bgp_unlock_node (top);
5014
5015 /* Add aggregate route to BGP table. */
5016 if (aggregate->count)
5017 {
5018 rn = bgp_node_get (table, p);
5019 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5020 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5021 aggregate->as_set,
5022 atomic_aggregate), rn);
5023 SET_FLAG (new->flags, BGP_INFO_VALID);
5024
5025 bgp_info_add (rn, new);
5026 bgp_unlock_node (rn);
5027
5028 /* Process change. */
5029 bgp_process (bgp, rn, afi, safi);
5030 }
5031 else
5032 {
5033 if (aspath)
5034 aspath_free (aspath);
5035 if (community)
5036 community_free (community);
5037 }
5038 }
5039
5040 void
5041 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5042 safi_t safi, struct bgp_aggregate *aggregate)
5043 {
5044 struct bgp_table *table;
5045 struct bgp_node *top;
5046 struct bgp_node *rn;
5047 struct bgp_info *ri;
5048 unsigned long match;
5049
5050 table = bgp->rib[afi][safi];
5051
5052 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5053 return;
5054 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5055 return;
5056
5057 /* If routes exists below this node, generate aggregate routes. */
5058 top = bgp_node_get (table, p);
5059 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5060 if (rn->p.prefixlen > p->prefixlen)
5061 {
5062 match = 0;
5063
5064 for (ri = rn->info; ri; ri = ri->next)
5065 {
5066 if (BGP_INFO_HOLDDOWN (ri))
5067 continue;
5068
5069 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5070 {
5071 if (aggregate->summary_only && ri->extra)
5072 {
5073 ri->extra->suppress--;
5074
5075 if (ri->extra->suppress == 0)
5076 {
5077 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5078 match++;
5079 }
5080 }
5081 aggregate->count--;
5082 }
5083 }
5084
5085 /* If this node was suppressed, process the change. */
5086 if (match)
5087 bgp_process (bgp, rn, afi, safi);
5088 }
5089 bgp_unlock_node (top);
5090
5091 /* Delete aggregate route from BGP table. */
5092 rn = bgp_node_get (table, p);
5093
5094 for (ri = rn->info; ri; ri = ri->next)
5095 if (ri->peer == bgp->peer_self
5096 && ri->type == ZEBRA_ROUTE_BGP
5097 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5098 break;
5099
5100 /* Withdraw static BGP route from routing table. */
5101 if (ri)
5102 {
5103 bgp_info_delete (rn, ri);
5104 bgp_process (bgp, rn, afi, safi);
5105 }
5106
5107 /* Unlock bgp_node_lookup. */
5108 bgp_unlock_node (rn);
5109 }
5110
5111 /* Aggregate route attribute. */
5112 #define AGGREGATE_SUMMARY_ONLY 1
5113 #define AGGREGATE_AS_SET 1
5114
5115 static int
5116 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5117 afi_t afi, safi_t safi)
5118 {
5119 int ret;
5120 struct prefix p;
5121 struct bgp_node *rn;
5122 struct bgp *bgp;
5123 struct bgp_aggregate *aggregate;
5124
5125 /* Convert string to prefix structure. */
5126 ret = str2prefix (prefix_str, &p);
5127 if (!ret)
5128 {
5129 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5130 return CMD_WARNING;
5131 }
5132 apply_mask (&p);
5133
5134 /* Get BGP structure. */
5135 bgp = vty->index;
5136
5137 /* Old configuration check. */
5138 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5139 if (! rn)
5140 {
5141 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5142 VTY_NEWLINE);
5143 return CMD_WARNING;
5144 }
5145
5146 aggregate = rn->info;
5147 if (aggregate->safi & SAFI_UNICAST)
5148 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5149 if (aggregate->safi & SAFI_MULTICAST)
5150 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5151
5152 /* Unlock aggregate address configuration. */
5153 rn->info = NULL;
5154 bgp_aggregate_free (aggregate);
5155 bgp_unlock_node (rn);
5156 bgp_unlock_node (rn);
5157
5158 return CMD_SUCCESS;
5159 }
5160
5161 static int
5162 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5163 afi_t afi, safi_t safi,
5164 u_char summary_only, u_char as_set)
5165 {
5166 int ret;
5167 struct prefix p;
5168 struct bgp_node *rn;
5169 struct bgp *bgp;
5170 struct bgp_aggregate *aggregate;
5171
5172 /* Convert string to prefix structure. */
5173 ret = str2prefix (prefix_str, &p);
5174 if (!ret)
5175 {
5176 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5177 return CMD_WARNING;
5178 }
5179 apply_mask (&p);
5180
5181 /* Get BGP structure. */
5182 bgp = vty->index;
5183
5184 /* Old configuration check. */
5185 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5186
5187 if (rn->info)
5188 {
5189 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5190 /* try to remove the old entry */
5191 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5192 if (ret)
5193 {
5194 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5195 bgp_unlock_node (rn);
5196 return CMD_WARNING;
5197 }
5198 }
5199
5200 /* Make aggregate address structure. */
5201 aggregate = bgp_aggregate_new ();
5202 aggregate->summary_only = summary_only;
5203 aggregate->as_set = as_set;
5204 aggregate->safi = safi;
5205 rn->info = aggregate;
5206
5207 /* Aggregate address insert into BGP routing table. */
5208 if (safi & SAFI_UNICAST)
5209 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5210 if (safi & SAFI_MULTICAST)
5211 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5212
5213 return CMD_SUCCESS;
5214 }
5215
5216 DEFUN (aggregate_address,
5217 aggregate_address_cmd,
5218 "aggregate-address A.B.C.D/M",
5219 "Configure BGP aggregate entries\n"
5220 "Aggregate prefix\n")
5221 {
5222 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5223 }
5224
5225 DEFUN (aggregate_address_mask,
5226 aggregate_address_mask_cmd,
5227 "aggregate-address A.B.C.D A.B.C.D",
5228 "Configure BGP aggregate entries\n"
5229 "Aggregate address\n"
5230 "Aggregate mask\n")
5231 {
5232 int ret;
5233 char prefix_str[BUFSIZ];
5234
5235 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5236
5237 if (! ret)
5238 {
5239 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5240 return CMD_WARNING;
5241 }
5242
5243 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5244 0, 0);
5245 }
5246
5247 DEFUN (aggregate_address_summary_only,
5248 aggregate_address_summary_only_cmd,
5249 "aggregate-address A.B.C.D/M summary-only",
5250 "Configure BGP aggregate entries\n"
5251 "Aggregate prefix\n"
5252 "Filter more specific routes from updates\n")
5253 {
5254 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5255 AGGREGATE_SUMMARY_ONLY, 0);
5256 }
5257
5258 DEFUN (aggregate_address_mask_summary_only,
5259 aggregate_address_mask_summary_only_cmd,
5260 "aggregate-address A.B.C.D A.B.C.D summary-only",
5261 "Configure BGP aggregate entries\n"
5262 "Aggregate address\n"
5263 "Aggregate mask\n"
5264 "Filter more specific routes from updates\n")
5265 {
5266 int ret;
5267 char prefix_str[BUFSIZ];
5268
5269 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5270
5271 if (! ret)
5272 {
5273 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5274 return CMD_WARNING;
5275 }
5276
5277 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5278 AGGREGATE_SUMMARY_ONLY, 0);
5279 }
5280
5281 DEFUN (aggregate_address_as_set,
5282 aggregate_address_as_set_cmd,
5283 "aggregate-address A.B.C.D/M as-set",
5284 "Configure BGP aggregate entries\n"
5285 "Aggregate prefix\n"
5286 "Generate AS set path information\n")
5287 {
5288 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5289 0, AGGREGATE_AS_SET);
5290 }
5291
5292 DEFUN (aggregate_address_mask_as_set,
5293 aggregate_address_mask_as_set_cmd,
5294 "aggregate-address A.B.C.D A.B.C.D as-set",
5295 "Configure BGP aggregate entries\n"
5296 "Aggregate address\n"
5297 "Aggregate mask\n"
5298 "Generate AS set path information\n")
5299 {
5300 int ret;
5301 char prefix_str[BUFSIZ];
5302
5303 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5304
5305 if (! ret)
5306 {
5307 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5308 return CMD_WARNING;
5309 }
5310
5311 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5312 0, AGGREGATE_AS_SET);
5313 }
5314
5315
5316 DEFUN (aggregate_address_as_set_summary,
5317 aggregate_address_as_set_summary_cmd,
5318 "aggregate-address A.B.C.D/M as-set summary-only",
5319 "Configure BGP aggregate entries\n"
5320 "Aggregate prefix\n"
5321 "Generate AS set path information\n"
5322 "Filter more specific routes from updates\n")
5323 {
5324 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5325 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5326 }
5327
5328 ALIAS (aggregate_address_as_set_summary,
5329 aggregate_address_summary_as_set_cmd,
5330 "aggregate-address A.B.C.D/M summary-only as-set",
5331 "Configure BGP aggregate entries\n"
5332 "Aggregate prefix\n"
5333 "Filter more specific routes from updates\n"
5334 "Generate AS set path information\n")
5335
5336 DEFUN (aggregate_address_mask_as_set_summary,
5337 aggregate_address_mask_as_set_summary_cmd,
5338 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5339 "Configure BGP aggregate entries\n"
5340 "Aggregate address\n"
5341 "Aggregate mask\n"
5342 "Generate AS set path information\n"
5343 "Filter more specific routes from updates\n")
5344 {
5345 int ret;
5346 char prefix_str[BUFSIZ];
5347
5348 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5349
5350 if (! ret)
5351 {
5352 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5353 return CMD_WARNING;
5354 }
5355
5356 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5357 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5358 }
5359
5360 ALIAS (aggregate_address_mask_as_set_summary,
5361 aggregate_address_mask_summary_as_set_cmd,
5362 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5363 "Configure BGP aggregate entries\n"
5364 "Aggregate address\n"
5365 "Aggregate mask\n"
5366 "Filter more specific routes from updates\n"
5367 "Generate AS set path information\n")
5368
5369 DEFUN (no_aggregate_address,
5370 no_aggregate_address_cmd,
5371 "no aggregate-address A.B.C.D/M",
5372 NO_STR
5373 "Configure BGP aggregate entries\n"
5374 "Aggregate prefix\n")
5375 {
5376 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5377 }
5378
5379 ALIAS (no_aggregate_address,
5380 no_aggregate_address_summary_only_cmd,
5381 "no aggregate-address A.B.C.D/M summary-only",
5382 NO_STR
5383 "Configure BGP aggregate entries\n"
5384 "Aggregate prefix\n"
5385 "Filter more specific routes from updates\n")
5386
5387 ALIAS (no_aggregate_address,
5388 no_aggregate_address_as_set_cmd,
5389 "no aggregate-address A.B.C.D/M as-set",
5390 NO_STR
5391 "Configure BGP aggregate entries\n"
5392 "Aggregate prefix\n"
5393 "Generate AS set path information\n")
5394
5395 ALIAS (no_aggregate_address,
5396 no_aggregate_address_as_set_summary_cmd,
5397 "no aggregate-address A.B.C.D/M as-set summary-only",
5398 NO_STR
5399 "Configure BGP aggregate entries\n"
5400 "Aggregate prefix\n"
5401 "Generate AS set path information\n"
5402 "Filter more specific routes from updates\n")
5403
5404 ALIAS (no_aggregate_address,
5405 no_aggregate_address_summary_as_set_cmd,
5406 "no aggregate-address A.B.C.D/M summary-only as-set",
5407 NO_STR
5408 "Configure BGP aggregate entries\n"
5409 "Aggregate prefix\n"
5410 "Filter more specific routes from updates\n"
5411 "Generate AS set path information\n")
5412
5413 DEFUN (no_aggregate_address_mask,
5414 no_aggregate_address_mask_cmd,
5415 "no aggregate-address A.B.C.D A.B.C.D",
5416 NO_STR
5417 "Configure BGP aggregate entries\n"
5418 "Aggregate address\n"
5419 "Aggregate mask\n")
5420 {
5421 int ret;
5422 char prefix_str[BUFSIZ];
5423
5424 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5425
5426 if (! ret)
5427 {
5428 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5429 return CMD_WARNING;
5430 }
5431
5432 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5433 }
5434
5435 ALIAS (no_aggregate_address_mask,
5436 no_aggregate_address_mask_summary_only_cmd,
5437 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5438 NO_STR
5439 "Configure BGP aggregate entries\n"
5440 "Aggregate address\n"
5441 "Aggregate mask\n"
5442 "Filter more specific routes from updates\n")
5443
5444 ALIAS (no_aggregate_address_mask,
5445 no_aggregate_address_mask_as_set_cmd,
5446 "no aggregate-address A.B.C.D A.B.C.D as-set",
5447 NO_STR
5448 "Configure BGP aggregate entries\n"
5449 "Aggregate address\n"
5450 "Aggregate mask\n"
5451 "Generate AS set path information\n")
5452
5453 ALIAS (no_aggregate_address_mask,
5454 no_aggregate_address_mask_as_set_summary_cmd,
5455 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5456 NO_STR
5457 "Configure BGP aggregate entries\n"
5458 "Aggregate address\n"
5459 "Aggregate mask\n"
5460 "Generate AS set path information\n"
5461 "Filter more specific routes from updates\n")
5462
5463 ALIAS (no_aggregate_address_mask,
5464 no_aggregate_address_mask_summary_as_set_cmd,
5465 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5466 NO_STR
5467 "Configure BGP aggregate entries\n"
5468 "Aggregate address\n"
5469 "Aggregate mask\n"
5470 "Filter more specific routes from updates\n"
5471 "Generate AS set path information\n")
5472
5473 #ifdef HAVE_IPV6
5474 DEFUN (ipv6_aggregate_address,
5475 ipv6_aggregate_address_cmd,
5476 "aggregate-address X:X::X:X/M",
5477 "Configure BGP aggregate entries\n"
5478 "Aggregate prefix\n")
5479 {
5480 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5481 }
5482
5483 DEFUN (ipv6_aggregate_address_summary_only,
5484 ipv6_aggregate_address_summary_only_cmd,
5485 "aggregate-address X:X::X:X/M summary-only",
5486 "Configure BGP aggregate entries\n"
5487 "Aggregate prefix\n"
5488 "Filter more specific routes from updates\n")
5489 {
5490 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5491 AGGREGATE_SUMMARY_ONLY, 0);
5492 }
5493
5494 DEFUN (no_ipv6_aggregate_address,
5495 no_ipv6_aggregate_address_cmd,
5496 "no aggregate-address X:X::X:X/M",
5497 NO_STR
5498 "Configure BGP aggregate entries\n"
5499 "Aggregate prefix\n")
5500 {
5501 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5502 }
5503
5504 DEFUN (no_ipv6_aggregate_address_summary_only,
5505 no_ipv6_aggregate_address_summary_only_cmd,
5506 "no aggregate-address X:X::X:X/M summary-only",
5507 NO_STR
5508 "Configure BGP aggregate entries\n"
5509 "Aggregate prefix\n"
5510 "Filter more specific routes from updates\n")
5511 {
5512 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5513 }
5514
5515 ALIAS (ipv6_aggregate_address,
5516 old_ipv6_aggregate_address_cmd,
5517 "ipv6 bgp aggregate-address X:X::X:X/M",
5518 IPV6_STR
5519 BGP_STR
5520 "Configure BGP aggregate entries\n"
5521 "Aggregate prefix\n")
5522
5523 ALIAS (ipv6_aggregate_address_summary_only,
5524 old_ipv6_aggregate_address_summary_only_cmd,
5525 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5526 IPV6_STR
5527 BGP_STR
5528 "Configure BGP aggregate entries\n"
5529 "Aggregate prefix\n"
5530 "Filter more specific routes from updates\n")
5531
5532 ALIAS (no_ipv6_aggregate_address,
5533 old_no_ipv6_aggregate_address_cmd,
5534 "no ipv6 bgp aggregate-address X:X::X:X/M",
5535 NO_STR
5536 IPV6_STR
5537 BGP_STR
5538 "Configure BGP aggregate entries\n"
5539 "Aggregate prefix\n")
5540
5541 ALIAS (no_ipv6_aggregate_address_summary_only,
5542 old_no_ipv6_aggregate_address_summary_only_cmd,
5543 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5544 NO_STR
5545 IPV6_STR
5546 BGP_STR
5547 "Configure BGP aggregate entries\n"
5548 "Aggregate prefix\n"
5549 "Filter more specific routes from updates\n")
5550 #endif /* HAVE_IPV6 */
5551
5552 /* Redistribute route treatment. */
5553 void
5554 bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
5555 const struct in6_addr *nexthop6, unsigned int ifindex,
5556 u_int32_t metric, u_char type, u_short instance, u_short tag)
5557 {
5558 struct bgp_info *new;
5559 struct bgp_info *bi;
5560 struct bgp_info info;
5561 struct bgp_node *bn;
5562 struct attr attr;
5563 struct attr *new_attr;
5564 afi_t afi;
5565 int ret;
5566 struct bgp_redist *red;
5567
5568 /* Make default attribute. */
5569 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5570 if (nexthop)
5571 attr.nexthop = *nexthop;
5572 attr.nh_ifindex = ifindex;
5573
5574 #ifdef HAVE_IPV6
5575 if (nexthop6)
5576 {
5577 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5578 extra->mp_nexthop_global = *nexthop6;
5579 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
5580 }
5581 #endif
5582
5583 attr.med = metric;
5584 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5585 attr.extra->tag = tag;
5586
5587 afi = family2afi (p->family);
5588
5589 red = bgp_redist_lookup(bgp, afi, type, instance);
5590 if (red)
5591 {
5592 struct attr attr_new;
5593 struct attr_extra extra_new;
5594
5595 /* Copy attribute for modification. */
5596 attr_new.extra = &extra_new;
5597 bgp_attr_dup (&attr_new, &attr);
5598
5599 if (red->redist_metric_flag)
5600 attr_new.med = red->redist_metric;
5601
5602 /* Apply route-map. */
5603 if (red->rmap.name)
5604 {
5605 info.peer = bgp->peer_self;
5606 info.attr = &attr_new;
5607
5608 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5609
5610 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5611
5612 bgp->peer_self->rmap_type = 0;
5613
5614 if (ret == RMAP_DENYMATCH)
5615 {
5616 /* Free uninterned attribute. */
5617 bgp_attr_flush (&attr_new);
5618
5619 /* Unintern original. */
5620 aspath_unintern (&attr.aspath);
5621 bgp_attr_extra_free (&attr);
5622 bgp_redistribute_delete (bgp, p, type, instance);
5623 return;
5624 }
5625 }
5626
5627 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5628 afi, SAFI_UNICAST, p, NULL);
5629
5630 new_attr = bgp_attr_intern (&attr_new);
5631
5632 for (bi = bn->info; bi; bi = bi->next)
5633 if (bi->peer == bgp->peer_self
5634 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5635 break;
5636
5637 if (bi)
5638 {
5639 /* Ensure the (source route) type is updated. */
5640 bi->type = type;
5641 if (attrhash_cmp (bi->attr, new_attr) &&
5642 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5643 {
5644 bgp_attr_unintern (&new_attr);
5645 aspath_unintern (&attr.aspath);
5646 bgp_attr_extra_free (&attr);
5647 bgp_unlock_node (bn);
5648 return;
5649 }
5650 else
5651 {
5652 /* The attribute is changed. */
5653 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5654
5655 /* Rewrite BGP route information. */
5656 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5657 bgp_info_restore(bn, bi);
5658 else
5659 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5660 bgp_attr_unintern (&bi->attr);
5661 bi->attr = new_attr;
5662 bi->uptime = bgp_clock ();
5663
5664 /* Process change. */
5665 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5666 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5667 bgp_unlock_node (bn);
5668 aspath_unintern (&attr.aspath);
5669 bgp_attr_extra_free (&attr);
5670 return;
5671 }
5672 }
5673
5674 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5675 new_attr, bn);
5676 SET_FLAG (new->flags, BGP_INFO_VALID);
5677
5678 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5679 bgp_info_add (bn, new);
5680 bgp_unlock_node (bn);
5681 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5682 }
5683
5684 /* Unintern original. */
5685 aspath_unintern (&attr.aspath);
5686 bgp_attr_extra_free (&attr);
5687 }
5688
5689 void
5690 bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
5691 {
5692 afi_t afi;
5693 struct bgp_node *rn;
5694 struct bgp_info *ri;
5695 struct bgp_redist *red;
5696
5697 afi = family2afi (p->family);
5698
5699 red = bgp_redist_lookup(bgp, afi, type, instance);
5700 if (red)
5701 {
5702 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5703
5704 for (ri = rn->info; ri; ri = ri->next)
5705 if (ri->peer == bgp->peer_self
5706 && ri->type == type)
5707 break;
5708
5709 if (ri)
5710 {
5711 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5712 bgp_info_delete (rn, ri);
5713 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5714 }
5715 bgp_unlock_node (rn);
5716 }
5717 }
5718
5719 /* Withdraw specified route type's route. */
5720 void
5721 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
5722 {
5723 struct bgp_node *rn;
5724 struct bgp_info *ri;
5725 struct bgp_table *table;
5726
5727 table = bgp->rib[afi][SAFI_UNICAST];
5728
5729 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5730 {
5731 for (ri = rn->info; ri; ri = ri->next)
5732 if (ri->peer == bgp->peer_self
5733 && ri->type == type
5734 && ri->instance == instance)
5735 break;
5736
5737 if (ri)
5738 {
5739 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5740 bgp_info_delete (rn, ri);
5741 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5742 }
5743 }
5744 }
5745
5746 /* Static function to display route. */
5747 static void
5748 route_vty_out_route (struct prefix *p, struct vty *vty)
5749 {
5750 int len;
5751 u_int32_t destination;
5752 char buf[BUFSIZ];
5753
5754 if (p->family == AF_INET)
5755 {
5756 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5757 destination = ntohl (p->u.prefix4.s_addr);
5758
5759 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5760 || (IN_CLASSB (destination) && p->prefixlen == 16)
5761 || (IN_CLASSA (destination) && p->prefixlen == 8)
5762 || p->u.prefix4.s_addr == 0)
5763 {
5764 /* When mask is natural, mask is not displayed. */
5765 }
5766 else
5767 len += vty_out (vty, "/%d", p->prefixlen);
5768 }
5769 else
5770 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5771 p->prefixlen);
5772
5773 len = 17 - len;
5774 if (len < 1)
5775 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5776 else
5777 vty_out (vty, "%*s", len, " ");
5778 }
5779
5780 enum bgp_display_type
5781 {
5782 normal_list,
5783 };
5784
5785 /* Print the short form route status for a bgp_info */
5786 static void
5787 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
5788 json_object *json_path)
5789 {
5790 if (json_path)
5791 {
5792
5793 /* Route status display. */
5794 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5795 json_object_boolean_true_add(json_path, "removed");
5796
5797 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5798 json_object_boolean_true_add(json_path, "stale");
5799
5800 if (binfo->extra && binfo->extra->suppress)
5801 json_object_boolean_true_add(json_path, "suppressed");
5802
5803 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5804 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5805 json_object_boolean_true_add(json_path, "valid");
5806
5807 /* Selected */
5808 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5809 json_object_boolean_true_add(json_path, "history");
5810
5811 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5812 json_object_boolean_true_add(json_path, "damped");
5813
5814 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5815 json_object_boolean_true_add(json_path, "bestpath");
5816
5817 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5818 json_object_boolean_true_add(json_path, "multipath");
5819
5820 /* Internal route. */
5821 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5822 json_object_string_add(json_path, "pathFrom", "internal");
5823 else
5824 json_object_string_add(json_path, "pathFrom", "external");
5825
5826 return;
5827 }
5828
5829 /* Route status display. */
5830 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5831 vty_out (vty, "R");
5832 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5833 vty_out (vty, "S");
5834 else if (binfo->extra && binfo->extra->suppress)
5835 vty_out (vty, "s");
5836 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5837 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5838 vty_out (vty, "*");
5839 else
5840 vty_out (vty, " ");
5841
5842 /* Selected */
5843 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5844 vty_out (vty, "h");
5845 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5846 vty_out (vty, "d");
5847 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5848 vty_out (vty, ">");
5849 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5850 vty_out (vty, "=");
5851 else
5852 vty_out (vty, " ");
5853
5854 /* Internal route. */
5855 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5856 vty_out (vty, "i");
5857 else
5858 vty_out (vty, " ");
5859 }
5860
5861 /* called from terminal list command */
5862 void
5863 route_vty_out (struct vty *vty, struct prefix *p,
5864 struct bgp_info *binfo, int display, safi_t safi,
5865 json_object *json_paths)
5866 {
5867 struct attr *attr;
5868 json_object *json_path = NULL;
5869 json_object *json_nexthops = NULL;
5870 json_object *json_nexthop_global = NULL;
5871 json_object *json_nexthop_ll = NULL;
5872
5873 if (json_paths)
5874 json_path = json_object_new_object();
5875
5876 /* short status lead text */
5877 route_vty_short_status_out (vty, binfo, json_path);
5878
5879 if (!json_paths)
5880 {
5881 /* print prefix and mask */
5882 if (! display)
5883 route_vty_out_route (p, vty);
5884 else
5885 vty_out (vty, "%*s", 17, " ");
5886 }
5887
5888 /* Print attribute */
5889 attr = binfo->attr;
5890 if (attr)
5891 {
5892 /*
5893 * For ENCAP routes, nexthop address family is not
5894 * neccessarily the same as the prefix address family.
5895 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5896 */
5897 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN))
5898 {
5899 if (attr->extra)
5900 {
5901 char buf[BUFSIZ];
5902 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5903
5904 switch (af)
5905 {
5906 case AF_INET:
5907 vty_out (vty, "%s", inet_ntop(af,
5908 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5909 break;
5910 #if HAVE_IPV6
5911 case AF_INET6:
5912 vty_out (vty, "%s", inet_ntop(af,
5913 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5914 break;
5915 #endif
5916 default:
5917 vty_out(vty, "?");
5918 break;
5919 }
5920 }
5921 else
5922 vty_out(vty, "?");
5923 }
5924 /* IPv4 Next Hop */
5925 else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5926 {
5927 if (json_paths)
5928 {
5929 json_nexthop_global = json_object_new_object();
5930
5931 if (safi == SAFI_MPLS_VPN)
5932 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
5933 else
5934 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
5935
5936 json_object_string_add(json_nexthop_global, "afi", "ipv4");
5937 json_object_boolean_true_add(json_nexthop_global, "used");
5938 }
5939 else
5940 {
5941 if (safi == SAFI_MPLS_VPN)
5942 vty_out (vty, "%-16s",
5943 inet_ntoa (attr->extra->mp_nexthop_global_in));
5944 else
5945 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5946 }
5947 }
5948
5949 /* IPv6 Next Hop */
5950 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5951 {
5952 int len;
5953 char buf[BUFSIZ];
5954
5955 if (json_paths)
5956 {
5957 json_nexthop_global = json_object_new_object();
5958 json_object_string_add(json_nexthop_global, "ip",
5959 inet_ntop (AF_INET6,
5960 &attr->extra->mp_nexthop_global,
5961 buf, BUFSIZ));
5962 json_object_string_add(json_nexthop_global, "afi", "ipv6");
5963 json_object_string_add(json_nexthop_global, "scope", "global");
5964
5965 /* We display both LL & GL if both have been received */
5966 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5967 {
5968 json_nexthop_ll = json_object_new_object();
5969 json_object_string_add(json_nexthop_ll, "ip",
5970 inet_ntop (AF_INET6,
5971 &attr->extra->mp_nexthop_local,
5972 buf, BUFSIZ));
5973 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
5974 json_object_string_add(json_nexthop_ll, "scope", "link-local");
5975
5976 if ((IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
5977 &attr->extra->mp_nexthop_local) != 0) &&
5978 !attr->extra->mp_nexthop_prefer_global)
5979 json_object_boolean_true_add(json_nexthop_ll, "used");
5980 else
5981 json_object_boolean_true_add(json_nexthop_global, "used");
5982 }
5983 else
5984 json_object_boolean_true_add(json_nexthop_global, "used");
5985 }
5986 else
5987 {
5988 /* Display LL if LL/Global both in table unless prefer-global is set */
5989 if (((attr->extra->mp_nexthop_len == 32) &&
5990 !attr->extra->mp_nexthop_prefer_global) ||
5991 (binfo->peer->conf_if))
5992 {
5993 if (binfo->peer->conf_if)
5994 {
5995 len = vty_out (vty, "%s",
5996 binfo->peer->conf_if);
5997 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
5998
5999 if (len < 1)
6000 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
6001 else
6002 vty_out (vty, "%*s", len, " ");
6003 }
6004 else
6005 {
6006 len = vty_out (vty, "%s",
6007 inet_ntop (AF_INET6,
6008 &attr->extra->mp_nexthop_local,
6009 buf, BUFSIZ));
6010 len = 16 - len;
6011
6012 if (len < 1)
6013 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6014 else
6015 vty_out (vty, "%*s", len, " ");
6016 }
6017 }
6018 else
6019 {
6020 len = vty_out (vty, "%s",
6021 inet_ntop (AF_INET6,
6022 &attr->extra->mp_nexthop_global,
6023 buf, BUFSIZ));
6024 len = 16 - len;
6025
6026 if (len < 1)
6027 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6028 else
6029 vty_out (vty, "%*s", len, " ");
6030 }
6031 }
6032 }
6033
6034 /* MED/Metric */
6035 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6036 if (json_paths)
6037 json_object_int_add(json_path, "med", attr->med);
6038 else
6039 vty_out (vty, "%10u", attr->med);
6040 else
6041 if (!json_paths)
6042 vty_out (vty, " ");
6043
6044 /* Local Pref */
6045 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6046 if (json_paths)
6047 json_object_int_add(json_path, "localpref", attr->local_pref);
6048 else
6049 vty_out (vty, "%7u", attr->local_pref);
6050 else
6051 if (!json_paths)
6052 vty_out (vty, " ");
6053
6054 if (json_paths)
6055 {
6056 if (attr->extra)
6057 json_object_int_add(json_path, "weight", attr->extra->weight);
6058 else
6059 json_object_int_add(json_path, "weight", 0);
6060 }
6061 else
6062 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6063
6064 if (json_paths) {
6065 char buf[BUFSIZ];
6066 json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6067 }
6068
6069 /* Print aspath */
6070 if (attr->aspath)
6071 {
6072 if (json_paths)
6073 json_object_string_add(json_path, "aspath", attr->aspath->str);
6074 else
6075 aspath_print_vty (vty, "%s", attr->aspath, " ");
6076 }
6077
6078 /* Print origin */
6079 if (json_paths)
6080 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6081 else
6082 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6083 }
6084 else
6085 {
6086 if (json_paths)
6087 json_object_string_add(json_path, "alert", "No attributes");
6088 else
6089 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6090 }
6091
6092 if (json_paths)
6093 {
6094 if (json_nexthop_global || json_nexthop_ll)
6095 {
6096 json_nexthops = json_object_new_array();
6097
6098 if (json_nexthop_global)
6099 json_object_array_add(json_nexthops, json_nexthop_global);
6100
6101 if (json_nexthop_ll)
6102 json_object_array_add(json_nexthops, json_nexthop_ll);
6103
6104 json_object_object_add(json_path, "nexthops", json_nexthops);
6105 }
6106
6107 json_object_array_add(json_paths, json_path);
6108 }
6109 else
6110 vty_out (vty, "%s", VTY_NEWLINE);
6111 }
6112
6113 /* called from terminal list command */
6114 void
6115 route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6116 u_char use_json, json_object *json_ar)
6117 {
6118 json_object *json_status = NULL;
6119 json_object *json_net = NULL;
6120 char buff[BUFSIZ];
6121 /* Route status display. */
6122 if (use_json)
6123 {
6124 json_status = json_object_new_object();
6125 json_net = json_object_new_object();
6126 }
6127 else
6128 {
6129 vty_out (vty, "*");
6130 vty_out (vty, ">");
6131 vty_out (vty, " ");
6132 }
6133
6134 /* print prefix and mask */
6135 if (use_json)
6136 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6137 else
6138 route_vty_out_route (p, vty);
6139
6140 /* Print attribute */
6141 if (attr)
6142 {
6143 if (use_json)
6144 {
6145 if (p->family == AF_INET &&
6146 (safi == SAFI_MPLS_VPN ||
6147 safi == SAFI_ENCAP ||
6148 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6149 {
6150 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6151 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6152 else
6153 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6154 }
6155 #ifdef HAVE_IPV6
6156 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6157 {
6158 char buf[BUFSIZ];
6159
6160 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6161 buf, BUFSIZ));
6162 }
6163 #endif /* HAVE_IPV6 */
6164
6165 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6166 json_object_int_add(json_net, "metric", attr->med);
6167
6168 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6169 json_object_int_add(json_net, "localPref", attr->local_pref);
6170
6171 if (attr->extra)
6172 json_object_int_add(json_net, "weight", attr->extra->weight);
6173 else
6174 json_object_int_add(json_net, "weight", 0);
6175
6176 /* Print aspath */
6177 if (attr->aspath)
6178 json_object_string_add(json_net, "asPath", attr->aspath->str);
6179
6180 /* Print origin */
6181 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
6182 }
6183 else
6184 {
6185 if (p->family == AF_INET &&
6186 (safi == SAFI_MPLS_VPN ||
6187 safi == SAFI_ENCAP ||
6188 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6189 {
6190 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6191 vty_out (vty, "%-16s",
6192 inet_ntoa (attr->extra->mp_nexthop_global_in));
6193 else
6194 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6195 }
6196 #ifdef HAVE_IPV6
6197 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6198 {
6199 int len;
6200 char buf[BUFSIZ];
6201
6202 assert (attr->extra);
6203
6204 len = vty_out (vty, "%s",
6205 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6206 buf, BUFSIZ));
6207 len = 16 - len;
6208 if (len < 1)
6209 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6210 else
6211 vty_out (vty, "%*s", len, " ");
6212 }
6213 #endif /* HAVE_IPV6 */
6214 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6215 vty_out (vty, "%10u", attr->med);
6216 else
6217 vty_out (vty, " ");
6218
6219 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6220 vty_out (vty, "%7u", attr->local_pref);
6221 else
6222 vty_out (vty, " ");
6223
6224 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6225
6226 /* Print aspath */
6227 if (attr->aspath)
6228 aspath_print_vty (vty, "%s", attr->aspath, " ");
6229
6230 /* Print origin */
6231 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6232 }
6233 }
6234 if (use_json)
6235 {
6236 json_object_boolean_true_add(json_status, "*");
6237 json_object_boolean_true_add(json_status, ">");
6238 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6239 char buf_cut[BUFSIZ];
6240 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6241 }
6242 else
6243 vty_out (vty, "%s", VTY_NEWLINE);
6244 }
6245
6246 void
6247 route_vty_out_tag (struct vty *vty, struct prefix *p,
6248 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
6249 {
6250 json_object *json_out = NULL;
6251 struct attr *attr;
6252 u_int32_t label = 0;
6253
6254 if (!binfo->extra)
6255 return;
6256
6257 if (json)
6258 json_out = json_object_new_object();
6259
6260 /* short status lead text */
6261 route_vty_short_status_out (vty, binfo, json_out);
6262
6263 /* print prefix and mask */
6264 if (json == NULL)
6265 {
6266 if (! display)
6267 route_vty_out_route (p, vty);
6268 else
6269 vty_out (vty, "%*s", 17, " ");
6270 }
6271
6272 /* Print attribute */
6273 attr = binfo->attr;
6274 if (attr)
6275 {
6276 if (p->family == AF_INET
6277 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6278 {
6279 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6280 {
6281 if (json)
6282 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6283 else
6284 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6285 }
6286 else
6287 {
6288 if (json)
6289 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6290 else
6291 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6292 }
6293 }
6294 #ifdef HAVE_IPV6
6295 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6296 {
6297 assert (attr->extra);
6298 char buf_a[BUFSIZ];
6299 char buf_b[BUFSIZ];
6300 char buf_c[BUFSIZ];
6301 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
6302 {
6303 if (json)
6304 json_object_string_add(json_out, "mpNexthopGlobalIn",
6305 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6306 else
6307 vty_out (vty, "%s",
6308 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6309 buf_a, BUFSIZ));
6310 }
6311 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6312 {
6313 if (json)
6314 {
6315 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6316 buf_a, BUFSIZ);
6317 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6318 buf_b, BUFSIZ);
6319 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6320 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6321 }
6322 else
6323 vty_out (vty, "%s(%s)",
6324 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6325 buf_a, BUFSIZ),
6326 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6327 buf_b, BUFSIZ));
6328 }
6329
6330 }
6331 #endif /* HAVE_IPV6 */
6332 }
6333
6334 label = decode_label (binfo->extra->tag);
6335
6336 if (json)
6337 {
6338 if (label)
6339 json_object_int_add(json_out, "notag", label);
6340 json_object_array_add(json, json_out);
6341 }
6342 else
6343 {
6344 vty_out (vty, "notag/%d", label);
6345 vty_out (vty, "%s", VTY_NEWLINE);
6346 }
6347 }
6348
6349 /* dampening route */
6350 static void
6351 damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6352 int display, safi_t safi, u_char use_json, json_object *json)
6353 {
6354 struct attr *attr;
6355 int len;
6356 char timebuf[BGP_UPTIME_LEN];
6357
6358 /* short status lead text */
6359 route_vty_short_status_out (vty, binfo, json);
6360
6361 /* print prefix and mask */
6362 if (!use_json)
6363 {
6364 if (! display)
6365 route_vty_out_route (p, vty);
6366 else
6367 vty_out (vty, "%*s", 17, " ");
6368 }
6369
6370 len = vty_out (vty, "%s", binfo->peer->host);
6371 len = 17 - len;
6372 if (len < 1)
6373 {
6374 if (!use_json)
6375 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6376 }
6377 else
6378 {
6379 if (use_json)
6380 json_object_int_add(json, "peerHost", len);
6381 else
6382 vty_out (vty, "%*s", len, " ");
6383 }
6384
6385 if (use_json)
6386 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6387 else
6388 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6389
6390 /* Print attribute */
6391 attr = binfo->attr;
6392 if (attr)
6393 {
6394 /* Print aspath */
6395 if (attr->aspath)
6396 {
6397 if (use_json)
6398 json_object_string_add(json, "asPath", attr->aspath->str);
6399 else
6400 aspath_print_vty (vty, "%s", attr->aspath, " ");
6401 }
6402
6403 /* Print origin */
6404 if (use_json)
6405 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6406 else
6407 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6408 }
6409 if (!use_json)
6410 vty_out (vty, "%s", VTY_NEWLINE);
6411 }
6412
6413 /* flap route */
6414 static void
6415 flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6416 int display, safi_t safi, u_char use_json, json_object *json)
6417 {
6418 struct attr *attr;
6419 struct bgp_damp_info *bdi;
6420 char timebuf[BGP_UPTIME_LEN];
6421 int len;
6422
6423 if (!binfo->extra)
6424 return;
6425
6426 bdi = binfo->extra->damp_info;
6427
6428 /* short status lead text */
6429 route_vty_short_status_out (vty, binfo, json);
6430
6431 /* print prefix and mask */
6432 if (!use_json)
6433 {
6434 if (! display)
6435 route_vty_out_route (p, vty);
6436 else
6437 vty_out (vty, "%*s", 17, " ");
6438 }
6439
6440 len = vty_out (vty, "%s", binfo->peer->host);
6441 len = 16 - len;
6442 if (len < 1)
6443 {
6444 if (!use_json)
6445 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6446 }
6447 else
6448 {
6449 if (use_json)
6450 json_object_int_add(json, "peerHost", len);
6451 else
6452 vty_out (vty, "%*s", len, " ");
6453 }
6454
6455 len = vty_out (vty, "%d", bdi->flap);
6456 len = 5 - len;
6457 if (len < 1)
6458 {
6459 if (!use_json)
6460 vty_out (vty, " ");
6461 }
6462 else
6463 {
6464 if (use_json)
6465 json_object_int_add(json, "bdiFlap", len);
6466 else
6467 vty_out (vty, "%*s", len, " ");
6468 }
6469
6470 if (use_json)
6471 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6472 else
6473 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6474 timebuf, BGP_UPTIME_LEN, 0, NULL));
6475
6476 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6477 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6478 {
6479 if (use_json)
6480 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6481 else
6482 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6483 }
6484 else
6485 {
6486 if (!use_json)
6487 vty_out (vty, "%*s ", 8, " ");
6488 }
6489
6490 /* Print attribute */
6491 attr = binfo->attr;
6492 if (attr)
6493 {
6494 /* Print aspath */
6495 if (attr->aspath)
6496 {
6497 if (use_json)
6498 json_object_string_add(json, "asPath", attr->aspath->str);
6499 else
6500 aspath_print_vty (vty, "%s", attr->aspath, " ");
6501 }
6502
6503 /* Print origin */
6504 if (use_json)
6505 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6506 else
6507 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6508 }
6509 if (!use_json)
6510 vty_out (vty, "%s", VTY_NEWLINE);
6511 }
6512
6513 static void
6514 route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6515 const char *header, json_object *json_adv_to)
6516 {
6517 char buf1[INET6_ADDRSTRLEN];
6518 json_object *json_peer = NULL;
6519
6520 if (json_adv_to)
6521 {
6522 /* 'advertised-to' is a dictionary of peers we have advertised this
6523 * prefix too. The key is the peer's IP or swpX, the value is the
6524 * hostname if we know it and "" if not.
6525 */
6526 json_peer = json_object_new_object();
6527
6528 if (peer->hostname)
6529 json_object_string_add(json_peer, "hostname", peer->hostname);
6530
6531 if (peer->conf_if)
6532 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6533 else
6534 json_object_object_add(json_adv_to,
6535 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6536 json_peer);
6537 }
6538 else
6539 {
6540 if (*first)
6541 {
6542 vty_out (vty, "%s", header);
6543 *first = 0;
6544 }
6545
6546 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6547 {
6548 if (peer->conf_if)
6549 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6550 else
6551 vty_out (vty, " %s(%s)", peer->hostname,
6552 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6553 }
6554 else
6555 {
6556 if (peer->conf_if)
6557 vty_out (vty, " %s", peer->conf_if);
6558 else
6559 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6560 }
6561 }
6562 }
6563
6564 static void
6565 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6566 struct bgp_info *binfo, afi_t afi, safi_t safi,
6567 json_object *json_paths)
6568 {
6569 char buf[INET6_ADDRSTRLEN];
6570 char buf1[BUFSIZ];
6571 struct attr *attr;
6572 int sockunion_vty_out (struct vty *, union sockunion *);
6573 #ifdef HAVE_CLOCK_MONOTONIC
6574 time_t tbuf;
6575 #endif
6576 json_object *json_bestpath = NULL;
6577 json_object *json_cluster_list = NULL;
6578 json_object *json_cluster_list_list = NULL;
6579 json_object *json_ext_community = NULL;
6580 json_object *json_last_update = NULL;
6581 json_object *json_nexthop_global = NULL;
6582 json_object *json_nexthop_ll = NULL;
6583 json_object *json_nexthops = NULL;
6584 json_object *json_path = NULL;
6585 json_object *json_peer = NULL;
6586 json_object *json_string = NULL;
6587 json_object *json_adv_to = NULL;
6588 int first = 0;
6589 struct listnode *node, *nnode;
6590 struct peer *peer;
6591 int addpath_capable;
6592 int has_adj;
6593 int first_as;
6594
6595 if (json_paths)
6596 {
6597 json_path = json_object_new_object();
6598 json_peer = json_object_new_object();
6599 json_nexthop_global = json_object_new_object();
6600 }
6601
6602 attr = binfo->attr;
6603
6604 if (attr)
6605 {
6606 /* Line1 display AS-path, Aggregator */
6607 if (attr->aspath)
6608 {
6609 if (json_paths)
6610 {
6611 json_object_lock(attr->aspath->json);
6612 json_object_object_add(json_path, "aspath", attr->aspath->json);
6613 }
6614 else
6615 {
6616 if (attr->aspath->segments)
6617 aspath_print_vty (vty, " %s", attr->aspath, "");
6618 else
6619 vty_out (vty, " Local");
6620 }
6621 }
6622
6623 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6624 {
6625 if (json_paths)
6626 json_object_boolean_true_add(json_path, "removed");
6627 else
6628 vty_out (vty, ", (removed)");
6629 }
6630
6631 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6632 {
6633 if (json_paths)
6634 json_object_boolean_true_add(json_path, "stale");
6635 else
6636 vty_out (vty, ", (stale)");
6637 }
6638
6639 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6640 {
6641 if (json_paths)
6642 {
6643 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6644 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
6645 }
6646 else
6647 {
6648 vty_out (vty, ", (aggregated by %u %s)",
6649 attr->extra->aggregator_as,
6650 inet_ntoa (attr->extra->aggregator_addr));
6651 }
6652 }
6653
6654 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6655 {
6656 if (json_paths)
6657 json_object_boolean_true_add(json_path, "rxedFromRrClient");
6658 else
6659 vty_out (vty, ", (Received from a RR-client)");
6660 }
6661
6662 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6663 {
6664 if (json_paths)
6665 json_object_boolean_true_add(json_path, "rxedFromRsClient");
6666 else
6667 vty_out (vty, ", (Received from a RS-client)");
6668 }
6669
6670 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6671 {
6672 if (json_paths)
6673 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
6674 else
6675 vty_out (vty, ", (history entry)");
6676 }
6677 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6678 {
6679 if (json_paths)
6680 json_object_boolean_true_add(json_path, "dampeningSuppressed");
6681 else
6682 vty_out (vty, ", (suppressed due to dampening)");
6683 }
6684
6685 if (!json_paths)
6686 vty_out (vty, "%s", VTY_NEWLINE);
6687
6688 /* Line2 display Next-hop, Neighbor, Router-id */
6689 /* Display the nexthop */
6690 if (p->family == AF_INET &&
6691 (safi == SAFI_MPLS_VPN ||
6692 safi == SAFI_ENCAP ||
6693 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6694 {
6695 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6696 {
6697 if (json_paths)
6698 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6699 else
6700 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6701 }
6702 else
6703 {
6704 if (json_paths)
6705 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6706 else
6707 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6708 }
6709
6710 if (json_paths)
6711 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6712 }
6713 else
6714 {
6715 assert (attr->extra);
6716 if (json_paths)
6717 {
6718 json_object_string_add(json_nexthop_global, "ip",
6719 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6720 buf, INET6_ADDRSTRLEN));
6721 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6722 json_object_string_add(json_nexthop_global, "scope", "global");
6723 }
6724 else
6725 {
6726 vty_out (vty, " %s",
6727 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6728 buf, INET6_ADDRSTRLEN));
6729 }
6730 }
6731
6732 /* Display the IGP cost or 'inaccessible' */
6733 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6734 {
6735 if (json_paths)
6736 json_object_boolean_false_add(json_nexthop_global, "accessible");
6737 else
6738 vty_out (vty, " (inaccessible)");
6739 }
6740 else
6741 {
6742 if (binfo->extra && binfo->extra->igpmetric)
6743 {
6744 if (json_paths)
6745 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
6746 else
6747 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
6748 }
6749
6750 /* IGP cost is 0, display this only for json */
6751 else
6752 {
6753 if (json_paths)
6754 json_object_int_add(json_nexthop_global, "metric", 0);
6755 }
6756
6757 if (json_paths)
6758 json_object_boolean_true_add(json_nexthop_global, "accessible");
6759 }
6760
6761 /* Display peer "from" output */
6762 /* This path was originated locally */
6763 if (binfo->peer == bgp->peer_self)
6764 {
6765
6766 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6767 {
6768 if (json_paths)
6769 json_object_string_add(json_peer, "peerId", "0.0.0.0");
6770 else
6771 vty_out (vty, " from 0.0.0.0 ");
6772 }
6773 else
6774 {
6775 if (json_paths)
6776 json_object_string_add(json_peer, "peerId", "::");
6777 else
6778 vty_out (vty, " from :: ");
6779 }
6780
6781 if (json_paths)
6782 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
6783 else
6784 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6785 }
6786
6787 /* We RXed this path from one of our peers */
6788 else
6789 {
6790
6791 if (json_paths)
6792 {
6793 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6794 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6795
6796 if (binfo->peer->hostname)
6797 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
6798
6799 if (binfo->peer->domainname)
6800 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
6801
6802 if (binfo->peer->conf_if)
6803 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
6804 }
6805 else
6806 {
6807 if (binfo->peer->conf_if)
6808 {
6809 if (binfo->peer->hostname &&
6810 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6811 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6812 binfo->peer->conf_if);
6813 else
6814 vty_out (vty, " from %s", binfo->peer->conf_if);
6815 }
6816 else
6817 {
6818 if (binfo->peer->hostname &&
6819 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6820 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6821 binfo->peer->host);
6822 else
6823 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6824 }
6825
6826 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6827 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6828 else
6829 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6830 }
6831 }
6832
6833 if (!json_paths)
6834 vty_out (vty, "%s", VTY_NEWLINE);
6835
6836 /* display the link-local nexthop */
6837 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6838 {
6839 if (json_paths)
6840 {
6841 json_nexthop_ll = json_object_new_object();
6842 json_object_string_add(json_nexthop_ll, "ip",
6843 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6844 buf, INET6_ADDRSTRLEN));
6845 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6846 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6847
6848 json_object_boolean_true_add(json_nexthop_ll, "accessible");
6849
6850 if (!attr->extra->mp_nexthop_prefer_global)
6851 json_object_boolean_true_add(json_nexthop_ll, "used");
6852 else
6853 json_object_boolean_true_add(json_nexthop_global, "used");
6854 }
6855 else
6856 {
6857 vty_out (vty, " (%s) %s%s",
6858 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6859 buf, INET6_ADDRSTRLEN),
6860 attr->extra->mp_nexthop_prefer_global ?
6861 "(prefer-global)" : "(used)",
6862 VTY_NEWLINE);
6863 }
6864 }
6865 /* If we do not have a link-local nexthop then we must flag the global as "used" */
6866 else
6867 {
6868 if (json_paths)
6869 json_object_boolean_true_add(json_nexthop_global, "used");
6870 }
6871
6872 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
6873 if (json_paths)
6874 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6875 else
6876 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6877
6878 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6879 {
6880 if (json_paths)
6881 json_object_int_add(json_path, "med", attr->med);
6882 else
6883 vty_out (vty, ", metric %u", attr->med);
6884 }
6885
6886 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6887 {
6888 if (json_paths)
6889 json_object_int_add(json_path, "localpref", attr->local_pref);
6890 else
6891 vty_out (vty, ", localpref %u", attr->local_pref);
6892 }
6893 else
6894 {
6895 if (json_paths)
6896 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
6897 else
6898 vty_out (vty, ", localpref %u", bgp->default_local_pref);
6899 }
6900
6901 if (attr->extra && attr->extra->weight != 0)
6902 {
6903 if (json_paths)
6904 json_object_int_add(json_path, "weight", attr->extra->weight);
6905 else
6906 vty_out (vty, ", weight %u", attr->extra->weight);
6907 }
6908
6909 if (attr->extra && attr->extra->tag != 0)
6910 {
6911 if (json_paths)
6912 json_object_int_add(json_path, "tag", attr->extra->tag);
6913 else
6914 vty_out (vty, ", tag %d", attr->extra->tag);
6915 }
6916
6917 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6918 {
6919 if (json_paths)
6920 json_object_boolean_false_add(json_path, "valid");
6921 else
6922 vty_out (vty, ", invalid");
6923 }
6924 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6925 {
6926 if (json_paths)
6927 json_object_boolean_true_add(json_path, "valid");
6928 else
6929 vty_out (vty, ", valid");
6930 }
6931
6932 if (binfo->peer != bgp->peer_self)
6933 {
6934 if (binfo->peer->as == binfo->peer->local_as)
6935 {
6936 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
6937 {
6938 if (json_paths)
6939 json_object_string_add(json_peer, "type", "confed-internal");
6940 else
6941 vty_out (vty, ", confed-internal");
6942 }
6943 else
6944 {
6945 if (json_paths)
6946 json_object_string_add(json_peer, "type", "internal");
6947 else
6948 vty_out (vty, ", internal");
6949 }
6950 }
6951 else
6952 {
6953 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
6954 {
6955 if (json_paths)
6956 json_object_string_add(json_peer, "type", "confed-external");
6957 else
6958 vty_out (vty, ", confed-external");
6959 }
6960 else
6961 {
6962 if (json_paths)
6963 json_object_string_add(json_peer, "type", "external");
6964 else
6965 vty_out (vty, ", external");
6966 }
6967 }
6968 }
6969 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6970 {
6971 if (json_paths)
6972 {
6973 json_object_boolean_true_add(json_path, "aggregated");
6974 json_object_boolean_true_add(json_path, "local");
6975 }
6976 else
6977 {
6978 vty_out (vty, ", aggregated, local");
6979 }
6980 }
6981 else if (binfo->type != ZEBRA_ROUTE_BGP)
6982 {
6983 if (json_paths)
6984 json_object_boolean_true_add(json_path, "sourced");
6985 else
6986 vty_out (vty, ", sourced");
6987 }
6988 else
6989 {
6990 if (json_paths)
6991 {
6992 json_object_boolean_true_add(json_path, "sourced");
6993 json_object_boolean_true_add(json_path, "local");
6994 }
6995 else
6996 {
6997 vty_out (vty, ", sourced, local");
6998 }
6999 }
7000
7001 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
7002 {
7003 if (json_paths)
7004 json_object_boolean_true_add(json_path, "atomicAggregate");
7005 else
7006 vty_out (vty, ", atomic-aggregate");
7007 }
7008
7009 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7010 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7011 bgp_info_mpath_count (binfo)))
7012 {
7013 if (json_paths)
7014 json_object_boolean_true_add(json_path, "multipath");
7015 else
7016 vty_out (vty, ", multipath");
7017 }
7018
7019 // Mark the bestpath(s)
7020 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
7021 {
7022 first_as = aspath_get_firstas(attr->aspath);
7023
7024 if (json_paths)
7025 {
7026 if (!json_bestpath)
7027 json_bestpath = json_object_new_object();
7028 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
7029 }
7030 else
7031 {
7032 if (first_as)
7033 vty_out (vty, ", bestpath-from-AS %d", first_as);
7034 else
7035 vty_out (vty, ", bestpath-from-AS Local");
7036 }
7037 }
7038
7039 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
7040 {
7041 if (json_paths)
7042 {
7043 if (!json_bestpath)
7044 json_bestpath = json_object_new_object();
7045 json_object_boolean_true_add(json_bestpath, "overall");
7046 }
7047 else
7048 vty_out (vty, ", best");
7049 }
7050
7051 if (json_bestpath)
7052 json_object_object_add(json_path, "bestpath", json_bestpath);
7053
7054 if (!json_paths)
7055 vty_out (vty, "%s", VTY_NEWLINE);
7056
7057 /* Line 4 display Community */
7058 if (attr->community)
7059 {
7060 if (json_paths)
7061 {
7062 json_object_lock(attr->community->json);
7063 json_object_object_add(json_path, "community", attr->community->json);
7064 }
7065 else
7066 {
7067 vty_out (vty, " Community: %s%s", attr->community->str,
7068 VTY_NEWLINE);
7069 }
7070 }
7071
7072 /* Line 5 display Extended-community */
7073 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
7074 {
7075 if (json_paths)
7076 {
7077 json_ext_community = json_object_new_object();
7078 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
7079 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
7080 }
7081 else
7082 {
7083 vty_out (vty, " Extended Community: %s%s",
7084 attr->extra->ecommunity->str, VTY_NEWLINE);
7085 }
7086 }
7087
7088 /* Line 6 display Originator, Cluster-id */
7089 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7090 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7091 {
7092 assert (attr->extra);
7093 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7094 {
7095 if (json_paths)
7096 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
7097 else
7098 vty_out (vty, " Originator: %s",
7099 inet_ntoa (attr->extra->originator_id));
7100 }
7101
7102 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7103 {
7104 int i;
7105
7106 if (json_paths)
7107 {
7108 json_cluster_list = json_object_new_object();
7109 json_cluster_list_list = json_object_new_array();
7110
7111 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7112 {
7113 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
7114 json_object_array_add(json_cluster_list_list, json_string);
7115 }
7116
7117 /* struct cluster_list does not have "str" variable like
7118 * aspath and community do. Add this someday if someone
7119 * asks for it.
7120 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7121 */
7122 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
7123 json_object_object_add(json_path, "clusterList", json_cluster_list);
7124 }
7125 else
7126 {
7127 vty_out (vty, ", Cluster list: ");
7128
7129 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7130 {
7131 vty_out (vty, "%s ",
7132 inet_ntoa (attr->extra->cluster->list[i]));
7133 }
7134 }
7135 }
7136
7137 if (!json_paths)
7138 vty_out (vty, "%s", VTY_NEWLINE);
7139 }
7140
7141 if (binfo->extra && binfo->extra->damp_info)
7142 bgp_damp_info_vty (vty, binfo, json_path);
7143
7144 /* Line 7 display Addpath IDs */
7145 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
7146 {
7147 if (json_paths)
7148 {
7149 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7150 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
7151 }
7152 else
7153 {
7154 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7155 binfo->addpath_rx_id, binfo->addpath_tx_id,
7156 VTY_NEWLINE);
7157 }
7158 }
7159
7160 /* If we used addpath to TX a non-bestpath we need to display
7161 * "Advertised to" on a path-by-path basis */
7162 if (bgp->addpath_tx_used[afi][safi])
7163 {
7164 first = 1;
7165
7166 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7167 {
7168 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7169 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7170
7171 if ((addpath_capable && has_adj) ||
7172 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7173 {
7174 if (json_path && !json_adv_to)
7175 json_adv_to = json_object_new_object();
7176
7177 route_vty_out_advertised_to(vty, peer, &first,
7178 " Advertised to:",
7179 json_adv_to);
7180 }
7181 }
7182
7183 if (json_path)
7184 {
7185 if (json_adv_to)
7186 {
7187 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7188 }
7189 }
7190 else
7191 {
7192 if (!first)
7193 {
7194 vty_out (vty, "%s", VTY_NEWLINE);
7195 }
7196 }
7197 }
7198
7199 /* Line 8 display Uptime */
7200 #ifdef HAVE_CLOCK_MONOTONIC
7201 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
7202 if (json_paths)
7203 {
7204 json_last_update = json_object_new_object();
7205 json_object_int_add(json_last_update, "epoch", tbuf);
7206 json_object_string_add(json_last_update, "string", ctime(&tbuf));
7207 json_object_object_add(json_path, "lastUpdate", json_last_update);
7208 }
7209 else
7210 vty_out (vty, " Last update: %s", ctime(&tbuf));
7211 #else
7212 if (json_paths)
7213 {
7214 json_last_update = json_object_new_object();
7215 json_object_int_add(json_last_update, "epoch", tbuf);
7216 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
7217 json_object_object_add(json_path, "lastUpdate", json_last_update);
7218 }
7219 else
7220 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
7221 #endif /* HAVE_CLOCK_MONOTONIC */
7222 }
7223
7224 /* We've constructed the json object for this path, add it to the json
7225 * array of paths
7226 */
7227 if (json_paths)
7228 {
7229 if (json_nexthop_global || json_nexthop_ll)
7230 {
7231 json_nexthops = json_object_new_array();
7232
7233 if (json_nexthop_global)
7234 json_object_array_add(json_nexthops, json_nexthop_global);
7235
7236 if (json_nexthop_ll)
7237 json_object_array_add(json_nexthops, json_nexthop_ll);
7238
7239 json_object_object_add(json_path, "nexthops", json_nexthops);
7240 }
7241
7242 json_object_object_add(json_path, "peer", json_peer);
7243 json_object_array_add(json_paths, json_path);
7244 }
7245 else
7246 vty_out (vty, "%s", VTY_NEWLINE);
7247 }
7248
7249 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
7250 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7251 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7252
7253 enum bgp_show_type
7254 {
7255 bgp_show_type_normal,
7256 bgp_show_type_regexp,
7257 bgp_show_type_prefix_list,
7258 bgp_show_type_filter_list,
7259 bgp_show_type_route_map,
7260 bgp_show_type_neighbor,
7261 bgp_show_type_cidr_only,
7262 bgp_show_type_prefix_longer,
7263 bgp_show_type_community_all,
7264 bgp_show_type_community,
7265 bgp_show_type_community_exact,
7266 bgp_show_type_community_list,
7267 bgp_show_type_community_list_exact,
7268 bgp_show_type_flap_statistics,
7269 bgp_show_type_flap_address,
7270 bgp_show_type_flap_prefix,
7271 bgp_show_type_flap_cidr_only,
7272 bgp_show_type_flap_regexp,
7273 bgp_show_type_flap_filter_list,
7274 bgp_show_type_flap_prefix_list,
7275 bgp_show_type_flap_prefix_longer,
7276 bgp_show_type_flap_route_map,
7277 bgp_show_type_flap_neighbor,
7278 bgp_show_type_dampend_paths,
7279 bgp_show_type_damp_neighbor
7280 };
7281
7282 static int
7283 bgp_show_prefix_list (struct vty *vty, const char *name,
7284 const char *prefix_list_str, afi_t afi,
7285 safi_t safi, enum bgp_show_type type);
7286 static int
7287 bgp_show_filter_list (struct vty *vty, const char *name,
7288 const char *filter, afi_t afi,
7289 safi_t safi, enum bgp_show_type type);
7290 static int
7291 bgp_show_route_map (struct vty *vty, const char *name,
7292 const char *rmap_str, afi_t afi,
7293 safi_t safi, enum bgp_show_type type);
7294 static int
7295 bgp_show_community_list (struct vty *vty, const char *name,
7296 const char *com, int exact,
7297 afi_t afi, safi_t safi);
7298 static int
7299 bgp_show_prefix_longer (struct vty *vty, const char *name,
7300 const char *prefix, afi_t afi,
7301 safi_t safi, enum bgp_show_type type);
7302
7303 static int
7304 bgp_show_table (struct vty *vty, struct bgp_table *table,
7305 struct in_addr *router_id, enum bgp_show_type type,
7306 void *output_arg, u_char use_json, json_object *json)
7307 {
7308 struct bgp_info *ri;
7309 struct bgp_node *rn;
7310 int header = 1;
7311 int display;
7312 unsigned long output_count;
7313 struct prefix *p;
7314 char buf[BUFSIZ];
7315 char buf2[BUFSIZ];
7316 json_object *json_paths = NULL;
7317 json_object *json_routes = NULL;
7318
7319 if (use_json)
7320 {
7321 if (json == NULL)
7322 json = json_object_new_object();
7323
7324 json_object_int_add(json, "tableVersion", table->version);
7325 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
7326 json_routes = json_object_new_object();
7327 }
7328
7329 /* This is first entry point, so reset total line. */
7330 output_count = 0;
7331
7332 /* Start processing of routes. */
7333 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7334 if (rn->info != NULL)
7335 {
7336 display = 0;
7337
7338 if (use_json)
7339 json_paths = json_object_new_array();
7340 else
7341 json_paths = NULL;
7342
7343 for (ri = rn->info; ri; ri = ri->next)
7344 {
7345 if (type == bgp_show_type_flap_statistics
7346 || type == bgp_show_type_flap_address
7347 || type == bgp_show_type_flap_prefix
7348 || type == bgp_show_type_flap_cidr_only
7349 || type == bgp_show_type_flap_regexp
7350 || type == bgp_show_type_flap_filter_list
7351 || type == bgp_show_type_flap_prefix_list
7352 || type == bgp_show_type_flap_prefix_longer
7353 || type == bgp_show_type_flap_route_map
7354 || type == bgp_show_type_flap_neighbor
7355 || type == bgp_show_type_dampend_paths
7356 || type == bgp_show_type_damp_neighbor)
7357 {
7358 if (!(ri->extra && ri->extra->damp_info))
7359 continue;
7360 }
7361 if (type == bgp_show_type_regexp
7362 || type == bgp_show_type_flap_regexp)
7363 {
7364 regex_t *regex = output_arg;
7365
7366 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7367 continue;
7368 }
7369 if (type == bgp_show_type_prefix_list
7370 || type == bgp_show_type_flap_prefix_list)
7371 {
7372 struct prefix_list *plist = output_arg;
7373
7374 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7375 continue;
7376 }
7377 if (type == bgp_show_type_filter_list
7378 || type == bgp_show_type_flap_filter_list)
7379 {
7380 struct as_list *as_list = output_arg;
7381
7382 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7383 continue;
7384 }
7385 if (type == bgp_show_type_route_map
7386 || type == bgp_show_type_flap_route_map)
7387 {
7388 struct route_map *rmap = output_arg;
7389 struct bgp_info binfo;
7390 struct attr dummy_attr;
7391 struct attr_extra dummy_extra;
7392 int ret;
7393
7394 dummy_attr.extra = &dummy_extra;
7395 bgp_attr_dup (&dummy_attr, ri->attr);
7396
7397 binfo.peer = ri->peer;
7398 binfo.attr = &dummy_attr;
7399
7400 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7401 if (ret == RMAP_DENYMATCH)
7402 continue;
7403 }
7404 if (type == bgp_show_type_neighbor
7405 || type == bgp_show_type_flap_neighbor
7406 || type == bgp_show_type_damp_neighbor)
7407 {
7408 union sockunion *su = output_arg;
7409
7410 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7411 continue;
7412 }
7413 if (type == bgp_show_type_cidr_only
7414 || type == bgp_show_type_flap_cidr_only)
7415 {
7416 u_int32_t destination;
7417
7418 destination = ntohl (rn->p.u.prefix4.s_addr);
7419 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7420 continue;
7421 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7422 continue;
7423 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7424 continue;
7425 }
7426 if (type == bgp_show_type_prefix_longer
7427 || type == bgp_show_type_flap_prefix_longer)
7428 {
7429 struct prefix *p = output_arg;
7430
7431 if (! prefix_match (p, &rn->p))
7432 continue;
7433 }
7434 if (type == bgp_show_type_community_all)
7435 {
7436 if (! ri->attr->community)
7437 continue;
7438 }
7439 if (type == bgp_show_type_community)
7440 {
7441 struct community *com = output_arg;
7442
7443 if (! ri->attr->community ||
7444 ! community_match (ri->attr->community, com))
7445 continue;
7446 }
7447 if (type == bgp_show_type_community_exact)
7448 {
7449 struct community *com = output_arg;
7450
7451 if (! ri->attr->community ||
7452 ! community_cmp (ri->attr->community, com))
7453 continue;
7454 }
7455 if (type == bgp_show_type_community_list)
7456 {
7457 struct community_list *list = output_arg;
7458
7459 if (! community_list_match (ri->attr->community, list))
7460 continue;
7461 }
7462 if (type == bgp_show_type_community_list_exact)
7463 {
7464 struct community_list *list = output_arg;
7465
7466 if (! community_list_exact_match (ri->attr->community, list))
7467 continue;
7468 }
7469 if (type == bgp_show_type_flap_address
7470 || type == bgp_show_type_flap_prefix)
7471 {
7472 struct prefix *p = output_arg;
7473
7474 if (! prefix_match (&rn->p, p))
7475 continue;
7476
7477 if (type == bgp_show_type_flap_prefix)
7478 if (p->prefixlen != rn->p.prefixlen)
7479 continue;
7480 }
7481 if (type == bgp_show_type_dampend_paths
7482 || type == bgp_show_type_damp_neighbor)
7483 {
7484 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7485 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7486 continue;
7487 }
7488
7489 if (!use_json && header)
7490 {
7491 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
7492 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7493 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7494 if (type == bgp_show_type_dampend_paths
7495 || type == bgp_show_type_damp_neighbor)
7496 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7497 else if (type == bgp_show_type_flap_statistics
7498 || type == bgp_show_type_flap_address
7499 || type == bgp_show_type_flap_prefix
7500 || type == bgp_show_type_flap_cidr_only
7501 || type == bgp_show_type_flap_regexp
7502 || type == bgp_show_type_flap_filter_list
7503 || type == bgp_show_type_flap_prefix_list
7504 || type == bgp_show_type_flap_prefix_longer
7505 || type == bgp_show_type_flap_route_map
7506 || type == bgp_show_type_flap_neighbor)
7507 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7508 else
7509 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7510 header = 0;
7511 }
7512
7513 if (type == bgp_show_type_dampend_paths
7514 || type == bgp_show_type_damp_neighbor)
7515 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7516 else if (type == bgp_show_type_flap_statistics
7517 || type == bgp_show_type_flap_address
7518 || type == bgp_show_type_flap_prefix
7519 || type == bgp_show_type_flap_cidr_only
7520 || type == bgp_show_type_flap_regexp
7521 || type == bgp_show_type_flap_filter_list
7522 || type == bgp_show_type_flap_prefix_list
7523 || type == bgp_show_type_flap_prefix_longer
7524 || type == bgp_show_type_flap_route_map
7525 || type == bgp_show_type_flap_neighbor)
7526 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7527 else
7528 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7529 display++;
7530 }
7531
7532 if (display)
7533 {
7534 output_count++;
7535 if (use_json)
7536 {
7537 p = &rn->p;
7538 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7539 json_object_object_add(json_routes, buf2, json_paths);
7540 }
7541 }
7542 }
7543
7544 if (use_json)
7545 {
7546 json_object_object_add(json, "routes", json_routes);
7547 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7548 json_object_free(json);
7549 }
7550 else
7551 {
7552 /* No route is displayed */
7553 if (output_count == 0)
7554 {
7555 if (type == bgp_show_type_normal)
7556 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
7557 }
7558 else
7559 vty_out (vty, "%sTotal number of prefixes %ld%s",
7560 VTY_NEWLINE, output_count, VTY_NEWLINE);
7561 }
7562
7563 return CMD_SUCCESS;
7564 }
7565
7566 static int
7567 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
7568 enum bgp_show_type type, void *output_arg, u_char use_json)
7569 {
7570 struct bgp_table *table;
7571
7572 if (bgp == NULL)
7573 {
7574 bgp = bgp_get_default ();
7575 }
7576
7577 if (bgp == NULL)
7578 {
7579 if (!use_json)
7580 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7581 return CMD_WARNING;
7582 }
7583
7584 table = bgp->rib[afi][safi];
7585
7586 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg,
7587 use_json, NULL);
7588 }
7589
7590 static void
7591 bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7592 u_char use_json)
7593 {
7594 struct listnode *node, *nnode;
7595 struct bgp *bgp;
7596 struct bgp_table *table;
7597 json_object *json = NULL;
7598 int is_first = 1;
7599
7600 if (use_json)
7601 vty_out (vty, "{%s", VTY_NEWLINE);
7602
7603 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7604 {
7605 if (use_json)
7606 {
7607 if (!(json = json_object_new_object()))
7608 {
7609 zlog_err("Unable to allocate memory for JSON object");
7610 vty_out (vty,
7611 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
7612 VTY_NEWLINE);
7613 return;
7614 }
7615 json_object_int_add(json, "vrfId",
7616 (bgp->vrf_id == VRF_UNKNOWN)
7617 ? -1 : bgp->vrf_id);
7618 json_object_string_add(json, "vrfName",
7619 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7620 ? "Default" : bgp->name);
7621 if (! is_first)
7622 vty_out (vty, ",%s", VTY_NEWLINE);
7623 else
7624 is_first = 0;
7625
7626 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7627 ? "Default" : bgp->name);
7628 }
7629 else
7630 {
7631 vty_out (vty, "%sInstance %s:%s",
7632 VTY_NEWLINE,
7633 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7634 ? "Default" : bgp->name,
7635 VTY_NEWLINE);
7636 }
7637 table = bgp->rib[afi][safi];
7638 bgp_show_table (vty, table, &bgp->router_id,
7639 bgp_show_type_normal, NULL, use_json, json);
7640
7641 }
7642
7643 if (use_json)
7644 vty_out (vty, "}%s", VTY_NEWLINE);
7645 }
7646
7647 /* Header of detailed BGP route information */
7648 static void
7649 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7650 struct bgp_node *rn,
7651 struct prefix_rd *prd, afi_t afi, safi_t safi,
7652 json_object *json)
7653 {
7654 struct bgp_info *ri;
7655 struct prefix *p;
7656 struct peer *peer;
7657 struct listnode *node, *nnode;
7658 char buf1[INET6_ADDRSTRLEN];
7659 char buf2[INET6_ADDRSTRLEN];
7660 int count = 0;
7661 int best = 0;
7662 int suppress = 0;
7663 int no_export = 0;
7664 int no_advertise = 0;
7665 int local_as = 0;
7666 int first = 1;
7667 json_object *json_adv_to = NULL;
7668
7669 p = &rn->p;
7670
7671 if (json)
7672 {
7673 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7674 json_object_int_add(json, "prefixlen", p->prefixlen);
7675 }
7676 else
7677 {
7678 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7679 ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ?
7680 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7681 safi == SAFI_MPLS_VPN ? ":" : "",
7682 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7683 p->prefixlen, VTY_NEWLINE);
7684 }
7685
7686 for (ri = rn->info; ri; ri = ri->next)
7687 {
7688 count++;
7689 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7690 {
7691 best = count;
7692 if (ri->extra && ri->extra->suppress)
7693 suppress = 1;
7694 if (ri->attr->community != NULL)
7695 {
7696 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7697 no_advertise = 1;
7698 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7699 no_export = 1;
7700 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7701 local_as = 1;
7702 }
7703 }
7704 }
7705
7706 if (!json)
7707 {
7708 vty_out (vty, "Paths: (%d available", count);
7709 if (best)
7710 {
7711 vty_out (vty, ", best #%d", best);
7712 if (safi == SAFI_UNICAST)
7713 vty_out (vty, ", table %s",
7714 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7715 ? "Default-IP-Routing-Table" : bgp->name);
7716 }
7717 else
7718 vty_out (vty, ", no best path");
7719
7720 if (no_advertise)
7721 vty_out (vty, ", not advertised to any peer");
7722 else if (no_export)
7723 vty_out (vty, ", not advertised to EBGP peer");
7724 else if (local_as)
7725 vty_out (vty, ", not advertised outside local AS");
7726
7727 if (suppress)
7728 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7729 vty_out (vty, ")%s", VTY_NEWLINE);
7730 }
7731
7732 /* If we are not using addpath then we can display Advertised to and that will
7733 * show what peers we advertised the bestpath to. If we are using addpath
7734 * though then we must display Advertised to on a path-by-path basis. */
7735 if (!bgp->addpath_tx_used[afi][safi])
7736 {
7737 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7738 {
7739 if (bgp_adj_out_lookup (peer, rn, 0))
7740 {
7741 if (json && !json_adv_to)
7742 json_adv_to = json_object_new_object();
7743
7744 route_vty_out_advertised_to(vty, peer, &first,
7745 " Advertised to non peer-group peers:\n ",
7746 json_adv_to);
7747 }
7748 }
7749
7750 if (json)
7751 {
7752 if (json_adv_to)
7753 {
7754 json_object_object_add(json, "advertisedTo", json_adv_to);
7755 }
7756 }
7757 else
7758 {
7759 if (first)
7760 vty_out (vty, " Not advertised to any peer");
7761 vty_out (vty, "%s", VTY_NEWLINE);
7762 }
7763 }
7764 }
7765
7766 /* Display specified route of BGP table. */
7767 static int
7768 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
7769 struct bgp_table *rib, const char *ip_str,
7770 afi_t afi, safi_t safi, struct prefix_rd *prd,
7771 int prefix_check, enum bgp_path_type pathtype,
7772 u_char use_json)
7773 {
7774 int ret;
7775 int header;
7776 int display = 0;
7777 struct prefix match;
7778 struct bgp_node *rn;
7779 struct bgp_node *rm;
7780 struct bgp_info *ri;
7781 struct bgp_table *table;
7782 json_object *json = NULL;
7783 json_object *json_paths = NULL;
7784
7785 /* Check IP address argument. */
7786 ret = str2prefix (ip_str, &match);
7787 if (! ret)
7788 {
7789 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
7790 return CMD_WARNING;
7791 }
7792
7793 match.family = afi2family (afi);
7794
7795 if (use_json)
7796 {
7797 json = json_object_new_object();
7798 json_paths = json_object_new_array();
7799 }
7800
7801 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
7802 {
7803 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
7804 {
7805 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
7806 continue;
7807
7808 if ((table = rn->info) != NULL)
7809 {
7810 header = 1;
7811
7812 if ((rm = bgp_node_match (table, &match)) != NULL)
7813 {
7814 if (prefix_check && rm->p.prefixlen != match.prefixlen)
7815 {
7816 bgp_unlock_node (rm);
7817 continue;
7818 }
7819
7820 for (ri = rm->info; ri; ri = ri->next)
7821 {
7822 if (header)
7823 {
7824 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
7825 AFI_IP, safi, json);
7826 header = 0;
7827 }
7828 display++;
7829
7830 if (pathtype == BGP_PATH_ALL ||
7831 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7832 (pathtype == BGP_PATH_MULTIPATH &&
7833 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7834 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths);
7835 }
7836
7837 bgp_unlock_node (rm);
7838 }
7839 }
7840 }
7841 }
7842 else
7843 {
7844 header = 1;
7845
7846 if ((rn = bgp_node_match (rib, &match)) != NULL)
7847 {
7848 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
7849 {
7850 for (ri = rn->info; ri; ri = ri->next)
7851 {
7852 if (header)
7853 {
7854 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
7855 header = 0;
7856 }
7857 display++;
7858
7859 if (pathtype == BGP_PATH_ALL ||
7860 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7861 (pathtype == BGP_PATH_MULTIPATH &&
7862 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7863 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
7864 }
7865 }
7866
7867 bgp_unlock_node (rn);
7868 }
7869 }
7870
7871 if (use_json)
7872 {
7873 if (display)
7874 json_object_object_add(json, "paths", json_paths);
7875
7876 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7877 json_object_free(json);
7878 }
7879 else
7880 {
7881 if (!display)
7882 {
7883 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7884 return CMD_WARNING;
7885 }
7886 }
7887
7888 return CMD_SUCCESS;
7889 }
7890
7891 /* Display specified route of Main RIB */
7892 static int
7893 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
7894 afi_t afi, safi_t safi, struct prefix_rd *prd,
7895 int prefix_check, enum bgp_path_type pathtype,
7896 u_char use_json)
7897 {
7898 struct bgp *bgp;
7899
7900 /* BGP structure lookup. */
7901 if (view_name)
7902 {
7903 bgp = bgp_lookup_by_name (view_name);
7904 if (bgp == NULL)
7905 {
7906 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
7907 return CMD_WARNING;
7908 }
7909 }
7910 else
7911 {
7912 bgp = bgp_get_default ();
7913 if (bgp == NULL)
7914 {
7915 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7916 return CMD_WARNING;
7917 }
7918 }
7919
7920 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
7921 afi, safi, prd, prefix_check, pathtype,
7922 use_json);
7923 }
7924
7925 /* BGP route print out function. */
7926 DEFUN (show_ip_bgp,
7927 show_ip_bgp_cmd,
7928 "show ip bgp {json}",
7929 SHOW_STR
7930 IP_STR
7931 BGP_STR
7932 "JavaScript Object Notation\n")
7933 {
7934 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
7935 }
7936
7937 DEFUN (show_ip_bgp_ipv4,
7938 show_ip_bgp_ipv4_cmd,
7939 "show ip bgp ipv4 (unicast|multicast) {json}",
7940 SHOW_STR
7941 IP_STR
7942 BGP_STR
7943 "Address family\n"
7944 "Address Family modifier\n"
7945 "Address Family modifier\n"
7946 "JavaScript Object Notation\n")
7947 {
7948 u_char uj = use_json(argc, argv);
7949
7950 if (strncmp (argv[0], "m", 1) == 0)
7951 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7952 NULL, uj);
7953
7954 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
7955 }
7956
7957 ALIAS (show_ip_bgp_ipv4,
7958 show_bgp_ipv4_safi_cmd,
7959 "show bgp ipv4 (unicast|multicast) {json}",
7960 SHOW_STR
7961 BGP_STR
7962 "Address family\n"
7963 "Address Family modifier\n"
7964 "Address Family modifier\n"
7965 "JavaScript Object Notation\n")
7966
7967 DEFUN (show_ip_bgp_route,
7968 show_ip_bgp_route_cmd,
7969 "show ip bgp A.B.C.D {json}",
7970 SHOW_STR
7971 IP_STR
7972 BGP_STR
7973 "Network in the BGP routing table to display\n"
7974 "JavaScript Object Notation\n")
7975 {
7976 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7977 }
7978
7979 DEFUN (show_ip_bgp_route_pathtype,
7980 show_ip_bgp_route_pathtype_cmd,
7981 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
7982 SHOW_STR
7983 IP_STR
7984 BGP_STR
7985 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7986 "Display only the bestpath\n"
7987 "Display only multipaths\n"
7988 "JavaScript Object Notation\n")
7989 {
7990 u_char uj = use_json(argc, argv);
7991
7992 if (strncmp (argv[1], "b", 1) == 0)
7993 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7994 else
7995 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7996 }
7997
7998 DEFUN (show_bgp_ipv4_safi_route_pathtype,
7999 show_bgp_ipv4_safi_route_pathtype_cmd,
8000 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
8001 SHOW_STR
8002 BGP_STR
8003 "Address family\n"
8004 "Address Family modifier\n"
8005 "Address Family modifier\n"
8006 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8007 "Display only the bestpath\n"
8008 "Display only multipaths\n"
8009 "JavaScript Object Notation\n")
8010 {
8011 u_char uj = use_json(argc, argv);
8012
8013 if (strncmp (argv[0], "m", 1) == 0)
8014 if (strncmp (argv[2], "b", 1) == 0)
8015 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8016 else
8017 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8018 else
8019 if (strncmp (argv[2], "b", 1) == 0)
8020 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8021 else
8022 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8023 }
8024
8025 DEFUN (show_ip_bgp_ipv4_route,
8026 show_ip_bgp_ipv4_route_cmd,
8027 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
8028 SHOW_STR
8029 IP_STR
8030 BGP_STR
8031 "Address family\n"
8032 "Address Family modifier\n"
8033 "Address Family modifier\n"
8034 "Network in the BGP routing table to display\n"
8035 "JavaScript Object Notation\n")
8036 {
8037 u_char uj = use_json(argc, argv);
8038
8039 if (strncmp (argv[0], "m", 1) == 0)
8040 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
8041
8042 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
8043 }
8044
8045 ALIAS (show_ip_bgp_ipv4_route,
8046 show_bgp_ipv4_safi_route_cmd,
8047 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
8048 SHOW_STR
8049 BGP_STR
8050 "Address family\n"
8051 "Address Family modifier\n"
8052 "Address Family modifier\n"
8053 "Network in the BGP routing table to display\n"
8054 "JavaScript Object Notation\n")
8055
8056 DEFUN (show_ip_bgp_vpnv4_all_route,
8057 show_ip_bgp_vpnv4_all_route_cmd,
8058 "show ip bgp vpnv4 all A.B.C.D {json}",
8059 SHOW_STR
8060 IP_STR
8061 BGP_STR
8062 "Display VPNv4 NLRI specific information\n"
8063 "Display information about all VPNv4 NLRIs\n"
8064 "Network in the BGP routing table to display\n"
8065 "JavaScript Object Notation\n")
8066 {
8067 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8068 }
8069
8070
8071 DEFUN (show_ip_bgp_vpnv4_rd_route,
8072 show_ip_bgp_vpnv4_rd_route_cmd,
8073 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
8074 SHOW_STR
8075 IP_STR
8076 BGP_STR
8077 "Display VPNv4 NLRI specific information\n"
8078 "Display information for a route distinguisher\n"
8079 "VPN Route Distinguisher\n"
8080 "Network in the BGP routing table to display\n"
8081 "JavaScript Object Notation\n")
8082 {
8083 int ret;
8084 struct prefix_rd prd;
8085 u_char uj= use_json(argc, argv);
8086
8087 ret = str2prefix_rd (argv[0], &prd);
8088 if (! ret)
8089 {
8090 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8091 return CMD_WARNING;
8092 }
8093 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj);
8094 }
8095
8096 DEFUN (show_ip_bgp_prefix,
8097 show_ip_bgp_prefix_cmd,
8098 "show ip bgp A.B.C.D/M {json}",
8099 SHOW_STR
8100 IP_STR
8101 BGP_STR
8102 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8103 "JavaScript Object Notation\n")
8104 {
8105 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8106 }
8107
8108 DEFUN (show_ip_bgp_prefix_pathtype,
8109 show_ip_bgp_prefix_pathtype_cmd,
8110 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
8111 SHOW_STR
8112 IP_STR
8113 BGP_STR
8114 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8115 "Display only the bestpath\n"
8116 "Display only multipaths\n"
8117 "JavaScript Object Notation\n")
8118 {
8119 u_char uj = use_json(argc, argv);
8120 if (strncmp (argv[1], "b", 1) == 0)
8121 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8122 else
8123 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8124 }
8125
8126 DEFUN (show_ip_bgp_ipv4_prefix,
8127 show_ip_bgp_ipv4_prefix_cmd,
8128 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
8129 SHOW_STR
8130 IP_STR
8131 BGP_STR
8132 "Address family\n"
8133 "Address Family modifier\n"
8134 "Address Family modifier\n"
8135 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8136 "JavaScript Object Notation\n")
8137 {
8138 u_char uj = use_json(argc, argv);
8139
8140 if (strncmp (argv[0], "m", 1) == 0)
8141 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
8142
8143 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
8144 }
8145
8146 ALIAS (show_ip_bgp_ipv4_prefix,
8147 show_bgp_ipv4_safi_prefix_cmd,
8148 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
8149 SHOW_STR
8150 BGP_STR
8151 "Address family\n"
8152 "Address Family modifier\n"
8153 "Address Family modifier\n"
8154 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8155 "JavaScript Object Notation\n")
8156
8157 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8158 show_ip_bgp_ipv4_prefix_pathtype_cmd,
8159 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
8160 SHOW_STR
8161 IP_STR
8162 BGP_STR
8163 "Address family\n"
8164 "Address Family modifier\n"
8165 "Address Family modifier\n"
8166 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8167 "Display only the bestpath\n"
8168 "Display only multipaths\n"
8169 "JavaScript Object Notation\n")
8170 {
8171 u_char uj = use_json(argc, argv);
8172
8173 if (strncmp (argv[0], "m", 1) == 0)
8174 if (strncmp (argv[2], "b", 1) == 0)
8175 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8176 else
8177 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8178 else
8179 if (strncmp (argv[2], "b", 1) == 0)
8180 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8181 else
8182 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8183 }
8184
8185 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8186 show_bgp_ipv4_safi_prefix_pathtype_cmd,
8187 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
8188 SHOW_STR
8189 BGP_STR
8190 "Address family\n"
8191 "Address Family modifier\n"
8192 "Address Family modifier\n"
8193 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8194 "Display only the bestpath\n"
8195 "Display only multipaths\n"
8196 "JavaScript Object Notation\n")
8197
8198 DEFUN (show_ip_bgp_vpnv4_all_prefix,
8199 show_ip_bgp_vpnv4_all_prefix_cmd,
8200 "show ip bgp vpnv4 all A.B.C.D/M {json}",
8201 SHOW_STR
8202 IP_STR
8203 BGP_STR
8204 "Display VPNv4 NLRI specific information\n"
8205 "Display information about all VPNv4 NLRIs\n"
8206 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8207 "JavaScript Object Notation\n")
8208 {
8209 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8210 }
8211
8212 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
8213 show_ip_bgp_vpnv4_rd_prefix_cmd,
8214 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
8215 SHOW_STR
8216 IP_STR
8217 BGP_STR
8218 "Display VPNv4 NLRI specific information\n"
8219 "Display information for a route distinguisher\n"
8220 "VPN Route Distinguisher\n"
8221 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8222 "JavaScript Object Notation\n")
8223 {
8224 int ret;
8225 struct prefix_rd prd;
8226
8227 ret = str2prefix_rd (argv[0], &prd);
8228 if (! ret)
8229 {
8230 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8231 return CMD_WARNING;
8232 }
8233 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv));
8234 }
8235
8236 DEFUN (show_ip_bgp_view,
8237 show_ip_bgp_instance_cmd,
8238 "show ip bgp " BGP_INSTANCE_CMD " {json}",
8239 SHOW_STR
8240 IP_STR
8241 BGP_STR
8242 BGP_INSTANCE_HELP_STR
8243 "JavaScript Object Notation\n")
8244 {
8245 struct bgp *bgp;
8246
8247 /* BGP structure lookup. */
8248 bgp = bgp_lookup_by_name (argv[1]);
8249 if (bgp == NULL)
8250 {
8251 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8252 return CMD_WARNING;
8253 }
8254
8255 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8256 }
8257
8258 DEFUN (show_ip_bgp_instance_all,
8259 show_ip_bgp_instance_all_cmd,
8260 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
8261 SHOW_STR
8262 IP_STR
8263 BGP_STR
8264 BGP_INSTANCE_ALL_HELP_STR
8265 "JavaScript Object Notation\n")
8266 {
8267 u_char uj = use_json(argc, argv);
8268
8269 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8270 return CMD_SUCCESS;
8271 }
8272
8273 DEFUN (show_ip_bgp_instance_route,
8274 show_ip_bgp_instance_route_cmd,
8275 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
8276 SHOW_STR
8277 IP_STR
8278 BGP_STR
8279 BGP_INSTANCE_HELP_STR
8280 "Network in the BGP routing table to display\n"
8281 "JavaScript Object Notation\n")
8282 {
8283 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8284 }
8285
8286 DEFUN (show_ip_bgp_instance_route_pathtype,
8287 show_ip_bgp_instance_route_pathtype_cmd,
8288 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
8289 SHOW_STR
8290 IP_STR
8291 BGP_STR
8292 BGP_INSTANCE_HELP_STR
8293 "Network in the BGP routing table to display\n"
8294 "Display only the bestpath\n"
8295 "Display only multipaths\n"
8296 "JavaScript Object Notation\n")
8297 {
8298 u_char uj = use_json(argc, argv);
8299
8300 if (strncmp (argv[3], "b", 1) == 0)
8301 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8302 else
8303 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8304 }
8305
8306 DEFUN (show_ip_bgp_instance_prefix,
8307 show_ip_bgp_instance_prefix_cmd,
8308 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
8309 SHOW_STR
8310 IP_STR
8311 BGP_STR
8312 BGP_INSTANCE_HELP_STR
8313 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8314 "JavaScript Object Notation\n")
8315 {
8316 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8317 }
8318
8319 DEFUN (show_ip_bgp_instance_prefix_pathtype,
8320 show_ip_bgp_instance_prefix_pathtype_cmd,
8321 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
8322 SHOW_STR
8323 IP_STR
8324 BGP_STR
8325 BGP_INSTANCE_HELP_STR
8326 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8327 "Display only the bestpath\n"
8328 "Display only multipaths\n"
8329 "JavaScript Object Notation\n")
8330 {
8331 u_char uj = use_json(argc, argv);
8332 if (strncmp (argv[3], "b", 1) == 0)
8333 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8334 else
8335 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8336 }
8337
8338 #ifdef HAVE_IPV6
8339 DEFUN (show_bgp,
8340 show_bgp_cmd,
8341 "show bgp {json}",
8342 SHOW_STR
8343 BGP_STR
8344 "JavaScript Object Notation\n")
8345 {
8346 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8347 NULL, use_json(argc, argv));
8348 }
8349
8350 ALIAS (show_bgp,
8351 show_bgp_ipv6_cmd,
8352 "show bgp ipv6 {json}",
8353 SHOW_STR
8354 BGP_STR
8355 "Address family\n"
8356 "JavaScript Object Notation\n")
8357
8358 DEFUN (show_bgp_ipv6_safi,
8359 show_bgp_ipv6_safi_cmd,
8360 "show bgp ipv6 (unicast|multicast) {json}",
8361 SHOW_STR
8362 BGP_STR
8363 "Address family\n"
8364 "Address Family modifier\n"
8365 "Address Family modifier\n"
8366 "JavaScript Object Notation\n")
8367 {
8368 u_char uj = use_json(argc, argv);
8369 if (strncmp (argv[0], "m", 1) == 0)
8370 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8371 NULL, uj);
8372
8373 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
8374 }
8375
8376 static void
8377 bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8378 {
8379 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8380 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8381 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8382 }
8383
8384 /* old command */
8385 DEFUN (show_ipv6_bgp,
8386 show_ipv6_bgp_cmd,
8387 "show ipv6 bgp {json}",
8388 SHOW_STR
8389 IP_STR
8390 BGP_STR
8391 "JavaScript Object Notation\n")
8392 {
8393 bgp_show_ipv6_bgp_deprecate_warning(vty);
8394 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8395 NULL, use_json(argc, argv));
8396 }
8397
8398 DEFUN (show_bgp_route,
8399 show_bgp_route_cmd,
8400 "show bgp X:X::X:X {json}",
8401 SHOW_STR
8402 BGP_STR
8403 "Network in the BGP routing table to display\n"
8404 "JavaScript Object Notation\n")
8405 {
8406 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8407 }
8408
8409 ALIAS (show_bgp_route,
8410 show_bgp_ipv6_route_cmd,
8411 "show bgp ipv6 X:X::X:X {json}",
8412 SHOW_STR
8413 BGP_STR
8414 "Address family\n"
8415 "Network in the BGP routing table to display\n"
8416 "JavaScript Object Notation\n")
8417
8418 DEFUN (show_bgp_ipv6_safi_route,
8419 show_bgp_ipv6_safi_route_cmd,
8420 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
8421 SHOW_STR
8422 BGP_STR
8423 "Address family\n"
8424 "Address Family modifier\n"
8425 "Address Family modifier\n"
8426 "Network in the BGP routing table to display\n"
8427 "JavaScript Object Notation\n")
8428 {
8429 u_char uj = use_json(argc, argv);
8430 if (strncmp (argv[0], "m", 1) == 0)
8431 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
8432
8433 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
8434 }
8435
8436 DEFUN (show_bgp_route_pathtype,
8437 show_bgp_route_pathtype_cmd,
8438 "show bgp X:X::X:X (bestpath|multipath) {json}",
8439 SHOW_STR
8440 BGP_STR
8441 "Network in the BGP routing table to display\n"
8442 "Display only the bestpath\n"
8443 "Display only multipaths\n"
8444 "JavaScript Object Notation\n")
8445 {
8446 u_char uj = use_json(argc, argv);
8447 if (strncmp (argv[1], "b", 1) == 0)
8448 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8449 else
8450 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8451 }
8452
8453 ALIAS (show_bgp_route_pathtype,
8454 show_bgp_ipv6_route_pathtype_cmd,
8455 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
8456 SHOW_STR
8457 BGP_STR
8458 "Address family\n"
8459 "Network in the BGP routing table to display\n"
8460 "Display only the bestpath\n"
8461 "Display only multipaths\n"
8462 "JavaScript Object Notation\n")
8463
8464 DEFUN (show_bgp_ipv6_safi_route_pathtype,
8465 show_bgp_ipv6_safi_route_pathtype_cmd,
8466 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
8467 SHOW_STR
8468 BGP_STR
8469 "Address family\n"
8470 "Address Family modifier\n"
8471 "Address Family modifier\n"
8472 "Network in the BGP routing table to display\n"
8473 "Display only the bestpath\n"
8474 "Display only multipaths\n"
8475 "JavaScript Object Notation\n")
8476 {
8477 u_char uj = use_json(argc, argv);
8478 if (strncmp (argv[0], "m", 1) == 0)
8479 if (strncmp (argv[2], "b", 1) == 0)
8480 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8481 else
8482 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8483 else
8484 if (strncmp (argv[2], "b", 1) == 0)
8485 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8486 else
8487 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8488 }
8489
8490 /* old command */
8491 DEFUN (show_ipv6_bgp_route,
8492 show_ipv6_bgp_route_cmd,
8493 "show ipv6 bgp X:X::X:X {json}",
8494 SHOW_STR
8495 IP_STR
8496 BGP_STR
8497 "Network in the BGP routing table to display\n"
8498 "JavaScript Object Notation\n")
8499 {
8500 bgp_show_ipv6_bgp_deprecate_warning(vty);
8501 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8502 }
8503
8504 DEFUN (show_bgp_prefix,
8505 show_bgp_prefix_cmd,
8506 "show bgp X:X::X:X/M {json}",
8507 SHOW_STR
8508 BGP_STR
8509 "IPv6 prefix <network>/<length>\n"
8510 "JavaScript Object Notation\n")
8511 {
8512 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8513 }
8514
8515 ALIAS (show_bgp_prefix,
8516 show_bgp_ipv6_prefix_cmd,
8517 "show bgp ipv6 X:X::X:X/M {json}",
8518 SHOW_STR
8519 BGP_STR
8520 "Address family\n"
8521 "IPv6 prefix <network>/<length>\n"
8522 "JavaScript Object Notation\n")
8523
8524 DEFUN (show_bgp_ipv6_safi_prefix,
8525 show_bgp_ipv6_safi_prefix_cmd,
8526 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
8527 SHOW_STR
8528 BGP_STR
8529 "Address family\n"
8530 "Address Family modifier\n"
8531 "Address Family modifier\n"
8532 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8533 "JavaScript Object Notation\n")
8534 {
8535 u_char uj = use_json(argc, argv);
8536 if (strncmp (argv[0], "m", 1) == 0)
8537 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
8538
8539 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
8540 }
8541
8542 DEFUN (show_bgp_prefix_pathtype,
8543 show_bgp_prefix_pathtype_cmd,
8544 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
8545 SHOW_STR
8546 BGP_STR
8547 "IPv6 prefix <network>/<length>\n"
8548 "Display only the bestpath\n"
8549 "Display only multipaths\n"
8550 "JavaScript Object Notation\n")
8551 {
8552 u_char uj = use_json(argc, argv);
8553 if (strncmp (argv[1], "b", 1) == 0)
8554 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8555 else
8556 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8557 }
8558
8559 ALIAS (show_bgp_prefix_pathtype,
8560 show_bgp_ipv6_prefix_pathtype_cmd,
8561 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8562 SHOW_STR
8563 BGP_STR
8564 "Address family\n"
8565 "IPv6 prefix <network>/<length>\n"
8566 "Display only the bestpath\n"
8567 "Display only multipaths\n"
8568 "JavaScript Object Notation\n")
8569
8570 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8571 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8572 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
8573 SHOW_STR
8574 BGP_STR
8575 "Address family\n"
8576 "Address Family modifier\n"
8577 "Address Family modifier\n"
8578 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8579 "Display only the bestpath\n"
8580 "Display only multipaths\n"
8581 "JavaScript Object Notation\n")
8582 {
8583 u_char uj = use_json(argc, argv);
8584 if (strncmp (argv[0], "m", 1) == 0)
8585 if (strncmp (argv[2], "b", 1) == 0)
8586 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8587 else
8588 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8589 else
8590 if (strncmp (argv[2], "b", 1) == 0)
8591 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8592 else
8593 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8594 }
8595
8596 /* old command */
8597 DEFUN (show_ipv6_bgp_prefix,
8598 show_ipv6_bgp_prefix_cmd,
8599 "show ipv6 bgp X:X::X:X/M {json}",
8600 SHOW_STR
8601 IP_STR
8602 BGP_STR
8603 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8604 "JavaScript Object Notation\n")
8605 {
8606 bgp_show_ipv6_bgp_deprecate_warning(vty);
8607 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8608 }
8609
8610 DEFUN (show_bgp_view,
8611 show_bgp_instance_cmd,
8612 "show bgp " BGP_INSTANCE_CMD " {json}",
8613 SHOW_STR
8614 BGP_STR
8615 BGP_INSTANCE_HELP_STR
8616 "JavaScript Object Notation\n")
8617 {
8618 struct bgp *bgp;
8619
8620 /* BGP structure lookup. */
8621 bgp = bgp_lookup_by_name (argv[1]);
8622 if (bgp == NULL)
8623 {
8624 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8625 return CMD_WARNING;
8626 }
8627
8628 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8629 }
8630
8631 DEFUN (show_bgp_instance_all,
8632 show_bgp_instance_all_cmd,
8633 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
8634 SHOW_STR
8635 BGP_STR
8636 BGP_INSTANCE_ALL_HELP_STR
8637 "JavaScript Object Notation\n")
8638 {
8639 u_char uj = use_json(argc, argv);
8640
8641 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
8642 return CMD_SUCCESS;
8643 }
8644
8645 ALIAS (show_bgp_view,
8646 show_bgp_instance_ipv6_cmd,
8647 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
8648 SHOW_STR
8649 BGP_STR
8650 BGP_INSTANCE_HELP_STR
8651 "Address family\n"
8652 "JavaScript Object Notation\n")
8653
8654 DEFUN (show_bgp_instance_route,
8655 show_bgp_instance_route_cmd,
8656 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
8657 SHOW_STR
8658 BGP_STR
8659 BGP_INSTANCE_HELP_STR
8660 "Network in the BGP routing table to display\n"
8661 "JavaScript Object Notation\n")
8662 {
8663 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8664 }
8665
8666 ALIAS (show_bgp_instance_route,
8667 show_bgp_instance_ipv6_route_cmd,
8668 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
8669 SHOW_STR
8670 BGP_STR
8671 BGP_INSTANCE_HELP_STR
8672 "Address family\n"
8673 "Network in the BGP routing table to display\n"
8674 "JavaScript Object Notation\n")
8675
8676 DEFUN (show_bgp_instance_route_pathtype,
8677 show_bgp_instance_route_pathtype_cmd,
8678 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
8679 SHOW_STR
8680 BGP_STR
8681 BGP_INSTANCE_HELP_STR
8682 "Network in the BGP routing table to display\n"
8683 "Display only the bestpath\n"
8684 "Display only multipaths\n"
8685 "JavaScript Object Notation\n")
8686 {
8687 u_char uj = use_json(argc, argv);
8688 if (strncmp (argv[3], "b", 1) == 0)
8689 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8690 else
8691 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8692 }
8693
8694 ALIAS (show_bgp_instance_route_pathtype,
8695 show_bgp_instance_ipv6_route_pathtype_cmd,
8696 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
8697 SHOW_STR
8698 BGP_STR
8699 BGP_INSTANCE_HELP_STR
8700 "Address family\n"
8701 "Network in the BGP routing table to display\n"
8702 "Display only the bestpath\n"
8703 "Display only multipaths\n"
8704 "JavaScript Object Notation\n")
8705
8706 DEFUN (show_bgp_instance_prefix,
8707 show_bgp_instance_prefix_cmd,
8708 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
8709 SHOW_STR
8710 BGP_STR
8711 BGP_INSTANCE_HELP_STR
8712 "IPv6 prefix <network>/<length>\n"
8713 "JavaScript Object Notation\n")
8714 {
8715 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8716 }
8717
8718 ALIAS (show_bgp_instance_prefix,
8719 show_bgp_instance_ipv6_prefix_cmd,
8720 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
8721 SHOW_STR
8722 BGP_STR
8723 BGP_INSTANCE_HELP_STR
8724 "Address family\n"
8725 "IPv6 prefix <network>/<length>\n"
8726 "JavaScript Object Notation\n")
8727
8728 DEFUN (show_bgp_instance_prefix_pathtype,
8729 show_bgp_instance_prefix_pathtype_cmd,
8730 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
8731 SHOW_STR
8732 BGP_STR
8733 BGP_INSTANCE_HELP_STR
8734 "IPv6 prefix <network>/<length>\n"
8735 "Display only the bestpath\n"
8736 "Display only multipaths\n"
8737 "JavaScript Object Notation\n")
8738 {
8739 u_char uj = use_json(argc, argv);
8740 if (strncmp (argv[3], "b", 1) == 0)
8741 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8742 else
8743 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8744 }
8745
8746 ALIAS (show_bgp_instance_prefix_pathtype,
8747 show_bgp_instance_ipv6_prefix_pathtype_cmd,
8748 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8749 SHOW_STR
8750 BGP_STR
8751 BGP_INSTANCE_HELP_STR
8752 "Address family\n"
8753 "IPv6 prefix <network>/<length>\n"
8754 "Display only the bestpath\n"
8755 "Display only multipaths\n"
8756 "JavaScript Object Notation\n")
8757
8758 DEFUN (show_bgp_instance_prefix_list,
8759 show_bgp_instance_prefix_list_cmd,
8760 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
8761 SHOW_STR
8762 BGP_STR
8763 BGP_INSTANCE_HELP_STR
8764 "Display routes conforming to the prefix-list\n"
8765 "IPv6 prefix-list name\n")
8766 {
8767 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8768 bgp_show_type_prefix_list);
8769 }
8770
8771 ALIAS (show_bgp_instance_prefix_list,
8772 show_bgp_instance_ipv6_prefix_list_cmd,
8773 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
8774 SHOW_STR
8775 BGP_STR
8776 BGP_INSTANCE_HELP_STR
8777 "Address family\n"
8778 "Display routes conforming to the prefix-list\n"
8779 "IPv6 prefix-list name\n")
8780
8781 DEFUN (show_bgp_instance_filter_list,
8782 show_bgp_instance_filter_list_cmd,
8783 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
8784 SHOW_STR
8785 BGP_STR
8786 BGP_INSTANCE_HELP_STR
8787 "Display routes conforming to the filter-list\n"
8788 "Regular expression access list name\n")
8789 {
8790 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8791 bgp_show_type_filter_list);
8792 }
8793
8794 ALIAS (show_bgp_instance_filter_list,
8795 show_bgp_instance_ipv6_filter_list_cmd,
8796 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
8797 SHOW_STR
8798 BGP_STR
8799 BGP_INSTANCE_HELP_STR
8800 "Address family\n"
8801 "Display routes conforming to the filter-list\n"
8802 "Regular expression access list name\n")
8803
8804 DEFUN (show_bgp_instance_route_map,
8805 show_bgp_instance_route_map_cmd,
8806 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
8807 SHOW_STR
8808 BGP_STR
8809 BGP_INSTANCE_HELP_STR
8810 "Display routes matching the route-map\n"
8811 "A route-map to match on\n")
8812 {
8813 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8814 bgp_show_type_route_map);
8815 }
8816
8817 ALIAS (show_bgp_instance_route_map,
8818 show_bgp_instance_ipv6_route_map_cmd,
8819 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
8820 SHOW_STR
8821 BGP_STR
8822 BGP_INSTANCE_HELP_STR
8823 "Address family\n"
8824 "Display routes matching the route-map\n"
8825 "A route-map to match on\n")
8826
8827 DEFUN (show_bgp_instance_community_list,
8828 show_bgp_instance_community_list_cmd,
8829 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
8830 SHOW_STR
8831 BGP_STR
8832 BGP_INSTANCE_HELP_STR
8833 "Display routes matching the community-list\n"
8834 "community-list number\n"
8835 "community-list name\n")
8836 {
8837 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
8838 }
8839
8840 ALIAS (show_bgp_instance_community_list,
8841 show_bgp_instance_ipv6_community_list_cmd,
8842 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
8843 SHOW_STR
8844 BGP_STR
8845 BGP_INSTANCE_HELP_STR
8846 "Address family\n"
8847 "Display routes matching the community-list\n"
8848 "community-list number\n"
8849 "community-list name\n")
8850
8851 DEFUN (show_bgp_instance_prefix_longer,
8852 show_bgp_instance_prefix_longer_cmd,
8853 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
8854 SHOW_STR
8855 BGP_STR
8856 BGP_INSTANCE_HELP_STR
8857 "IPv6 prefix <network>/<length>\n"
8858 "Display route and more specific routes\n")
8859 {
8860 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8861 bgp_show_type_prefix_longer);
8862 }
8863
8864 ALIAS (show_bgp_instance_prefix_longer,
8865 show_bgp_instance_ipv6_prefix_longer_cmd,
8866 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
8867 SHOW_STR
8868 BGP_STR
8869 BGP_INSTANCE_HELP_STR
8870 "Address family\n"
8871 "IPv6 prefix <network>/<length>\n"
8872 "Display route and more specific routes\n")
8873
8874 /* old command */
8875 DEFUN (show_ipv6_mbgp,
8876 show_ipv6_mbgp_cmd,
8877 "show ipv6 mbgp {json}",
8878 SHOW_STR
8879 IP_STR
8880 MBGP_STR
8881 "JavaScript Object Notation\n")
8882 {
8883 bgp_show_ipv6_bgp_deprecate_warning(vty);
8884 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8885 NULL, use_json(argc, argv));
8886 }
8887
8888 /* old command */
8889 DEFUN (show_ipv6_mbgp_route,
8890 show_ipv6_mbgp_route_cmd,
8891 "show ipv6 mbgp X:X::X:X {json}",
8892 SHOW_STR
8893 IP_STR
8894 MBGP_STR
8895 "Network in the MBGP routing table to display\n"
8896 "JavaScript Object Notation\n")
8897 {
8898 bgp_show_ipv6_bgp_deprecate_warning(vty);
8899 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8900 }
8901
8902 /* old command */
8903 DEFUN (show_ipv6_mbgp_prefix,
8904 show_ipv6_mbgp_prefix_cmd,
8905 "show ipv6 mbgp X:X::X:X/M {json}",
8906 SHOW_STR
8907 IP_STR
8908 MBGP_STR
8909 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8910 "JavaScript Object Notation\n")
8911 {
8912 bgp_show_ipv6_bgp_deprecate_warning(vty);
8913 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8914 }
8915 #endif
8916
8917
8918 static int
8919 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
8920 safi_t safi, enum bgp_show_type type)
8921 {
8922 int i;
8923 struct buffer *b;
8924 char *regstr;
8925 int first;
8926 regex_t *regex;
8927 int rc;
8928
8929 first = 0;
8930 b = buffer_new (1024);
8931 for (i = 0; i < argc; i++)
8932 {
8933 if (first)
8934 buffer_putc (b, ' ');
8935 else
8936 {
8937 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8938 continue;
8939 first = 1;
8940 }
8941
8942 buffer_putstr (b, argv[i]);
8943 }
8944 buffer_putc (b, '\0');
8945
8946 regstr = buffer_getstr (b);
8947 buffer_free (b);
8948
8949 regex = bgp_regcomp (regstr);
8950 XFREE(MTYPE_TMP, regstr);
8951 if (! regex)
8952 {
8953 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8954 VTY_NEWLINE);
8955 return CMD_WARNING;
8956 }
8957
8958 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
8959 bgp_regex_free (regex);
8960 return rc;
8961 }
8962
8963 DEFUN (show_ip_bgp_regexp,
8964 show_ip_bgp_regexp_cmd,
8965 "show ip bgp regexp .LINE",
8966 SHOW_STR
8967 IP_STR
8968 BGP_STR
8969 "Display routes matching the AS path regular expression\n"
8970 "A regular-expression to match the BGP AS paths\n")
8971 {
8972 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8973 bgp_show_type_regexp);
8974 }
8975
8976 DEFUN (show_ip_bgp_flap_regexp,
8977 show_ip_bgp_flap_regexp_cmd,
8978 "show ip bgp flap-statistics regexp .LINE",
8979 SHOW_STR
8980 IP_STR
8981 BGP_STR
8982 "Display flap statistics of routes\n"
8983 "Display routes matching the AS path regular expression\n"
8984 "A regular-expression to match the BGP AS paths\n")
8985 {
8986 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8987 bgp_show_type_flap_regexp);
8988 }
8989
8990 ALIAS (show_ip_bgp_flap_regexp,
8991 show_ip_bgp_damp_flap_regexp_cmd,
8992 "show ip bgp dampening flap-statistics regexp .LINE",
8993 SHOW_STR
8994 IP_STR
8995 BGP_STR
8996 "Display detailed information about dampening\n"
8997 "Display flap statistics of routes\n"
8998 "Display routes matching the AS path regular expression\n"
8999 "A regular-expression to match the BGP AS paths\n")
9000
9001 DEFUN (show_ip_bgp_ipv4_regexp,
9002 show_ip_bgp_ipv4_regexp_cmd,
9003 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
9004 SHOW_STR
9005 IP_STR
9006 BGP_STR
9007 "Address family\n"
9008 "Address Family modifier\n"
9009 "Address Family modifier\n"
9010 "Display routes matching the AS path regular expression\n"
9011 "A regular-expression to match the BGP AS paths\n")
9012 {
9013 if (strncmp (argv[0], "m", 1) == 0)
9014 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
9015 bgp_show_type_regexp);
9016
9017 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9018 bgp_show_type_regexp);
9019 }
9020
9021 #ifdef HAVE_IPV6
9022 DEFUN (show_bgp_regexp,
9023 show_bgp_regexp_cmd,
9024 "show bgp regexp .LINE",
9025 SHOW_STR
9026 BGP_STR
9027 "Display routes matching the AS path regular expression\n"
9028 "A regular-expression to match the BGP AS paths\n")
9029 {
9030 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9031 bgp_show_type_regexp);
9032 }
9033
9034 ALIAS (show_bgp_regexp,
9035 show_bgp_ipv6_regexp_cmd,
9036 "show bgp ipv6 regexp .LINE",
9037 SHOW_STR
9038 BGP_STR
9039 "Address family\n"
9040 "Display routes matching the AS path regular expression\n"
9041 "A regular-expression to match the BGP AS paths\n")
9042
9043 /* old command */
9044 DEFUN (show_ipv6_bgp_regexp,
9045 show_ipv6_bgp_regexp_cmd,
9046 "show ipv6 bgp regexp .LINE",
9047 SHOW_STR
9048 IP_STR
9049 BGP_STR
9050 "Display routes matching the AS path regular expression\n"
9051 "A regular-expression to match the BGP AS paths\n")
9052 {
9053 bgp_show_ipv6_bgp_deprecate_warning(vty);
9054 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9055 bgp_show_type_regexp);
9056 }
9057
9058 /* old command */
9059 DEFUN (show_ipv6_mbgp_regexp,
9060 show_ipv6_mbgp_regexp_cmd,
9061 "show ipv6 mbgp regexp .LINE",
9062 SHOW_STR
9063 IP_STR
9064 BGP_STR
9065 "Display routes matching the AS path regular expression\n"
9066 "A regular-expression to match the MBGP AS paths\n")
9067 {
9068 bgp_show_ipv6_bgp_deprecate_warning(vty);
9069 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9070 bgp_show_type_regexp);
9071 }
9072 #endif /* HAVE_IPV6 */
9073
9074 static int
9075 bgp_show_prefix_list (struct vty *vty, const char *name,
9076 const char *prefix_list_str, afi_t afi,
9077 safi_t safi, enum bgp_show_type type)
9078 {
9079 struct prefix_list *plist;
9080 struct bgp *bgp = NULL;
9081
9082 if (name && !(bgp = bgp_lookup_by_name(name)))
9083 {
9084 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9085 return CMD_WARNING;
9086 }
9087
9088 plist = prefix_list_lookup (afi, prefix_list_str);
9089 if (plist == NULL)
9090 {
9091 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9092 prefix_list_str, VTY_NEWLINE);
9093 return CMD_WARNING;
9094 }
9095
9096 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
9097 }
9098
9099 DEFUN (show_ip_bgp_prefix_list,
9100 show_ip_bgp_prefix_list_cmd,
9101 "show ip bgp prefix-list WORD",
9102 SHOW_STR
9103 IP_STR
9104 BGP_STR
9105 "Display routes conforming to the prefix-list\n"
9106 "IP prefix-list name\n")
9107 {
9108 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9109 bgp_show_type_prefix_list);
9110 }
9111
9112 DEFUN (show_ip_bgp_instance_prefix_list,
9113 show_ip_bgp_instance_prefix_list_cmd,
9114 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9115 SHOW_STR
9116 IP_STR
9117 BGP_STR
9118 BGP_INSTANCE_HELP_STR
9119 "Display routes conforming to the prefix-list\n"
9120 "IP prefix-list name\n")
9121 {
9122 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9123 bgp_show_type_prefix_list);
9124 }
9125
9126 DEFUN (show_ip_bgp_flap_prefix_list,
9127 show_ip_bgp_flap_prefix_list_cmd,
9128 "show ip bgp flap-statistics prefix-list WORD",
9129 SHOW_STR
9130 IP_STR
9131 BGP_STR
9132 "Display flap statistics of routes\n"
9133 "Display routes conforming to the prefix-list\n"
9134 "IP prefix-list name\n")
9135 {
9136 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9137 bgp_show_type_flap_prefix_list);
9138 }
9139
9140 ALIAS (show_ip_bgp_flap_prefix_list,
9141 show_ip_bgp_damp_flap_prefix_list_cmd,
9142 "show ip bgp dampening flap-statistics prefix-list WORD",
9143 SHOW_STR
9144 IP_STR
9145 BGP_STR
9146 "Display detailed information about dampening\n"
9147 "Display flap statistics of routes\n"
9148 "Display routes conforming to the prefix-list\n"
9149 "IP prefix-list name\n")
9150
9151 DEFUN (show_ip_bgp_ipv4_prefix_list,
9152 show_ip_bgp_ipv4_prefix_list_cmd,
9153 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9154 SHOW_STR
9155 IP_STR
9156 BGP_STR
9157 "Address family\n"
9158 "Address Family modifier\n"
9159 "Address Family modifier\n"
9160 "Display routes conforming to the prefix-list\n"
9161 "IP prefix-list name\n")
9162 {
9163 if (strncmp (argv[0], "m", 1) == 0)
9164 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9165 bgp_show_type_prefix_list);
9166
9167 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9168 bgp_show_type_prefix_list);
9169 }
9170
9171 #ifdef HAVE_IPV6
9172 DEFUN (show_bgp_prefix_list,
9173 show_bgp_prefix_list_cmd,
9174 "show bgp prefix-list WORD",
9175 SHOW_STR
9176 BGP_STR
9177 "Display routes conforming to the prefix-list\n"
9178 "IPv6 prefix-list name\n")
9179 {
9180 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9181 bgp_show_type_prefix_list);
9182 }
9183
9184 ALIAS (show_bgp_prefix_list,
9185 show_bgp_ipv6_prefix_list_cmd,
9186 "show bgp ipv6 prefix-list WORD",
9187 SHOW_STR
9188 BGP_STR
9189 "Address family\n"
9190 "Display routes conforming to the prefix-list\n"
9191 "IPv6 prefix-list name\n")
9192
9193 /* old command */
9194 DEFUN (show_ipv6_bgp_prefix_list,
9195 show_ipv6_bgp_prefix_list_cmd,
9196 "show ipv6 bgp prefix-list WORD",
9197 SHOW_STR
9198 IPV6_STR
9199 BGP_STR
9200 "Display routes matching the prefix-list\n"
9201 "IPv6 prefix-list name\n")
9202 {
9203 bgp_show_ipv6_bgp_deprecate_warning(vty);
9204 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9205 bgp_show_type_prefix_list);
9206 }
9207
9208 /* old command */
9209 DEFUN (show_ipv6_mbgp_prefix_list,
9210 show_ipv6_mbgp_prefix_list_cmd,
9211 "show ipv6 mbgp prefix-list WORD",
9212 SHOW_STR
9213 IPV6_STR
9214 MBGP_STR
9215 "Display routes matching the prefix-list\n"
9216 "IPv6 prefix-list name\n")
9217 {
9218 bgp_show_ipv6_bgp_deprecate_warning(vty);
9219 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9220 bgp_show_type_prefix_list);
9221 }
9222 #endif /* HAVE_IPV6 */
9223
9224 static int
9225 bgp_show_filter_list (struct vty *vty, const char *name,
9226 const char *filter, afi_t afi,
9227 safi_t safi, enum bgp_show_type type)
9228 {
9229 struct as_list *as_list;
9230 struct bgp *bgp = NULL;
9231
9232 if (name && !(bgp = bgp_lookup_by_name(name)))
9233 {
9234 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9235 return CMD_WARNING;
9236 }
9237
9238 as_list = as_list_lookup (filter);
9239 if (as_list == NULL)
9240 {
9241 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9242 return CMD_WARNING;
9243 }
9244
9245 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
9246 }
9247
9248 DEFUN (show_ip_bgp_filter_list,
9249 show_ip_bgp_filter_list_cmd,
9250 "show ip bgp filter-list WORD",
9251 SHOW_STR
9252 IP_STR
9253 BGP_STR
9254 "Display routes conforming to the filter-list\n"
9255 "Regular expression access list name\n")
9256 {
9257 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9258 bgp_show_type_filter_list);
9259 }
9260
9261 DEFUN (show_ip_bgp_instance_filter_list,
9262 show_ip_bgp_instance_filter_list_cmd,
9263 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
9264 SHOW_STR
9265 IP_STR
9266 BGP_STR
9267 BGP_INSTANCE_HELP_STR
9268 "Display routes conforming to the filter-list\n"
9269 "Regular expression access list name\n")
9270 {
9271 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9272 bgp_show_type_filter_list);
9273 }
9274
9275 DEFUN (show_ip_bgp_flap_filter_list,
9276 show_ip_bgp_flap_filter_list_cmd,
9277 "show ip bgp flap-statistics filter-list WORD",
9278 SHOW_STR
9279 IP_STR
9280 BGP_STR
9281 "Display flap statistics of routes\n"
9282 "Display routes conforming to the filter-list\n"
9283 "Regular expression access list name\n")
9284 {
9285 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9286 bgp_show_type_flap_filter_list);
9287 }
9288
9289 ALIAS (show_ip_bgp_flap_filter_list,
9290 show_ip_bgp_damp_flap_filter_list_cmd,
9291 "show ip bgp dampening flap-statistics filter-list WORD",
9292 SHOW_STR
9293 IP_STR
9294 BGP_STR
9295 "Display detailed information about dampening\n"
9296 "Display flap statistics of routes\n"
9297 "Display routes conforming to the filter-list\n"
9298 "Regular expression access list name\n")
9299
9300 DEFUN (show_ip_bgp_ipv4_filter_list,
9301 show_ip_bgp_ipv4_filter_list_cmd,
9302 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9303 SHOW_STR
9304 IP_STR
9305 BGP_STR
9306 "Address family\n"
9307 "Address Family modifier\n"
9308 "Address Family modifier\n"
9309 "Display routes conforming to the filter-list\n"
9310 "Regular expression access list name\n")
9311 {
9312 if (strncmp (argv[0], "m", 1) == 0)
9313 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9314 bgp_show_type_filter_list);
9315
9316 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9317 bgp_show_type_filter_list);
9318 }
9319
9320 #ifdef HAVE_IPV6
9321 DEFUN (show_bgp_filter_list,
9322 show_bgp_filter_list_cmd,
9323 "show bgp filter-list WORD",
9324 SHOW_STR
9325 BGP_STR
9326 "Display routes conforming to the filter-list\n"
9327 "Regular expression access list name\n")
9328 {
9329 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9330 bgp_show_type_filter_list);
9331 }
9332
9333 ALIAS (show_bgp_filter_list,
9334 show_bgp_ipv6_filter_list_cmd,
9335 "show bgp ipv6 filter-list WORD",
9336 SHOW_STR
9337 BGP_STR
9338 "Address family\n"
9339 "Display routes conforming to the filter-list\n"
9340 "Regular expression access list name\n")
9341
9342 /* old command */
9343 DEFUN (show_ipv6_bgp_filter_list,
9344 show_ipv6_bgp_filter_list_cmd,
9345 "show ipv6 bgp filter-list WORD",
9346 SHOW_STR
9347 IPV6_STR
9348 BGP_STR
9349 "Display routes conforming to the filter-list\n"
9350 "Regular expression access list name\n")
9351 {
9352 bgp_show_ipv6_bgp_deprecate_warning(vty);
9353 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9354 bgp_show_type_filter_list);
9355 }
9356
9357 /* old command */
9358 DEFUN (show_ipv6_mbgp_filter_list,
9359 show_ipv6_mbgp_filter_list_cmd,
9360 "show ipv6 mbgp filter-list WORD",
9361 SHOW_STR
9362 IPV6_STR
9363 MBGP_STR
9364 "Display routes conforming to the filter-list\n"
9365 "Regular expression access list name\n")
9366 {
9367 bgp_show_ipv6_bgp_deprecate_warning(vty);
9368 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9369 bgp_show_type_filter_list);
9370 }
9371 #endif /* HAVE_IPV6 */
9372
9373 DEFUN (show_ip_bgp_dampening_info,
9374 show_ip_bgp_dampening_params_cmd,
9375 "show ip bgp dampening parameters",
9376 SHOW_STR
9377 IP_STR
9378 BGP_STR
9379 "Display detailed information about dampening\n"
9380 "Display detail of configured dampening parameters\n")
9381 {
9382 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9383 }
9384
9385 static int
9386 bgp_show_route_map (struct vty *vty, const char *name,
9387 const char *rmap_str, afi_t afi,
9388 safi_t safi, enum bgp_show_type type)
9389 {
9390 struct route_map *rmap;
9391 struct bgp *bgp = NULL;
9392
9393 if (name && !(bgp = bgp_lookup_by_name(name)))
9394 {
9395 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9396 return CMD_WARNING;
9397 }
9398
9399 rmap = route_map_lookup_by_name (rmap_str);
9400 if (! rmap)
9401 {
9402 vty_out (vty, "%% %s is not a valid route-map name%s",
9403 rmap_str, VTY_NEWLINE);
9404 return CMD_WARNING;
9405 }
9406
9407 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
9408 }
9409
9410 DEFUN (show_ip_bgp_route_map,
9411 show_ip_bgp_route_map_cmd,
9412 "show ip bgp route-map WORD",
9413 SHOW_STR
9414 IP_STR
9415 BGP_STR
9416 "Display routes matching the route-map\n"
9417 "A route-map to match on\n")
9418 {
9419 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9420 bgp_show_type_route_map);
9421 }
9422
9423 DEFUN (show_ip_bgp_instance_route_map,
9424 show_ip_bgp_instance_route_map_cmd,
9425 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
9426 SHOW_STR
9427 IP_STR
9428 BGP_STR
9429 BGP_INSTANCE_HELP_STR
9430 "Display routes matching the route-map\n"
9431 "A route-map to match on\n")
9432 {
9433 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9434 bgp_show_type_route_map);
9435 }
9436
9437 DEFUN (show_ip_bgp_flap_route_map,
9438 show_ip_bgp_flap_route_map_cmd,
9439 "show ip bgp flap-statistics route-map WORD",
9440 SHOW_STR
9441 IP_STR
9442 BGP_STR
9443 "Display flap statistics of routes\n"
9444 "Display routes matching the route-map\n"
9445 "A route-map to match on\n")
9446 {
9447 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9448 bgp_show_type_flap_route_map);
9449 }
9450
9451 ALIAS (show_ip_bgp_flap_route_map,
9452 show_ip_bgp_damp_flap_route_map_cmd,
9453 "show ip bgp dampening flap-statistics route-map WORD",
9454 SHOW_STR
9455 IP_STR
9456 BGP_STR
9457 "Display detailed information about dampening\n"
9458 "Display flap statistics of routes\n"
9459 "Display routes matching the route-map\n"
9460 "A route-map to match on\n")
9461
9462 DEFUN (show_ip_bgp_ipv4_route_map,
9463 show_ip_bgp_ipv4_route_map_cmd,
9464 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9465 SHOW_STR
9466 IP_STR
9467 BGP_STR
9468 "Address family\n"
9469 "Address Family modifier\n"
9470 "Address Family modifier\n"
9471 "Display routes matching the route-map\n"
9472 "A route-map to match on\n")
9473 {
9474 if (strncmp (argv[0], "m", 1) == 0)
9475 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9476 bgp_show_type_route_map);
9477
9478 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9479 bgp_show_type_route_map);
9480 }
9481
9482 DEFUN (show_bgp_route_map,
9483 show_bgp_route_map_cmd,
9484 "show bgp route-map WORD",
9485 SHOW_STR
9486 BGP_STR
9487 "Display routes matching the route-map\n"
9488 "A route-map to match on\n")
9489 {
9490 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9491 bgp_show_type_route_map);
9492 }
9493
9494 ALIAS (show_bgp_route_map,
9495 show_bgp_ipv6_route_map_cmd,
9496 "show bgp ipv6 route-map WORD",
9497 SHOW_STR
9498 BGP_STR
9499 "Address family\n"
9500 "Display routes matching the route-map\n"
9501 "A route-map to match on\n")
9502
9503 DEFUN (show_ip_bgp_cidr_only,
9504 show_ip_bgp_cidr_only_cmd,
9505 "show ip bgp cidr-only",
9506 SHOW_STR
9507 IP_STR
9508 BGP_STR
9509 "Display only routes with non-natural netmasks\n")
9510 {
9511 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9512 bgp_show_type_cidr_only, NULL, 0);
9513 }
9514
9515 DEFUN (show_ip_bgp_flap_cidr_only,
9516 show_ip_bgp_flap_cidr_only_cmd,
9517 "show ip bgp flap-statistics cidr-only",
9518 SHOW_STR
9519 IP_STR
9520 BGP_STR
9521 "Display flap statistics of routes\n"
9522 "Display only routes with non-natural netmasks\n")
9523 {
9524 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9525 bgp_show_type_flap_cidr_only, NULL, 0);
9526 }
9527
9528 ALIAS (show_ip_bgp_flap_cidr_only,
9529 show_ip_bgp_damp_flap_cidr_only_cmd,
9530 "show ip bgp dampening flap-statistics cidr-only",
9531 SHOW_STR
9532 IP_STR
9533 BGP_STR
9534 "Display detailed information about dampening\n"
9535 "Display flap statistics of routes\n"
9536 "Display only routes with non-natural netmasks\n")
9537
9538 DEFUN (show_ip_bgp_ipv4_cidr_only,
9539 show_ip_bgp_ipv4_cidr_only_cmd,
9540 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9541 SHOW_STR
9542 IP_STR
9543 BGP_STR
9544 "Address family\n"
9545 "Address Family modifier\n"
9546 "Address Family modifier\n"
9547 "Display only routes with non-natural netmasks\n")
9548 {
9549 if (strncmp (argv[0], "m", 1) == 0)
9550 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9551 bgp_show_type_cidr_only, NULL, 0);
9552
9553 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9554 bgp_show_type_cidr_only, NULL, 0);
9555 }
9556
9557 DEFUN (show_ip_bgp_community_all,
9558 show_ip_bgp_community_all_cmd,
9559 "show ip bgp community",
9560 SHOW_STR
9561 IP_STR
9562 BGP_STR
9563 "Display routes matching the communities\n")
9564 {
9565 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9566 bgp_show_type_community_all, NULL, 0);
9567 }
9568
9569 DEFUN (show_ip_bgp_ipv4_community_all,
9570 show_ip_bgp_ipv4_community_all_cmd,
9571 "show ip bgp ipv4 (unicast|multicast) community",
9572 SHOW_STR
9573 IP_STR
9574 BGP_STR
9575 "Address family\n"
9576 "Address Family modifier\n"
9577 "Address Family modifier\n"
9578 "Display routes matching the communities\n")
9579 {
9580 if (strncmp (argv[0], "m", 1) == 0)
9581 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9582 bgp_show_type_community_all, NULL, 0);
9583
9584 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9585 bgp_show_type_community_all, NULL, 0);
9586 }
9587
9588 #ifdef HAVE_IPV6
9589 DEFUN (show_bgp_community_all,
9590 show_bgp_community_all_cmd,
9591 "show bgp community",
9592 SHOW_STR
9593 BGP_STR
9594 "Display routes matching the communities\n")
9595 {
9596 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9597 bgp_show_type_community_all, NULL, 0);
9598 }
9599
9600 ALIAS (show_bgp_community_all,
9601 show_bgp_ipv6_community_all_cmd,
9602 "show bgp ipv6 community",
9603 SHOW_STR
9604 BGP_STR
9605 "Address family\n"
9606 "Display routes matching the communities\n")
9607
9608 /* old command */
9609 DEFUN (show_ipv6_bgp_community_all,
9610 show_ipv6_bgp_community_all_cmd,
9611 "show ipv6 bgp community",
9612 SHOW_STR
9613 IPV6_STR
9614 BGP_STR
9615 "Display routes matching the communities\n")
9616 {
9617 bgp_show_ipv6_bgp_deprecate_warning(vty);
9618 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9619 bgp_show_type_community_all, NULL, 0);
9620 }
9621
9622 /* old command */
9623 DEFUN (show_ipv6_mbgp_community_all,
9624 show_ipv6_mbgp_community_all_cmd,
9625 "show ipv6 mbgp community",
9626 SHOW_STR
9627 IPV6_STR
9628 MBGP_STR
9629 "Display routes matching the communities\n")
9630 {
9631 bgp_show_ipv6_bgp_deprecate_warning(vty);
9632 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9633 bgp_show_type_community_all, NULL, 0);
9634 }
9635 #endif /* HAVE_IPV6 */
9636
9637 static int
9638 bgp_show_community (struct vty *vty, const char *view_name, int argc,
9639 const char **argv, int exact, afi_t afi, safi_t safi)
9640 {
9641 struct community *com;
9642 struct buffer *b;
9643 struct bgp *bgp;
9644 int i;
9645 char *str;
9646 int first = 0;
9647
9648 /* BGP structure lookup */
9649 if (view_name)
9650 {
9651 bgp = bgp_lookup_by_name (view_name);
9652 if (bgp == NULL)
9653 {
9654 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
9655 return CMD_WARNING;
9656 }
9657 }
9658 else
9659 {
9660 bgp = bgp_get_default ();
9661 if (bgp == NULL)
9662 {
9663 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9664 return CMD_WARNING;
9665 }
9666 }
9667
9668 b = buffer_new (1024);
9669 for (i = 0; i < argc; i++)
9670 {
9671 if (first)
9672 buffer_putc (b, ' ');
9673 else
9674 {
9675 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9676 continue;
9677 first = 1;
9678 }
9679
9680 buffer_putstr (b, argv[i]);
9681 }
9682 buffer_putc (b, '\0');
9683
9684 str = buffer_getstr (b);
9685 buffer_free (b);
9686
9687 com = community_str2com (str);
9688 XFREE (MTYPE_TMP, str);
9689 if (! com)
9690 {
9691 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9692 return CMD_WARNING;
9693 }
9694
9695 return bgp_show (vty, bgp, afi, safi,
9696 (exact ? bgp_show_type_community_exact :
9697 bgp_show_type_community), com, 0);
9698 }
9699
9700 DEFUN (show_ip_bgp_community,
9701 show_ip_bgp_community_cmd,
9702 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9703 SHOW_STR
9704 IP_STR
9705 BGP_STR
9706 "Display routes matching the communities\n"
9707 COMMUNITY_AANN_STR
9708 "Do not send outside local AS (well-known community)\n"
9709 "Do not advertise to any peer (well-known community)\n"
9710 "Do not export to next AS (well-known community)\n")
9711 {
9712 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9713 }
9714
9715 ALIAS (show_ip_bgp_community,
9716 show_ip_bgp_community2_cmd,
9717 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9718 SHOW_STR
9719 IP_STR
9720 BGP_STR
9721 "Display routes matching the communities\n"
9722 COMMUNITY_AANN_STR
9723 "Do not send outside local AS (well-known community)\n"
9724 "Do not advertise to any peer (well-known community)\n"
9725 "Do not export to next AS (well-known community)\n"
9726 COMMUNITY_AANN_STR
9727 "Do not send outside local AS (well-known community)\n"
9728 "Do not advertise to any peer (well-known community)\n"
9729 "Do not export to next AS (well-known community)\n")
9730
9731 ALIAS (show_ip_bgp_community,
9732 show_ip_bgp_community3_cmd,
9733 "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)",
9734 SHOW_STR
9735 IP_STR
9736 BGP_STR
9737 "Display routes matching the communities\n"
9738 COMMUNITY_AANN_STR
9739 "Do not send outside local AS (well-known community)\n"
9740 "Do not advertise to any peer (well-known community)\n"
9741 "Do not export to next AS (well-known community)\n"
9742 COMMUNITY_AANN_STR
9743 "Do not send outside local AS (well-known community)\n"
9744 "Do not advertise to any peer (well-known community)\n"
9745 "Do not export to next AS (well-known community)\n"
9746 COMMUNITY_AANN_STR
9747 "Do not send outside local AS (well-known community)\n"
9748 "Do not advertise to any peer (well-known community)\n"
9749 "Do not export to next AS (well-known community)\n")
9750
9751 ALIAS (show_ip_bgp_community,
9752 show_ip_bgp_community4_cmd,
9753 "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)",
9754 SHOW_STR
9755 IP_STR
9756 BGP_STR
9757 "Display routes matching the communities\n"
9758 COMMUNITY_AANN_STR
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_AANN_STR
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 COMMUNITY_AANN_STR
9767 "Do not send outside local AS (well-known community)\n"
9768 "Do not advertise to any peer (well-known community)\n"
9769 "Do not export to next AS (well-known community)\n"
9770 COMMUNITY_AANN_STR
9771 "Do not send outside local AS (well-known community)\n"
9772 "Do not advertise to any peer (well-known community)\n"
9773 "Do not export to next AS (well-known community)\n")
9774
9775 DEFUN (show_ip_bgp_ipv4_community,
9776 show_ip_bgp_ipv4_community_cmd,
9777 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9778 SHOW_STR
9779 IP_STR
9780 BGP_STR
9781 "Address family\n"
9782 "Address Family modifier\n"
9783 "Address Family modifier\n"
9784 "Display routes matching the communities\n"
9785 COMMUNITY_AANN_STR
9786 "Do not send outside local AS (well-known community)\n"
9787 "Do not advertise to any peer (well-known community)\n"
9788 "Do not export to next AS (well-known community)\n")
9789 {
9790 if (strncmp (argv[0], "m", 1) == 0)
9791 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9792
9793 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9794 }
9795
9796 ALIAS (show_ip_bgp_ipv4_community,
9797 show_ip_bgp_ipv4_community2_cmd,
9798 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9799 SHOW_STR
9800 IP_STR
9801 BGP_STR
9802 "Address family\n"
9803 "Address Family modifier\n"
9804 "Address Family modifier\n"
9805 "Display routes matching the communities\n"
9806 COMMUNITY_AANN_STR
9807 "Do not send outside local AS (well-known community)\n"
9808 "Do not advertise to any peer (well-known community)\n"
9809 "Do not export to next AS (well-known community)\n"
9810 COMMUNITY_AANN_STR
9811 "Do not send outside local AS (well-known community)\n"
9812 "Do not advertise to any peer (well-known community)\n"
9813 "Do not export to next AS (well-known community)\n")
9814
9815 ALIAS (show_ip_bgp_ipv4_community,
9816 show_ip_bgp_ipv4_community3_cmd,
9817 "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)",
9818 SHOW_STR
9819 IP_STR
9820 BGP_STR
9821 "Address family\n"
9822 "Address Family modifier\n"
9823 "Address Family modifier\n"
9824 "Display routes matching the communities\n"
9825 COMMUNITY_AANN_STR
9826 "Do not send outside local AS (well-known community)\n"
9827 "Do not advertise to any peer (well-known community)\n"
9828 "Do not export to next AS (well-known community)\n"
9829 COMMUNITY_AANN_STR
9830 "Do not send outside local AS (well-known community)\n"
9831 "Do not advertise to any peer (well-known community)\n"
9832 "Do not export to next AS (well-known community)\n"
9833 COMMUNITY_AANN_STR
9834 "Do not send outside local AS (well-known community)\n"
9835 "Do not advertise to any peer (well-known community)\n"
9836 "Do not export to next AS (well-known community)\n")
9837
9838 ALIAS (show_ip_bgp_ipv4_community,
9839 show_ip_bgp_ipv4_community4_cmd,
9840 "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)",
9841 SHOW_STR
9842 IP_STR
9843 BGP_STR
9844 "Address family\n"
9845 "Address Family modifier\n"
9846 "Address Family modifier\n"
9847 "Display routes matching the communities\n"
9848 COMMUNITY_AANN_STR
9849 "Do not send outside local AS (well-known community)\n"
9850 "Do not advertise to any peer (well-known community)\n"
9851 "Do not export to next AS (well-known community)\n"
9852 COMMUNITY_AANN_STR
9853 "Do not send outside local AS (well-known community)\n"
9854 "Do not advertise to any peer (well-known community)\n"
9855 "Do not export to next AS (well-known community)\n"
9856 COMMUNITY_AANN_STR
9857 "Do not send outside local AS (well-known community)\n"
9858 "Do not advertise to any peer (well-known community)\n"
9859 "Do not export to next AS (well-known community)\n"
9860 COMMUNITY_AANN_STR
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 DEFUN (show_bgp_instance_afi_safi_community_all,
9866 show_bgp_instance_afi_safi_community_all_cmd,
9867 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
9868 SHOW_STR
9869 BGP_STR
9870 BGP_INSTANCE_HELP_STR
9871 "Address family\n"
9872 "Address family\n"
9873 "Address Family modifier\n"
9874 "Address Family modifier\n"
9875 "Display routes matching the communities\n")
9876 {
9877 int afi;
9878 int safi;
9879 struct bgp *bgp;
9880
9881 /* BGP structure lookup. */
9882 bgp = bgp_lookup_by_name (argv[1]);
9883 if (bgp == NULL)
9884 {
9885 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
9886 return CMD_WARNING;
9887 }
9888
9889 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9890 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9891 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
9892 }
9893
9894 DEFUN (show_bgp_instance_afi_safi_community,
9895 show_bgp_instance_afi_safi_community_cmd,
9896 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9897 SHOW_STR
9898 BGP_STR
9899 BGP_INSTANCE_HELP_STR
9900 "Address family\n"
9901 "Address family\n"
9902 "Address family modifier\n"
9903 "Address family modifier\n"
9904 "Display routes matching the communities\n"
9905 COMMUNITY_AANN_STR
9906 "Do not send outside local AS (well-known community)\n"
9907 "Do not advertise to any peer (well-known community)\n"
9908 "Do not export to next AS (well-known community)\n")
9909 {
9910 int afi;
9911 int safi;
9912
9913 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9914 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9915 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
9916 }
9917
9918 ALIAS (show_bgp_instance_afi_safi_community,
9919 show_bgp_instance_afi_safi_community2_cmd,
9920 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9921 SHOW_STR
9922 BGP_STR
9923 BGP_INSTANCE_HELP_STR
9924 "Address family\n"
9925 "Address family\n"
9926 "Address family modifier\n"
9927 "Address family modifier\n"
9928 "Display routes matching the communities\n"
9929 COMMUNITY_AANN_STR
9930 "Do not send outside local AS (well-known community)\n"
9931 "Do not advertise to any peer (well-known community)\n"
9932 "Do not export to next AS (well-known community)\n"
9933 COMMUNITY_AANN_STR
9934 "Do not send outside local AS (well-known community)\n"
9935 "Do not advertise to any peer (well-known community)\n"
9936 "Do not export to next AS (well-known community)\n")
9937
9938 ALIAS (show_bgp_instance_afi_safi_community,
9939 show_bgp_instance_afi_safi_community3_cmd,
9940 "show bgp " BGP_INSTANCE_CMD " (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)",
9941 SHOW_STR
9942 BGP_STR
9943 BGP_INSTANCE_HELP_STR
9944 "Address family\n"
9945 "Address family\n"
9946 "Address family modifier\n"
9947 "Address family modifier\n"
9948 "Display routes matching the communities\n"
9949 COMMUNITY_AANN_STR
9950 "Do not send outside local AS (well-known community)\n"
9951 "Do not advertise to any peer (well-known community)\n"
9952 "Do not export to next AS (well-known community)\n"
9953 COMMUNITY_AANN_STR
9954 "Do not send outside local AS (well-known community)\n"
9955 "Do not advertise to any peer (well-known community)\n"
9956 "Do not export to next AS (well-known community)\n"
9957 COMMUNITY_AANN_STR
9958 "Do not send outside local AS (well-known community)\n"
9959 "Do not advertise to any peer (well-known community)\n"
9960 "Do not export to next AS (well-known community)\n")
9961
9962 ALIAS (show_bgp_instance_afi_safi_community,
9963 show_bgp_instance_afi_safi_community4_cmd,
9964 "show bgp " BGP_INSTANCE_CMD " (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)",
9965 SHOW_STR
9966 BGP_STR
9967 BGP_INSTANCE_HELP_STR
9968 "Address family\n"
9969 "Address family\n"
9970 "Address family modifier\n"
9971 "Address family modifier\n"
9972 "Display routes matching the communities\n"
9973 COMMUNITY_AANN_STR
9974 "Do not send outside local AS (well-known community)\n"
9975 "Do not advertise to any peer (well-known community)\n"
9976 "Do not export to next AS (well-known community)\n"
9977 COMMUNITY_AANN_STR
9978 "Do not send outside local AS (well-known community)\n"
9979 "Do not advertise to any peer (well-known community)\n"
9980 "Do not export to next AS (well-known community)\n"
9981 COMMUNITY_AANN_STR
9982 "Do not send outside local AS (well-known community)\n"
9983 "Do not advertise to any peer (well-known community)\n"
9984 "Do not export to next AS (well-known community)\n"
9985 COMMUNITY_AANN_STR
9986 "Do not send outside local AS (well-known community)\n"
9987 "Do not advertise to any peer (well-known community)\n"
9988 "Do not export to next AS (well-known community)\n")
9989
9990 DEFUN (show_ip_bgp_community_exact,
9991 show_ip_bgp_community_exact_cmd,
9992 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9993 SHOW_STR
9994 IP_STR
9995 BGP_STR
9996 "Display routes matching the communities\n"
9997 COMMUNITY_AANN_STR
9998 "Do not send outside local AS (well-known community)\n"
9999 "Do not advertise to any peer (well-known community)\n"
10000 "Do not export to next AS (well-known community)\n"
10001 "Exact match of the communities")
10002 {
10003 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10004 }
10005
10006 ALIAS (show_ip_bgp_community_exact,
10007 show_ip_bgp_community2_exact_cmd,
10008 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10009 SHOW_STR
10010 IP_STR
10011 BGP_STR
10012 "Display routes matching the communities\n"
10013 COMMUNITY_AANN_STR
10014 "Do not send outside local AS (well-known community)\n"
10015 "Do not advertise to any peer (well-known community)\n"
10016 "Do not export to next AS (well-known community)\n"
10017 COMMUNITY_AANN_STR
10018 "Do not send outside local AS (well-known community)\n"
10019 "Do not advertise to any peer (well-known community)\n"
10020 "Do not export to next AS (well-known community)\n"
10021 "Exact match of the communities")
10022
10023 ALIAS (show_ip_bgp_community_exact,
10024 show_ip_bgp_community3_exact_cmd,
10025 "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",
10026 SHOW_STR
10027 IP_STR
10028 BGP_STR
10029 "Display routes matching the communities\n"
10030 COMMUNITY_AANN_STR
10031 "Do not send outside local AS (well-known community)\n"
10032 "Do not advertise to any peer (well-known community)\n"
10033 "Do not export to next AS (well-known community)\n"
10034 COMMUNITY_AANN_STR
10035 "Do not send outside local AS (well-known community)\n"
10036 "Do not advertise to any peer (well-known community)\n"
10037 "Do not export to next AS (well-known community)\n"
10038 COMMUNITY_AANN_STR
10039 "Do not send outside local AS (well-known community)\n"
10040 "Do not advertise to any peer (well-known community)\n"
10041 "Do not export to next AS (well-known community)\n"
10042 "Exact match of the communities")
10043
10044 ALIAS (show_ip_bgp_community_exact,
10045 show_ip_bgp_community4_exact_cmd,
10046 "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",
10047 SHOW_STR
10048 IP_STR
10049 BGP_STR
10050 "Display routes matching the communities\n"
10051 COMMUNITY_AANN_STR
10052 "Do not send outside local AS (well-known community)\n"
10053 "Do not advertise to any peer (well-known community)\n"
10054 "Do not export to next AS (well-known community)\n"
10055 COMMUNITY_AANN_STR
10056 "Do not send outside local AS (well-known community)\n"
10057 "Do not advertise to any peer (well-known community)\n"
10058 "Do not export to next AS (well-known community)\n"
10059 COMMUNITY_AANN_STR
10060 "Do not send outside local AS (well-known community)\n"
10061 "Do not advertise to any peer (well-known community)\n"
10062 "Do not export to next AS (well-known community)\n"
10063 COMMUNITY_AANN_STR
10064 "Do not send outside local AS (well-known community)\n"
10065 "Do not advertise to any peer (well-known community)\n"
10066 "Do not export to next AS (well-known community)\n"
10067 "Exact match of the communities")
10068
10069 DEFUN (show_ip_bgp_ipv4_community_exact,
10070 show_ip_bgp_ipv4_community_exact_cmd,
10071 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10072 SHOW_STR
10073 IP_STR
10074 BGP_STR
10075 "Address family\n"
10076 "Address Family modifier\n"
10077 "Address Family modifier\n"
10078 "Display routes matching the communities\n"
10079 COMMUNITY_AANN_STR
10080 "Do not send outside local AS (well-known community)\n"
10081 "Do not advertise to any peer (well-known community)\n"
10082 "Do not export to next AS (well-known community)\n"
10083 "Exact match of the communities")
10084 {
10085 if (strncmp (argv[0], "m", 1) == 0)
10086 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
10087
10088 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10089 }
10090
10091 ALIAS (show_ip_bgp_ipv4_community_exact,
10092 show_ip_bgp_ipv4_community2_exact_cmd,
10093 "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",
10094 SHOW_STR
10095 IP_STR
10096 BGP_STR
10097 "Address family\n"
10098 "Address Family modifier\n"
10099 "Address Family modifier\n"
10100 "Display routes matching the communities\n"
10101 COMMUNITY_AANN_STR
10102 "Do not send outside local AS (well-known community)\n"
10103 "Do not advertise to any peer (well-known community)\n"
10104 "Do not export to next AS (well-known community)\n"
10105 COMMUNITY_AANN_STR
10106 "Do not send outside local AS (well-known community)\n"
10107 "Do not advertise to any peer (well-known community)\n"
10108 "Do not export to next AS (well-known community)\n"
10109 "Exact match of the communities")
10110
10111 ALIAS (show_ip_bgp_ipv4_community_exact,
10112 show_ip_bgp_ipv4_community3_exact_cmd,
10113 "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",
10114 SHOW_STR
10115 IP_STR
10116 BGP_STR
10117 "Address family\n"
10118 "Address Family modifier\n"
10119 "Address Family modifier\n"
10120 "Display routes matching the communities\n"
10121 COMMUNITY_AANN_STR
10122 "Do not send outside local AS (well-known community)\n"
10123 "Do not advertise to any peer (well-known community)\n"
10124 "Do not export to next AS (well-known community)\n"
10125 COMMUNITY_AANN_STR
10126 "Do not send outside local AS (well-known community)\n"
10127 "Do not advertise to any peer (well-known community)\n"
10128 "Do not export to next AS (well-known community)\n"
10129 COMMUNITY_AANN_STR
10130 "Do not send outside local AS (well-known community)\n"
10131 "Do not advertise to any peer (well-known community)\n"
10132 "Do not export to next AS (well-known community)\n"
10133 "Exact match of the communities")
10134
10135 ALIAS (show_ip_bgp_ipv4_community_exact,
10136 show_ip_bgp_ipv4_community4_exact_cmd,
10137 "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",
10138 SHOW_STR
10139 IP_STR
10140 BGP_STR
10141 "Address family\n"
10142 "Address Family modifier\n"
10143 "Address Family modifier\n"
10144 "Display routes matching the communities\n"
10145 COMMUNITY_AANN_STR
10146 "Do not send outside local AS (well-known community)\n"
10147 "Do not advertise to any peer (well-known community)\n"
10148 "Do not export to next AS (well-known community)\n"
10149 COMMUNITY_AANN_STR
10150 "Do not send outside local AS (well-known community)\n"
10151 "Do not advertise to any peer (well-known community)\n"
10152 "Do not export to next AS (well-known community)\n"
10153 COMMUNITY_AANN_STR
10154 "Do not send outside local AS (well-known community)\n"
10155 "Do not advertise to any peer (well-known community)\n"
10156 "Do not export to next AS (well-known community)\n"
10157 COMMUNITY_AANN_STR
10158 "Do not send outside local AS (well-known community)\n"
10159 "Do not advertise to any peer (well-known community)\n"
10160 "Do not export to next AS (well-known community)\n"
10161 "Exact match of the communities")
10162
10163 #ifdef HAVE_IPV6
10164 DEFUN (show_bgp_community,
10165 show_bgp_community_cmd,
10166 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10167 SHOW_STR
10168 BGP_STR
10169 "Display routes matching the communities\n"
10170 COMMUNITY_AANN_STR
10171 "Do not send outside local AS (well-known community)\n"
10172 "Do not advertise to any peer (well-known community)\n"
10173 "Do not export to next AS (well-known community)\n")
10174 {
10175 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10176 }
10177
10178 ALIAS (show_bgp_community,
10179 show_bgp_ipv6_community_cmd,
10180 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10181 SHOW_STR
10182 BGP_STR
10183 "Address family\n"
10184 "Display routes matching the communities\n"
10185 COMMUNITY_AANN_STR
10186 "Do not send outside local AS (well-known community)\n"
10187 "Do not advertise to any peer (well-known community)\n"
10188 "Do not export to next AS (well-known community)\n")
10189
10190 ALIAS (show_bgp_community,
10191 show_bgp_community2_cmd,
10192 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10193 SHOW_STR
10194 BGP_STR
10195 "Display routes matching the communities\n"
10196 COMMUNITY_AANN_STR
10197 "Do not send outside local AS (well-known community)\n"
10198 "Do not advertise to any peer (well-known community)\n"
10199 "Do not export to next AS (well-known community)\n"
10200 COMMUNITY_AANN_STR
10201 "Do not send outside local AS (well-known community)\n"
10202 "Do not advertise to any peer (well-known community)\n"
10203 "Do not export to next AS (well-known community)\n")
10204
10205 ALIAS (show_bgp_community,
10206 show_bgp_ipv6_community2_cmd,
10207 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10208 SHOW_STR
10209 BGP_STR
10210 "Address family\n"
10211 "Display routes matching the communities\n"
10212 COMMUNITY_AANN_STR
10213 "Do not send outside local AS (well-known community)\n"
10214 "Do not advertise to any peer (well-known community)\n"
10215 "Do not export to next AS (well-known community)\n"
10216 COMMUNITY_AANN_STR
10217 "Do not send outside local AS (well-known community)\n"
10218 "Do not advertise to any peer (well-known community)\n"
10219 "Do not export to next AS (well-known community)\n")
10220
10221 ALIAS (show_bgp_community,
10222 show_bgp_community3_cmd,
10223 "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)",
10224 SHOW_STR
10225 BGP_STR
10226 "Display routes matching the communities\n"
10227 COMMUNITY_AANN_STR
10228 "Do not send outside local AS (well-known community)\n"
10229 "Do not advertise to any peer (well-known community)\n"
10230 "Do not export to next AS (well-known community)\n"
10231 COMMUNITY_AANN_STR
10232 "Do not send outside local AS (well-known community)\n"
10233 "Do not advertise to any peer (well-known community)\n"
10234 "Do not export to next AS (well-known community)\n"
10235 COMMUNITY_AANN_STR
10236 "Do not send outside local AS (well-known community)\n"
10237 "Do not advertise to any peer (well-known community)\n"
10238 "Do not export to next AS (well-known community)\n")
10239
10240 ALIAS (show_bgp_community,
10241 show_bgp_ipv6_community3_cmd,
10242 "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)",
10243 SHOW_STR
10244 BGP_STR
10245 "Address family\n"
10246 "Display routes matching the communities\n"
10247 COMMUNITY_AANN_STR
10248 "Do not send outside local AS (well-known community)\n"
10249 "Do not advertise to any peer (well-known community)\n"
10250 "Do not export to next AS (well-known community)\n"
10251 COMMUNITY_AANN_STR
10252 "Do not send outside local AS (well-known community)\n"
10253 "Do not advertise to any peer (well-known community)\n"
10254 "Do not export to next AS (well-known community)\n"
10255 COMMUNITY_AANN_STR
10256 "Do not send outside local AS (well-known community)\n"
10257 "Do not advertise to any peer (well-known community)\n"
10258 "Do not export to next AS (well-known community)\n")
10259
10260 ALIAS (show_bgp_community,
10261 show_bgp_community4_cmd,
10262 "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)",
10263 SHOW_STR
10264 BGP_STR
10265 "Display routes matching the communities\n"
10266 COMMUNITY_AANN_STR
10267 "Do not send outside local AS (well-known community)\n"
10268 "Do not advertise to any peer (well-known community)\n"
10269 "Do not export to next AS (well-known community)\n"
10270 COMMUNITY_AANN_STR
10271 "Do not send outside local AS (well-known community)\n"
10272 "Do not advertise to any peer (well-known community)\n"
10273 "Do not export to next AS (well-known community)\n"
10274 COMMUNITY_AANN_STR
10275 "Do not send outside local AS (well-known community)\n"
10276 "Do not advertise to any peer (well-known community)\n"
10277 "Do not export to next AS (well-known community)\n"
10278 COMMUNITY_AANN_STR
10279 "Do not send outside local AS (well-known community)\n"
10280 "Do not advertise to any peer (well-known community)\n"
10281 "Do not export to next AS (well-known community)\n")
10282
10283 ALIAS (show_bgp_community,
10284 show_bgp_ipv6_community4_cmd,
10285 "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)",
10286 SHOW_STR
10287 BGP_STR
10288 "Address family\n"
10289 "Display routes matching the communities\n"
10290 COMMUNITY_AANN_STR
10291 "Do not send outside local AS (well-known community)\n"
10292 "Do not advertise to any peer (well-known community)\n"
10293 "Do not export to next AS (well-known community)\n"
10294 COMMUNITY_AANN_STR
10295 "Do not send outside local AS (well-known community)\n"
10296 "Do not advertise to any peer (well-known community)\n"
10297 "Do not export to next AS (well-known community)\n"
10298 COMMUNITY_AANN_STR
10299 "Do not send outside local AS (well-known community)\n"
10300 "Do not advertise to any peer (well-known community)\n"
10301 "Do not export to next AS (well-known community)\n"
10302 COMMUNITY_AANN_STR
10303 "Do not send outside local AS (well-known community)\n"
10304 "Do not advertise to any peer (well-known community)\n"
10305 "Do not export to next AS (well-known community)\n")
10306
10307 /* old command */
10308 DEFUN (show_ipv6_bgp_community,
10309 show_ipv6_bgp_community_cmd,
10310 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10311 SHOW_STR
10312 IPV6_STR
10313 BGP_STR
10314 "Display routes matching the communities\n"
10315 COMMUNITY_AANN_STR
10316 "Do not send outside local AS (well-known community)\n"
10317 "Do not advertise to any peer (well-known community)\n"
10318 "Do not export to next AS (well-known community)\n")
10319 {
10320 bgp_show_ipv6_bgp_deprecate_warning(vty);
10321 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10322 }
10323
10324 /* old command */
10325 ALIAS (show_ipv6_bgp_community,
10326 show_ipv6_bgp_community2_cmd,
10327 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10328 SHOW_STR
10329 IPV6_STR
10330 BGP_STR
10331 "Display routes matching the communities\n"
10332 COMMUNITY_AANN_STR
10333 "Do not send outside local AS (well-known community)\n"
10334 "Do not advertise to any peer (well-known community)\n"
10335 "Do not export to next AS (well-known community)\n"
10336 COMMUNITY_AANN_STR
10337 "Do not send outside local AS (well-known community)\n"
10338 "Do not advertise to any peer (well-known community)\n"
10339 "Do not export to next AS (well-known community)\n")
10340
10341 /* old command */
10342 ALIAS (show_ipv6_bgp_community,
10343 show_ipv6_bgp_community3_cmd,
10344 "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)",
10345 SHOW_STR
10346 IPV6_STR
10347 BGP_STR
10348 "Display routes matching the communities\n"
10349 COMMUNITY_AANN_STR
10350 "Do not send outside local AS (well-known community)\n"
10351 "Do not advertise to any peer (well-known community)\n"
10352 "Do not export to next AS (well-known community)\n"
10353 COMMUNITY_AANN_STR
10354 "Do not send outside local AS (well-known community)\n"
10355 "Do not advertise to any peer (well-known community)\n"
10356 "Do not export to next AS (well-known community)\n"
10357 COMMUNITY_AANN_STR
10358 "Do not send outside local AS (well-known community)\n"
10359 "Do not advertise to any peer (well-known community)\n"
10360 "Do not export to next AS (well-known community)\n")
10361
10362 /* old command */
10363 ALIAS (show_ipv6_bgp_community,
10364 show_ipv6_bgp_community4_cmd,
10365 "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)",
10366 SHOW_STR
10367 IPV6_STR
10368 BGP_STR
10369 "Display routes matching the communities\n"
10370 COMMUNITY_AANN_STR
10371 "Do not send outside local AS (well-known community)\n"
10372 "Do not advertise to any peer (well-known community)\n"
10373 "Do not export to next AS (well-known community)\n"
10374 COMMUNITY_AANN_STR
10375 "Do not send outside local AS (well-known community)\n"
10376 "Do not advertise to any peer (well-known community)\n"
10377 "Do not export to next AS (well-known community)\n"
10378 COMMUNITY_AANN_STR
10379 "Do not send outside local AS (well-known community)\n"
10380 "Do not advertise to any peer (well-known community)\n"
10381 "Do not export to next AS (well-known community)\n"
10382 COMMUNITY_AANN_STR
10383 "Do not send outside local AS (well-known community)\n"
10384 "Do not advertise to any peer (well-known community)\n"
10385 "Do not export to next AS (well-known community)\n")
10386
10387 DEFUN (show_bgp_community_exact,
10388 show_bgp_community_exact_cmd,
10389 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10390 SHOW_STR
10391 BGP_STR
10392 "Display routes matching the communities\n"
10393 COMMUNITY_AANN_STR
10394 "Do not send outside local AS (well-known community)\n"
10395 "Do not advertise to any peer (well-known community)\n"
10396 "Do not export to next AS (well-known community)\n"
10397 "Exact match of the communities")
10398 {
10399 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10400 }
10401
10402 ALIAS (show_bgp_community_exact,
10403 show_bgp_ipv6_community_exact_cmd,
10404 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10405 SHOW_STR
10406 BGP_STR
10407 "Address family\n"
10408 "Display routes matching the communities\n"
10409 COMMUNITY_AANN_STR
10410 "Do not send outside local AS (well-known community)\n"
10411 "Do not advertise to any peer (well-known community)\n"
10412 "Do not export to next AS (well-known community)\n"
10413 "Exact match of the communities")
10414
10415 ALIAS (show_bgp_community_exact,
10416 show_bgp_community2_exact_cmd,
10417 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10418 SHOW_STR
10419 BGP_STR
10420 "Display routes matching the communities\n"
10421 COMMUNITY_AANN_STR
10422 "Do not send outside local AS (well-known community)\n"
10423 "Do not advertise to any peer (well-known community)\n"
10424 "Do not export to next AS (well-known community)\n"
10425 COMMUNITY_AANN_STR
10426 "Do not send outside local AS (well-known community)\n"
10427 "Do not advertise to any peer (well-known community)\n"
10428 "Do not export to next AS (well-known community)\n"
10429 "Exact match of the communities")
10430
10431 ALIAS (show_bgp_community_exact,
10432 show_bgp_ipv6_community2_exact_cmd,
10433 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10434 SHOW_STR
10435 BGP_STR
10436 "Address family\n"
10437 "Display routes matching the communities\n"
10438 COMMUNITY_AANN_STR
10439 "Do not send outside local AS (well-known community)\n"
10440 "Do not advertise to any peer (well-known community)\n"
10441 "Do not export to next AS (well-known community)\n"
10442 COMMUNITY_AANN_STR
10443 "Do not send outside local AS (well-known community)\n"
10444 "Do not advertise to any peer (well-known community)\n"
10445 "Do not export to next AS (well-known community)\n"
10446 "Exact match of the communities")
10447
10448 ALIAS (show_bgp_community_exact,
10449 show_bgp_community3_exact_cmd,
10450 "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",
10451 SHOW_STR
10452 BGP_STR
10453 "Display routes matching the communities\n"
10454 COMMUNITY_AANN_STR
10455 "Do not send outside local AS (well-known community)\n"
10456 "Do not advertise to any peer (well-known community)\n"
10457 "Do not export to next AS (well-known community)\n"
10458 COMMUNITY_AANN_STR
10459 "Do not send outside local AS (well-known community)\n"
10460 "Do not advertise to any peer (well-known community)\n"
10461 "Do not export to next AS (well-known community)\n"
10462 COMMUNITY_AANN_STR
10463 "Do not send outside local AS (well-known community)\n"
10464 "Do not advertise to any peer (well-known community)\n"
10465 "Do not export to next AS (well-known community)\n"
10466 "Exact match of the communities")
10467
10468 ALIAS (show_bgp_community_exact,
10469 show_bgp_ipv6_community3_exact_cmd,
10470 "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",
10471 SHOW_STR
10472 BGP_STR
10473 "Address family\n"
10474 "Display routes matching the communities\n"
10475 COMMUNITY_AANN_STR
10476 "Do not send outside local AS (well-known community)\n"
10477 "Do not advertise to any peer (well-known community)\n"
10478 "Do not export to next AS (well-known community)\n"
10479 COMMUNITY_AANN_STR
10480 "Do not send outside local AS (well-known community)\n"
10481 "Do not advertise to any peer (well-known community)\n"
10482 "Do not export to next AS (well-known community)\n"
10483 COMMUNITY_AANN_STR
10484 "Do not send outside local AS (well-known community)\n"
10485 "Do not advertise to any peer (well-known community)\n"
10486 "Do not export to next AS (well-known community)\n"
10487 "Exact match of the communities")
10488
10489 ALIAS (show_bgp_community_exact,
10490 show_bgp_community4_exact_cmd,
10491 "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",
10492 SHOW_STR
10493 BGP_STR
10494 "Display routes matching the communities\n"
10495 COMMUNITY_AANN_STR
10496 "Do not send outside local AS (well-known community)\n"
10497 "Do not advertise to any peer (well-known community)\n"
10498 "Do not export to next AS (well-known community)\n"
10499 COMMUNITY_AANN_STR
10500 "Do not send outside local AS (well-known community)\n"
10501 "Do not advertise to any peer (well-known community)\n"
10502 "Do not export to next AS (well-known community)\n"
10503 COMMUNITY_AANN_STR
10504 "Do not send outside local AS (well-known community)\n"
10505 "Do not advertise to any peer (well-known community)\n"
10506 "Do not export to next AS (well-known community)\n"
10507 COMMUNITY_AANN_STR
10508 "Do not send outside local AS (well-known community)\n"
10509 "Do not advertise to any peer (well-known community)\n"
10510 "Do not export to next AS (well-known community)\n"
10511 "Exact match of the communities")
10512
10513 ALIAS (show_bgp_community_exact,
10514 show_bgp_ipv6_community4_exact_cmd,
10515 "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",
10516 SHOW_STR
10517 BGP_STR
10518 "Address family\n"
10519 "Display routes matching the communities\n"
10520 COMMUNITY_AANN_STR
10521 "Do not send outside local AS (well-known community)\n"
10522 "Do not advertise to any peer (well-known community)\n"
10523 "Do not export to next AS (well-known community)\n"
10524 COMMUNITY_AANN_STR
10525 "Do not send outside local AS (well-known community)\n"
10526 "Do not advertise to any peer (well-known community)\n"
10527 "Do not export to next AS (well-known community)\n"
10528 COMMUNITY_AANN_STR
10529 "Do not send outside local AS (well-known community)\n"
10530 "Do not advertise to any peer (well-known community)\n"
10531 "Do not export to next AS (well-known community)\n"
10532 COMMUNITY_AANN_STR
10533 "Do not send outside local AS (well-known community)\n"
10534 "Do not advertise to any peer (well-known community)\n"
10535 "Do not export to next AS (well-known community)\n"
10536 "Exact match of the communities")
10537
10538 /* old command */
10539 DEFUN (show_ipv6_bgp_community_exact,
10540 show_ipv6_bgp_community_exact_cmd,
10541 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10542 SHOW_STR
10543 IPV6_STR
10544 BGP_STR
10545 "Display routes matching the communities\n"
10546 COMMUNITY_AANN_STR
10547 "Do not send outside local AS (well-known community)\n"
10548 "Do not advertise to any peer (well-known community)\n"
10549 "Do not export to next AS (well-known community)\n"
10550 "Exact match of the communities")
10551 {
10552 bgp_show_ipv6_bgp_deprecate_warning(vty);
10553 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10554 }
10555
10556 /* old command */
10557 ALIAS (show_ipv6_bgp_community_exact,
10558 show_ipv6_bgp_community2_exact_cmd,
10559 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10560 SHOW_STR
10561 IPV6_STR
10562 BGP_STR
10563 "Display routes matching the communities\n"
10564 COMMUNITY_AANN_STR
10565 "Do not send outside local AS (well-known community)\n"
10566 "Do not advertise to any peer (well-known community)\n"
10567 "Do not export to next AS (well-known community)\n"
10568 COMMUNITY_AANN_STR
10569 "Do not send outside local AS (well-known community)\n"
10570 "Do not advertise to any peer (well-known community)\n"
10571 "Do not export to next AS (well-known community)\n"
10572 "Exact match of the communities")
10573
10574 /* old command */
10575 ALIAS (show_ipv6_bgp_community_exact,
10576 show_ipv6_bgp_community3_exact_cmd,
10577 "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",
10578 SHOW_STR
10579 IPV6_STR
10580 BGP_STR
10581 "Display routes matching the communities\n"
10582 COMMUNITY_AANN_STR
10583 "Do not send outside local AS (well-known community)\n"
10584 "Do not advertise to any peer (well-known community)\n"
10585 "Do not export to next AS (well-known community)\n"
10586 COMMUNITY_AANN_STR
10587 "Do not send outside local AS (well-known community)\n"
10588 "Do not advertise to any peer (well-known community)\n"
10589 "Do not export to next AS (well-known community)\n"
10590 COMMUNITY_AANN_STR
10591 "Do not send outside local AS (well-known community)\n"
10592 "Do not advertise to any peer (well-known community)\n"
10593 "Do not export to next AS (well-known community)\n"
10594 "Exact match of the communities")
10595
10596 /* old command */
10597 ALIAS (show_ipv6_bgp_community_exact,
10598 show_ipv6_bgp_community4_exact_cmd,
10599 "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",
10600 SHOW_STR
10601 IPV6_STR
10602 BGP_STR
10603 "Display routes matching the communities\n"
10604 COMMUNITY_AANN_STR
10605 "Do not send outside local AS (well-known community)\n"
10606 "Do not advertise to any peer (well-known community)\n"
10607 "Do not export to next AS (well-known community)\n"
10608 COMMUNITY_AANN_STR
10609 "Do not send outside local AS (well-known community)\n"
10610 "Do not advertise to any peer (well-known community)\n"
10611 "Do not export to next AS (well-known community)\n"
10612 COMMUNITY_AANN_STR
10613 "Do not send outside local AS (well-known community)\n"
10614 "Do not advertise to any peer (well-known community)\n"
10615 "Do not export to next AS (well-known community)\n"
10616 COMMUNITY_AANN_STR
10617 "Do not send outside local AS (well-known community)\n"
10618 "Do not advertise to any peer (well-known community)\n"
10619 "Do not export to next AS (well-known community)\n"
10620 "Exact match of the communities")
10621
10622 /* old command */
10623 DEFUN (show_ipv6_mbgp_community,
10624 show_ipv6_mbgp_community_cmd,
10625 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10626 SHOW_STR
10627 IPV6_STR
10628 MBGP_STR
10629 "Display routes matching the communities\n"
10630 COMMUNITY_AANN_STR
10631 "Do not send outside local AS (well-known community)\n"
10632 "Do not advertise to any peer (well-known community)\n"
10633 "Do not export to next AS (well-known community)\n")
10634 {
10635 bgp_show_ipv6_bgp_deprecate_warning(vty);
10636 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10637 }
10638
10639 /* old command */
10640 ALIAS (show_ipv6_mbgp_community,
10641 show_ipv6_mbgp_community2_cmd,
10642 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10643 SHOW_STR
10644 IPV6_STR
10645 MBGP_STR
10646 "Display routes matching the communities\n"
10647 COMMUNITY_AANN_STR
10648 "Do not send outside local AS (well-known community)\n"
10649 "Do not advertise to any peer (well-known community)\n"
10650 "Do not export to next AS (well-known community)\n"
10651 COMMUNITY_AANN_STR
10652 "Do not send outside local AS (well-known community)\n"
10653 "Do not advertise to any peer (well-known community)\n"
10654 "Do not export to next AS (well-known community)\n")
10655
10656 /* old command */
10657 ALIAS (show_ipv6_mbgp_community,
10658 show_ipv6_mbgp_community3_cmd,
10659 "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)",
10660 SHOW_STR
10661 IPV6_STR
10662 MBGP_STR
10663 "Display routes matching the communities\n"
10664 COMMUNITY_AANN_STR
10665 "Do not send outside local AS (well-known community)\n"
10666 "Do not advertise to any peer (well-known community)\n"
10667 "Do not export to next AS (well-known community)\n"
10668 COMMUNITY_AANN_STR
10669 "Do not send outside local AS (well-known community)\n"
10670 "Do not advertise to any peer (well-known community)\n"
10671 "Do not export to next AS (well-known community)\n"
10672 COMMUNITY_AANN_STR
10673 "Do not send outside local AS (well-known community)\n"
10674 "Do not advertise to any peer (well-known community)\n"
10675 "Do not export to next AS (well-known community)\n")
10676
10677 /* old command */
10678 ALIAS (show_ipv6_mbgp_community,
10679 show_ipv6_mbgp_community4_cmd,
10680 "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)",
10681 SHOW_STR
10682 IPV6_STR
10683 MBGP_STR
10684 "Display routes matching the communities\n"
10685 COMMUNITY_AANN_STR
10686 "Do not send outside local AS (well-known community)\n"
10687 "Do not advertise to any peer (well-known community)\n"
10688 "Do not export to next AS (well-known community)\n"
10689 COMMUNITY_AANN_STR
10690 "Do not send outside local AS (well-known community)\n"
10691 "Do not advertise to any peer (well-known community)\n"
10692 "Do not export to next AS (well-known community)\n"
10693 COMMUNITY_AANN_STR
10694 "Do not send outside local AS (well-known community)\n"
10695 "Do not advertise to any peer (well-known community)\n"
10696 "Do not export to next AS (well-known community)\n"
10697 COMMUNITY_AANN_STR
10698 "Do not send outside local AS (well-known community)\n"
10699 "Do not advertise to any peer (well-known community)\n"
10700 "Do not export to next AS (well-known community)\n")
10701
10702 /* old command */
10703 DEFUN (show_ipv6_mbgp_community_exact,
10704 show_ipv6_mbgp_community_exact_cmd,
10705 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10706 SHOW_STR
10707 IPV6_STR
10708 MBGP_STR
10709 "Display routes matching the communities\n"
10710 COMMUNITY_AANN_STR
10711 "Do not send outside local AS (well-known community)\n"
10712 "Do not advertise to any peer (well-known community)\n"
10713 "Do not export to next AS (well-known community)\n"
10714 "Exact match of the communities")
10715 {
10716 bgp_show_ipv6_bgp_deprecate_warning(vty);
10717 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10718 }
10719
10720 /* old command */
10721 ALIAS (show_ipv6_mbgp_community_exact,
10722 show_ipv6_mbgp_community2_exact_cmd,
10723 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10724 SHOW_STR
10725 IPV6_STR
10726 MBGP_STR
10727 "Display routes matching the communities\n"
10728 COMMUNITY_AANN_STR
10729 "Do not send outside local AS (well-known community)\n"
10730 "Do not advertise to any peer (well-known community)\n"
10731 "Do not export to next AS (well-known community)\n"
10732 COMMUNITY_AANN_STR
10733 "Do not send outside local AS (well-known community)\n"
10734 "Do not advertise to any peer (well-known community)\n"
10735 "Do not export to next AS (well-known community)\n"
10736 "Exact match of the communities")
10737
10738 /* old command */
10739 ALIAS (show_ipv6_mbgp_community_exact,
10740 show_ipv6_mbgp_community3_exact_cmd,
10741 "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",
10742 SHOW_STR
10743 IPV6_STR
10744 MBGP_STR
10745 "Display routes matching the communities\n"
10746 COMMUNITY_AANN_STR
10747 "Do not send outside local AS (well-known community)\n"
10748 "Do not advertise to any peer (well-known community)\n"
10749 "Do not export to next AS (well-known community)\n"
10750 COMMUNITY_AANN_STR
10751 "Do not send outside local AS (well-known community)\n"
10752 "Do not advertise to any peer (well-known community)\n"
10753 "Do not export to next AS (well-known community)\n"
10754 COMMUNITY_AANN_STR
10755 "Do not send outside local AS (well-known community)\n"
10756 "Do not advertise to any peer (well-known community)\n"
10757 "Do not export to next AS (well-known community)\n"
10758 "Exact match of the communities")
10759
10760 /* old command */
10761 ALIAS (show_ipv6_mbgp_community_exact,
10762 show_ipv6_mbgp_community4_exact_cmd,
10763 "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",
10764 SHOW_STR
10765 IPV6_STR
10766 MBGP_STR
10767 "Display routes matching the communities\n"
10768 COMMUNITY_AANN_STR
10769 "Do not send outside local AS (well-known community)\n"
10770 "Do not advertise to any peer (well-known community)\n"
10771 "Do not export to next AS (well-known community)\n"
10772 COMMUNITY_AANN_STR
10773 "Do not send outside local AS (well-known community)\n"
10774 "Do not advertise to any peer (well-known community)\n"
10775 "Do not export to next AS (well-known community)\n"
10776 COMMUNITY_AANN_STR
10777 "Do not send outside local AS (well-known community)\n"
10778 "Do not advertise to any peer (well-known community)\n"
10779 "Do not export to next AS (well-known community)\n"
10780 COMMUNITY_AANN_STR
10781 "Do not send outside local AS (well-known community)\n"
10782 "Do not advertise to any peer (well-known community)\n"
10783 "Do not export to next AS (well-known community)\n"
10784 "Exact match of the communities")
10785 #endif /* HAVE_IPV6 */
10786
10787 static int
10788 bgp_show_community_list (struct vty *vty, const char *name,
10789 const char *com, int exact,
10790 afi_t afi, safi_t safi)
10791 {
10792 struct community_list *list;
10793 struct bgp *bgp = NULL;
10794
10795 if (name && !(bgp = bgp_lookup_by_name(name)))
10796 {
10797 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
10798 return CMD_WARNING;
10799 }
10800
10801 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
10802 if (list == NULL)
10803 {
10804 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10805 VTY_NEWLINE);
10806 return CMD_WARNING;
10807 }
10808
10809 return bgp_show (vty, bgp, afi, safi,
10810 (exact ? bgp_show_type_community_list_exact :
10811 bgp_show_type_community_list), list, 0);
10812 }
10813
10814 DEFUN (show_ip_bgp_community_list,
10815 show_ip_bgp_community_list_cmd,
10816 "show ip bgp community-list (<1-500>|WORD)",
10817 SHOW_STR
10818 IP_STR
10819 BGP_STR
10820 "Display routes matching the community-list\n"
10821 "community-list number\n"
10822 "community-list name\n")
10823 {
10824 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
10825 }
10826
10827 DEFUN (show_ip_bgp_instance_community_list,
10828 show_ip_bgp_instance_community_list_cmd,
10829 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
10830 SHOW_STR
10831 IP_STR
10832 BGP_STR
10833 BGP_INSTANCE_HELP_STR
10834 "Display routes matching the community-list\n"
10835 "community-list number\n"
10836 "community-list name\n")
10837 {
10838 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
10839 }
10840
10841 DEFUN (show_ip_bgp_ipv4_community_list,
10842 show_ip_bgp_ipv4_community_list_cmd,
10843 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
10844 SHOW_STR
10845 IP_STR
10846 BGP_STR
10847 "Address family\n"
10848 "Address Family modifier\n"
10849 "Address Family modifier\n"
10850 "Display routes matching the community-list\n"
10851 "community-list number\n"
10852 "community-list name\n")
10853 {
10854 if (strncmp (argv[0], "m", 1) == 0)
10855 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10856
10857 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_UNICAST);
10858 }
10859
10860 DEFUN (show_ip_bgp_community_list_exact,
10861 show_ip_bgp_community_list_exact_cmd,
10862 "show ip bgp community-list (<1-500>|WORD) exact-match",
10863 SHOW_STR
10864 IP_STR
10865 BGP_STR
10866 "Display routes matching the community-list\n"
10867 "community-list number\n"
10868 "community-list name\n"
10869 "Exact match of the communities\n")
10870 {
10871 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
10872 }
10873
10874 DEFUN (show_ip_bgp_ipv4_community_list_exact,
10875 show_ip_bgp_ipv4_community_list_exact_cmd,
10876 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
10877 SHOW_STR
10878 IP_STR
10879 BGP_STR
10880 "Address family\n"
10881 "Address Family modifier\n"
10882 "Address Family modifier\n"
10883 "Display routes matching the community-list\n"
10884 "community-list number\n"
10885 "community-list name\n"
10886 "Exact match of the communities\n")
10887 {
10888 if (strncmp (argv[0], "m", 1) == 0)
10889 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10890
10891 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_UNICAST);
10892 }
10893
10894 #ifdef HAVE_IPV6
10895 DEFUN (show_bgp_community_list,
10896 show_bgp_community_list_cmd,
10897 "show bgp community-list (<1-500>|WORD)",
10898 SHOW_STR
10899 BGP_STR
10900 "Display routes matching the community-list\n"
10901 "community-list number\n"
10902 "community-list name\n")
10903 {
10904 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10905 }
10906
10907 ALIAS (show_bgp_community_list,
10908 show_bgp_ipv6_community_list_cmd,
10909 "show bgp ipv6 community-list (<1-500>|WORD)",
10910 SHOW_STR
10911 BGP_STR
10912 "Address family\n"
10913 "Display routes matching the community-list\n"
10914 "community-list number\n"
10915 "community-list name\n")
10916
10917 /* old command */
10918 DEFUN (show_ipv6_bgp_community_list,
10919 show_ipv6_bgp_community_list_cmd,
10920 "show ipv6 bgp community-list WORD",
10921 SHOW_STR
10922 IPV6_STR
10923 BGP_STR
10924 "Display routes matching the community-list\n"
10925 "community-list name\n")
10926 {
10927 bgp_show_ipv6_bgp_deprecate_warning(vty);
10928 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10929 }
10930
10931 /* old command */
10932 DEFUN (show_ipv6_mbgp_community_list,
10933 show_ipv6_mbgp_community_list_cmd,
10934 "show ipv6 mbgp community-list WORD",
10935 SHOW_STR
10936 IPV6_STR
10937 MBGP_STR
10938 "Display routes matching the community-list\n"
10939 "community-list name\n")
10940 {
10941 bgp_show_ipv6_bgp_deprecate_warning(vty);
10942 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10943 }
10944
10945 DEFUN (show_bgp_community_list_exact,
10946 show_bgp_community_list_exact_cmd,
10947 "show bgp community-list (<1-500>|WORD) exact-match",
10948 SHOW_STR
10949 BGP_STR
10950 "Display routes matching the community-list\n"
10951 "community-list number\n"
10952 "community-list name\n"
10953 "Exact match of the communities\n")
10954 {
10955 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10956 }
10957
10958 ALIAS (show_bgp_community_list_exact,
10959 show_bgp_ipv6_community_list_exact_cmd,
10960 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
10961 SHOW_STR
10962 BGP_STR
10963 "Address family\n"
10964 "Display routes matching the community-list\n"
10965 "community-list number\n"
10966 "community-list name\n"
10967 "Exact match of the communities\n")
10968
10969 /* old command */
10970 DEFUN (show_ipv6_bgp_community_list_exact,
10971 show_ipv6_bgp_community_list_exact_cmd,
10972 "show ipv6 bgp community-list WORD exact-match",
10973 SHOW_STR
10974 IPV6_STR
10975 BGP_STR
10976 "Display routes matching the community-list\n"
10977 "community-list name\n"
10978 "Exact match of the communities\n")
10979 {
10980 bgp_show_ipv6_bgp_deprecate_warning(vty);
10981 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10982 }
10983
10984 /* old command */
10985 DEFUN (show_ipv6_mbgp_community_list_exact,
10986 show_ipv6_mbgp_community_list_exact_cmd,
10987 "show ipv6 mbgp community-list WORD exact-match",
10988 SHOW_STR
10989 IPV6_STR
10990 MBGP_STR
10991 "Display routes matching the community-list\n"
10992 "community-list name\n"
10993 "Exact match of the communities\n")
10994 {
10995 bgp_show_ipv6_bgp_deprecate_warning(vty);
10996 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
10997 }
10998 #endif /* HAVE_IPV6 */
10999
11000 static int
11001 bgp_show_prefix_longer (struct vty *vty, const char *name,
11002 const char *prefix, afi_t afi,
11003 safi_t safi, enum bgp_show_type type)
11004 {
11005 int ret;
11006 struct prefix *p;
11007 struct bgp *bgp = NULL;
11008
11009 if (name && !(bgp = bgp_lookup_by_name(name)))
11010 {
11011 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11012 return CMD_WARNING;
11013 }
11014
11015 p = prefix_new();
11016
11017 ret = str2prefix (prefix, p);
11018 if (! ret)
11019 {
11020 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11021 return CMD_WARNING;
11022 }
11023
11024 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
11025 prefix_free(p);
11026 return ret;
11027 }
11028
11029 DEFUN (show_ip_bgp_prefix_longer,
11030 show_ip_bgp_prefix_longer_cmd,
11031 "show ip bgp A.B.C.D/M longer-prefixes",
11032 SHOW_STR
11033 IP_STR
11034 BGP_STR
11035 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11036 "Display route and more specific routes\n")
11037 {
11038 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11039 bgp_show_type_prefix_longer);
11040 }
11041
11042 DEFUN (show_ip_bgp_instance_prefix_longer,
11043 show_ip_bgp_instance_prefix_longer_cmd,
11044 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
11045 SHOW_STR
11046 IP_STR
11047 BGP_STR
11048 BGP_INSTANCE_HELP_STR
11049 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11050 "Display route and more specific routes\n")
11051 {
11052 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
11053 bgp_show_type_prefix_longer);
11054 }
11055
11056 DEFUN (show_ip_bgp_flap_prefix_longer,
11057 show_ip_bgp_flap_prefix_longer_cmd,
11058 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11059 SHOW_STR
11060 IP_STR
11061 BGP_STR
11062 "Display flap statistics of routes\n"
11063 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11064 "Display route and more specific routes\n")
11065 {
11066 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11067 bgp_show_type_flap_prefix_longer);
11068 }
11069
11070 ALIAS (show_ip_bgp_flap_prefix_longer,
11071 show_ip_bgp_damp_flap_prefix_longer_cmd,
11072 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11073 SHOW_STR
11074 IP_STR
11075 BGP_STR
11076 "Display detailed information about dampening\n"
11077 "Display flap statistics of routes\n"
11078 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11079 "Display route and more specific routes\n")
11080
11081 DEFUN (show_ip_bgp_ipv4_prefix_longer,
11082 show_ip_bgp_ipv4_prefix_longer_cmd,
11083 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11084 SHOW_STR
11085 IP_STR
11086 BGP_STR
11087 "Address family\n"
11088 "Address Family modifier\n"
11089 "Address Family modifier\n"
11090 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11091 "Display route and more specific routes\n")
11092 {
11093 if (strncmp (argv[0], "m", 1) == 0)
11094 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
11095 bgp_show_type_prefix_longer);
11096
11097 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
11098 bgp_show_type_prefix_longer);
11099 }
11100
11101 DEFUN (show_ip_bgp_flap_address,
11102 show_ip_bgp_flap_address_cmd,
11103 "show ip bgp flap-statistics A.B.C.D",
11104 SHOW_STR
11105 IP_STR
11106 BGP_STR
11107 "Display flap statistics of routes\n"
11108 "Network in the BGP routing table to display\n")
11109 {
11110 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11111 bgp_show_type_flap_address);
11112 }
11113
11114 ALIAS (show_ip_bgp_flap_address,
11115 show_ip_bgp_damp_flap_address_cmd,
11116 "show ip bgp dampening flap-statistics A.B.C.D",
11117 SHOW_STR
11118 IP_STR
11119 BGP_STR
11120 "Display detailed information about dampening\n"
11121 "Display flap statistics of routes\n"
11122 "Network in the BGP routing table to display\n")
11123
11124 DEFUN (show_ip_bgp_flap_prefix,
11125 show_ip_bgp_flap_prefix_cmd,
11126 "show ip bgp flap-statistics A.B.C.D/M",
11127 SHOW_STR
11128 IP_STR
11129 BGP_STR
11130 "Display flap statistics of routes\n"
11131 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11132 {
11133 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11134 bgp_show_type_flap_prefix);
11135 }
11136
11137 ALIAS (show_ip_bgp_flap_prefix,
11138 show_ip_bgp_damp_flap_prefix_cmd,
11139 "show ip bgp dampening flap-statistics A.B.C.D/M",
11140 SHOW_STR
11141 IP_STR
11142 BGP_STR
11143 "Display detailed information about dampening\n"
11144 "Display flap statistics of routes\n"
11145 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11146
11147 #ifdef HAVE_IPV6
11148 DEFUN (show_bgp_prefix_longer,
11149 show_bgp_prefix_longer_cmd,
11150 "show bgp X:X::X:X/M longer-prefixes",
11151 SHOW_STR
11152 BGP_STR
11153 "IPv6 prefix <network>/<length>\n"
11154 "Display route and more specific routes\n")
11155 {
11156 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11157 bgp_show_type_prefix_longer);
11158 }
11159
11160 ALIAS (show_bgp_prefix_longer,
11161 show_bgp_ipv6_prefix_longer_cmd,
11162 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11163 SHOW_STR
11164 BGP_STR
11165 "Address family\n"
11166 "IPv6 prefix <network>/<length>\n"
11167 "Display route and more specific routes\n")
11168
11169 /* old command */
11170 DEFUN (show_ipv6_bgp_prefix_longer,
11171 show_ipv6_bgp_prefix_longer_cmd,
11172 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11173 SHOW_STR
11174 IPV6_STR
11175 BGP_STR
11176 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11177 "Display route and more specific routes\n")
11178 {
11179 bgp_show_ipv6_bgp_deprecate_warning(vty);
11180 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11181 bgp_show_type_prefix_longer);
11182 }
11183
11184 /* old command */
11185 DEFUN (show_ipv6_mbgp_prefix_longer,
11186 show_ipv6_mbgp_prefix_longer_cmd,
11187 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11188 SHOW_STR
11189 IPV6_STR
11190 MBGP_STR
11191 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11192 "Display route and more specific routes\n")
11193 {
11194 bgp_show_ipv6_bgp_deprecate_warning(vty);
11195 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
11196 bgp_show_type_prefix_longer);
11197 }
11198 #endif /* HAVE_IPV6 */
11199
11200 static struct peer *
11201 peer_lookup_in_view (struct vty *vty, const char *view_name,
11202 const char *ip_str, u_char use_json)
11203 {
11204 int ret;
11205 struct bgp *bgp;
11206 struct peer *peer;
11207 union sockunion su;
11208
11209 /* BGP structure lookup. */
11210 if (view_name)
11211 {
11212 bgp = bgp_lookup_by_name (view_name);
11213 if (! bgp)
11214 {
11215 if (use_json)
11216 {
11217 json_object *json_no = NULL;
11218 json_no = json_object_new_object();
11219 json_object_string_add(json_no, "warning", "Can't find BGP view");
11220 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11221 json_object_free(json_no);
11222 }
11223 else
11224 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
11225 return NULL;
11226 }
11227 }
11228 else
11229 {
11230 bgp = bgp_get_default ();
11231 if (! bgp)
11232 {
11233 if (use_json)
11234 {
11235 json_object *json_no = NULL;
11236 json_no = json_object_new_object();
11237 json_object_string_add(json_no, "warning", "No BGP process configured");
11238 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11239 json_object_free(json_no);
11240 }
11241 else
11242 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11243 return NULL;
11244 }
11245 }
11246
11247 /* Get peer sockunion. */
11248 ret = str2sockunion (ip_str, &su);
11249 if (ret < 0)
11250 {
11251 peer = peer_lookup_by_conf_if (bgp, ip_str);
11252 if (!peer)
11253 {
11254 peer = peer_lookup_by_hostname(bgp, ip_str);
11255
11256 if (!peer)
11257 {
11258 if (use_json)
11259 {
11260 json_object *json_no = NULL;
11261 json_no = json_object_new_object();
11262 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11263 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11264 json_object_free(json_no);
11265 }
11266 else
11267 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11268 return NULL;
11269 }
11270 }
11271 return peer;
11272 }
11273
11274 /* Peer structure lookup. */
11275 peer = peer_lookup (bgp, &su);
11276 if (! peer)
11277 {
11278 if (use_json)
11279 {
11280 json_object *json_no = NULL;
11281 json_no = json_object_new_object();
11282 json_object_string_add(json_no, "warning","No such neighbor");
11283 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11284 json_object_free(json_no);
11285 }
11286 else
11287 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11288 return NULL;
11289 }
11290
11291 return peer;
11292 }
11293
11294 enum bgp_stats
11295 {
11296 BGP_STATS_MAXBITLEN = 0,
11297 BGP_STATS_RIB,
11298 BGP_STATS_PREFIXES,
11299 BGP_STATS_TOTPLEN,
11300 BGP_STATS_UNAGGREGATEABLE,
11301 BGP_STATS_MAX_AGGREGATEABLE,
11302 BGP_STATS_AGGREGATES,
11303 BGP_STATS_SPACE,
11304 BGP_STATS_ASPATH_COUNT,
11305 BGP_STATS_ASPATH_MAXHOPS,
11306 BGP_STATS_ASPATH_TOTHOPS,
11307 BGP_STATS_ASPATH_MAXSIZE,
11308 BGP_STATS_ASPATH_TOTSIZE,
11309 BGP_STATS_ASN_HIGHEST,
11310 BGP_STATS_MAX,
11311 };
11312
11313 static const char *table_stats_strs[] =
11314 {
11315 [BGP_STATS_PREFIXES] = "Total Prefixes",
11316 [BGP_STATS_TOTPLEN] = "Average prefix length",
11317 [BGP_STATS_RIB] = "Total Advertisements",
11318 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11319 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11320 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11321 [BGP_STATS_SPACE] = "Address space advertised",
11322 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11323 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11324 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11325 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11326 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11327 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11328 [BGP_STATS_MAX] = NULL,
11329 };
11330
11331 struct bgp_table_stats
11332 {
11333 struct bgp_table *table;
11334 unsigned long long counts[BGP_STATS_MAX];
11335 };
11336
11337 #if 0
11338 #define TALLY_SIGFIG 100000
11339 static unsigned long
11340 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11341 {
11342 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11343 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11344 unsigned long ret = newtot / count;
11345
11346 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11347 return ret + 1;
11348 else
11349 return ret;
11350 }
11351 #endif
11352
11353 static int
11354 bgp_table_stats_walker (struct thread *t)
11355 {
11356 struct bgp_node *rn;
11357 struct bgp_node *top;
11358 struct bgp_table_stats *ts = THREAD_ARG (t);
11359 unsigned int space = 0;
11360
11361 if (!(top = bgp_table_top (ts->table)))
11362 return 0;
11363
11364 switch (top->p.family)
11365 {
11366 case AF_INET:
11367 space = IPV4_MAX_BITLEN;
11368 break;
11369 case AF_INET6:
11370 space = IPV6_MAX_BITLEN;
11371 break;
11372 }
11373
11374 ts->counts[BGP_STATS_MAXBITLEN] = space;
11375
11376 for (rn = top; rn; rn = bgp_route_next (rn))
11377 {
11378 struct bgp_info *ri;
11379 struct bgp_node *prn = bgp_node_parent_nolock (rn);
11380 unsigned int rinum = 0;
11381
11382 if (rn == top)
11383 continue;
11384
11385 if (!rn->info)
11386 continue;
11387
11388 ts->counts[BGP_STATS_PREFIXES]++;
11389 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11390
11391 #if 0
11392 ts->counts[BGP_STATS_AVGPLEN]
11393 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11394 ts->counts[BGP_STATS_AVGPLEN],
11395 rn->p.prefixlen);
11396 #endif
11397
11398 /* check if the prefix is included by any other announcements */
11399 while (prn && !prn->info)
11400 prn = bgp_node_parent_nolock (prn);
11401
11402 if (prn == NULL || prn == top)
11403 {
11404 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11405 /* announced address space */
11406 if (space)
11407 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11408 }
11409 else if (prn->info)
11410 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11411
11412 for (ri = rn->info; ri; ri = ri->next)
11413 {
11414 rinum++;
11415 ts->counts[BGP_STATS_RIB]++;
11416
11417 if (ri->attr &&
11418 (CHECK_FLAG (ri->attr->flag,
11419 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11420 ts->counts[BGP_STATS_AGGREGATES]++;
11421
11422 /* as-path stats */
11423 if (ri->attr && ri->attr->aspath)
11424 {
11425 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11426 unsigned int size = aspath_size (ri->attr->aspath);
11427 as_t highest = aspath_highest (ri->attr->aspath);
11428
11429 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11430
11431 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11432 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11433
11434 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11435 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11436
11437 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11438 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11439 #if 0
11440 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11441 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11442 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11443 hops);
11444 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11445 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11446 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11447 size);
11448 #endif
11449 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11450 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11451 }
11452 }
11453 }
11454 return 0;
11455 }
11456
11457 static int
11458 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11459 {
11460 struct bgp_table_stats ts;
11461 unsigned int i;
11462
11463 if (!bgp->rib[afi][safi])
11464 {
11465 vty_out (vty, "%% No RIB exist's for the AFI(%d)/SAFI(%d)%s",
11466 afi, safi, VTY_NEWLINE);
11467 return CMD_WARNING;
11468 }
11469
11470 memset (&ts, 0, sizeof (ts));
11471 ts.table = bgp->rib[afi][safi];
11472 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11473
11474 vty_out (vty, "BGP %s RIB statistics%s%s",
11475 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11476
11477 for (i = 0; i < BGP_STATS_MAX; i++)
11478 {
11479 if (!table_stats_strs[i])
11480 continue;
11481
11482 switch (i)
11483 {
11484 #if 0
11485 case BGP_STATS_ASPATH_AVGHOPS:
11486 case BGP_STATS_ASPATH_AVGSIZE:
11487 case BGP_STATS_AVGPLEN:
11488 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11489 vty_out (vty, "%12.2f",
11490 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11491 break;
11492 #endif
11493 case BGP_STATS_ASPATH_TOTHOPS:
11494 case BGP_STATS_ASPATH_TOTSIZE:
11495 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11496 vty_out (vty, "%12.2f",
11497 ts.counts[i] ?
11498 (float)ts.counts[i] /
11499 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11500 : 0);
11501 break;
11502 case BGP_STATS_TOTPLEN:
11503 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11504 vty_out (vty, "%12.2f",
11505 ts.counts[i] ?
11506 (float)ts.counts[i] /
11507 (float)ts.counts[BGP_STATS_PREFIXES]
11508 : 0);
11509 break;
11510 case BGP_STATS_SPACE:
11511 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11512 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11513 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11514 break;
11515 vty_out (vty, "%30s: ", "%% announced ");
11516 vty_out (vty, "%12.2f%s",
11517 100 * (float)ts.counts[BGP_STATS_SPACE] /
11518 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
11519 VTY_NEWLINE);
11520 vty_out (vty, "%30s: ", "/8 equivalent ");
11521 vty_out (vty, "%12.2f%s",
11522 (float)ts.counts[BGP_STATS_SPACE] /
11523 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11524 VTY_NEWLINE);
11525 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11526 break;
11527 vty_out (vty, "%30s: ", "/24 equivalent ");
11528 vty_out (vty, "%12.2f",
11529 (float)ts.counts[BGP_STATS_SPACE] /
11530 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11531 break;
11532 default:
11533 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11534 vty_out (vty, "%12llu", ts.counts[i]);
11535 }
11536
11537 vty_out (vty, "%s", VTY_NEWLINE);
11538 }
11539 return CMD_SUCCESS;
11540 }
11541
11542 static int
11543 bgp_table_stats_vty (struct vty *vty, const char *name,
11544 const char *afi_str, const char *safi_str)
11545 {
11546 struct bgp *bgp;
11547 afi_t afi;
11548 safi_t safi;
11549
11550 if (name)
11551 bgp = bgp_lookup_by_name (name);
11552 else
11553 bgp = bgp_get_default ();
11554
11555 if (!bgp)
11556 {
11557 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
11558 return CMD_WARNING;
11559 }
11560 if (strncmp (afi_str, "ipv", 3) == 0)
11561 {
11562 if (strncmp (afi_str, "ipv4", 4) == 0)
11563 afi = AFI_IP;
11564 else if (strncmp (afi_str, "ipv6", 4) == 0)
11565 afi = AFI_IP6;
11566 else
11567 {
11568 vty_out (vty, "%% Invalid address family %s%s",
11569 afi_str, VTY_NEWLINE);
11570 return CMD_WARNING;
11571 }
11572 if (strncmp (safi_str, "m", 1) == 0)
11573 safi = SAFI_MULTICAST;
11574 else if (strncmp (safi_str, "u", 1) == 0)
11575 safi = SAFI_UNICAST;
11576 else if (strncmp (safi_str, "e", 1) == 0)
11577 safi = SAFI_ENCAP;
11578 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
11579 safi = SAFI_MPLS_VPN;
11580 else
11581 {
11582 vty_out (vty, "%% Invalid subsequent address family %s%s",
11583 safi_str, VTY_NEWLINE);
11584 return CMD_WARNING;
11585 }
11586 }
11587 else
11588 {
11589 vty_out (vty, "%% Invalid address family \"%s\"%s",
11590 afi_str, VTY_NEWLINE);
11591 return CMD_WARNING;
11592 }
11593
11594 return bgp_table_stats (vty, bgp, afi, safi);
11595 }
11596
11597 DEFUN (show_bgp_statistics,
11598 show_bgp_statistics_cmd,
11599 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
11600 SHOW_STR
11601 BGP_STR
11602 "Address family\n"
11603 "Address family\n"
11604 "Address Family modifier\n"
11605 "Address Family modifier\n"
11606 "Address Family modifier\n"
11607 "Address Family modifier\n"
11608 "BGP RIB advertisement statistics\n")
11609 {
11610 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11611 }
11612
11613 DEFUN (show_bgp_statistics_view,
11614 show_bgp_statistics_view_cmd,
11615 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast|vpn|encap) statistics",
11616 SHOW_STR
11617 BGP_STR
11618 BGP_INSTANCE_HELP_STR
11619 "Address family\n"
11620 "Address family\n"
11621 "Address Family modifier\n"
11622 "Address Family modifier\n"
11623 "Address Family modifier\n"
11624 "Address Family modifier\n"
11625 "BGP RIB advertisement statistics\n")
11626 {
11627 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
11628 }
11629
11630 enum bgp_pcounts
11631 {
11632 PCOUNT_ADJ_IN = 0,
11633 PCOUNT_DAMPED,
11634 PCOUNT_REMOVED,
11635 PCOUNT_HISTORY,
11636 PCOUNT_STALE,
11637 PCOUNT_VALID,
11638 PCOUNT_ALL,
11639 PCOUNT_COUNTED,
11640 PCOUNT_PFCNT, /* the figure we display to users */
11641 PCOUNT_MAX,
11642 };
11643
11644 static const char *pcount_strs[] =
11645 {
11646 [PCOUNT_ADJ_IN] = "Adj-in",
11647 [PCOUNT_DAMPED] = "Damped",
11648 [PCOUNT_REMOVED] = "Removed",
11649 [PCOUNT_HISTORY] = "History",
11650 [PCOUNT_STALE] = "Stale",
11651 [PCOUNT_VALID] = "Valid",
11652 [PCOUNT_ALL] = "All RIB",
11653 [PCOUNT_COUNTED] = "PfxCt counted",
11654 [PCOUNT_PFCNT] = "Useable",
11655 [PCOUNT_MAX] = NULL,
11656 };
11657
11658 struct peer_pcounts
11659 {
11660 unsigned int count[PCOUNT_MAX];
11661 const struct peer *peer;
11662 const struct bgp_table *table;
11663 };
11664
11665 static int
11666 bgp_peer_count_walker (struct thread *t)
11667 {
11668 struct bgp_node *rn;
11669 struct peer_pcounts *pc = THREAD_ARG (t);
11670 const struct peer *peer = pc->peer;
11671
11672 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
11673 {
11674 struct bgp_adj_in *ain;
11675 struct bgp_info *ri;
11676
11677 for (ain = rn->adj_in; ain; ain = ain->next)
11678 if (ain->peer == peer)
11679 pc->count[PCOUNT_ADJ_IN]++;
11680
11681 for (ri = rn->info; ri; ri = ri->next)
11682 {
11683 char buf[SU_ADDRSTRLEN];
11684
11685 if (ri->peer != peer)
11686 continue;
11687
11688 pc->count[PCOUNT_ALL]++;
11689
11690 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
11691 pc->count[PCOUNT_DAMPED]++;
11692 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
11693 pc->count[PCOUNT_HISTORY]++;
11694 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
11695 pc->count[PCOUNT_REMOVED]++;
11696 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
11697 pc->count[PCOUNT_STALE]++;
11698 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
11699 pc->count[PCOUNT_VALID]++;
11700 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11701 pc->count[PCOUNT_PFCNT]++;
11702
11703 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11704 {
11705 pc->count[PCOUNT_COUNTED]++;
11706 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11707 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
11708 peer->host,
11709 inet_ntop(rn->p.family, &rn->p.u.prefix,
11710 buf, SU_ADDRSTRLEN),
11711 rn->p.prefixlen,
11712 ri->flags);
11713 }
11714 else
11715 {
11716 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11717 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
11718 peer->host,
11719 inet_ntop(rn->p.family, &rn->p.u.prefix,
11720 buf, SU_ADDRSTRLEN),
11721 rn->p.prefixlen,
11722 ri->flags);
11723 }
11724 }
11725 }
11726 return 0;
11727 }
11728
11729 static int
11730 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
11731 {
11732 struct peer_pcounts pcounts = { .peer = peer };
11733 unsigned int i;
11734 json_object *json = NULL;
11735 json_object *json_loop = NULL;
11736
11737 if (use_json)
11738 {
11739 json = json_object_new_object();
11740 json_loop = json_object_new_object();
11741 }
11742
11743 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11744 || !peer->bgp->rib[afi][safi])
11745 {
11746 if (use_json)
11747 {
11748 json_object_string_add(json, "warning", "No such neighbor or address family");
11749 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11750 json_object_free(json);
11751 }
11752 else
11753 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11754
11755 return CMD_WARNING;
11756 }
11757
11758 memset (&pcounts, 0, sizeof(pcounts));
11759 pcounts.peer = peer;
11760 pcounts.table = peer->bgp->rib[afi][safi];
11761
11762 /* in-place call via thread subsystem so as to record execution time
11763 * * stats for the thread-walk (i.e. ensure this can't be blamed on
11764 * * on just vty_read()).
11765 * */
11766 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
11767
11768 if (use_json)
11769 {
11770 json_object_string_add(json, "prefixCountsFor", peer->host);
11771 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
11772 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
11773
11774 for (i = 0; i < PCOUNT_MAX; i++)
11775 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
11776
11777 json_object_object_add(json, "ribTableWalkCounters", json_loop);
11778
11779 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11780 {
11781 json_object_string_add(json, "pfxctDriftFor", peer->host);
11782 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
11783 }
11784 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11785 json_object_free(json);
11786 }
11787 else
11788 {
11789
11790 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
11791 {
11792 vty_out (vty, "Prefix counts for %s/%s, %s%s",
11793 peer->hostname, peer->host, afi_safi_print (afi, safi),
11794 VTY_NEWLINE);
11795 }
11796 else
11797 {
11798 vty_out (vty, "Prefix counts for %s, %s%s",
11799 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
11800 }
11801
11802 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
11803 vty_out (vty, "%sCounts from RIB table walk:%s%s",
11804 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
11805
11806 for (i = 0; i < PCOUNT_MAX; i++)
11807 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
11808
11809 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11810 {
11811 vty_out (vty, "%s [pcount] PfxCt drift!%s",
11812 peer->host, VTY_NEWLINE);
11813 vty_out (vty, "Please report this bug, with the above command output%s",
11814 VTY_NEWLINE);
11815 }
11816 }
11817
11818 return CMD_SUCCESS;
11819 }
11820
11821 DEFUN (show_ip_bgp_neighbor_prefix_counts,
11822 show_ip_bgp_neighbor_prefix_counts_cmd,
11823 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11824 SHOW_STR
11825 IP_STR
11826 BGP_STR
11827 "Detailed information on TCP and BGP neighbor connections\n"
11828 "Neighbor to display information about\n"
11829 "Neighbor to display information about\n"
11830 "Neighbor on bgp configured interface\n"
11831 "Display detailed prefix count information\n"
11832 "JavaScript Object Notation\n")
11833 {
11834 struct peer *peer;
11835 u_char uj = use_json(argc, argv);
11836
11837 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11838 if (! peer)
11839 return CMD_WARNING;
11840
11841 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11842 }
11843
11844 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
11845 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
11846 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11847 SHOW_STR
11848 IP_STR
11849 BGP_STR
11850 BGP_INSTANCE_HELP_STR
11851 "Detailed information on TCP and BGP neighbor connections\n"
11852 "Neighbor to display information about\n"
11853 "Neighbor to display information about\n"
11854 "Neighbor on bgp configured interface\n"
11855 "Display detailed prefix count information\n"
11856 "JavaScript Object Notation\n")
11857 {
11858 struct peer *peer;
11859 u_char uj = use_json(argc, argv);
11860
11861 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11862 if (! peer)
11863 return CMD_WARNING;
11864
11865 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11866 }
11867
11868 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
11869 show_bgp_ipv6_neighbor_prefix_counts_cmd,
11870 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11871 SHOW_STR
11872 BGP_STR
11873 "Address family\n"
11874 "Detailed information on TCP and BGP neighbor connections\n"
11875 "Neighbor to display information about\n"
11876 "Neighbor to display information about\n"
11877 "Neighbor on bgp configured interface\n"
11878 "Display detailed prefix count information\n"
11879 "JavaScript Object Notation\n")
11880 {
11881 struct peer *peer;
11882 u_char uj = use_json(argc, argv);
11883
11884 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11885 if (! peer)
11886 return CMD_WARNING;
11887
11888 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
11889 }
11890
11891 DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
11892 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
11893 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11894 SHOW_STR
11895 BGP_STR
11896 BGP_INSTANCE_HELP_STR
11897 "Address family\n"
11898 "Detailed information on TCP and BGP neighbor connections\n"
11899 "Neighbor to display information about\n"
11900 "Neighbor to display information about\n"
11901 "Neighbor on bgp configured interface\n"
11902 "Display detailed prefix count information\n"
11903 "JavaScript Object Notation\n")
11904 {
11905 struct peer *peer;
11906 u_char uj = use_json(argc, argv);
11907
11908 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11909 if (! peer)
11910 return CMD_WARNING;
11911
11912 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
11913 }
11914
11915 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
11916 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
11917 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11918 SHOW_STR
11919 IP_STR
11920 BGP_STR
11921 "Address family\n"
11922 "Address Family modifier\n"
11923 "Address Family modifier\n"
11924 "Detailed information on TCP and BGP neighbor connections\n"
11925 "Neighbor to display information about\n"
11926 "Neighbor to display information about\n"
11927 "Neighbor on bgp configured interface\n"
11928 "Display detailed prefix count information\n"
11929 "JavaScript Object Notation\n")
11930 {
11931 struct peer *peer;
11932 u_char uj = use_json(argc, argv);
11933
11934 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
11935 if (! peer)
11936 return CMD_WARNING;
11937
11938 if (strncmp (argv[0], "m", 1) == 0)
11939 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj);
11940
11941 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11942 }
11943
11944 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
11945 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
11946 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11947 SHOW_STR
11948 IP_STR
11949 BGP_STR
11950 "Address family\n"
11951 "Address Family modifier\n"
11952 "Address Family modifier\n"
11953 "Detailed information on TCP and BGP neighbor connections\n"
11954 "Neighbor to display information about\n"
11955 "Neighbor to display information about\n"
11956 "Neighbor on bgp configured interface\n"
11957 "Display detailed prefix count information\n"
11958 "JavaScript Object Notation\n")
11959 {
11960 struct peer *peer;
11961 u_char uj = use_json(argc, argv);
11962
11963 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11964 if (! peer)
11965 return CMD_WARNING;
11966
11967 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
11968 }
11969
11970 static void
11971 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
11972 int in, const char *rmap_name, u_char use_json, json_object *json)
11973 {
11974 struct bgp_table *table;
11975 struct bgp_adj_in *ain;
11976 struct bgp_adj_out *adj;
11977 unsigned long output_count;
11978 unsigned long filtered_count;
11979 struct bgp_node *rn;
11980 int header1 = 1;
11981 struct bgp *bgp;
11982 int header2 = 1;
11983 struct attr attr;
11984 struct attr_extra extra;
11985 int ret;
11986 struct update_subgroup *subgrp;
11987 json_object *json_scode = NULL;
11988 json_object *json_ocode = NULL;
11989 json_object *json_ar = NULL;
11990 struct peer_af *paf;
11991
11992 if (use_json)
11993 {
11994 json_scode = json_object_new_object();
11995 json_ocode = json_object_new_object();
11996 json_ar = json_object_new_object();
11997
11998 json_object_string_add(json_scode, "suppressed", "s");
11999 json_object_string_add(json_scode, "damped", "d");
12000 json_object_string_add(json_scode, "history", "h");
12001 json_object_string_add(json_scode, "valid", "*");
12002 json_object_string_add(json_scode, "best", ">");
12003 json_object_string_add(json_scode, "multipath", "=");
12004 json_object_string_add(json_scode, "internal", "i");
12005 json_object_string_add(json_scode, "ribFailure", "r");
12006 json_object_string_add(json_scode, "stale", "S");
12007 json_object_string_add(json_scode, "removed", "R");
12008
12009 json_object_string_add(json_ocode, "igp", "i");
12010 json_object_string_add(json_ocode, "egp", "e");
12011 json_object_string_add(json_ocode, "incomplete", "?");
12012 }
12013
12014 bgp = peer->bgp;
12015
12016 if (! bgp)
12017 {
12018 if (use_json)
12019 {
12020 json_object_string_add(json, "alert", "no BGP");
12021 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12022 json_object_free(json);
12023 }
12024 else
12025 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
12026 return;
12027 }
12028
12029 table = bgp->rib[afi][safi];
12030
12031 output_count = filtered_count = 0;
12032 subgrp = peer_subgroup(peer, afi, safi);
12033
12034 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
12035 {
12036 if (use_json)
12037 {
12038 json_object_int_add(json, "bgpTableVersion", table->version);
12039 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12040 json_object_object_add(json, "bgpStatusCodes", json_scode);
12041 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12042 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
12043 }
12044 else
12045 {
12046 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
12047 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12048 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12049
12050 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12051 VTY_NEWLINE, VTY_NEWLINE);
12052 }
12053 header1 = 0;
12054 }
12055
12056 attr.extra = &extra;
12057 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12058 {
12059 if (in)
12060 {
12061 for (ain = rn->adj_in; ain; ain = ain->next)
12062 {
12063 if (ain->peer == peer)
12064 {
12065 if (header1)
12066 {
12067 if (use_json)
12068 {
12069 json_object_int_add(json, "bgpTableVersion", 0);
12070 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12071 json_object_object_add(json, "bgpStatusCodes", json_scode);
12072 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12073 }
12074 else
12075 {
12076 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12077 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12078 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12079 }
12080 header1 = 0;
12081 }
12082 if (header2)
12083 {
12084 if (!use_json)
12085 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12086 header2 = 0;
12087 }
12088 if (ain->attr)
12089 {
12090 bgp_attr_dup(&attr, ain->attr);
12091 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12092 {
12093 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12094 output_count++;
12095 }
12096 else
12097 filtered_count++;
12098 }
12099 }
12100 }
12101 }
12102 else
12103 {
12104 for (adj = rn->adj_out; adj; adj = adj->next)
12105 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12106 if (paf->peer == peer)
12107 {
12108 if (header1)
12109 {
12110 if (use_json)
12111 {
12112 json_object_int_add(json, "bgpTableVersion", table->version);
12113 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12114 json_object_object_add(json, "bgpStatusCodes", json_scode);
12115 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12116 }
12117 else
12118 {
12119 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12120 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12121 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12122 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12123 }
12124 header1 = 0;
12125 }
12126
12127 if (header2)
12128 {
12129 if (!use_json)
12130 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12131 header2 = 0;
12132 }
12133
12134 if (adj->attr)
12135 {
12136 bgp_attr_dup(&attr, adj->attr);
12137 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12138 if (ret != RMAP_DENY)
12139 {
12140 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12141 output_count++;
12142 }
12143 else
12144 filtered_count++;
12145 }
12146 }
12147 }
12148 }
12149 if (use_json)
12150 json_object_object_add(json, "advertisedRoutes", json_ar);
12151
12152 if (output_count != 0)
12153 {
12154 if (use_json)
12155 json_object_int_add(json, "totalPrefixCounter", output_count);
12156 else
12157 vty_out (vty, "%sTotal number of prefixes %ld%s",
12158 VTY_NEWLINE, output_count, VTY_NEWLINE);
12159 }
12160 if (use_json)
12161 {
12162 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12163 json_object_free(json);
12164 }
12165
12166 }
12167
12168 static int
12169 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12170 int in, const char *rmap_name, u_char use_json)
12171 {
12172 json_object *json = NULL;
12173
12174 if (use_json)
12175 json = json_object_new_object();
12176
12177 if (!peer || !peer->afc[afi][safi])
12178 {
12179 if (use_json)
12180 {
12181 json_object_string_add(json, "warning", "No such neighbor or address family");
12182 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12183 json_object_free(json);
12184 }
12185 else
12186 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12187
12188 return CMD_WARNING;
12189 }
12190
12191 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12192 {
12193 if (use_json)
12194 {
12195 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12196 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
12197 json_object_free(json);
12198 }
12199 else
12200 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12201
12202 return CMD_WARNING;
12203 }
12204
12205 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
12206
12207 return CMD_SUCCESS;
12208 }
12209
12210 DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12211 show_ip_bgp_instance_neighbor_advertised_route_cmd,
12212 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12213 SHOW_STR
12214 IP_STR
12215 BGP_STR
12216 BGP_INSTANCE_HELP_STR
12217 "Detailed information on TCP and BGP neighbor connections\n"
12218 "Neighbor to display information about\n"
12219 "Neighbor to display information about\n"
12220 "Display the routes advertised to a BGP neighbor\n"
12221 "JavaScript Object Notation\n")
12222 {
12223 struct peer *peer;
12224 u_char uj = use_json(argc, argv);
12225
12226 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12227 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12228 else
12229 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12230
12231 if (! peer)
12232 return CMD_WARNING;
12233
12234 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
12235 }
12236
12237 DEFUN (show_ip_bgp_neighbor_advertised_route,
12238 show_ip_bgp_neighbor_advertised_route_cmd,
12239 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12240 SHOW_STR
12241 IP_STR
12242 BGP_STR
12243 "Detailed information on TCP and BGP neighbor connections\n"
12244 "Neighbor to display information about\n"
12245 "Neighbor to display information about\n"
12246 "Neighbor on bgp configured interface\n"
12247 "Display the routes advertised to a BGP neighbor\n"
12248 "JavaScript Object Notation\n")
12249
12250 {
12251 struct peer *peer;
12252 const char *rmap_name = NULL;
12253 u_char uj = use_json(argc, argv);
12254
12255 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12256
12257 if (! peer)
12258 return CMD_WARNING;
12259
12260 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12261 || (argc == 3))
12262 rmap_name = argv[1];
12263
12264 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12265 }
12266
12267 ALIAS (show_ip_bgp_neighbor_advertised_route,
12268 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
12269 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12270 SHOW_STR
12271 IP_STR
12272 BGP_STR
12273 "Detailed information on TCP and BGP neighbor connections\n"
12274 "Neighbor to display information about\n"
12275 "Neighbor to display information about\n"
12276 "Neighbor on bgp configured interface\n"
12277 "Display the routes advertised to a BGP neighbor\n"
12278 "JavaScript Object Notation\n")
12279
12280 ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12281 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12282 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12283 SHOW_STR
12284 IP_STR
12285 BGP_STR
12286 BGP_INSTANCE_HELP_STR
12287 "Detailed information on TCP and BGP neighbor connections\n"
12288 "Neighbor to display information about\n"
12289 "Neighbor to display information about\n"
12290 "Neighbor on bgp configured interface\n"
12291 "Display the routes advertised to a BGP neighbor\n"
12292 "JavaScript Object Notation\n")
12293 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12294 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12295 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12296 SHOW_STR
12297 IP_STR
12298 BGP_STR
12299 "Address family\n"
12300 "Address Family modifier\n"
12301 "Address Family modifier\n"
12302 "Detailed information on TCP and BGP neighbor connections\n"
12303 "Neighbor to display information about\n"
12304 "Neighbor to display information about\n"
12305 "Neighbor on bgp configured interface\n"
12306 "Display the routes advertised to a BGP neighbor\n"
12307 "JavaScript Object Notation\n")
12308 {
12309 struct peer *peer;
12310 const char *rmap_name = NULL;
12311 u_char uj = use_json(argc, argv);
12312
12313 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12314 if (! peer)
12315 return CMD_WARNING;
12316
12317 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12318 rmap_name = argv[2];
12319
12320 if (strncmp (argv[0], "m", 1) == 0)
12321 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj);
12322 else
12323 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12324 }
12325
12326 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12327 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
12328 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12329 SHOW_STR
12330 IP_STR
12331 BGP_STR
12332 "Address family\n"
12333 "Address Family modifier\n"
12334 "Address Family modifier\n"
12335 "Detailed information on TCP and BGP neighbor connections\n"
12336 "Neighbor to display information about\n"
12337 "Neighbor to display information about\n"
12338 "Neighbor on bgp configured interface\n"
12339 "Display the routes advertised to a BGP neighbor\n"
12340 "Route-map to control what is displayed\n"
12341 "JavaScript Object Notation\n")
12342
12343 #ifdef HAVE_IPV6
12344 DEFUN (show_bgp_instance_neighbor_advertised_route,
12345 show_bgp_instance_neighbor_advertised_route_cmd,
12346 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12347 SHOW_STR
12348 BGP_STR
12349 BGP_INSTANCE_HELP_STR
12350 "Detailed information on TCP and BGP neighbor connections\n"
12351 "Neighbor to display information about\n"
12352 "Neighbor to display information about\n"
12353 "Neighbor on bgp configured interface\n"
12354 "Display the routes advertised to a BGP neighbor\n"
12355 "JavaScript Object Notation\n")
12356 {
12357 struct peer *peer;
12358 u_char uj = use_json(argc, argv);
12359
12360 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12361 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12362 else
12363 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12364
12365 if (! peer)
12366 return CMD_WARNING;
12367
12368 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
12369 }
12370
12371 ALIAS (show_bgp_instance_neighbor_advertised_route,
12372 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12373 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12374 SHOW_STR
12375 BGP_STR
12376 BGP_INSTANCE_HELP_STR
12377 "Address family\n"
12378 "Detailed information on TCP and BGP neighbor connections\n"
12379 "Neighbor to display information about\n"
12380 "Neighbor to display information about\n"
12381 "Neighbor on bgp configured interface\n"
12382 "Display the routes advertised to a BGP neighbor\n"
12383 "JavaScript Object Notation\n")
12384
12385 DEFUN (show_bgp_neighbor_advertised_route,
12386 show_bgp_neighbor_advertised_route_cmd,
12387 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12388 SHOW_STR
12389 BGP_STR
12390 "Detailed information on TCP and BGP neighbor connections\n"
12391 "Neighbor to display information about\n"
12392 "Neighbor to display information about\n"
12393 "Neighbor on bgp configured interface\n"
12394 "Display the routes advertised to a BGP neighbor\n"
12395 "JavaScript Object Notation\n")
12396
12397 {
12398 struct peer *peer;
12399 const char *rmap_name = NULL;
12400 u_char uj = use_json(argc, argv);
12401
12402 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12403
12404 if (!peer)
12405 return CMD_WARNING;
12406
12407 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12408 rmap_name = argv[1];
12409
12410 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
12411 }
12412
12413 ALIAS (show_bgp_neighbor_advertised_route,
12414 show_bgp_ipv6_neighbor_advertised_route_cmd,
12415 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12416 SHOW_STR
12417 BGP_STR
12418 "Address family\n"
12419 "Detailed information on TCP and BGP neighbor connections\n"
12420 "Neighbor to display information about\n"
12421 "Neighbor to display information about\n"
12422 "Neighbor on bgp configured interface\n"
12423 "Display the routes advertised to a BGP neighbor\n"
12424 "JavaScript Object Notation\n")
12425
12426 /* old command */
12427 ALIAS (show_bgp_neighbor_advertised_route,
12428 ipv6_bgp_neighbor_advertised_route_cmd,
12429 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12430 SHOW_STR
12431 IPV6_STR
12432 BGP_STR
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 the routes advertised to a BGP neighbor\n"
12438 "JavaScript Object Notation\n")
12439
12440 /* old command */
12441 DEFUN (ipv6_mbgp_neighbor_advertised_route,
12442 ipv6_mbgp_neighbor_advertised_route_cmd,
12443 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12444 SHOW_STR
12445 IPV6_STR
12446 MBGP_STR
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 "Neighbor on bgp configured interface\n"
12452 "Display the routes advertised to a BGP neighbor\n"
12453 "JavaScript Object Notation\n")
12454 {
12455 struct peer *peer;
12456 u_char uj = use_json(argc, argv);
12457
12458 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12459 if (! peer)
12460 return CMD_WARNING;
12461
12462 bgp_show_ipv6_bgp_deprecate_warning(vty);
12463 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
12464 }
12465 #endif /* HAVE_IPV6 */
12466
12467 DEFUN (show_bgp_instance_neighbor_received_routes,
12468 show_bgp_instance_neighbor_received_routes_cmd,
12469 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12470 SHOW_STR
12471 BGP_STR
12472 BGP_INSTANCE_HELP_STR
12473 "Detailed information on TCP and BGP neighbor connections\n"
12474 "Neighbor to display information about\n"
12475 "Neighbor to display information about\n"
12476 "Neighbor on bgp configured interface\n"
12477 "Display the received routes from neighbor\n"
12478 "JavaScript Object Notation\n")
12479 {
12480 struct peer *peer;
12481 u_char uj = use_json(argc, argv);
12482
12483 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12484 if (! peer)
12485 return CMD_WARNING;
12486
12487 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
12488 }
12489
12490 DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12491 show_ip_bgp_instance_neighbor_received_routes_cmd,
12492 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12493 SHOW_STR
12494 IP_STR
12495 BGP_STR
12496 BGP_INSTANCE_HELP_STR
12497 "Detailed information on TCP and BGP neighbor connections\n"
12498 "Neighbor to display information about\n"
12499 "Neighbor to display information about\n"
12500 "Neighbor on bgp configured interface\n"
12501 "Display the received routes from neighbor\n"
12502 "JavaScript Object Notation\n")
12503 {
12504 struct peer *peer;
12505 u_char uj = use_json(argc, argv);
12506
12507 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12508 if (! peer)
12509 return CMD_WARNING;
12510
12511 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
12512 }
12513
12514 ALIAS (show_bgp_instance_neighbor_received_routes,
12515 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12516 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12517 SHOW_STR
12518 BGP_STR
12519 BGP_INSTANCE_HELP_STR
12520 "Address family\n"
12521 "Detailed information on TCP and BGP neighbor connections\n"
12522 "Neighbor to display information about\n"
12523 "Neighbor to display information about\n"
12524 "Neighbor on bgp configured interface\n"
12525 "Display the received routes from neighbor\n"
12526 "JavaScript Object Notation\n")
12527
12528 DEFUN (show_ip_bgp_neighbor_received_routes,
12529 show_ip_bgp_neighbor_received_routes_cmd,
12530 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12531 SHOW_STR
12532 IP_STR
12533 BGP_STR
12534 "Detailed information on TCP and BGP neighbor connections\n"
12535 "Neighbor to display information about\n"
12536 "Neighbor to display information about\n"
12537 "Neighbor on bgp configured interface\n"
12538 "Display the received routes from neighbor\n"
12539 "JavaScript Object Notation\n")
12540
12541 {
12542 struct peer *peer;
12543 const char *rmap_name = NULL;
12544 u_char uj = use_json(argc, argv);
12545
12546 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12547
12548 if (! peer)
12549 return CMD_WARNING;
12550
12551 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12552 rmap_name = argv[1];
12553
12554 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12555 }
12556
12557 ALIAS (show_ip_bgp_neighbor_received_routes,
12558 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12559 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12560 SHOW_STR
12561 IP_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 the received routes from neighbor\n"
12568 "JavaScript Object Notation\n")
12569
12570 ALIAS (show_ip_bgp_instance_neighbor_received_routes,
12571 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
12572 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12573 SHOW_STR
12574 IP_STR
12575 BGP_STR
12576 BGP_INSTANCE_HELP_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 the received routes from neighbor\n"
12582 "JavaScript Object Notation\n")
12583
12584 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12585 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12586 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12587 SHOW_STR
12588 IP_STR
12589 BGP_STR
12590 "Address family\n"
12591 "Address Family modifier\n"
12592 "Address Family modifier\n"
12593 "Detailed information on TCP and BGP neighbor connections\n"
12594 "Neighbor to display information about\n"
12595 "Neighbor to display information about\n"
12596 "Neighbor on bgp configured interface\n"
12597 "Display the received routes from neighbor\n"
12598 "JavaScript Object Notation\n")
12599 {
12600 struct peer *peer;
12601 const char *rmap_name = NULL;
12602 u_char uj = use_json(argc, argv);
12603
12604 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12605 if (! peer)
12606 return CMD_WARNING;
12607
12608 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12609 rmap_name = argv[2];
12610
12611 if (strncmp (argv[0], "m", 1) == 0)
12612 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj);
12613 else
12614 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12615 }
12616
12617 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12618 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
12619 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12620 SHOW_STR
12621 IP_STR
12622 BGP_STR
12623 "Address family\n"
12624 "Address Family modifier\n"
12625 "Address Family modifier\n"
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 received routes from neighbor\n"
12631 "JavaScript Object Notation\n")
12632
12633 DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12634 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
12635 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
12636 SHOW_STR
12637 BGP_STR
12638 BGP_INSTANCE_HELP_STR
12639 "Address family\n"
12640 "Address family\n"
12641 "Address family modifier\n"
12642 "Address family modifier\n"
12643 "Detailed information on TCP and BGP neighbor connections\n"
12644 "Neighbor to display information about\n"
12645 "Neighbor to display information about\n"
12646 "Neighbor on bgp configured interface\n"
12647 "Display the advertised routes to neighbor\n"
12648 "Display the received routes from neighbor\n"
12649 "JavaScript Object Notation\n")
12650 {
12651 int afi;
12652 int safi;
12653 int in;
12654 struct peer *peer;
12655 u_char uj = use_json(argc, argv);
12656
12657 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
12658
12659 if (! peer)
12660 return CMD_WARNING;
12661
12662 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12663 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12664 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
12665
12666 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
12667 }
12668
12669 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12670 show_ip_bgp_neighbor_received_prefix_filter_cmd,
12671 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12672 SHOW_STR
12673 IP_STR
12674 BGP_STR
12675 "Detailed information on TCP and BGP neighbor connections\n"
12676 "Neighbor to display information about\n"
12677 "Neighbor to display information about\n"
12678 "Neighbor on bgp configured interface\n"
12679 "Display information received from a BGP neighbor\n"
12680 "Display the prefixlist filter\n"
12681 "JavaScript Object Notation\n")
12682 {
12683 char name[BUFSIZ];
12684 union sockunion su;
12685 struct peer *peer;
12686 int count, ret;
12687 u_char uj = use_json(argc, argv);
12688
12689 ret = str2sockunion (argv[0], &su);
12690 if (ret < 0)
12691 {
12692 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12693 if (! peer)
12694 {
12695 if (uj)
12696 {
12697 json_object *json_no = NULL;
12698 json_object *json_sub = NULL;
12699 json_no = json_object_new_object();
12700 json_sub = json_object_new_object();
12701 json_object_string_add(json_no, "warning", "Malformed address or name");
12702 json_object_string_add(json_sub, "warningCause", argv[0]);
12703 json_object_object_add(json_no, "detail", json_sub);
12704 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12705 json_object_free(json_no);
12706 }
12707 else
12708 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12709 return CMD_WARNING;
12710 }
12711 }
12712 else
12713 {
12714 peer = peer_lookup (NULL, &su);
12715 if (! peer)
12716 {
12717 if (uj)
12718 {
12719 json_object *json_no = NULL;
12720 json_no = json_object_new_object();
12721 json_object_string_add(json_no, "warning", "Peer not found");
12722 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12723 json_object_free(json_no);
12724 }
12725 else
12726 vty_out (vty, "No peer%s", VTY_NEWLINE);
12727 return CMD_WARNING;
12728 }
12729 }
12730
12731 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12732 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12733 if (count)
12734 {
12735 if (!uj)
12736 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12737 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12738 }
12739 else
12740 {
12741 if (uj)
12742 {
12743 json_object *json_no = NULL;
12744 json_no = json_object_new_object();
12745 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12746 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12747 json_object_free(json_no);
12748 }
12749 else
12750 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12751 }
12752
12753 return CMD_SUCCESS;
12754 }
12755
12756 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12757 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
12758 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12759 SHOW_STR
12760 IP_STR
12761 BGP_STR
12762 "Address family\n"
12763 "Address Family modifier\n"
12764 "Address Family modifier\n"
12765 "Detailed information on TCP and BGP neighbor connections\n"
12766 "Neighbor to display information about\n"
12767 "Neighbor to display information about\n"
12768 "Neighbor on bgp configured interface\n"
12769 "Display information received from a BGP neighbor\n"
12770 "Display the prefixlist filter\n"
12771 "JavaScript Object Notation\n")
12772 {
12773 char name[BUFSIZ];
12774 union sockunion su;
12775 struct peer *peer;
12776 int count, ret;
12777 u_char uj = use_json(argc, argv);
12778
12779 ret = str2sockunion (argv[1], &su);
12780 if (ret < 0)
12781 {
12782 peer = peer_lookup_by_conf_if (NULL, argv[1]);
12783 if (! peer)
12784 {
12785 if (uj)
12786 {
12787 json_object *json_no = NULL;
12788 json_object *json_sub = NULL;
12789 json_no = json_object_new_object();
12790 json_sub = json_object_new_object();
12791 json_object_string_add(json_no, "warning", "Malformed address or name");
12792 json_object_string_add(json_sub, "warningCause", argv[1]);
12793 json_object_object_add(json_no, "detail", json_sub);
12794 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12795 json_object_free(json_no);
12796 }
12797 else
12798 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12799 return CMD_WARNING;
12800 }
12801 }
12802 else
12803 {
12804 peer = peer_lookup (NULL, &su);
12805 if (! peer)
12806 {
12807 if (uj)
12808 {
12809 json_object *json_no = NULL;
12810 json_no = json_object_new_object();
12811 json_object_string_add(json_no, "warning", "Peer not found");
12812 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12813 json_object_free(json_no);
12814 }
12815 else
12816 vty_out (vty, "No peer%s", VTY_NEWLINE);
12817 return CMD_WARNING;
12818 }
12819 }
12820
12821 if (strncmp (argv[0], "m", 1) == 0)
12822 {
12823 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
12824 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12825 if (count)
12826 {
12827 if (!uj)
12828 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
12829 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12830 }
12831 else
12832 {
12833 if (uj)
12834 {
12835 json_object *json_no = NULL;
12836 json_no = json_object_new_object();
12837 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12838 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12839 json_object_free(json_no);
12840 }
12841 else
12842 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12843 }
12844 }
12845 else
12846 {
12847 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12848 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12849 if (count)
12850 {
12851 if (!uj)
12852 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12853 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12854 }
12855 else
12856 {
12857 if (uj)
12858 {
12859 json_object *json_no = NULL;
12860 json_no = json_object_new_object();
12861 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12862 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12863 json_object_free(json_no);
12864 }
12865 else
12866 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12867 }
12868 }
12869
12870 return CMD_SUCCESS;
12871 }
12872 #ifdef HAVE_IPV6
12873 DEFUN (show_bgp_neighbor_received_routes,
12874 show_bgp_neighbor_received_routes_cmd,
12875 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12876 SHOW_STR
12877 BGP_STR
12878 "Detailed information on TCP and BGP neighbor connections\n"
12879 "Neighbor to display information about\n"
12880 "Neighbor to display information about\n"
12881 "Neighbor on bgp configured interface\n"
12882 "Display the received routes from neighbor\n"
12883 "JavaScript Object Notation\n")
12884 {
12885 struct peer *peer;
12886 const char *rmap_name = NULL;
12887 u_char uj = use_json(argc, argv);
12888
12889 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12890
12891 if (! peer)
12892 return CMD_WARNING;
12893
12894 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12895 rmap_name = argv[1];
12896
12897 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
12898 }
12899
12900 ALIAS (show_bgp_neighbor_received_routes,
12901 show_bgp_ipv6_neighbor_received_routes_cmd,
12902 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12903 SHOW_STR
12904 BGP_STR
12905 "Address family\n"
12906 "Detailed information on TCP and BGP neighbor connections\n"
12907 "Neighbor to display information about\n"
12908 "Neighbor to display information about\n"
12909 "Neighbor on bgp configured interface\n"
12910 "Display the received routes from neighbor\n"
12911 "JavaScript Object Notation\n")
12912
12913 DEFUN (show_bgp_neighbor_received_prefix_filter,
12914 show_bgp_neighbor_received_prefix_filter_cmd,
12915 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12916 SHOW_STR
12917 BGP_STR
12918 "Detailed information on TCP and BGP neighbor connections\n"
12919 "Neighbor to display information about\n"
12920 "Neighbor to display information about\n"
12921 "Neighbor on bgp configured interface\n"
12922 "Display information received from a BGP neighbor\n"
12923 "Display the prefixlist filter\n"
12924 "JavaScript Object Notation\n")
12925 {
12926 char name[BUFSIZ];
12927 union sockunion su;
12928 struct peer *peer;
12929 int count, ret;
12930 u_char uj = use_json(argc, argv);
12931
12932 ret = str2sockunion (argv[0], &su);
12933 if (ret < 0)
12934 {
12935 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12936 if (! peer)
12937 {
12938 if (uj)
12939 {
12940 json_object *json_no = NULL;
12941 json_object *json_sub = NULL;
12942 json_no = json_object_new_object();
12943 json_sub = json_object_new_object();
12944 json_object_string_add(json_no, "warning", "Malformed address or name");
12945 json_object_string_add(json_sub, "warningCause", argv[0]);
12946 json_object_object_add(json_no, "detail", json_sub);
12947 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12948 json_object_free(json_no);
12949 }
12950 else
12951 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12952 return CMD_WARNING;
12953 }
12954 }
12955 else
12956 {
12957 peer = peer_lookup (NULL, &su);
12958 if (! peer)
12959 {
12960 if (uj)
12961 {
12962 json_object *json_no = NULL;
12963 json_no = json_object_new_object();
12964 json_object_string_add(json_no, "warning", "No Peer");
12965 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12966 json_object_free(json_no);
12967 }
12968 else
12969 vty_out (vty, "No peer%s", VTY_NEWLINE);
12970 return CMD_WARNING;
12971 }
12972 }
12973
12974 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12975 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
12976 if (count)
12977 {
12978 if (!uj)
12979 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12980 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
12981 }
12982 else
12983 {
12984 if (uj)
12985 {
12986 json_object *json_no = NULL;
12987 json_no = json_object_new_object();
12988 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12989 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12990 json_object_free(json_no);
12991 }
12992 else
12993 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12994 }
12995
12996 return CMD_SUCCESS;
12997 }
12998
12999 ALIAS (show_bgp_neighbor_received_prefix_filter,
13000 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13001 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13002 SHOW_STR
13003 BGP_STR
13004 "Address family\n"
13005 "Detailed information on TCP and BGP neighbor connections\n"
13006 "Neighbor to display information about\n"
13007 "Neighbor to display information about\n"
13008 "Neighbor on bgp configured interface\n"
13009 "Display information received from a BGP neighbor\n"
13010 "Display the prefixlist filter\n"
13011 "JavaScript Object Notation\n")
13012
13013 /* old command */
13014 ALIAS (show_bgp_neighbor_received_routes,
13015 ipv6_bgp_neighbor_received_routes_cmd,
13016 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13017 SHOW_STR
13018 IPV6_STR
13019 BGP_STR
13020 "Detailed information on TCP and BGP neighbor connections\n"
13021 "Neighbor to display information about\n"
13022 "Neighbor to display information about\n"
13023 "Neighbor on bgp configured interface\n"
13024 "Display the received routes from neighbor\n"
13025 "JavaScript Object Notation\n")
13026
13027 /* old command */
13028 DEFUN (ipv6_mbgp_neighbor_received_routes,
13029 ipv6_mbgp_neighbor_received_routes_cmd,
13030 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13031 SHOW_STR
13032 IPV6_STR
13033 MBGP_STR
13034 "Detailed information on TCP and BGP neighbor connections\n"
13035 "Neighbor to display information about\n"
13036 "Neighbor to display information about\n"
13037 "Neighbor on bgp configured interface\n"
13038 "Display the received routes from neighbor\n"
13039 "JavaScript Object Notation\n")
13040 {
13041 struct peer *peer;
13042 u_char uj = use_json(argc, argv);
13043
13044 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13045 if (! peer)
13046 return CMD_WARNING;
13047
13048 bgp_show_ipv6_bgp_deprecate_warning(vty);
13049 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
13050 }
13051
13052 DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
13053 show_bgp_instance_neighbor_received_prefix_filter_cmd,
13054 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13055 SHOW_STR
13056 BGP_STR
13057 BGP_INSTANCE_HELP_STR
13058 "Detailed information on TCP and BGP neighbor connections\n"
13059 "Neighbor to display information about\n"
13060 "Neighbor to display information about\n"
13061 "Neighbor on bgp configured interface\n"
13062 "Display information received from a BGP neighbor\n"
13063 "Display the prefixlist filter\n"
13064 "JavaScript Object Notation\n")
13065 {
13066 char name[BUFSIZ];
13067 union sockunion su;
13068 struct peer *peer;
13069 struct bgp *bgp;
13070 int count, ret;
13071 u_char uj = use_json(argc, argv);
13072
13073 /* BGP structure lookup. */
13074 bgp = bgp_lookup_by_name (argv[1]);
13075 if (bgp == NULL)
13076 {
13077 if (uj)
13078 {
13079 json_object *json_no = NULL;
13080 json_no = json_object_new_object();
13081 json_object_string_add(json_no, "warning", "Can't find BGP view");
13082 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13083 json_object_free(json_no);
13084 }
13085 else
13086 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
13087 return CMD_WARNING;
13088 }
13089
13090 ret = str2sockunion (argv[2], &su);
13091 if (ret < 0)
13092 {
13093 peer = peer_lookup_by_conf_if (bgp, argv[2]);
13094 if (! peer)
13095 {
13096 if (uj)
13097 {
13098 json_object *json_no = NULL;
13099 json_object *json_sub = NULL;
13100 json_no = json_object_new_object();
13101 json_sub = json_object_new_object();
13102 json_object_string_add(json_no, "warning", "Malformed address or name");
13103 json_object_string_add(json_sub, "warningCause", argv[2]);
13104 json_object_object_add(json_no, "detail", json_sub);
13105 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13106 json_object_free(json_no);
13107 }
13108 else
13109 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
13110 return CMD_WARNING;
13111 }
13112 }
13113 else
13114 {
13115 peer = peer_lookup (bgp, &su);
13116 if (! peer)
13117 {
13118 if (uj)
13119 {
13120 json_object *json_no = NULL;
13121 json_no = json_object_new_object();
13122 json_object_boolean_true_add(json_no, "noPeer");
13123 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13124 json_object_free(json_no);
13125 }
13126 else
13127 vty_out (vty, "No peer%s", VTY_NEWLINE);
13128 return CMD_WARNING;
13129 }
13130
13131 }
13132
13133 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13134 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13135 if (count)
13136 {
13137 if (!uj)
13138 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13139 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13140 }
13141
13142 return CMD_SUCCESS;
13143 }
13144 ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
13145 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
13146 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13147 SHOW_STR
13148 BGP_STR
13149 BGP_INSTANCE_HELP_STR
13150 "Address family\n"
13151 "Detailed information on TCP and BGP neighbor connections\n"
13152 "Neighbor to display information about\n"
13153 "Neighbor to display information about\n"
13154 "Neighbor on bgp configured interface\n"
13155 "Display information received from a BGP neighbor\n"
13156 "Display the prefixlist filter\n"
13157 "JavaScript Object NOtation\n")
13158 #endif /* HAVE_IPV6 */
13159
13160 static int
13161 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
13162 safi_t safi, enum bgp_show_type type, u_char use_json)
13163 {
13164 if (! peer || ! peer->afc[afi][safi])
13165 {
13166 if (use_json)
13167 {
13168 json_object *json_no = NULL;
13169 json_no = json_object_new_object();
13170 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13171 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13172 json_object_free(json_no);
13173 }
13174 else
13175 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
13176 return CMD_WARNING;
13177 }
13178
13179 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
13180 }
13181
13182 DEFUN (show_ip_bgp_neighbor_routes,
13183 show_ip_bgp_neighbor_routes_cmd,
13184 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13185 SHOW_STR
13186 IP_STR
13187 BGP_STR
13188 "Detailed information on TCP and BGP neighbor connections\n"
13189 "Neighbor to display information about\n"
13190 "Neighbor to display information about\n"
13191 "Neighbor on bgp configured interface\n"
13192 "Display routes learned from neighbor\n"
13193 "JavaScript Object Notation\n")
13194 {
13195 struct peer *peer;
13196 u_char uj = use_json(argc, argv);
13197
13198 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13199 if (! peer)
13200 return CMD_WARNING;
13201
13202 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13203 bgp_show_type_neighbor, uj);
13204 }
13205
13206 DEFUN (show_ip_bgp_instance_neighbor_routes,
13207 show_ip_bgp_instance_neighbor_routes_cmd,
13208 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13209 SHOW_STR
13210 IP_STR
13211 BGP_STR
13212 BGP_INSTANCE_HELP_STR
13213 "Detailed information on TCP and BGP neighbor connections\n"
13214 "Neighbor to display information about\n"
13215 "Neighbor to display information about\n"
13216 "Neighbor on bgp configured interface\n"
13217 "Display routes learned from neighbor\n"
13218 "JavaScript Object Notation\n")
13219 {
13220 struct peer *peer;
13221 u_char uj = use_json(argc, argv);
13222
13223 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13224 if (! peer)
13225 return CMD_WARNING;
13226
13227 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13228 bgp_show_type_neighbor, uj);
13229 }
13230
13231 DEFUN (show_ip_bgp_neighbor_flap,
13232 show_ip_bgp_neighbor_flap_cmd,
13233 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13234 SHOW_STR
13235 IP_STR
13236 BGP_STR
13237 "Detailed information on TCP and BGP neighbor connections\n"
13238 "Neighbor to display information about\n"
13239 "Neighbor to display information about\n"
13240 "Neighbor on bgp configured interface\n"
13241 "Display flap statistics of the routes learned from neighbor\n"
13242 "JavaScript Object Notation\n")
13243 {
13244 struct peer *peer;
13245 u_char uj = use_json(argc, argv);
13246
13247 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13248 if (! peer)
13249 return CMD_WARNING;
13250
13251 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13252 bgp_show_type_flap_neighbor, uj);
13253 }
13254
13255 DEFUN (show_ip_bgp_neighbor_damp,
13256 show_ip_bgp_neighbor_damp_cmd,
13257 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13258 SHOW_STR
13259 IP_STR
13260 BGP_STR
13261 "Detailed information on TCP and BGP neighbor connections\n"
13262 "Neighbor to display information about\n"
13263 "Neighbor to display information about\n"
13264 "Neighbor on bgp configured interface\n"
13265 "Display the dampened routes received from neighbor\n"
13266 "JavaScript Object Notation\n")
13267 {
13268 struct peer *peer;
13269 u_char uj = use_json(argc, argv);
13270
13271 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13272 if (! peer)
13273 return CMD_WARNING;
13274
13275 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13276 bgp_show_type_damp_neighbor, uj);
13277 }
13278
13279 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13280 show_ip_bgp_ipv4_neighbor_routes_cmd,
13281 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13282 SHOW_STR
13283 IP_STR
13284 BGP_STR
13285 "Address family\n"
13286 "Address Family modifier\n"
13287 "Address Family modifier\n"
13288 "Detailed information on TCP and BGP neighbor connections\n"
13289 "Neighbor to display information about\n"
13290 "Neighbor to display information about\n"
13291 "Neighbor on bgp configured interface\n"
13292 "Display routes learned from neighbor\n"
13293 "JavaScript Object Notation\n")
13294 {
13295 struct peer *peer;
13296 u_char uj = use_json(argc, argv);
13297
13298 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13299 if (! peer)
13300 return CMD_WARNING;
13301
13302 if (strncmp (argv[0], "m", 1) == 0)
13303 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13304 bgp_show_type_neighbor, uj);
13305
13306 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13307 bgp_show_type_neighbor, uj);
13308 }
13309
13310 #ifdef HAVE_IPV6
13311 DEFUN (show_bgp_instance_neighbor_routes,
13312 show_bgp_instance_neighbor_routes_cmd,
13313 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13314 SHOW_STR
13315 BGP_STR
13316 BGP_INSTANCE_HELP_STR
13317 "Detailed information on TCP and BGP neighbor connections\n"
13318 "Neighbor to display information about\n"
13319 "Neighbor to display information about\n"
13320 "Neighbor on bgp configured interface\n"
13321 "Display routes learned from neighbor\n"
13322 "JavaScript Object Notation\n")
13323 {
13324 struct peer *peer;
13325 u_char uj = use_json(argc, argv);
13326
13327 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13328 if (! peer)
13329 return CMD_WARNING;
13330
13331 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13332 bgp_show_type_neighbor, uj);
13333 }
13334
13335 ALIAS (show_bgp_instance_neighbor_routes,
13336 show_bgp_instance_ipv6_neighbor_routes_cmd,
13337 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13338 SHOW_STR
13339 BGP_STR
13340 BGP_INSTANCE_HELP_STR
13341 "Address family\n"
13342 "Detailed information on TCP and BGP neighbor connections\n"
13343 "Neighbor to display information about\n"
13344 "Neighbor to display information about\n"
13345 "Neighbor on bgp configured interface\n"
13346 "Display routes learned from neighbor\n"
13347 "JavaScript Object Notation\n")
13348
13349 DEFUN (show_bgp_instance_neighbor_damp,
13350 show_bgp_instance_neighbor_damp_cmd,
13351 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13352 SHOW_STR
13353 BGP_STR
13354 BGP_INSTANCE_HELP_STR
13355 "Detailed information on TCP and BGP neighbor connections\n"
13356 "Neighbor to display information about\n"
13357 "Neighbor to display information about\n"
13358 "Neighbor on bgp configured interface\n"
13359 "Display the dampened routes received from neighbor\n"
13360 "JavaScript Object Notation\n")
13361 {
13362 struct peer *peer;
13363 u_char uj = use_json(argc, argv);
13364
13365 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13366 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13367 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13368 else
13369 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13370
13371 if (! peer)
13372 return CMD_WARNING;
13373
13374 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13375 bgp_show_type_damp_neighbor, uj);
13376 }
13377
13378 ALIAS (show_bgp_instance_neighbor_damp,
13379 show_bgp_instance_ipv6_neighbor_damp_cmd,
13380 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13381 SHOW_STR
13382 BGP_STR
13383 BGP_INSTANCE_HELP_STR
13384 "Address family\n"
13385 "Detailed information on TCP and BGP neighbor connections\n"
13386 "Neighbor to display information about\n"
13387 "Neighbor to display information about\n"
13388 "Neighbor on bgp configured interface\n"
13389 "Display the dampened routes received from neighbor\n"
13390 "JavaScript Object Notation\n")
13391
13392 DEFUN (show_bgp_instance_neighbor_flap,
13393 show_bgp_instance_neighbor_flap_cmd,
13394 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13395 SHOW_STR
13396 BGP_STR
13397 BGP_INSTANCE_HELP_STR
13398 "Detailed information on TCP and BGP neighbor connections\n"
13399 "Neighbor to display information about\n"
13400 "Neighbor to display information about\n"
13401 "Neighbor on bgp configured interface\n"
13402 "Display flap statistics of the routes learned from neighbor\n"
13403 "JavaScript Object Notation\n")
13404 {
13405 struct peer *peer;
13406 u_char uj = use_json(argc, argv);
13407
13408 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13409 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13410 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13411 else
13412 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13413
13414 if (! peer)
13415 return CMD_WARNING;
13416
13417 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13418 bgp_show_type_flap_neighbor, uj);
13419 }
13420
13421 ALIAS (show_bgp_instance_neighbor_flap,
13422 show_bgp_instance_ipv6_neighbor_flap_cmd,
13423 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13424 SHOW_STR
13425 BGP_STR
13426 BGP_INSTANCE_HELP_STR
13427 "Address family\n"
13428 "Detailed information on TCP and BGP neighbor connections\n"
13429 "Neighbor to display information about\n"
13430 "Neighbor to display information about\n"
13431 "Neighbor on bgp configured interface\n"
13432 "Display flap statistics of the routes learned from neighbor\n"
13433 "JavaScript Object Notation\n")
13434
13435 DEFUN (show_bgp_neighbor_routes,
13436 show_bgp_neighbor_routes_cmd,
13437 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13438 SHOW_STR
13439 BGP_STR
13440 "Detailed information on TCP and BGP neighbor connections\n"
13441 "Neighbor to display information about\n"
13442 "Neighbor to display information about\n"
13443 "Neighbor on bgp configured interface\n"
13444 "Display routes learned from neighbor\n"
13445 "JavaScript Object Notation\n")
13446 {
13447 struct peer *peer;
13448 u_char uj = use_json(argc, argv);
13449
13450 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13451 if (! peer)
13452 return CMD_WARNING;
13453
13454 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13455 bgp_show_type_neighbor, uj);
13456 }
13457
13458
13459 ALIAS (show_bgp_neighbor_routes,
13460 show_bgp_ipv6_neighbor_routes_cmd,
13461 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13462 SHOW_STR
13463 BGP_STR
13464 "Address family\n"
13465 "Detailed information on TCP and BGP neighbor connections\n"
13466 "Neighbor to display information about\n"
13467 "Neighbor to display information about\n"
13468 "Neighbor on bgp configured interface\n"
13469 "Display routes learned from neighbor\n"
13470 "JavaScript Object Notation\n")
13471
13472 /* old command */
13473 ALIAS (show_bgp_neighbor_routes,
13474 ipv6_bgp_neighbor_routes_cmd,
13475 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13476 SHOW_STR
13477 IPV6_STR
13478 BGP_STR
13479 "Detailed information on TCP and BGP neighbor connections\n"
13480 "Neighbor to display information about\n"
13481 "Neighbor to display information about\n"
13482 "Neighbor on bgp configured interface\n"
13483 "Display routes learned from neighbor\n"
13484 "JavaScript Object Notation\n")
13485
13486 /* old command */
13487 DEFUN (ipv6_mbgp_neighbor_routes,
13488 ipv6_mbgp_neighbor_routes_cmd,
13489 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13490 SHOW_STR
13491 IPV6_STR
13492 MBGP_STR
13493 "Detailed information on TCP and BGP neighbor connections\n"
13494 "Neighbor to display information about\n"
13495 "Neighbor to display information about\n"
13496 "Neighbor on bgp configured interface\n"
13497 "Display routes learned from neighbor\n"
13498 "JavaScript Object Notation\n")
13499 {
13500 struct peer *peer;
13501 u_char uj = use_json(argc, argv);
13502
13503 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13504 if (! peer)
13505 return CMD_WARNING;
13506
13507 bgp_show_ipv6_bgp_deprecate_warning(vty);
13508 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
13509 bgp_show_type_neighbor, uj);
13510 }
13511
13512 ALIAS (show_bgp_instance_neighbor_flap,
13513 show_bgp_neighbor_flap_cmd,
13514 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13515 SHOW_STR
13516 BGP_STR
13517 "Detailed information on TCP and BGP neighbor connections\n"
13518 "Neighbor to display information about\n"
13519 "Neighbor to display information about\n"
13520 "Neighbor on bgp configured interface\n"
13521 "Display flap statistics of the routes learned from neighbor\n"
13522 "JavaScript Object Notation\n")
13523
13524 ALIAS (show_bgp_instance_neighbor_flap,
13525 show_bgp_ipv6_neighbor_flap_cmd,
13526 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13527 SHOW_STR
13528 BGP_STR
13529 "Address family\n"
13530 "Detailed information on TCP and BGP neighbor connections\n"
13531 "Neighbor to display information about\n"
13532 "Neighbor to display information about\n"
13533 "Neighbor on bgp configured interface\n"
13534 "Display flap statistics of the routes learned from neighbor\n"
13535 "JavaScript Object Notation\n")
13536
13537 ALIAS (show_bgp_instance_neighbor_damp,
13538 show_bgp_neighbor_damp_cmd,
13539 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13540 SHOW_STR
13541 BGP_STR
13542 "Detailed information on TCP and BGP neighbor connections\n"
13543 "Neighbor to display information about\n"
13544 "Neighbor to display information about\n"
13545 "Neighbor on bgp configured interface\n"
13546 "Display the dampened routes received from neighbor\n"
13547 "JavaScript Object Notation\n")
13548
13549 ALIAS (show_bgp_instance_neighbor_damp,
13550 show_bgp_ipv6_neighbor_damp_cmd,
13551 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13552 SHOW_STR
13553 BGP_STR
13554 "Address family\n"
13555 "Detailed information on TCP and BGP neighbor connections\n"
13556 "Neighbor to display information about\n"
13557 "Neighbor to display information about\n"
13558 "Neighbor on bgp configured interface\n"
13559 "Display the dampened routes received from neighbor\n"
13560 "JavaScript Object Notation\n")
13561
13562 #endif /* HAVE_IPV6 */
13563
13564 struct bgp_table *bgp_distance_table;
13565
13566 struct bgp_distance
13567 {
13568 /* Distance value for the IP source prefix. */
13569 u_char distance;
13570
13571 /* Name of the access-list to be matched. */
13572 char *access_list;
13573 };
13574
13575 static struct bgp_distance *
13576 bgp_distance_new (void)
13577 {
13578 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
13579 }
13580
13581 static void
13582 bgp_distance_free (struct bgp_distance *bdistance)
13583 {
13584 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13585 }
13586
13587 static int
13588 bgp_distance_set (struct vty *vty, const char *distance_str,
13589 const char *ip_str, const char *access_list_str)
13590 {
13591 int ret;
13592 struct prefix_ipv4 p;
13593 u_char distance;
13594 struct bgp_node *rn;
13595 struct bgp_distance *bdistance;
13596
13597 ret = str2prefix_ipv4 (ip_str, &p);
13598 if (ret == 0)
13599 {
13600 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13601 return CMD_WARNING;
13602 }
13603
13604 distance = atoi (distance_str);
13605
13606 /* Get BGP distance node. */
13607 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
13608 if (rn->info)
13609 {
13610 bdistance = rn->info;
13611 bgp_unlock_node (rn);
13612 }
13613 else
13614 {
13615 bdistance = bgp_distance_new ();
13616 rn->info = bdistance;
13617 }
13618
13619 /* Set distance value. */
13620 bdistance->distance = distance;
13621
13622 /* Reset access-list configuration. */
13623 if (bdistance->access_list)
13624 {
13625 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13626 bdistance->access_list = NULL;
13627 }
13628 if (access_list_str)
13629 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
13630
13631 return CMD_SUCCESS;
13632 }
13633
13634 static int
13635 bgp_distance_unset (struct vty *vty, const char *distance_str,
13636 const char *ip_str, const char *access_list_str)
13637 {
13638 int ret;
13639 int distance;
13640 struct prefix_ipv4 p;
13641 struct bgp_node *rn;
13642 struct bgp_distance *bdistance;
13643
13644 ret = str2prefix_ipv4 (ip_str, &p);
13645 if (ret == 0)
13646 {
13647 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13648 return CMD_WARNING;
13649 }
13650
13651 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
13652 if (! rn)
13653 {
13654 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13655 return CMD_WARNING;
13656 }
13657
13658 bdistance = rn->info;
13659 distance = atoi(distance_str);
13660
13661 if (bdistance->distance != distance)
13662 {
13663 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
13664 return CMD_WARNING;
13665 }
13666
13667 if (bdistance->access_list)
13668 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13669 bgp_distance_free (bdistance);
13670
13671 rn->info = NULL;
13672 bgp_unlock_node (rn);
13673 bgp_unlock_node (rn);
13674
13675 return CMD_SUCCESS;
13676 }
13677
13678 /* Apply BGP information to distance method. */
13679 u_char
13680 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
13681 {
13682 struct bgp_node *rn;
13683 struct prefix_ipv4 q;
13684 struct peer *peer;
13685 struct bgp_distance *bdistance;
13686 struct access_list *alist;
13687 struct bgp_static *bgp_static;
13688
13689 if (! bgp)
13690 return 0;
13691
13692 if (p->family != AF_INET)
13693 return 0;
13694
13695 peer = rinfo->peer;
13696
13697 if (peer->su.sa.sa_family != AF_INET)
13698 return 0;
13699
13700 memset (&q, 0, sizeof (struct prefix_ipv4));
13701 q.family = AF_INET;
13702 q.prefix = peer->su.sin.sin_addr;
13703 q.prefixlen = IPV4_MAX_BITLEN;
13704
13705 /* Check source address. */
13706 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
13707 if (rn)
13708 {
13709 bdistance = rn->info;
13710 bgp_unlock_node (rn);
13711
13712 if (bdistance->access_list)
13713 {
13714 alist = access_list_lookup (AFI_IP, bdistance->access_list);
13715 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13716 return bdistance->distance;
13717 }
13718 else
13719 return bdistance->distance;
13720 }
13721
13722 /* Backdoor check. */
13723 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
13724 if (rn)
13725 {
13726 bgp_static = rn->info;
13727 bgp_unlock_node (rn);
13728
13729 if (bgp_static->backdoor)
13730 {
13731 if (bgp->distance_local)
13732 return bgp->distance_local;
13733 else
13734 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13735 }
13736 }
13737
13738 if (peer->sort == BGP_PEER_EBGP)
13739 {
13740 if (bgp->distance_ebgp)
13741 return bgp->distance_ebgp;
13742 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13743 }
13744 else
13745 {
13746 if (bgp->distance_ibgp)
13747 return bgp->distance_ibgp;
13748 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13749 }
13750 }
13751
13752 DEFUN (bgp_distance,
13753 bgp_distance_cmd,
13754 "distance bgp <1-255> <1-255> <1-255>",
13755 "Define an administrative distance\n"
13756 "BGP distance\n"
13757 "Distance for routes external to the AS\n"
13758 "Distance for routes internal to the AS\n"
13759 "Distance for local routes\n")
13760 {
13761 struct bgp *bgp;
13762
13763 bgp = vty->index;
13764
13765 bgp->distance_ebgp = atoi (argv[0]);
13766 bgp->distance_ibgp = atoi (argv[1]);
13767 bgp->distance_local = atoi (argv[2]);
13768 return CMD_SUCCESS;
13769 }
13770
13771 DEFUN (no_bgp_distance,
13772 no_bgp_distance_cmd,
13773 "no distance bgp <1-255> <1-255> <1-255>",
13774 NO_STR
13775 "Define an administrative distance\n"
13776 "BGP distance\n"
13777 "Distance for routes external to the AS\n"
13778 "Distance for routes internal to the AS\n"
13779 "Distance for local routes\n")
13780 {
13781 struct bgp *bgp;
13782
13783 bgp = vty->index;
13784
13785 bgp->distance_ebgp= 0;
13786 bgp->distance_ibgp = 0;
13787 bgp->distance_local = 0;
13788 return CMD_SUCCESS;
13789 }
13790
13791 ALIAS (no_bgp_distance,
13792 no_bgp_distance2_cmd,
13793 "no distance bgp",
13794 NO_STR
13795 "Define an administrative distance\n"
13796 "BGP distance\n")
13797
13798 DEFUN (bgp_distance_source,
13799 bgp_distance_source_cmd,
13800 "distance <1-255> A.B.C.D/M",
13801 "Define an administrative distance\n"
13802 "Administrative distance\n"
13803 "IP source prefix\n")
13804 {
13805 bgp_distance_set (vty, argv[0], argv[1], NULL);
13806 return CMD_SUCCESS;
13807 }
13808
13809 DEFUN (no_bgp_distance_source,
13810 no_bgp_distance_source_cmd,
13811 "no distance <1-255> A.B.C.D/M",
13812 NO_STR
13813 "Define an administrative distance\n"
13814 "Administrative distance\n"
13815 "IP source prefix\n")
13816 {
13817 bgp_distance_unset (vty, argv[0], argv[1], NULL);
13818 return CMD_SUCCESS;
13819 }
13820
13821 DEFUN (bgp_distance_source_access_list,
13822 bgp_distance_source_access_list_cmd,
13823 "distance <1-255> A.B.C.D/M WORD",
13824 "Define an administrative distance\n"
13825 "Administrative distance\n"
13826 "IP source prefix\n"
13827 "Access list name\n")
13828 {
13829 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
13830 return CMD_SUCCESS;
13831 }
13832
13833 DEFUN (no_bgp_distance_source_access_list,
13834 no_bgp_distance_source_access_list_cmd,
13835 "no distance <1-255> A.B.C.D/M WORD",
13836 NO_STR
13837 "Define an administrative distance\n"
13838 "Administrative distance\n"
13839 "IP source prefix\n"
13840 "Access list name\n")
13841 {
13842 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
13843 return CMD_SUCCESS;
13844 }
13845
13846 DEFUN (bgp_damp_set,
13847 bgp_damp_set_cmd,
13848 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13849 "BGP Specific commands\n"
13850 "Enable route-flap dampening\n"
13851 "Half-life time for the penalty\n"
13852 "Value to start reusing a route\n"
13853 "Value to start suppressing a route\n"
13854 "Maximum duration to suppress a stable route\n")
13855 {
13856 struct bgp *bgp;
13857 int half = DEFAULT_HALF_LIFE * 60;
13858 int reuse = DEFAULT_REUSE;
13859 int suppress = DEFAULT_SUPPRESS;
13860 int max = 4 * half;
13861
13862 if (argc == 4)
13863 {
13864 half = atoi (argv[0]) * 60;
13865 reuse = atoi (argv[1]);
13866 suppress = atoi (argv[2]);
13867 max = atoi (argv[3]) * 60;
13868 }
13869 else if (argc == 1)
13870 {
13871 half = atoi (argv[0]) * 60;
13872 max = 4 * half;
13873 }
13874
13875 bgp = vty->index;
13876
13877 if (suppress < reuse)
13878 {
13879 vty_out (vty, "Suppress value cannot be less than reuse value %s",
13880 VTY_NEWLINE);
13881 return 0;
13882 }
13883
13884 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
13885 half, reuse, suppress, max);
13886 }
13887
13888 ALIAS (bgp_damp_set,
13889 bgp_damp_set2_cmd,
13890 "bgp dampening <1-45>",
13891 "BGP Specific commands\n"
13892 "Enable route-flap dampening\n"
13893 "Half-life time for the penalty\n")
13894
13895 ALIAS (bgp_damp_set,
13896 bgp_damp_set3_cmd,
13897 "bgp dampening",
13898 "BGP Specific commands\n"
13899 "Enable route-flap dampening\n")
13900
13901 DEFUN (bgp_damp_unset,
13902 bgp_damp_unset_cmd,
13903 "no bgp dampening",
13904 NO_STR
13905 "BGP Specific commands\n"
13906 "Enable route-flap dampening\n")
13907 {
13908 struct bgp *bgp;
13909
13910 bgp = vty->index;
13911 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
13912 }
13913
13914 ALIAS (bgp_damp_unset,
13915 bgp_damp_unset2_cmd,
13916 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13917 NO_STR
13918 "BGP Specific commands\n"
13919 "Enable route-flap dampening\n"
13920 "Half-life time for the penalty\n"
13921 "Value to start reusing a route\n"
13922 "Value to start suppressing a route\n"
13923 "Maximum duration to suppress a stable route\n")
13924
13925 ALIAS (bgp_damp_unset,
13926 bgp_damp_unset3_cmd,
13927 "no bgp dampening <1-45>",
13928 NO_STR
13929 "BGP Specific commands\n"
13930 "Enable route-flap dampening\n"
13931 "Half-life time for the penalty\n")
13932
13933 DEFUN (show_ip_bgp_dampened_paths,
13934 show_ip_bgp_dampened_paths_cmd,
13935 "show ip bgp dampened-paths",
13936 SHOW_STR
13937 IP_STR
13938 BGP_STR
13939 "Display paths suppressed due to dampening\n")
13940 {
13941 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
13942 NULL, 0);
13943 }
13944
13945 ALIAS (show_ip_bgp_dampened_paths,
13946 show_ip_bgp_damp_dampened_paths_cmd,
13947 "show ip bgp dampening dampened-paths",
13948 SHOW_STR
13949 IP_STR
13950 BGP_STR
13951 "Display detailed information about dampening\n"
13952 "Display paths suppressed due to dampening\n")
13953
13954 DEFUN (show_ip_bgp_flap_statistics,
13955 show_ip_bgp_flap_statistics_cmd,
13956 "show ip bgp flap-statistics",
13957 SHOW_STR
13958 IP_STR
13959 BGP_STR
13960 "Display flap statistics of routes\n")
13961 {
13962 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
13963 bgp_show_type_flap_statistics, NULL, 0);
13964 }
13965
13966 ALIAS (show_ip_bgp_flap_statistics,
13967 show_ip_bgp_damp_flap_statistics_cmd,
13968 "show ip bgp dampening flap-statistics",
13969 SHOW_STR
13970 IP_STR
13971 BGP_STR
13972 "Display detailed information about dampening\n"
13973 "Display flap statistics of routes\n")
13974
13975 /* Display specified route of BGP table. */
13976 static int
13977 bgp_clear_damp_route (struct vty *vty, const char *view_name,
13978 const char *ip_str, afi_t afi, safi_t safi,
13979 struct prefix_rd *prd, int prefix_check)
13980 {
13981 int ret;
13982 struct prefix match;
13983 struct bgp_node *rn;
13984 struct bgp_node *rm;
13985 struct bgp_info *ri;
13986 struct bgp_info *ri_temp;
13987 struct bgp *bgp;
13988 struct bgp_table *table;
13989
13990 /* BGP structure lookup. */
13991 if (view_name)
13992 {
13993 bgp = bgp_lookup_by_name (view_name);
13994 if (bgp == NULL)
13995 {
13996 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
13997 return CMD_WARNING;
13998 }
13999 }
14000 else
14001 {
14002 bgp = bgp_get_default ();
14003 if (bgp == NULL)
14004 {
14005 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14006 return CMD_WARNING;
14007 }
14008 }
14009
14010 /* Check IP address argument. */
14011 ret = str2prefix (ip_str, &match);
14012 if (! ret)
14013 {
14014 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14015 return CMD_WARNING;
14016 }
14017
14018 match.family = afi2family (afi);
14019
14020 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
14021 {
14022 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
14023 {
14024 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14025 continue;
14026
14027 if ((table = rn->info) != NULL)
14028 if ((rm = bgp_node_match (table, &match)) != NULL)
14029 {
14030 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14031 {
14032 ri = rm->info;
14033 while (ri)
14034 {
14035 if (ri->extra && ri->extra->damp_info)
14036 {
14037 ri_temp = ri->next;
14038 bgp_damp_info_free (ri->extra->damp_info, 1);
14039 ri = ri_temp;
14040 }
14041 else
14042 ri = ri->next;
14043 }
14044 }
14045
14046 bgp_unlock_node (rm);
14047 }
14048 }
14049 }
14050 else
14051 {
14052 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
14053 {
14054 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14055 {
14056 ri = rn->info;
14057 while (ri)
14058 {
14059 if (ri->extra && ri->extra->damp_info)
14060 {
14061 ri_temp = ri->next;
14062 bgp_damp_info_free (ri->extra->damp_info, 1);
14063 ri = ri_temp;
14064 }
14065 else
14066 ri = ri->next;
14067 }
14068 }
14069
14070 bgp_unlock_node (rn);
14071 }
14072 }
14073
14074 return CMD_SUCCESS;
14075 }
14076
14077 DEFUN (clear_ip_bgp_dampening,
14078 clear_ip_bgp_dampening_cmd,
14079 "clear ip bgp dampening",
14080 CLEAR_STR
14081 IP_STR
14082 BGP_STR
14083 "Clear route flap dampening information\n")
14084 {
14085 bgp_damp_info_clean ();
14086 return CMD_SUCCESS;
14087 }
14088
14089 DEFUN (clear_ip_bgp_dampening_prefix,
14090 clear_ip_bgp_dampening_prefix_cmd,
14091 "clear ip bgp dampening A.B.C.D/M",
14092 CLEAR_STR
14093 IP_STR
14094 BGP_STR
14095 "Clear route flap dampening information\n"
14096 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14097 {
14098 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14099 SAFI_UNICAST, NULL, 1);
14100 }
14101
14102 DEFUN (clear_ip_bgp_dampening_address,
14103 clear_ip_bgp_dampening_address_cmd,
14104 "clear ip bgp dampening A.B.C.D",
14105 CLEAR_STR
14106 IP_STR
14107 BGP_STR
14108 "Clear route flap dampening information\n"
14109 "Network to clear damping information\n")
14110 {
14111 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14112 SAFI_UNICAST, NULL, 0);
14113 }
14114
14115 DEFUN (clear_ip_bgp_dampening_address_mask,
14116 clear_ip_bgp_dampening_address_mask_cmd,
14117 "clear ip bgp dampening A.B.C.D A.B.C.D",
14118 CLEAR_STR
14119 IP_STR
14120 BGP_STR
14121 "Clear route flap dampening information\n"
14122 "Network to clear damping information\n"
14123 "Network mask\n")
14124 {
14125 int ret;
14126 char prefix_str[BUFSIZ];
14127
14128 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14129 if (! ret)
14130 {
14131 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14132 return CMD_WARNING;
14133 }
14134
14135 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14136 SAFI_UNICAST, NULL, 0);
14137 }
14138
14139 /* also used for encap safi */
14140 static int
14141 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14142 afi_t afi, safi_t safi, int *write)
14143 {
14144 struct bgp_node *prn;
14145 struct bgp_node *rn;
14146 struct bgp_table *table;
14147 struct prefix *p;
14148 struct prefix_rd *prd;
14149 struct bgp_static *bgp_static;
14150 u_int32_t label;
14151 char buf[SU_ADDRSTRLEN];
14152 char rdbuf[RD_ADDRSTRLEN];
14153
14154 /* Network configuration. */
14155 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14156 if ((table = prn->info) != NULL)
14157 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14158 if ((bgp_static = rn->info) != NULL)
14159 {
14160 p = &rn->p;
14161 prd = (struct prefix_rd *) &prn->p;
14162
14163 /* "address-family" display. */
14164 bgp_config_write_family_header (vty, afi, safi, write);
14165
14166 /* "network" configuration display. */
14167 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14168 label = decode_label (bgp_static->tag);
14169
14170 vty_out (vty, " network %s/%d rd %s tag %d",
14171 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14172 p->prefixlen,
14173 rdbuf, label);
14174 vty_out (vty, "%s", VTY_NEWLINE);
14175 }
14176 return 0;
14177 }
14178
14179 /* Configuration of static route announcement and aggregate
14180 information. */
14181 int
14182 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14183 afi_t afi, safi_t safi, int *write)
14184 {
14185 struct bgp_node *rn;
14186 struct prefix *p;
14187 struct bgp_static *bgp_static;
14188 struct bgp_aggregate *bgp_aggregate;
14189 char buf[SU_ADDRSTRLEN];
14190
14191 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
14192 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14193
14194 /* Network configuration. */
14195 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14196 if ((bgp_static = rn->info) != NULL)
14197 {
14198 p = &rn->p;
14199
14200 /* "address-family" display. */
14201 bgp_config_write_family_header (vty, afi, safi, write);
14202
14203 /* "network" configuration display. */
14204 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14205 {
14206 u_int32_t destination;
14207 struct in_addr netmask;
14208
14209 destination = ntohl (p->u.prefix4.s_addr);
14210 masklen2ip (p->prefixlen, &netmask);
14211 vty_out (vty, " network %s",
14212 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14213
14214 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14215 || (IN_CLASSB (destination) && p->prefixlen == 16)
14216 || (IN_CLASSA (destination) && p->prefixlen == 8)
14217 || p->u.prefix4.s_addr == 0)
14218 {
14219 /* Natural mask is not display. */
14220 }
14221 else
14222 vty_out (vty, " mask %s", inet_ntoa (netmask));
14223 }
14224 else
14225 {
14226 vty_out (vty, " network %s/%d",
14227 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14228 p->prefixlen);
14229 }
14230
14231 if (bgp_static->rmap.name)
14232 vty_out (vty, " route-map %s", bgp_static->rmap.name);
14233 else
14234 {
14235 if (bgp_static->backdoor)
14236 vty_out (vty, " backdoor");
14237 }
14238
14239 vty_out (vty, "%s", VTY_NEWLINE);
14240 }
14241
14242 /* Aggregate-address configuration. */
14243 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14244 if ((bgp_aggregate = rn->info) != NULL)
14245 {
14246 p = &rn->p;
14247
14248 /* "address-family" display. */
14249 bgp_config_write_family_header (vty, afi, safi, write);
14250
14251 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14252 {
14253 struct in_addr netmask;
14254
14255 masklen2ip (p->prefixlen, &netmask);
14256 vty_out (vty, " aggregate-address %s %s",
14257 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14258 inet_ntoa (netmask));
14259 }
14260 else
14261 {
14262 vty_out (vty, " aggregate-address %s/%d",
14263 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14264 p->prefixlen);
14265 }
14266
14267 if (bgp_aggregate->as_set)
14268 vty_out (vty, " as-set");
14269
14270 if (bgp_aggregate->summary_only)
14271 vty_out (vty, " summary-only");
14272
14273 vty_out (vty, "%s", VTY_NEWLINE);
14274 }
14275
14276 return 0;
14277 }
14278
14279 int
14280 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
14281 {
14282 struct bgp_node *rn;
14283 struct bgp_distance *bdistance;
14284
14285 /* Distance configuration. */
14286 if (bgp->distance_ebgp
14287 && bgp->distance_ibgp
14288 && bgp->distance_local
14289 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
14290 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
14291 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
14292 vty_out (vty, " distance bgp %d %d %d%s",
14293 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
14294 VTY_NEWLINE);
14295
14296 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
14297 if ((bdistance = rn->info) != NULL)
14298 {
14299 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
14300 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
14301 bdistance->access_list ? bdistance->access_list : "",
14302 VTY_NEWLINE);
14303 }
14304
14305 return 0;
14306 }
14307
14308 /* Allocate routing table structure and install commands. */
14309 void
14310 bgp_route_init (void)
14311 {
14312 /* Init BGP distance table. */
14313 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
14314
14315 /* IPv4 BGP commands. */
14316 install_element (BGP_NODE, &bgp_table_map_cmd);
14317 install_element (BGP_NODE, &bgp_network_cmd);
14318 install_element (BGP_NODE, &bgp_network_mask_cmd);
14319 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14320 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14321 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14322 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14323 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14324 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14325 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
14326 install_element (BGP_NODE, &no_bgp_table_map_cmd);
14327 install_element (BGP_NODE, &no_bgp_network_cmd);
14328 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14329 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14330 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14331 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14332 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14333 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14334 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14335 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14336
14337 install_element (BGP_NODE, &aggregate_address_cmd);
14338 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14339 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14340 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14341 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14342 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14343 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14344 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14345 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14346 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14347 install_element (BGP_NODE, &no_aggregate_address_cmd);
14348 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14349 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14350 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14351 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14352 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14353 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14354 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14355 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14356 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14357
14358 /* IPv4 unicast configuration. */
14359 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
14360 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14361 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14362 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14363 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14364 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14365 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
14366 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
14367 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
14368 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14369 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14370 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14371 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14372 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14373
14374 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14375 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14376 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14377 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14378 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14379 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14380 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14381 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14382 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14383 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14384 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14385 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14386 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14387 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14388 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14389 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14390 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14391 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14392 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14393 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14394
14395 /* IPv4 multicast configuration. */
14396 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
14397 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14398 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14399 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14400 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14401 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14402 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
14403 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
14404 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14405 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14406 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14407 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14408 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14409 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14410 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14411 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14412 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14413 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14414 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14415 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14416 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14417 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14418 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14419 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14420 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14421 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14422 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14423 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14424 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14425 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14426 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14427 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14428 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14429 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14430
14431 install_element (VIEW_NODE, &show_ip_bgp_cmd);
14432 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
14433 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
14434 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
14435 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
14436 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
14437 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
14438 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14439 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14440 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14441 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
14442 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
14443 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14444 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14445 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14446 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
14447 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14448 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14449 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14450 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14451 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14452 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14453 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14454 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14455
14456 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14457 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14458 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14459 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14460 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14461 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14462 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
14463 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14464 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14465 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
14466 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14467 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14468 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14469 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14470 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14471 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14472 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14473 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14474 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14475 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14476 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14477 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14478 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
14479 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14480 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14481 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14482 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14483 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14484 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14485 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14486 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14487 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14488 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14489 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14490 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14491 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14492 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14493 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
14494 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14495 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14496 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14497 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14498 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14499 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14500 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14501 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14502 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14503 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14505 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14506 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14507 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14508 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14509 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14512 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14513 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
14514 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14516 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14518 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
14519 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14520 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
14521 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14522 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
14523 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14524 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
14525 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14526 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14527 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
14528 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14529 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14530 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
14531 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14532 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14533 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14534 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
14535 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14536 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
14537 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14538 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
14539
14540 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
14541 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
14542 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14543 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
14544 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14545 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14546 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
14547 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
14548 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14549 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
14550 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
14551 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14552 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14553 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14554 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14555 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14556 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14557 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14558 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14559 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14560 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
14561 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
14562 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
14563 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
14564 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
14565 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
14566 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
14567 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
14568 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
14569 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14570 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_cmd);
14571 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14572 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14573 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14574 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
14575 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
14576 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
14577 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
14578 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14579 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14580 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14581 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14582
14583 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
14584 install_element (ENABLE_NODE, &show_ip_bgp_instance_cmd);
14585 install_element (ENABLE_NODE, &show_ip_bgp_instance_all_cmd);
14586 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
14587 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
14588 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
14589 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_cmd);
14590 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
14591 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14592 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14593 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
14594 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
14595 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14596 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14597 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
14598 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_cmd);
14599 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14600 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14601 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14602 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14603 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14604 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14605 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14606 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14607
14608 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
14609 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14610 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
14611 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14613 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
14614 install_element (ENABLE_NODE, &show_ip_bgp_instance_filter_list_cmd);
14615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14616 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
14617 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_map_cmd);
14618 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14619 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
14620 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14621 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
14622 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14623 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
14624 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
14625 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
14626 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
14627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
14628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
14629 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
14630 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
14631 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14632 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_cmd);
14633 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14634 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14635 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14636 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
14637 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
14638 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
14639 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
14640 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14641 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14642 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14643 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14644 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
14645 install_element (ENABLE_NODE, &show_ip_bgp_instance_community_list_cmd);
14646 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14647 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
14648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14649 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
14650 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14652 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14653 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14654 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14655 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14657 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14658 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14659 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14660 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14661 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14663 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14664 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14665 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
14666 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14667 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14668 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14669 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14670 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
14671 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
14672 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
14673 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
14674 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
14675 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
14676 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
14677 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
14678 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14679 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
14680 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
14681 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
14682 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
14683 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
14684 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14685 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14686 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14687 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14688 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
14689 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
14690 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
14691 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
14692 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
14693
14694 /* BGP dampening clear commands */
14695 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14696 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14697 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14698 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14699
14700 /* prefix count */
14701 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14702 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
14703 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14704 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
14705 #ifdef HAVE_IPV6
14706 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14707 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
14708
14709 /* New config IPv6 BGP commands. */
14710 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
14711 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14712 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
14713 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
14714 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14715 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14716
14717 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14718 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14719 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14720 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
14721
14722 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14723 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
14724
14725 /* Old config IPv6 BGP commands. */
14726 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14727 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14728
14729 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14730 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14731 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14732 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14733
14734 install_element (VIEW_NODE, &show_bgp_cmd);
14735 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
14736 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
14737 install_element (VIEW_NODE, &show_bgp_route_cmd);
14738 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
14739 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
14740 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14741 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14742 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14743 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14744 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
14745 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14746 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14747 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14748 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14749 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14750 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14751 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14752 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14753 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14754 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14755 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14756 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14757 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14758 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14759 install_element (VIEW_NODE, &show_bgp_community_cmd);
14760 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14761 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14762 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14763 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14764 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14765 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14766 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14767 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14768 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14769 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14770 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14771 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14772 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14773 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14774 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14775 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14776 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14777 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14778 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14779 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14780 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14781 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14782 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14783 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14784 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14785 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14786 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14787 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14788 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14789 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14790 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14791 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14792 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14793 install_element (VIEW_NODE, &show_bgp_instance_cmd);
14794 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
14795 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
14796 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
14797 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
14798 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
14799 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14800 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
14801 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14802 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14803 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14804 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
14805 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14806 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
14807 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14808 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
14809 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14810 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
14811 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14812 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
14813 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14814 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14815 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14816 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14817 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14818 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
14819 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14820 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14821 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14822 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
14823 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14824 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
14825 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
14826
14827 /* Restricted:
14828 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
14829 */
14830 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
14831 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
14832 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
14833 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
14834 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14835 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14836 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
14837 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
14838 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14839 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
14840 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14841 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14842 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
14843 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
14844 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
14845 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
14846 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
14847 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
14848 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
14849 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
14850 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
14851 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
14852 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
14853 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
14854 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
14855 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
14856 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
14857 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
14858 install_element (RESTRICTED_NODE, &show_bgp_instance_route_cmd);
14859 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_cmd);
14860 install_element (RESTRICTED_NODE, &show_bgp_instance_route_pathtype_cmd);
14861 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14862 install_element (RESTRICTED_NODE, &show_bgp_instance_prefix_cmd);
14863 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14864 install_element (RESTRICTED_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14865 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14866
14867 install_element (ENABLE_NODE, &show_bgp_cmd);
14868 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
14869 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
14870 install_element (ENABLE_NODE, &show_bgp_route_cmd);
14871 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
14872 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
14873 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
14874 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14875 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14876 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
14877 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
14878 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14879 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14880 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
14881 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14882 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
14883 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
14884 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
14885 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
14886 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
14887 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
14888 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
14889 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
14890 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
14891 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
14892 install_element (ENABLE_NODE, &show_bgp_community_cmd);
14893 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
14894 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
14895 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
14896 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
14897 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
14898 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
14899 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
14900 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
14901 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
14902 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
14903 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
14904 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
14905 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
14906 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
14907 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
14908 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
14909 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
14910 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
14911 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14912 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
14913 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14914 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
14915 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14916 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
14917 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14918 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
14919 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14920 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14921 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14922 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
14923 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14924 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
14925 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14926 install_element (ENABLE_NODE, &show_bgp_instance_cmd);
14927 install_element (ENABLE_NODE, &show_bgp_instance_all_cmd);
14928 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_cmd);
14929 install_element (ENABLE_NODE, &show_bgp_instance_route_cmd);
14930 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_cmd);
14931 install_element (ENABLE_NODE, &show_bgp_instance_route_pathtype_cmd);
14932 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14933 install_element (ENABLE_NODE, &show_bgp_instance_prefix_cmd);
14934 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14935 install_element (ENABLE_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14936 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14937 install_element (ENABLE_NODE, &show_bgp_instance_prefix_list_cmd);
14938 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14939 install_element (ENABLE_NODE, &show_bgp_instance_filter_list_cmd);
14940 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14941 install_element (ENABLE_NODE, &show_bgp_instance_route_map_cmd);
14942 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14943 install_element (ENABLE_NODE, &show_bgp_instance_community_list_cmd);
14944 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14945 install_element (ENABLE_NODE, &show_bgp_instance_prefix_longer_cmd);
14946 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14947 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14948 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14949 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14950 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14951 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_routes_cmd);
14952 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14953 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14954 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14955 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_flap_cmd);
14956 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14957 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_damp_cmd);
14958 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
14959
14960 /* Statistics */
14961 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
14962 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
14963 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
14964 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
14965
14966 /* old command */
14967 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14968 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14969 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
14970 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
14971 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
14972 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
14973 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
14974 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
14975 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
14976 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
14977 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
14978 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
14979 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
14980 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
14981 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
14982 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
14983 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14984 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14985 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
14986 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
14987 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
14988 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
14989 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14990 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
14991 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
14992 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
14993 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
14994 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
14995 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
14996 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
14997 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14998 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14999 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15000 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15001 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15002 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15003
15004 /* old command */
15005 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
15006 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
15007 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
15008 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
15009 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
15010 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
15011 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
15012 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
15013 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
15014 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
15015 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
15016 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
15017 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
15018 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
15019 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
15020 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
15021 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15022 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15023 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
15024 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
15025 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
15026 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
15027 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15028 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
15029 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
15030 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
15031 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
15032 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
15033 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
15034 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
15035 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15036 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15037 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15038 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
15039 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15040 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15041
15042 /* old command */
15043 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15044 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15045 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15046 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15047
15048 /* old command */
15049 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15050 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15051 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15052 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15053
15054 /* old command */
15055 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
15056 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
15057 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15058 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15059 #endif /* HAVE_IPV6 */
15060
15061 install_element (BGP_NODE, &bgp_distance_cmd);
15062 install_element (BGP_NODE, &no_bgp_distance_cmd);
15063 install_element (BGP_NODE, &no_bgp_distance2_cmd);
15064 install_element (BGP_NODE, &bgp_distance_source_cmd);
15065 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15066 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15067 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
15068
15069 install_element (BGP_NODE, &bgp_damp_set_cmd);
15070 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15071 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15072 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15073 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
15074 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
15075 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15076 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15077 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15078 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15079 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
15080 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
15081 }
15082
15083 void
15084 bgp_route_finish (void)
15085 {
15086 bgp_table_unlock (bgp_distance_table);
15087 bgp_distance_table = NULL;
15088 }