]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
adc6407bb9a7d1d05744b5093a7f9420de1d7be7
[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)
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)
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 bgp_info_path_with_addpath_rx_str (exist, exist_buf);
380
381 newattr = new->attr;
382 existattr = exist->attr;
383 newattre = newattr->extra;
384 existattre = existattr->extra;
385
386 /* 1. Weight check. */
387 new_weight = exist_weight = 0;
388
389 if (newattre)
390 new_weight = newattre->weight;
391 if (existattre)
392 exist_weight = existattre->weight;
393
394 if (new_weight > exist_weight)
395 {
396 if (debug)
397 zlog_debug("%s: %s wins over %s due to weight %d > %d",
398 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
399 return 1;
400 }
401
402 if (new_weight < exist_weight)
403 {
404 if (debug)
405 zlog_debug("%s: %s loses to %s due to weight %d < %d",
406 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
407 return 0;
408 }
409
410 /* 2. Local preference check. */
411 new_pref = exist_pref = bgp->default_local_pref;
412
413 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
414 new_pref = newattr->local_pref;
415 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
416 exist_pref = existattr->local_pref;
417
418 if (new_pref > exist_pref)
419 {
420 if (debug)
421 zlog_debug("%s: %s wins over %s due to localpref %d > %d",
422 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
423 return 1;
424 }
425
426 if (new_pref < exist_pref)
427 {
428 if (debug)
429 zlog_debug("%s: %s loses to %s due to localpref %d < %d",
430 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
431 return 0;
432 }
433
434 /* 3. Local route check. We prefer:
435 * - BGP_ROUTE_STATIC
436 * - BGP_ROUTE_AGGREGATE
437 * - BGP_ROUTE_REDISTRIBUTE
438 */
439 if (! (new->sub_type == BGP_ROUTE_NORMAL))
440 {
441 if (debug)
442 zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type",
443 pfx_buf, new_buf, exist_buf);
444 return 1;
445 }
446
447 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
448 {
449 if (debug)
450 zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type",
451 pfx_buf, new_buf, exist_buf);
452 return 0;
453 }
454
455 /* 4. AS path length check. */
456 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
457 {
458 int exist_hops = aspath_count_hops (existattr->aspath);
459 int exist_confeds = aspath_count_confeds (existattr->aspath);
460
461 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
462 {
463 int aspath_hops;
464
465 aspath_hops = aspath_count_hops (newattr->aspath);
466 aspath_hops += aspath_count_confeds (newattr->aspath);
467
468 if ( aspath_hops < (exist_hops + exist_confeds))
469 {
470 if (debug)
471 zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
472 pfx_buf, new_buf, exist_buf,
473 aspath_hops, (exist_hops + exist_confeds));
474 return 1;
475 }
476
477 if ( aspath_hops > (exist_hops + exist_confeds))
478 {
479 if (debug)
480 zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
481 pfx_buf, new_buf, exist_buf,
482 aspath_hops, (exist_hops + exist_confeds));
483 return 0;
484 }
485 }
486 else
487 {
488 int newhops = aspath_count_hops (newattr->aspath);
489
490 if (newhops < exist_hops)
491 {
492 if (debug)
493 zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d",
494 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
495 return 1;
496 }
497
498 if (newhops > exist_hops)
499 {
500 if (debug)
501 zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d",
502 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
503 return 0;
504 }
505 }
506 }
507
508 /* 5. Origin check. */
509 if (newattr->origin < existattr->origin)
510 {
511 if (debug)
512 zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
513 pfx_buf, new_buf, exist_buf,
514 bgp_origin_long_str[newattr->origin],
515 bgp_origin_long_str[existattr->origin]);
516 return 1;
517 }
518
519 if (newattr->origin > existattr->origin)
520 {
521 if (debug)
522 zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
523 pfx_buf, new_buf, exist_buf,
524 bgp_origin_long_str[newattr->origin],
525 bgp_origin_long_str[existattr->origin]);
526 return 0;
527 }
528
529 /* 6. MED check. */
530 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
531 && aspath_count_hops (existattr->aspath) == 0);
532 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
533 && aspath_count_confeds (existattr->aspath) > 0
534 && aspath_count_hops (newattr->aspath) == 0
535 && aspath_count_hops (existattr->aspath) == 0);
536
537 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
538 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
539 && confed_as_route)
540 || aspath_cmp_left (newattr->aspath, existattr->aspath)
541 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
542 || internal_as_route)
543 {
544 new_med = bgp_med_value (new->attr, bgp);
545 exist_med = bgp_med_value (exist->attr, bgp);
546
547 if (new_med < exist_med)
548 {
549 if (debug)
550 zlog_debug("%s: %s wins over %s due to MED %d < %d",
551 pfx_buf, new_buf, exist_buf, new_med, exist_med);
552 return 1;
553 }
554
555 if (new_med > exist_med)
556 {
557 if (debug)
558 zlog_debug("%s: %s loses to %s due to MED %d > %d",
559 pfx_buf, new_buf, exist_buf, new_med, exist_med);
560 return 0;
561 }
562 }
563
564 /* 7. Peer type check. */
565 new_sort = new->peer->sort;
566 exist_sort = exist->peer->sort;
567
568 if (new_sort == BGP_PEER_EBGP
569 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
570 {
571 if (debug)
572 zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer",
573 pfx_buf, new_buf, exist_buf);
574 return 1;
575 }
576
577 if (exist_sort == BGP_PEER_EBGP
578 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
579 {
580 if (debug)
581 zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer",
582 pfx_buf, new_buf, exist_buf);
583 return 0;
584 }
585
586 /* 8. IGP metric check. */
587 newm = existm = 0;
588
589 if (new->extra)
590 newm = new->extra->igpmetric;
591 if (exist->extra)
592 existm = exist->extra->igpmetric;
593
594 if (newm < existm)
595 {
596 if (debug)
597 zlog_debug("%s: %s wins over %s due to IGP metric %d < %d",
598 pfx_buf, new_buf, exist_buf, newm, existm);
599 ret = 1;
600 }
601
602 if (newm > existm)
603 {
604 if (debug)
605 zlog_debug("%s: %s loses to %s due to IGP metric %d > %d",
606 pfx_buf, new_buf, exist_buf, newm, existm);
607 ret = 0;
608 }
609
610 /* 9. Same IGP metric. Compare the cluster list length as
611 representative of IGP hops metric. Rewrite the metric value
612 pair (newm, existm) with the cluster list length. Prefer the
613 path with smaller cluster list length. */
614 if (newm == existm)
615 {
616 if (peer_sort (new->peer) == BGP_PEER_IBGP
617 && peer_sort (exist->peer) == BGP_PEER_IBGP
618 && CHECK_FLAG (mpath_cfg->ibgp_flags,
619 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
620 {
621 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
622 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
623
624 if (newm < existm)
625 {
626 if (debug)
627 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
628 pfx_buf, new_buf, exist_buf, newm, existm);
629 ret = 1;
630 }
631
632 if (newm > existm)
633 {
634 if (debug)
635 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
636 pfx_buf, new_buf, exist_buf, newm, existm);
637 ret = 0;
638 }
639 }
640 }
641
642 /* 10. confed-external vs. confed-internal */
643 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
644 {
645 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
646 {
647 if (debug)
648 zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer",
649 pfx_buf, new_buf, exist_buf);
650 return 1;
651 }
652
653 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
654 {
655 if (debug)
656 zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer",
657 pfx_buf, new_buf, exist_buf);
658 return 0;
659 }
660 }
661
662 /* 11. Maximum path check. */
663 if (newm == existm)
664 {
665 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
666 {
667
668 /*
669 * For the two paths, all comparison steps till IGP metric
670 * have succeeded - including AS_PATH hop count. Since 'bgp
671 * bestpath as-path multipath-relax' knob is on, we don't need
672 * an exact match of AS_PATH. Thus, mark the paths are equal.
673 * That will trigger both these paths to get into the multipath
674 * array.
675 */
676 *paths_eq = 1;
677
678 if (debug)
679 zlog_debug("%s: %s and %s are equal via multipath-relax",
680 pfx_buf, new_buf, exist_buf);
681 }
682 else if (new->peer->sort == BGP_PEER_IBGP)
683 {
684 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
685 {
686 *paths_eq = 1;
687
688 if (debug)
689 zlog_debug("%s: %s and %s are equal via matching aspaths",
690 pfx_buf, new_buf, exist_buf);
691 }
692 }
693 else if (new->peer->as == exist->peer->as)
694 {
695 *paths_eq = 1;
696
697 if (debug)
698 zlog_debug("%s: %s and %s are equal via same remote-as",
699 pfx_buf, new_buf, exist_buf);
700 }
701 }
702 else
703 {
704 /*
705 * TODO: If unequal cost ibgp multipath is enabled we can
706 * mark the paths as equal here instead of returning
707 */
708 return ret;
709 }
710
711 /* 12. If both paths are external, prefer the path that was received
712 first (the oldest one). This step minimizes route-flap, since a
713 newer path won't displace an older one, even if it was the
714 preferred route based on the additional decision criteria below. */
715 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
716 && new_sort == BGP_PEER_EBGP
717 && exist_sort == BGP_PEER_EBGP)
718 {
719 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
720 {
721 if (debug)
722 zlog_debug("%s: %s wins over %s due to oldest external",
723 pfx_buf, new_buf, exist_buf);
724 return 1;
725 }
726
727 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
728 {
729 if (debug)
730 zlog_debug("%s: %s loses to %s due to oldest external",
731 pfx_buf, new_buf, exist_buf);
732 return 0;
733 }
734 }
735
736 /* 13. Router-ID comparision. */
737 /* If one of the paths is "stale", the corresponding peer router-id will
738 * be 0 and would always win over the other path. If originator id is
739 * used for the comparision, it will decide which path is better.
740 */
741 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
742 new_id.s_addr = newattre->originator_id.s_addr;
743 else
744 new_id.s_addr = new->peer->remote_id.s_addr;
745 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
746 exist_id.s_addr = existattre->originator_id.s_addr;
747 else
748 exist_id.s_addr = exist->peer->remote_id.s_addr;
749
750 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
751 {
752 if (debug)
753 zlog_debug("%s: %s wins over %s due to Router-ID comparison",
754 pfx_buf, new_buf, exist_buf);
755 return 1;
756 }
757
758 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
759 {
760 if (debug)
761 zlog_debug("%s: %s loses to %s due to Router-ID comparison",
762 pfx_buf, new_buf, exist_buf);
763 return 0;
764 }
765
766 /* 14. Cluster length comparision. */
767 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
768 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
769
770 if (new_cluster < exist_cluster)
771 {
772 if (debug)
773 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
774 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
775 return 1;
776 }
777
778 if (new_cluster > exist_cluster)
779 {
780 if (debug)
781 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
782 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
783 return 0;
784 }
785
786 /* 15. Neighbor address comparision. */
787 /* Do this only if neither path is "stale" as stale paths do not have
788 * valid peer information (as the connection may or may not be up).
789 */
790 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
791 {
792 if (debug)
793 zlog_debug("%s: %s wins over %s due to latter path being STALE",
794 pfx_buf, new_buf, exist_buf);
795 return 1;
796 }
797
798 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
799 {
800 if (debug)
801 zlog_debug("%s: %s loses to %s due to former path being STALE",
802 pfx_buf, new_buf, exist_buf);
803 return 0;
804 }
805
806 /* locally configured routes to advertise do not have su_remote */
807 if (new->peer->su_remote == NULL)
808 return 0;
809 if (exist->peer->su_remote == NULL)
810 return 1;
811
812 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
813
814 if (ret == 1)
815 {
816 if (debug)
817 zlog_debug("%s: %s loses to %s due to Neighor IP comparison",
818 pfx_buf, new_buf, exist_buf);
819 return 0;
820 }
821
822 if (ret == -1)
823 {
824 if (debug)
825 zlog_debug("%s: %s wins over %s due to Neighor IP comparison",
826 pfx_buf, new_buf, exist_buf);
827 return 1;
828 }
829
830 if (debug)
831 zlog_debug("%s: %s wins over %s due to nothing left to compare",
832 pfx_buf, new_buf, exist_buf);
833
834 return 1;
835 }
836
837 static enum filter_type
838 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
839 afi_t afi, safi_t safi)
840 {
841 struct bgp_filter *filter;
842
843 filter = &peer->filter[afi][safi];
844
845 #define FILTER_EXIST_WARN(F,f,filter) \
846 if (BGP_DEBUG (update, UPDATE_IN) \
847 && !(F ## _IN (filter))) \
848 zlog_warn ("%s: Could not find configured input %s-list %s!", \
849 peer->host, #f, F ## _IN_NAME(filter));
850
851 if (DISTRIBUTE_IN_NAME (filter)) {
852 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
853
854 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
855 return FILTER_DENY;
856 }
857
858 if (PREFIX_LIST_IN_NAME (filter)) {
859 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
860
861 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
862 return FILTER_DENY;
863 }
864
865 if (FILTER_LIST_IN_NAME (filter)) {
866 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
867
868 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
869 return FILTER_DENY;
870 }
871
872 return FILTER_PERMIT;
873 #undef FILTER_EXIST_WARN
874 }
875
876 static enum filter_type
877 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
878 afi_t afi, safi_t safi)
879 {
880 struct bgp_filter *filter;
881
882 filter = &peer->filter[afi][safi];
883
884 #define FILTER_EXIST_WARN(F,f,filter) \
885 if (BGP_DEBUG (update, UPDATE_OUT) \
886 && !(F ## _OUT (filter))) \
887 zlog_warn ("%s: Could not find configured output %s-list %s!", \
888 peer->host, #f, F ## _OUT_NAME(filter));
889
890 if (DISTRIBUTE_OUT_NAME (filter)) {
891 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
892
893 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
894 return FILTER_DENY;
895 }
896
897 if (PREFIX_LIST_OUT_NAME (filter)) {
898 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
899
900 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
901 return FILTER_DENY;
902 }
903
904 if (FILTER_LIST_OUT_NAME (filter)) {
905 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
906
907 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
908 return FILTER_DENY;
909 }
910
911 return FILTER_PERMIT;
912 #undef FILTER_EXIST_WARN
913 }
914
915 /* If community attribute includes no_export then return 1. */
916 static int
917 bgp_community_filter (struct peer *peer, struct attr *attr)
918 {
919 if (attr->community)
920 {
921 /* NO_ADVERTISE check. */
922 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
923 return 1;
924
925 /* NO_EXPORT check. */
926 if (peer->sort == BGP_PEER_EBGP &&
927 community_include (attr->community, COMMUNITY_NO_EXPORT))
928 return 1;
929
930 /* NO_EXPORT_SUBCONFED check. */
931 if (peer->sort == BGP_PEER_EBGP
932 || peer->sort == BGP_PEER_CONFED)
933 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
934 return 1;
935 }
936 return 0;
937 }
938
939 /* Route reflection loop check. */
940 static int
941 bgp_cluster_filter (struct peer *peer, struct attr *attr)
942 {
943 struct in_addr cluster_id;
944
945 if (attr->extra && attr->extra->cluster)
946 {
947 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
948 cluster_id = peer->bgp->cluster_id;
949 else
950 cluster_id = peer->bgp->router_id;
951
952 if (cluster_loop_check (attr->extra->cluster, cluster_id))
953 return 1;
954 }
955 return 0;
956 }
957
958 static int
959 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
960 afi_t afi, safi_t safi, const char *rmap_name)
961 {
962 struct bgp_filter *filter;
963 struct bgp_info info;
964 route_map_result_t ret;
965 struct route_map *rmap = NULL;
966
967 filter = &peer->filter[afi][safi];
968
969 /* Apply default weight value. */
970 if (peer->weight)
971 (bgp_attr_extra_get (attr))->weight = peer->weight;
972
973 if (rmap_name)
974 {
975 rmap = route_map_lookup_by_name(rmap_name);
976
977 if (rmap == NULL)
978 return RMAP_DENY;
979 }
980 else
981 {
982 if (ROUTE_MAP_IN_NAME(filter))
983 {
984 rmap = ROUTE_MAP_IN (filter);
985
986 if (rmap == NULL)
987 return RMAP_DENY;
988 }
989 }
990
991 /* Route map apply. */
992 if (rmap)
993 {
994 /* Duplicate current value to new strucutre for modification. */
995 info.peer = peer;
996 info.attr = attr;
997
998 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
999
1000 /* Apply BGP route map to the attribute. */
1001 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1002
1003 peer->rmap_type = 0;
1004
1005 if (ret == RMAP_DENYMATCH)
1006 {
1007 /* Free newly generated AS path and community by route-map. */
1008 bgp_attr_flush (attr);
1009 return RMAP_DENY;
1010 }
1011 }
1012 return RMAP_PERMIT;
1013 }
1014
1015 static int
1016 bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1017 afi_t afi, safi_t safi, const char *rmap_name)
1018 {
1019 struct bgp_filter *filter;
1020 struct bgp_info info;
1021 route_map_result_t ret;
1022 struct route_map *rmap = NULL;
1023
1024 filter = &peer->filter[afi][safi];
1025
1026 /* Apply default weight value. */
1027 if (peer->weight)
1028 (bgp_attr_extra_get (attr))->weight = peer->weight;
1029
1030 if (rmap_name)
1031 {
1032 rmap = route_map_lookup_by_name(rmap_name);
1033
1034 if (rmap == NULL)
1035 return RMAP_DENY;
1036 }
1037 else
1038 {
1039 if (ROUTE_MAP_OUT_NAME(filter))
1040 {
1041 rmap = ROUTE_MAP_OUT (filter);
1042
1043 if (rmap == NULL)
1044 return RMAP_DENY;
1045 }
1046 }
1047
1048 /* Route map apply. */
1049 if (rmap)
1050 {
1051 /* Duplicate current value to new strucutre for modification. */
1052 info.peer = peer;
1053 info.attr = attr;
1054
1055 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1056
1057 /* Apply BGP route map to the attribute. */
1058 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1059
1060 peer->rmap_type = 0;
1061
1062 if (ret == RMAP_DENYMATCH)
1063 /* caller has multiple error paths with bgp_attr_flush() */
1064 return RMAP_DENY;
1065 }
1066 return RMAP_PERMIT;
1067 }
1068
1069 /* If this is an EBGP peer with remove-private-AS */
1070 static void
1071 bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1072 struct peer *peer, struct attr *attr)
1073 {
1074 if (peer->sort == BGP_PEER_EBGP &&
1075 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1076 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1077 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1078 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
1079 {
1080 // Take action on the entire aspath
1081 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1082 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
1083 {
1084 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
1085 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1086
1087 // The entire aspath consists of private ASNs so create an empty aspath
1088 else if (aspath_private_as_check (attr->aspath))
1089 attr->aspath = aspath_empty_get ();
1090
1091 // There are some public and some private ASNs, remove the private ASNs
1092 else
1093 attr->aspath = aspath_remove_private_asns (attr->aspath);
1094 }
1095
1096 // 'all' was not specified so the entire aspath must be private ASNs
1097 // for us to do anything
1098 else if (aspath_private_as_check (attr->aspath))
1099 {
1100 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1101 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1102 else
1103 attr->aspath = aspath_empty_get ();
1104 }
1105 }
1106 }
1107
1108 /* If this is an EBGP peer with as-override */
1109 static void
1110 bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1111 struct peer *peer, struct attr *attr)
1112 {
1113 if (peer->sort == BGP_PEER_EBGP &&
1114 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1115 {
1116 if (aspath_single_asn_check (attr->aspath, peer->as))
1117 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1118 }
1119 }
1120
1121 static void
1122 subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1123 {
1124 if (family == AF_INET)
1125 attr->nexthop.s_addr = 0;
1126 #ifdef HAVE_IPV6
1127 if (family == AF_INET6)
1128 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1129 #endif
1130 }
1131
1132 int
1133 subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1134 struct prefix *p, struct attr *attr)
1135 {
1136 struct bgp_filter *filter;
1137 struct peer *from;
1138 struct peer *peer;
1139 struct peer *onlypeer;
1140 struct bgp *bgp;
1141 struct attr *riattr;
1142 struct peer_af *paf;
1143 char buf[SU_ADDRSTRLEN];
1144 int ret;
1145 int transparent;
1146 int reflect;
1147 afi_t afi;
1148 safi_t safi;
1149
1150 if (DISABLE_BGP_ANNOUNCE)
1151 return 0;
1152
1153 afi = SUBGRP_AFI(subgrp);
1154 safi = SUBGRP_SAFI(subgrp);
1155 peer = SUBGRP_PEER(subgrp);
1156 onlypeer = NULL;
1157 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1158 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1159
1160 from = ri->peer;
1161 filter = &peer->filter[afi][safi];
1162 bgp = SUBGRP_INST(subgrp);
1163 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1164
1165 /* With addpath we may be asked to TX all kinds of paths so make sure
1166 * ri is valid */
1167 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1168 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1169 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1170 {
1171 return 0;
1172 }
1173
1174 /* If this is not the bestpath then check to see if there is an enabled addpath
1175 * feature that requires us to advertise it */
1176 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1177 {
1178 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1179 {
1180 return 0;
1181 }
1182 }
1183
1184 /* Aggregate-address suppress check. */
1185 if (ri->extra && ri->extra->suppress)
1186 if (! UNSUPPRESS_MAP_NAME (filter))
1187 {
1188 return 0;
1189 }
1190
1191 /* Do not send back route to sender. */
1192 if (onlypeer && from == onlypeer)
1193 {
1194 return 0;
1195 }
1196
1197 /* Do not send the default route in the BGP table if the neighbor is
1198 * configured for default-originate */
1199 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1200 {
1201 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1202 return 0;
1203 #ifdef HAVE_IPV6
1204 else if (p->family == AF_INET6 && p->prefixlen == 0)
1205 return 0;
1206 #endif /* HAVE_IPV6 */
1207 }
1208
1209 /* Transparency check. */
1210 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1211 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1212 transparent = 1;
1213 else
1214 transparent = 0;
1215
1216 /* If community is not disabled check the no-export and local. */
1217 if (! transparent && bgp_community_filter (peer, riattr))
1218 {
1219 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1220 zlog_debug ("subgrpannouncecheck: community filter check fail");
1221 return 0;
1222 }
1223
1224 /* If the attribute has originator-id and it is same as remote
1225 peer's id. */
1226 if (onlypeer &&
1227 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1228 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1229 {
1230 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1231 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1232 "remote router-id",
1233 onlypeer->host,
1234 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1235 p->prefixlen);
1236 return 0;
1237 }
1238
1239 /* ORF prefix-list filter check */
1240 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1241 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1242 || CHECK_FLAG (peer->af_cap[afi][safi],
1243 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1244 if (peer->orf_plist[afi][safi])
1245 {
1246 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1247 {
1248 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1249 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1250 peer->host,
1251 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1252 p->prefixlen);
1253 return 0;
1254 }
1255 }
1256
1257 /* Output filter check. */
1258 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1259 {
1260 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1261 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1262 peer->host,
1263 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1264 p->prefixlen);
1265 return 0;
1266 }
1267
1268 #ifdef BGP_SEND_ASPATH_CHECK
1269 /* AS path loop check. */
1270 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1271 {
1272 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1273 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1274 "that is part of AS path.",
1275 onlypeer->host, onlypeer->as);
1276 return 0;
1277 }
1278 #endif /* BGP_SEND_ASPATH_CHECK */
1279
1280 /* If we're a CONFED we need to loop check the CONFED ID too */
1281 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1282 {
1283 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
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 " is AS path.",
1288 peer->host,
1289 bgp->confed_id);
1290 return 0;
1291 }
1292 }
1293
1294 /* Route-Reflect check. */
1295 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1296 reflect = 1;
1297 else
1298 reflect = 0;
1299
1300 /* IBGP reflection check. */
1301 if (reflect)
1302 {
1303 /* A route from a Client peer. */
1304 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1305 {
1306 /* Reflect to all the Non-Client peers and also to the
1307 Client peers other than the originator. Originator check
1308 is already done. So there is noting to do. */
1309 /* no bgp client-to-client reflection check. */
1310 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1311 if (CHECK_FLAG (peer->af_flags[afi][safi],
1312 PEER_FLAG_REFLECTOR_CLIENT))
1313 return 0;
1314 }
1315 else
1316 {
1317 /* A route from a Non-client peer. Reflect to all other
1318 clients. */
1319 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1320 PEER_FLAG_REFLECTOR_CLIENT))
1321 return 0;
1322 }
1323 }
1324
1325 /* For modify attribute, copy it to temporary structure. */
1326 bgp_attr_dup (attr, riattr);
1327
1328 /* If local-preference is not set. */
1329 if ((peer->sort == BGP_PEER_IBGP
1330 || peer->sort == BGP_PEER_CONFED)
1331 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1332 {
1333 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1334 attr->local_pref = bgp->default_local_pref;
1335 }
1336
1337 /* If originator-id is not set and the route is to be reflected,
1338 set the originator id */
1339 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1340 {
1341 attr->extra = bgp_attr_extra_get(attr);
1342 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1343 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1344 }
1345
1346 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1347 if (peer->sort == BGP_PEER_EBGP
1348 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1349 {
1350 if (from != bgp->peer_self && ! transparent
1351 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1352 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1353 }
1354
1355 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1356 * in announce check, only certain flags and length (or number of nexthops
1357 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1358 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1359 * Typically, the source nexthop in the attribute is preserved but in the
1360 * scenarios where we know it will always be overwritten, we reset the
1361 * nexthop to "0" in an attempt to achieve better Update packing. An
1362 * example of this is when a prefix from each of 2 IBGP peers needs to be
1363 * announced to an EBGP peer (and they have the same attributes barring
1364 * their nexthop).
1365 */
1366 if (reflect)
1367 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1368
1369 #ifdef HAVE_IPV6
1370 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1371 * the peer (group) is configured to receive link-local nexthop unchanged
1372 * and it is available in the prefix OR we're not reflecting the route and
1373 * the peer (group) to whom we're going to announce is on a shared network
1374 * and this is either a self-originated route or the peer is EBGP.
1375 */
1376 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1377 {
1378 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
1379 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1380 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1381 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1382 (!reflect && peer->shared_network &&
1383 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
1384 {
1385 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
1386 }
1387
1388 /* Clear off link-local nexthop in source, whenever it is not needed to
1389 * ensure more prefixes share the same attribute for announcement.
1390 */
1391 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1392 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1393 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1394 }
1395 #endif /* HAVE_IPV6 */
1396
1397 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1398 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1399
1400 /* Route map & unsuppress-map apply. */
1401 if (ROUTE_MAP_OUT_NAME (filter)
1402 || (ri->extra && ri->extra->suppress) )
1403 {
1404 struct bgp_info info;
1405 struct attr dummy_attr;
1406 struct attr_extra dummy_extra;
1407
1408 dummy_attr.extra = &dummy_extra;
1409
1410 info.peer = peer;
1411 info.attr = attr;
1412 /* don't confuse inbound and outbound setting */
1413 RESET_FLAG(attr->rmap_change_flags);
1414
1415 /*
1416 * The route reflector is not allowed to modify the attributes
1417 * of the reflected IBGP routes unless explicitly allowed.
1418 */
1419 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1420 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1421 {
1422 bgp_attr_dup (&dummy_attr, attr);
1423 info.attr = &dummy_attr;
1424 }
1425
1426 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1427
1428 if (ri->extra && ri->extra->suppress)
1429 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1430 else
1431 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1432
1433 peer->rmap_type = 0;
1434
1435 if (ret == RMAP_DENYMATCH)
1436 {
1437 bgp_attr_flush (attr);
1438 return 0;
1439 }
1440 }
1441
1442 /* After route-map has been applied, we check to see if the nexthop to
1443 * be carried in the attribute (that is used for the announcement) can
1444 * be cleared off or not. We do this in all cases where we would be
1445 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1446 * the global nexthop here; the link-local nexthop would have been cleared
1447 * already, and if not, it is required by the update formation code.
1448 * Also see earlier comments in this function.
1449 */
1450 /*
1451 * If route-map has performed some operation on the nexthop or the peer
1452 * configuration says to pass it unchanged, we cannot reset the nexthop
1453 * here, so only attempt to do it if these aren't true. Note that the
1454 * route-map handler itself might have cleared the nexthop, if for example,
1455 * it is configured as 'peer-address'.
1456 */
1457 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1458 riattr->rmap_change_flags) &&
1459 !transparent &&
1460 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
1461 {
1462 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
1463 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1464 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
1465 {
1466 if (!reflect ||
1467 CHECK_FLAG (peer->af_flags[afi][safi],
1468 PEER_FLAG_FORCE_NEXTHOP_SELF))
1469 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1470 AF_INET6 : p->family), attr);
1471 }
1472 else if (peer->sort == BGP_PEER_EBGP)
1473 {
1474 /* Can also reset the nexthop if announcing to EBGP, but only if
1475 * no peer in the subgroup is on a shared subnet.
1476 * Note: 3rd party nexthop currently implemented for IPv4 only.
1477 */
1478 SUBGRP_FOREACH_PEER (subgrp, paf)
1479 {
1480 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1481 break;
1482 }
1483 if (!paf)
1484 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
1485 }
1486 /* If IPv6/MP and nexthop does not have any override and happens to
1487 * be a link-local address, reset it so that we don't pass along the
1488 * source's link-local IPv6 address to recipients who may not be on
1489 * the same interface.
1490 */
1491 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1492 {
1493 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1494 subgroup_announce_reset_nhop (AF_INET6, attr);
1495 }
1496 }
1497
1498 return 1;
1499 }
1500
1501 struct bgp_info_pair
1502 {
1503 struct bgp_info *old;
1504 struct bgp_info *new;
1505 };
1506
1507 static void
1508 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1509 struct bgp_maxpaths_cfg *mpath_cfg,
1510 struct bgp_info_pair *result)
1511 {
1512 struct bgp_info *new_select;
1513 struct bgp_info *old_select;
1514 struct bgp_info *ri;
1515 struct bgp_info *ri1;
1516 struct bgp_info *ri2;
1517 struct bgp_info *nextri = NULL;
1518 int paths_eq, do_mpath, debug;
1519 struct list mp_list;
1520 char pfx_buf[PREFIX2STR_BUFFER];
1521 char path_buf[PATH_ADDPATH_STR_BUFFER];
1522
1523 result->old = result->new = NULL;
1524
1525 if (rn->info == NULL)
1526 {
1527 char buf[PREFIX2STR_BUFFER];
1528 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1529 __func__,
1530 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1531 return;
1532 }
1533
1534 bgp_mp_list_init (&mp_list);
1535 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
1536
1537 debug = bgp_debug_bestpath(&rn->p);
1538
1539 if (debug)
1540 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1541
1542 /* bgp deterministic-med */
1543 new_select = NULL;
1544 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1545 {
1546
1547 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1548 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1549 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1550
1551 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1552 {
1553 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1554 continue;
1555 if (BGP_INFO_HOLDDOWN (ri1))
1556 continue;
1557 if (ri1->peer && ri1->peer != bgp->peer_self)
1558 if (ri1->peer->status != Established)
1559 continue;
1560
1561 new_select = ri1;
1562 if (ri1->next)
1563 {
1564 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1565 {
1566 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1567 continue;
1568 if (BGP_INFO_HOLDDOWN (ri2))
1569 continue;
1570 if (ri2->peer &&
1571 ri2->peer != bgp->peer_self &&
1572 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1573 if (ri2->peer->status != Established)
1574 continue;
1575
1576 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1577 || aspath_cmp_left_confed (ri1->attr->aspath,
1578 ri2->attr->aspath))
1579 {
1580 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1581 mpath_cfg, debug, pfx_buf))
1582 {
1583 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1584 new_select = ri2;
1585 }
1586
1587 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1588 }
1589 }
1590 }
1591 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1592 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1593
1594 if (debug)
1595 {
1596 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1597 zlog_debug("%s: %s is the bestpath from AS %d",
1598 pfx_buf, path_buf, aspath_get_firstas(new_select->attr->aspath));
1599 }
1600 }
1601 }
1602
1603 /* Check old selected route and new selected route. */
1604 old_select = NULL;
1605 new_select = NULL;
1606 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1607 {
1608 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1609 old_select = ri;
1610
1611 if (BGP_INFO_HOLDDOWN (ri))
1612 {
1613 /* reap REMOVED routes, if needs be
1614 * selected route must stay for a while longer though
1615 */
1616 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1617 && (ri != old_select))
1618 bgp_info_reap (rn, ri);
1619
1620 continue;
1621 }
1622
1623 if (ri->peer &&
1624 ri->peer != bgp->peer_self &&
1625 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1626 if (ri->peer->status != Established)
1627 continue;
1628
1629 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1630 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1631 {
1632 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1633 continue;
1634 }
1635
1636 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1637
1638 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
1639 {
1640 new_select = ri;
1641 }
1642 }
1643
1644 /* Now that we know which path is the bestpath see if any of the other paths
1645 * qualify as multipaths
1646 */
1647 if (do_mpath && new_select)
1648 {
1649 if (debug)
1650 {
1651 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1652 zlog_debug("%s: %s is the bestpath, now find multipaths", pfx_buf, path_buf);
1653 }
1654
1655 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1656 {
1657
1658 if (debug)
1659 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1660
1661 if (ri == new_select)
1662 {
1663 if (debug)
1664 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1665 pfx_buf, path_buf);
1666 bgp_mp_list_add (&mp_list, ri);
1667 continue;
1668 }
1669
1670 if (BGP_INFO_HOLDDOWN (ri))
1671 continue;
1672
1673 if (ri->peer &&
1674 ri->peer != bgp->peer_self &&
1675 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1676 if (ri->peer->status != Established)
1677 continue;
1678
1679 if (!bgp_info_nexthop_cmp (ri, new_select))
1680 {
1681 if (debug)
1682 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1683 pfx_buf, path_buf);
1684 continue;
1685 }
1686
1687 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
1688
1689 if (paths_eq)
1690 {
1691 if (debug)
1692 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1693 pfx_buf, path_buf);
1694 bgp_mp_list_add (&mp_list, ri);
1695 }
1696 }
1697 }
1698
1699 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1700 bgp_info_mpath_aggregate_update (new_select, old_select);
1701 bgp_mp_list_clear (&mp_list);
1702
1703 result->old = old_select;
1704 result->new = new_select;
1705
1706 return;
1707 }
1708
1709 /*
1710 * A new route/change in bestpath of an existing route. Evaluate the path
1711 * for advertisement to the subgroup.
1712 */
1713 int
1714 subgroup_process_announce_selected (struct update_subgroup *subgrp,
1715 struct bgp_info *selected,
1716 struct bgp_node *rn,
1717 u_int32_t addpath_tx_id)
1718 {
1719 struct prefix *p;
1720 struct peer *onlypeer;
1721 struct attr attr;
1722 struct attr_extra extra;
1723 afi_t afi;
1724 safi_t safi;
1725
1726 p = &rn->p;
1727 afi = SUBGRP_AFI(subgrp);
1728 safi = SUBGRP_SAFI(subgrp);
1729 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1730 (SUBGRP_PFIRST(subgrp))->peer : NULL);
1731
1732 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1733 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1734 PEER_STATUS_ORF_WAIT_REFRESH))
1735 return 0;
1736
1737 /* It's initialized in bgp_announce_check() */
1738 attr.extra = &extra;
1739
1740 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1741 if (selected)
1742 {
1743 if (subgroup_announce_check(selected, subgrp, p, &attr))
1744 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1745 else
1746 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1747 }
1748
1749 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1750 else
1751 {
1752 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
1753 }
1754
1755 return 0;
1756 }
1757
1758 struct bgp_process_queue
1759 {
1760 struct bgp *bgp;
1761 struct bgp_node *rn;
1762 afi_t afi;
1763 safi_t safi;
1764 };
1765
1766 static wq_item_status
1767 bgp_process_main (struct work_queue *wq, void *data)
1768 {
1769 struct bgp_process_queue *pq = data;
1770 struct bgp *bgp = pq->bgp;
1771 struct bgp_node *rn = pq->rn;
1772 afi_t afi = pq->afi;
1773 safi_t safi = pq->safi;
1774 struct prefix *p = &rn->p;
1775 struct bgp_info *new_select;
1776 struct bgp_info *old_select;
1777 struct bgp_info_pair old_and_new;
1778
1779 /* Is it end of initial update? (after startup) */
1780 if (!rn)
1781 {
1782 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1783 sizeof(bgp->update_delay_zebra_resume_time));
1784
1785 bgp->main_zebra_update_hold = 0;
1786 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1787 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1788 {
1789 bgp_zebra_announce_table(bgp, afi, safi);
1790 }
1791 bgp->main_peers_update_hold = 0;
1792
1793 bgp_start_routeadv(bgp);
1794 return WQ_SUCCESS;
1795 }
1796
1797 /* Best path selection. */
1798 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1799 old_select = old_and_new.old;
1800 new_select = old_and_new.new;
1801
1802 /* Nothing to do. */
1803 if (old_select && old_select == new_select &&
1804 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1805 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1806 !bgp->addpath_tx_used[afi][safi])
1807 {
1808 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1809 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
1810 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1811
1812 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1813 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1814 return WQ_SUCCESS;
1815 }
1816
1817 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1818 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1819
1820 /* bestpath has changed; bump version */
1821 if (old_select || new_select)
1822 {
1823 bgp_bump_version(rn);
1824
1825 if (!bgp->t_rmap_def_originate_eval)
1826 {
1827 bgp_lock (bgp);
1828 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
1829 update_group_refresh_default_originate_route_map,
1830 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1831 }
1832 }
1833
1834 if (old_select)
1835 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1836 if (new_select)
1837 {
1838 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1839 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1840 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1841 }
1842
1843 group_announce_route(bgp, afi, safi, rn, new_select);
1844
1845 /* FIB update. */
1846 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) &&
1847 (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) &&
1848 !bgp_option_check (BGP_OPT_NO_FIB))
1849 {
1850 if (new_select
1851 && new_select->type == ZEBRA_ROUTE_BGP
1852 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1853 new_select->sub_type == BGP_ROUTE_AGGREGATE))
1854 bgp_zebra_announce (p, new_select, bgp, afi, safi);
1855 else
1856 {
1857 /* Withdraw the route from the kernel. */
1858 if (old_select
1859 && old_select->type == ZEBRA_ROUTE_BGP
1860 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
1861 old_select->sub_type == BGP_ROUTE_AGGREGATE))
1862 bgp_zebra_withdraw (p, old_select, safi);
1863 }
1864 }
1865
1866 /* Reap old select bgp_info, if it has been removed */
1867 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1868 bgp_info_reap (rn, old_select);
1869
1870 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1871 return WQ_SUCCESS;
1872 }
1873
1874 static void
1875 bgp_processq_del (struct work_queue *wq, void *data)
1876 {
1877 struct bgp_process_queue *pq = data;
1878 struct bgp_table *table;
1879
1880 bgp_unlock (pq->bgp);
1881 if (pq->rn)
1882 {
1883 table = bgp_node_table (pq->rn);
1884 bgp_unlock_node (pq->rn);
1885 bgp_table_unlock (table);
1886 }
1887 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1888 }
1889
1890 void
1891 bgp_process_queue_init (void)
1892 {
1893 if (!bm->process_main_queue)
1894 {
1895 bm->process_main_queue
1896 = work_queue_new (bm->master, "process_main_queue");
1897
1898 if ( !bm->process_main_queue)
1899 {
1900 zlog_err ("%s: Failed to allocate work queue", __func__);
1901 exit (1);
1902 }
1903 }
1904
1905 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1906 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1907 bm->process_main_queue->spec.max_retries = 0;
1908 bm->process_main_queue->spec.hold = 50;
1909 /* Use a higher yield value of 50ms for main queue processing */
1910 bm->process_main_queue->spec.yield = 50 * 1000L;
1911 }
1912
1913 void
1914 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1915 {
1916 struct bgp_process_queue *pqnode;
1917
1918 /* already scheduled for processing? */
1919 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1920 return;
1921
1922 if (rn->info == NULL)
1923 {
1924 /* XXX: Perhaps remove before next release, after we've flushed out
1925 * any obvious cases
1926 */
1927 assert (rn->info != NULL);
1928 char buf[PREFIX2STR_BUFFER];
1929 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1930 __func__,
1931 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1932 return;
1933 }
1934
1935 if (bm->process_main_queue == NULL)
1936 bgp_process_queue_init ();
1937
1938 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1939 sizeof (struct bgp_process_queue));
1940 if (!pqnode)
1941 return;
1942
1943 /* all unlocked in bgp_processq_del */
1944 bgp_table_lock (bgp_node_table (rn));
1945 pqnode->rn = bgp_lock_node (rn);
1946 pqnode->bgp = bgp;
1947 bgp_lock (bgp);
1948 pqnode->afi = afi;
1949 pqnode->safi = safi;
1950 work_queue_add (bm->process_main_queue, pqnode);
1951 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1952 return;
1953 }
1954
1955 void
1956 bgp_add_eoiu_mark (struct bgp *bgp)
1957 {
1958 struct bgp_process_queue *pqnode;
1959
1960 if (bm->process_main_queue == NULL)
1961 bgp_process_queue_init ();
1962
1963 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1964 sizeof (struct bgp_process_queue));
1965 if (!pqnode)
1966 return;
1967
1968 pqnode->rn = NULL;
1969 pqnode->bgp = bgp;
1970 bgp_lock (bgp);
1971 work_queue_add (bm->process_main_queue, pqnode);
1972 }
1973
1974 static int
1975 bgp_maximum_prefix_restart_timer (struct thread *thread)
1976 {
1977 struct peer *peer;
1978
1979 peer = THREAD_ARG (thread);
1980 peer->t_pmax_restart = NULL;
1981
1982 if (bgp_debug_neighbor_events(peer))
1983 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1984 peer->host);
1985
1986 peer_clear (peer, NULL);
1987
1988 return 0;
1989 }
1990
1991 int
1992 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1993 safi_t safi, int always)
1994 {
1995 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1996 return 0;
1997
1998 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
1999 {
2000 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2001 && ! always)
2002 return 0;
2003
2004 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2005 "limit %ld", afi_safi_print (afi, safi), peer->host,
2006 peer->pcount[afi][safi], peer->pmax[afi][safi]);
2007 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2008
2009 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2010 return 0;
2011
2012 {
2013 u_int8_t ndata[7];
2014
2015 if (safi == SAFI_MPLS_VPN)
2016 safi = SAFI_MPLS_LABELED_VPN;
2017
2018 ndata[0] = (afi >> 8);
2019 ndata[1] = afi;
2020 ndata[2] = safi;
2021 ndata[3] = (peer->pmax[afi][safi] >> 24);
2022 ndata[4] = (peer->pmax[afi][safi] >> 16);
2023 ndata[5] = (peer->pmax[afi][safi] >> 8);
2024 ndata[6] = (peer->pmax[afi][safi]);
2025
2026 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2027 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2028 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2029 }
2030
2031 /* Dynamic peers will just close their connection. */
2032 if (peer_dynamic_neighbor (peer))
2033 return 1;
2034
2035 /* restart timer start */
2036 if (peer->pmax_restart[afi][safi])
2037 {
2038 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2039
2040 if (bgp_debug_neighbor_events(peer))
2041 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2042 peer->host, peer->v_pmax_restart);
2043
2044 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2045 peer->v_pmax_restart);
2046 }
2047
2048 return 1;
2049 }
2050 else
2051 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2052
2053 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2054 {
2055 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2056 && ! always)
2057 return 0;
2058
2059 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2060 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2061 peer->pmax[afi][safi]);
2062 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2063 }
2064 else
2065 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2066 return 0;
2067 }
2068
2069 /* Unconditionally remove the route from the RIB, without taking
2070 * damping into consideration (eg, because the session went down)
2071 */
2072 static void
2073 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2074 afi_t afi, safi_t safi)
2075 {
2076 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2077
2078 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2079 bgp_info_delete (rn, ri); /* keep historical info */
2080
2081 bgp_process (peer->bgp, rn, afi, safi);
2082 }
2083
2084 static void
2085 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2086 afi_t afi, safi_t safi)
2087 {
2088 int status = BGP_DAMP_NONE;
2089
2090 /* apply dampening, if result is suppressed, we'll be retaining
2091 * the bgp_info in the RIB for historical reference.
2092 */
2093 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2094 && peer->sort == BGP_PEER_EBGP)
2095 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2096 == BGP_DAMP_SUPPRESSED)
2097 {
2098 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2099 return;
2100 }
2101
2102 bgp_rib_remove (rn, ri, peer, afi, safi);
2103 }
2104
2105 static struct bgp_info *
2106 info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
2107 struct bgp_node *rn)
2108 {
2109 struct bgp_info *new;
2110
2111 /* Make new BGP info. */
2112 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2113 new->type = type;
2114 new->instance = instance;
2115 new->sub_type = sub_type;
2116 new->peer = peer;
2117 new->attr = attr;
2118 new->uptime = bgp_clock ();
2119 new->net = rn;
2120 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
2121 return new;
2122 }
2123
2124 static void
2125 bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
2126 {
2127 if (addpath_id)
2128 sprintf(buf, " with addpath ID %d", addpath_id);
2129 }
2130
2131
2132 /* Check if received nexthop is valid or not. */
2133 static int
2134 bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
2135 {
2136 struct attr_extra *attre = attr->extra;
2137 int ret = 0;
2138
2139 /* Only validated for unicast and multicast currently. */
2140 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2141 return 0;
2142
2143 /* If NEXT_HOP is present, validate it. */
2144 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2145 {
2146 if (attr->nexthop.s_addr == 0 ||
2147 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2148 bgp_nexthop_self (bgp, attr))
2149 ret = 1;
2150 }
2151
2152 /* If MP_NEXTHOP is present, validate it. */
2153 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2154 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2155 * it is not an IPv6 link-local address.
2156 */
2157 if (attre && attre->mp_nexthop_len)
2158 {
2159 switch (attre->mp_nexthop_len)
2160 {
2161 case BGP_ATTR_NHLEN_IPV4:
2162 case BGP_ATTR_NHLEN_VPNV4:
2163 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2164 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2165 break;
2166
2167 #ifdef HAVE_IPV6
2168 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2169 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2170 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2171 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2172 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2173 break;
2174 #endif /* HAVE_IPV6 */
2175
2176 default:
2177 ret = 1;
2178 break;
2179 }
2180 }
2181
2182 return ret;
2183 }
2184
2185 int
2186 bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2187 struct attr *attr, afi_t afi, safi_t safi, int type,
2188 int sub_type, struct prefix_rd *prd, u_char *tag,
2189 int soft_reconfig)
2190 {
2191 int ret;
2192 int aspath_loop_count = 0;
2193 struct bgp_node *rn;
2194 struct bgp *bgp;
2195 struct attr new_attr;
2196 struct attr_extra new_extra;
2197 struct attr *attr_new;
2198 struct bgp_info *ri;
2199 struct bgp_info *new;
2200 const char *reason;
2201 char buf[SU_ADDRSTRLEN];
2202 char buf2[30];
2203 int connected = 0;
2204
2205 bgp = peer->bgp;
2206 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2207
2208 /* When peer's soft reconfiguration enabled. Record input packet in
2209 Adj-RIBs-In. */
2210 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2211 && peer != bgp->peer_self)
2212 bgp_adj_in_set (rn, peer, attr, addpath_id);
2213
2214 /* Check previously received route. */
2215 for (ri = rn->info; ri; ri = ri->next)
2216 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2217 ri->addpath_rx_id == addpath_id)
2218 break;
2219
2220 /* AS path local-as loop check. */
2221 if (peer->change_local_as)
2222 {
2223 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2224 aspath_loop_count = 1;
2225
2226 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2227 {
2228 reason = "as-path contains our own AS;";
2229 goto filtered;
2230 }
2231 }
2232
2233 /* AS path loop check. */
2234 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2235 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2236 && aspath_loop_check(attr->aspath, bgp->confed_id)
2237 > peer->allowas_in[afi][safi]))
2238 {
2239 reason = "as-path contains our own AS;";
2240 goto filtered;
2241 }
2242
2243 /* Route reflector originator ID check. */
2244 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2245 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2246 {
2247 reason = "originator is us;";
2248 goto filtered;
2249 }
2250
2251 /* Route reflector cluster ID check. */
2252 if (bgp_cluster_filter (peer, attr))
2253 {
2254 reason = "reflected from the same cluster;";
2255 goto filtered;
2256 }
2257
2258 /* Apply incoming filter. */
2259 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2260 {
2261 reason = "filter;";
2262 goto filtered;
2263 }
2264
2265 new_attr.extra = &new_extra;
2266 bgp_attr_dup (&new_attr, attr);
2267
2268 /* Apply incoming route-map.
2269 * NB: new_attr may now contain newly allocated values from route-map "set"
2270 * commands, so we need bgp_attr_flush in the error paths, until we intern
2271 * the attr (which takes over the memory references) */
2272 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2273 {
2274 reason = "route-map;";
2275 bgp_attr_flush (&new_attr);
2276 goto filtered;
2277 }
2278
2279 /* next hop check. */
2280 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
2281 {
2282 reason = "martian or self next-hop;";
2283 bgp_attr_flush (&new_attr);
2284 goto filtered;
2285 }
2286
2287 attr_new = bgp_attr_intern (&new_attr);
2288
2289 /* If the update is implicit withdraw. */
2290 if (ri)
2291 {
2292 ri->uptime = bgp_clock ();
2293
2294 /* Same attribute comes in. */
2295 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2296 && attrhash_cmp (ri->attr, attr_new))
2297 {
2298 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2299 && peer->sort == BGP_PEER_EBGP
2300 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2301 {
2302 if (bgp_debug_update(peer, p, NULL, 1))
2303 {
2304 bgp_info_addpath_rx_str(addpath_id, buf2);
2305 zlog_debug ("%s rcvd %s/%d%s",
2306 peer->host,
2307 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2308 p->prefixlen, buf2);
2309 }
2310
2311 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2312 {
2313 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2314 bgp_process (bgp, rn, afi, safi);
2315 }
2316 }
2317 else /* Duplicate - odd */
2318 {
2319 if (bgp_debug_update(peer, p, NULL, 1))
2320 {
2321 if (!peer->rcvd_attr_printed)
2322 {
2323 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2324 peer->rcvd_attr_printed = 1;
2325 }
2326
2327 bgp_info_addpath_rx_str(addpath_id, buf2);
2328 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
2329 peer->host,
2330 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2331 p->prefixlen, buf2);
2332 }
2333
2334 /* graceful restart STALE flag unset. */
2335 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2336 {
2337 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2338 bgp_process (bgp, rn, afi, safi);
2339 }
2340 }
2341
2342 bgp_unlock_node (rn);
2343 bgp_attr_unintern (&attr_new);
2344
2345 return 0;
2346 }
2347
2348 /* Withdraw/Announce before we fully processed the withdraw */
2349 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2350 {
2351 if (bgp_debug_update(peer, p, NULL, 1))
2352 {
2353 bgp_info_addpath_rx_str(addpath_id, buf2);
2354 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2355 peer->host,
2356 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2357 p->prefixlen, buf2);
2358 }
2359 bgp_info_restore (rn, ri);
2360 }
2361
2362 /* Received Logging. */
2363 if (bgp_debug_update(peer, p, NULL, 1))
2364 {
2365 bgp_info_addpath_rx_str(addpath_id, buf2);
2366 zlog_debug ("%s rcvd %s/%d%s",
2367 peer->host,
2368 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2369 p->prefixlen, buf2);
2370 }
2371
2372 /* graceful restart STALE flag unset. */
2373 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2374 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2375
2376 /* The attribute is changed. */
2377 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2378
2379 /* implicit withdraw, decrement aggregate and pcount here.
2380 * only if update is accepted, they'll increment below.
2381 */
2382 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2383
2384 /* Update bgp route dampening information. */
2385 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2386 && peer->sort == BGP_PEER_EBGP)
2387 {
2388 /* This is implicit withdraw so we should update dampening
2389 information. */
2390 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2391 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2392 }
2393
2394 /* Update to new attribute. */
2395 bgp_attr_unintern (&ri->attr);
2396 ri->attr = attr_new;
2397
2398 /* Update MPLS tag. */
2399 if (safi == SAFI_MPLS_VPN)
2400 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2401
2402 /* Update bgp route dampening information. */
2403 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2404 && peer->sort == BGP_PEER_EBGP)
2405 {
2406 /* Now we do normal update dampening. */
2407 ret = bgp_damp_update (ri, rn, afi, safi);
2408 if (ret == BGP_DAMP_SUPPRESSED)
2409 {
2410 bgp_unlock_node (rn);
2411 return 0;
2412 }
2413 }
2414
2415 /* Nexthop reachability check. */
2416 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2417 {
2418 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2419 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2420 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2421 connected = 1;
2422 else
2423 connected = 0;
2424
2425 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
2426 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2427 else
2428 {
2429 if (BGP_DEBUG(nht, NHT))
2430 {
2431 char buf1[INET6_ADDRSTRLEN];
2432 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2433 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2434 }
2435 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2436 }
2437 }
2438 else
2439 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2440
2441 /* Process change. */
2442 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2443
2444 bgp_process (bgp, rn, afi, safi);
2445 bgp_unlock_node (rn);
2446
2447 return 0;
2448 } // End of implicit withdraw
2449
2450 /* Received Logging. */
2451 if (bgp_debug_update(peer, p, NULL, 1))
2452 {
2453 if (!peer->rcvd_attr_printed)
2454 {
2455 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2456 peer->rcvd_attr_printed = 1;
2457 }
2458
2459 bgp_info_addpath_rx_str(addpath_id, buf2);
2460 zlog_debug ("%s rcvd %s/%d%s",
2461 peer->host,
2462 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2463 p->prefixlen, buf2);
2464 }
2465
2466 /* Make new BGP info. */
2467 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2468
2469 /* Update MPLS tag. */
2470 if (safi == SAFI_MPLS_VPN)
2471 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2472
2473 /* Nexthop reachability check. */
2474 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2475 {
2476 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2477 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2478 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2479 connected = 1;
2480 else
2481 connected = 0;
2482
2483 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
2484 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2485 else
2486 {
2487 if (BGP_DEBUG(nht, NHT))
2488 {
2489 char buf1[INET6_ADDRSTRLEN];
2490 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2491 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2492 }
2493 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2494 }
2495 }
2496 else
2497 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2498
2499 /* Addpath ID */
2500 new->addpath_rx_id = addpath_id;
2501
2502 /* Increment prefix */
2503 bgp_aggregate_increment (bgp, p, new, afi, safi);
2504
2505 /* Register new BGP information. */
2506 bgp_info_add (rn, new);
2507
2508 /* route_node_get lock */
2509 bgp_unlock_node (rn);
2510
2511 /* If maximum prefix count is configured and current prefix
2512 count exeed it. */
2513 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2514 return -1;
2515
2516 /* Process change. */
2517 bgp_process (bgp, rn, afi, safi);
2518
2519 return 0;
2520
2521 /* This BGP update is filtered. Log the reason then update BGP
2522 entry. */
2523 filtered:
2524 if (bgp_debug_update(peer, p, NULL, 1))
2525 {
2526 if (!peer->rcvd_attr_printed)
2527 {
2528 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2529 peer->rcvd_attr_printed = 1;
2530 }
2531
2532 bgp_info_addpath_rx_str(addpath_id, buf2);
2533 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
2534 peer->host,
2535 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2536 p->prefixlen, buf2, reason);
2537 }
2538
2539 if (ri)
2540 bgp_rib_remove (rn, ri, peer, afi, safi);
2541
2542 bgp_unlock_node (rn);
2543
2544 return 0;
2545 }
2546
2547 int
2548 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2549 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2550 struct prefix_rd *prd, u_char *tag)
2551 {
2552 struct bgp *bgp;
2553 char buf[SU_ADDRSTRLEN];
2554 char buf2[30];
2555 struct bgp_node *rn;
2556 struct bgp_info *ri;
2557
2558 bgp = peer->bgp;
2559
2560 /* Lookup node. */
2561 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2562
2563 /* If peer is soft reconfiguration enabled. Record input packet for
2564 further calculation. */
2565 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2566 && peer != bgp->peer_self)
2567 bgp_adj_in_unset (rn, peer, addpath_id);
2568
2569 /* Lookup withdrawn route. */
2570 for (ri = rn->info; ri; ri = ri->next)
2571 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2572 ri->addpath_rx_id == addpath_id)
2573 break;
2574
2575 /* Logging. */
2576 if (bgp_debug_update(peer, p, NULL, 1))
2577 {
2578 bgp_info_addpath_rx_str(addpath_id, buf2);
2579 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2580 peer->host,
2581 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2582 p->prefixlen, buf2);
2583 }
2584
2585 /* Withdraw specified route from routing table. */
2586 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2587 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2588 else if (bgp_debug_update(peer, p, NULL, 1))
2589 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2590 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2591 p->prefixlen);
2592
2593 /* Unlock bgp_node_get() lock. */
2594 bgp_unlock_node (rn);
2595
2596 return 0;
2597 }
2598
2599 void
2600 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2601 {
2602 struct update_subgroup *subgrp;
2603 subgrp = peer_subgroup(peer, afi, safi);
2604 subgroup_default_originate(subgrp, withdraw);
2605 }
2606
2607
2608 /*
2609 * bgp_stop_announce_route_timer
2610 */
2611 void
2612 bgp_stop_announce_route_timer (struct peer_af *paf)
2613 {
2614 if (!paf->t_announce_route)
2615 return;
2616
2617 THREAD_TIMER_OFF (paf->t_announce_route);
2618 }
2619
2620 /*
2621 * bgp_announce_route_timer_expired
2622 *
2623 * Callback that is invoked when the route announcement timer for a
2624 * peer_af expires.
2625 */
2626 static int
2627 bgp_announce_route_timer_expired (struct thread *t)
2628 {
2629 struct peer_af *paf;
2630 struct peer *peer;
2631
2632
2633 paf = THREAD_ARG (t);
2634 peer = paf->peer;
2635
2636 assert (paf->t_announce_route);
2637 paf->t_announce_route = NULL;
2638
2639 if (peer->status != Established)
2640 return 0;
2641
2642 if (!peer->afc_nego[paf->afi][paf->safi])
2643 return 0;
2644
2645 peer_af_announce_route (paf, 1);
2646 return 0;
2647 }
2648
2649 /*
2650 * bgp_announce_route
2651 *
2652 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2653 */
2654 void
2655 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2656 {
2657 struct peer_af *paf;
2658 struct update_subgroup *subgrp;
2659
2660 paf = peer_af_find (peer, afi, safi);
2661 if (!paf)
2662 return;
2663 subgrp = PAF_SUBGRP(paf);
2664
2665 /*
2666 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2667 * or a refresh has already been triggered.
2668 */
2669 if (!subgrp || paf->t_announce_route)
2670 return;
2671
2672 /*
2673 * Start a timer to stagger/delay the announce. This serves
2674 * two purposes - announcement can potentially be combined for
2675 * multiple peers and the announcement doesn't happen in the
2676 * vty context.
2677 */
2678 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
2679 bgp_announce_route_timer_expired, paf,
2680 (subgrp->peer_count == 1) ?
2681 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2682 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2683 }
2684
2685 /*
2686 * Announce routes from all AF tables to a peer.
2687 *
2688 * This should ONLY be called when there is a need to refresh the
2689 * routes to the peer based on a policy change for this peer alone
2690 * or a route refresh request received from the peer.
2691 * The operation will result in splitting the peer from its existing
2692 * subgroups and putting it in new subgroups.
2693 */
2694 void
2695 bgp_announce_route_all (struct peer *peer)
2696 {
2697 afi_t afi;
2698 safi_t safi;
2699
2700 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2701 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2702 bgp_announce_route (peer, afi, safi);
2703 }
2704
2705 static void
2706 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2707 struct bgp_table *table, struct prefix_rd *prd)
2708 {
2709 int ret;
2710 struct bgp_node *rn;
2711 struct bgp_adj_in *ain;
2712
2713 if (! table)
2714 table = peer->bgp->rib[afi][safi];
2715
2716 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2717 for (ain = rn->adj_in; ain; ain = ain->next)
2718 {
2719 if (ain->peer == peer)
2720 {
2721 struct bgp_info *ri = rn->info;
2722 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2723
2724 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
2725 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2726 prd, tag, 1);
2727
2728 if (ret < 0)
2729 {
2730 bgp_unlock_node (rn);
2731 return;
2732 }
2733 }
2734 }
2735 }
2736
2737 void
2738 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2739 {
2740 struct bgp_node *rn;
2741 struct bgp_table *table;
2742
2743 if (peer->status != Established)
2744 return;
2745
2746 if (safi != SAFI_MPLS_VPN)
2747 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
2748 else
2749 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2750 rn = bgp_route_next (rn))
2751 if ((table = rn->info) != NULL)
2752 {
2753 struct prefix_rd prd;
2754 prd.family = AF_UNSPEC;
2755 prd.prefixlen = 64;
2756 memcpy(&prd.val, rn->p.u.val, 8);
2757
2758 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2759 }
2760 }
2761
2762
2763 struct bgp_clear_node_queue
2764 {
2765 struct bgp_node *rn;
2766 };
2767
2768 static wq_item_status
2769 bgp_clear_route_node (struct work_queue *wq, void *data)
2770 {
2771 struct bgp_clear_node_queue *cnq = data;
2772 struct bgp_node *rn = cnq->rn;
2773 struct peer *peer = wq->spec.data;
2774 struct bgp_info *ri;
2775 afi_t afi = bgp_node_table (rn)->afi;
2776 safi_t safi = bgp_node_table (rn)->safi;
2777
2778 assert (rn && peer);
2779
2780 /* It is possible that we have multiple paths for a prefix from a peer
2781 * if that peer is using AddPath.
2782 */
2783 for (ri = rn->info; ri; ri = ri->next)
2784 if (ri->peer == peer)
2785 {
2786 /* graceful restart STALE flag set. */
2787 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2788 && peer->nsf[afi][safi]
2789 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2790 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2791 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
2792 else
2793 bgp_rib_remove (rn, ri, peer, afi, safi);
2794 }
2795 return WQ_SUCCESS;
2796 }
2797
2798 static void
2799 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
2800 {
2801 struct bgp_clear_node_queue *cnq = data;
2802 struct bgp_node *rn = cnq->rn;
2803 struct bgp_table *table = bgp_node_table (rn);
2804
2805 bgp_unlock_node (rn);
2806 bgp_table_unlock (table);
2807 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
2808 }
2809
2810 static void
2811 bgp_clear_node_complete (struct work_queue *wq)
2812 {
2813 struct peer *peer = wq->spec.data;
2814
2815 /* Tickle FSM to start moving again */
2816 BGP_EVENT_ADD (peer, Clearing_Completed);
2817
2818 peer_unlock (peer); /* bgp_clear_route */
2819 }
2820
2821 static void
2822 bgp_clear_node_queue_init (struct peer *peer)
2823 {
2824 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
2825
2826 snprintf (wname, sizeof(wname), "clear %s", peer->host);
2827 #undef CLEAR_QUEUE_NAME_LEN
2828
2829 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
2830 {
2831 zlog_err ("%s: Failed to allocate work queue", __func__);
2832 exit (1);
2833 }
2834 peer->clear_node_queue->spec.hold = 10;
2835 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2836 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2837 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2838 peer->clear_node_queue->spec.max_retries = 0;
2839
2840 /* we only 'lock' this peer reference when the queue is actually active */
2841 peer->clear_node_queue->spec.data = peer;
2842 }
2843
2844 static void
2845 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2846 struct bgp_table *table)
2847 {
2848 struct bgp_node *rn;
2849
2850
2851 if (! table)
2852 table = peer->bgp->rib[afi][safi];
2853
2854 /* If still no table => afi/safi isn't configured at all or smth. */
2855 if (! table)
2856 return;
2857
2858 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2859 {
2860 struct bgp_info *ri;
2861 struct bgp_adj_in *ain;
2862 struct bgp_adj_in *ain_next;
2863
2864 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2865 * queued for every clearing peer, regardless of whether it is
2866 * relevant to the peer at hand.
2867 *
2868 * Overview: There are 3 different indices which need to be
2869 * scrubbed, potentially, when a peer is removed:
2870 *
2871 * 1 peer's routes visible via the RIB (ie accepted routes)
2872 * 2 peer's routes visible by the (optional) peer's adj-in index
2873 * 3 other routes visible by the peer's adj-out index
2874 *
2875 * 3 there is no hurry in scrubbing, once the struct peer is
2876 * removed from bgp->peer, we could just GC such deleted peer's
2877 * adj-outs at our leisure.
2878 *
2879 * 1 and 2 must be 'scrubbed' in some way, at least made
2880 * invisible via RIB index before peer session is allowed to be
2881 * brought back up. So one needs to know when such a 'search' is
2882 * complete.
2883 *
2884 * Ideally:
2885 *
2886 * - there'd be a single global queue or a single RIB walker
2887 * - rather than tracking which route_nodes still need to be
2888 * examined on a peer basis, we'd track which peers still
2889 * aren't cleared
2890 *
2891 * Given that our per-peer prefix-counts now should be reliable,
2892 * this may actually be achievable. It doesn't seem to be a huge
2893 * problem at this time,
2894 *
2895 * It is possible that we have multiple paths for a prefix from a peer
2896 * if that peer is using AddPath.
2897 */
2898 ain = rn->adj_in;
2899 while (ain)
2900 {
2901 ain_next = ain->next;
2902
2903 if (ain->peer == peer)
2904 {
2905 bgp_adj_in_remove (rn, ain);
2906 bgp_unlock_node (rn);
2907 }
2908
2909 ain = ain_next;
2910 }
2911
2912 for (ri = rn->info; ri; ri = ri->next)
2913 if (ri->peer == peer)
2914 {
2915 struct bgp_clear_node_queue *cnq;
2916
2917 /* both unlocked in bgp_clear_node_queue_del */
2918 bgp_table_lock (bgp_node_table (rn));
2919 bgp_lock_node (rn);
2920 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2921 sizeof (struct bgp_clear_node_queue));
2922 cnq->rn = rn;
2923 work_queue_add (peer->clear_node_queue, cnq);
2924 break;
2925 }
2926 }
2927 return;
2928 }
2929
2930 void
2931 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2932 {
2933 struct bgp_node *rn;
2934 struct bgp_table *table;
2935
2936 if (peer->clear_node_queue == NULL)
2937 bgp_clear_node_queue_init (peer);
2938
2939 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2940 * Idle until it receives a Clearing_Completed event. This protects
2941 * against peers which flap faster than we can we clear, which could
2942 * lead to:
2943 *
2944 * a) race with routes from the new session being installed before
2945 * clear_route_node visits the node (to delete the route of that
2946 * peer)
2947 * b) resource exhaustion, clear_route_node likely leads to an entry
2948 * on the process_main queue. Fast-flapping could cause that queue
2949 * to grow and grow.
2950 */
2951
2952 /* lock peer in assumption that clear-node-queue will get nodes; if so,
2953 * the unlock will happen upon work-queue completion; other wise, the
2954 * unlock happens at the end of this function.
2955 */
2956 if (!peer->clear_node_queue->thread)
2957 peer_lock (peer);
2958
2959 if (safi != SAFI_MPLS_VPN)
2960 bgp_clear_route_table (peer, afi, safi, NULL);
2961 else
2962 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2963 rn = bgp_route_next (rn))
2964 if ((table = rn->info) != NULL)
2965 bgp_clear_route_table (peer, afi, safi, table);
2966
2967 /* unlock if no nodes got added to the clear-node-queue. */
2968 if (!peer->clear_node_queue->thread)
2969 peer_unlock (peer);
2970
2971 }
2972
2973 void
2974 bgp_clear_route_all (struct peer *peer)
2975 {
2976 afi_t afi;
2977 safi_t safi;
2978
2979 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2980 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2981 bgp_clear_route (peer, afi, safi);
2982 }
2983
2984 void
2985 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2986 {
2987 struct bgp_table *table;
2988 struct bgp_node *rn;
2989 struct bgp_adj_in *ain;
2990 struct bgp_adj_in *ain_next;
2991
2992 table = peer->bgp->rib[afi][safi];
2993
2994 /* It is possible that we have multiple paths for a prefix from a peer
2995 * if that peer is using AddPath.
2996 */
2997 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2998 {
2999 ain = rn->adj_in;
3000
3001 while (ain)
3002 {
3003 ain_next = ain->next;
3004
3005 if (ain->peer == peer)
3006 {
3007 bgp_adj_in_remove (rn, ain);
3008 bgp_unlock_node (rn);
3009 }
3010
3011 ain = ain_next;
3012 }
3013 }
3014 }
3015
3016 void
3017 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3018 {
3019 struct bgp_node *rn;
3020 struct bgp_info *ri;
3021 struct bgp_table *table;
3022
3023 table = peer->bgp->rib[afi][safi];
3024
3025 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3026 {
3027 for (ri = rn->info; ri; ri = ri->next)
3028 if (ri->peer == peer)
3029 {
3030 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3031 bgp_rib_remove (rn, ri, peer, afi, safi);
3032 break;
3033 }
3034 }
3035 }
3036
3037 /* Delete all kernel routes. */
3038 void
3039 bgp_cleanup_routes (void)
3040 {
3041 struct bgp *bgp;
3042 struct listnode *node, *nnode;
3043 struct bgp_node *rn;
3044 struct bgp_table *table;
3045 struct bgp_info *ri;
3046
3047 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
3048 {
3049 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3050
3051 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3052 for (ri = rn->info; ri; ri = ri->next)
3053 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3054 && ri->type == ZEBRA_ROUTE_BGP
3055 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3056 ri->sub_type == BGP_ROUTE_AGGREGATE))
3057 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
3058
3059 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3060
3061 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3062 for (ri = rn->info; ri; ri = ri->next)
3063 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3064 && ri->type == ZEBRA_ROUTE_BGP
3065 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3066 ri->sub_type == BGP_ROUTE_AGGREGATE))
3067 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
3068 }
3069 }
3070
3071 void
3072 bgp_reset (void)
3073 {
3074 vty_reset ();
3075 bgp_zclient_reset ();
3076 access_list_reset ();
3077 prefix_list_reset ();
3078 }
3079
3080 static int
3081 bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3082 {
3083 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3084 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3085 }
3086
3087 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3088 value. */
3089 int
3090 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3091 {
3092 u_char *pnt;
3093 u_char *lim;
3094 struct prefix p;
3095 int psize;
3096 int ret;
3097 afi_t afi;
3098 safi_t safi;
3099 int addpath_encoded;
3100 u_int32_t addpath_id;
3101
3102 /* Check peer status. */
3103 if (peer->status != Established)
3104 return 0;
3105
3106 pnt = packet->nlri;
3107 lim = pnt + packet->length;
3108 afi = packet->afi;
3109 safi = packet->safi;
3110 addpath_id = 0;
3111 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3112
3113 for (; pnt < lim; pnt += psize)
3114 {
3115 /* Clear prefix structure. */
3116 memset (&p, 0, sizeof (struct prefix));
3117
3118 if (addpath_encoded)
3119 {
3120
3121 /* When packet overflow occurs return immediately. */
3122 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3123 return -1;
3124
3125 addpath_id = ntohl(*((uint32_t*) pnt));
3126 pnt += BGP_ADDPATH_ID_LEN;
3127 }
3128
3129 /* Fetch prefix length. */
3130 p.prefixlen = *pnt++;
3131 p.family = afi2family (afi);
3132
3133 /* Already checked in nlri_sanity_check(). We do double check
3134 here. */
3135 if ((afi == AFI_IP && p.prefixlen > 32)
3136 || (afi == AFI_IP6 && p.prefixlen > 128))
3137 return -1;
3138
3139 /* Packet size overflow check. */
3140 psize = PSIZE (p.prefixlen);
3141
3142 /* When packet overflow occur return immediately. */
3143 if (pnt + psize > lim)
3144 return -1;
3145
3146 /* Fetch prefix from NLRI packet. */
3147 memcpy (&p.u.prefix, pnt, psize);
3148
3149 /* Check address. */
3150 if (afi == AFI_IP && safi == SAFI_UNICAST)
3151 {
3152 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3153 {
3154 /*
3155 * From draft-ietf-idr-bgp4-22, Section 6.3:
3156 * If a BGP router receives an UPDATE message with a
3157 * semantically incorrect NLRI field, in which a prefix is
3158 * semantically incorrect (eg. an unexpected multicast IP
3159 * address), it should ignore the prefix.
3160 */
3161 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3162 inet_ntoa (p.u.prefix4));
3163
3164 return -1;
3165 }
3166 }
3167
3168 #ifdef HAVE_IPV6
3169 /* Check address. */
3170 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3171 {
3172 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3173 {
3174 char buf[BUFSIZ];
3175
3176 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3177 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3178
3179 continue;
3180 }
3181 }
3182 #endif /* HAVE_IPV6 */
3183
3184 /* Normal process. */
3185 if (attr)
3186 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3187 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3188 else
3189 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3190 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3191
3192 /* Address family configuration mismatch or maximum-prefix count
3193 overflow. */
3194 if (ret < 0)
3195 return -1;
3196 }
3197
3198 /* Packet length consistency check. */
3199 if (pnt != lim)
3200 return -1;
3201
3202 return 0;
3203 }
3204
3205 /* NLRI encode syntax check routine. */
3206 int
3207 bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
3208 bgp_size_t length, int *numpfx)
3209 {
3210 u_char *end;
3211 u_char prefixlen;
3212 int psize;
3213 int addpath_encoded;
3214
3215 *numpfx = 0;
3216 end = pnt + length;
3217 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3218
3219 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3220 syntactic validity. If the field is syntactically incorrect,
3221 then the Error Subcode is set to Invalid Network Field. */
3222
3223 while (pnt < end)
3224 {
3225
3226 /* If the NLRI is encoded using addpath then the first 4 bytes are
3227 * the addpath ID. */
3228 if (addpath_encoded)
3229 {
3230 if (pnt + BGP_ADDPATH_ID_LEN > end)
3231 {
3232 zlog_err ("%s [Error] Update packet error"
3233 " (prefix data addpath overflow)",
3234 peer->host);
3235 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3236 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3237 return -1;
3238 }
3239 pnt += BGP_ADDPATH_ID_LEN;
3240 }
3241
3242 prefixlen = *pnt++;
3243
3244 /* Prefix length check. */
3245 if ((afi == AFI_IP && prefixlen > 32)
3246 || (afi == AFI_IP6 && prefixlen > 128))
3247 {
3248 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
3249 peer->host, prefixlen);
3250 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3251 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3252 return -1;
3253 }
3254
3255 /* Packet size overflow check. */
3256 psize = PSIZE (prefixlen);
3257
3258 if (pnt + psize > end)
3259 {
3260 zlog_err ("%s [Error] Update packet error"
3261 " (prefix data overflow prefix size is %d)",
3262 peer->host, psize);
3263 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3264 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3265 return -1;
3266 }
3267
3268 pnt += psize;
3269 (*numpfx)++;
3270 }
3271
3272 /* Packet length consistency check. */
3273 if (pnt != end)
3274 {
3275 zlog_err ("%s [Error] Update packet error"
3276 " (prefix length mismatch with total length)",
3277 peer->host);
3278 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3279 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3280 return -1;
3281 }
3282 return 0;
3283 }
3284
3285 static struct bgp_static *
3286 bgp_static_new (void)
3287 {
3288 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3289 }
3290
3291 static void
3292 bgp_static_free (struct bgp_static *bgp_static)
3293 {
3294 if (bgp_static->rmap.name)
3295 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3296 XFREE (MTYPE_BGP_STATIC, bgp_static);
3297 }
3298
3299 static void
3300 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3301 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3302 {
3303 struct bgp_node *rn;
3304 struct bgp_info *ri;
3305 struct bgp_info *new;
3306 struct bgp_info info;
3307 struct attr attr;
3308 struct attr *attr_new;
3309 int ret;
3310
3311 assert (bgp_static);
3312 if (!bgp_static)
3313 return;
3314
3315 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3316
3317 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3318
3319 attr.nexthop = bgp_static->igpnexthop;
3320 attr.med = bgp_static->igpmetric;
3321 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3322
3323 if (bgp_static->atomic)
3324 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3325
3326 /* Apply route-map. */
3327 if (bgp_static->rmap.name)
3328 {
3329 struct attr attr_tmp = attr;
3330 info.peer = bgp->peer_self;
3331 info.attr = &attr_tmp;
3332
3333 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3334
3335 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3336
3337 bgp->peer_self->rmap_type = 0;
3338
3339 if (ret == RMAP_DENYMATCH)
3340 {
3341 /* Free uninterned attribute. */
3342 bgp_attr_flush (&attr_tmp);
3343
3344 /* Unintern original. */
3345 aspath_unintern (&attr.aspath);
3346 bgp_attr_extra_free (&attr);
3347 bgp_static_withdraw (bgp, p, afi, safi);
3348 return;
3349 }
3350 attr_new = bgp_attr_intern (&attr_tmp);
3351 }
3352 else
3353 attr_new = bgp_attr_intern (&attr);
3354
3355 for (ri = rn->info; ri; ri = ri->next)
3356 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3357 && ri->sub_type == BGP_ROUTE_STATIC)
3358 break;
3359
3360 if (ri)
3361 {
3362 if (attrhash_cmp (ri->attr, attr_new) &&
3363 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3364 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
3365 {
3366 bgp_unlock_node (rn);
3367 bgp_attr_unintern (&attr_new);
3368 aspath_unintern (&attr.aspath);
3369 bgp_attr_extra_free (&attr);
3370 return;
3371 }
3372 else
3373 {
3374 /* The attribute is changed. */
3375 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3376
3377 /* Rewrite BGP route information. */
3378 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3379 bgp_info_restore(rn, ri);
3380 else
3381 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3382 bgp_attr_unintern (&ri->attr);
3383 ri->attr = attr_new;
3384 ri->uptime = bgp_clock ();
3385
3386 /* Nexthop reachability check. */
3387 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3388 {
3389 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
3390 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3391 else
3392 {
3393 if (BGP_DEBUG(nht, NHT))
3394 {
3395 char buf1[INET6_ADDRSTRLEN];
3396 inet_ntop(p->family, &p->u.prefix, buf1,
3397 INET6_ADDRSTRLEN);
3398 zlog_debug("%s(%s): Route not in table, not advertising",
3399 __FUNCTION__, buf1);
3400 }
3401 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3402 }
3403 }
3404 else
3405 {
3406 /* Delete the NHT structure if any, if we're toggling between
3407 * enabling/disabling import check. We deregister the route
3408 * from NHT to avoid overloading NHT and the process interaction
3409 */
3410 bgp_unlink_nexthop(ri);
3411 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3412 }
3413 /* Process change. */
3414 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3415 bgp_process (bgp, rn, afi, safi);
3416 bgp_unlock_node (rn);
3417 aspath_unintern (&attr.aspath);
3418 bgp_attr_extra_free (&attr);
3419 return;
3420 }
3421 }
3422
3423 /* Make new BGP info. */
3424 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3425 rn);
3426 /* Nexthop reachability check. */
3427 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3428 {
3429 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
3430 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3431 else
3432 {
3433 if (BGP_DEBUG(nht, NHT))
3434 {
3435 char buf1[INET6_ADDRSTRLEN];
3436 inet_ntop(p->family, &p->u.prefix, buf1,
3437 INET6_ADDRSTRLEN);
3438 zlog_debug("%s(%s): Route not in table, not advertising",
3439 __FUNCTION__, buf1);
3440 }
3441 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3442 }
3443 }
3444 else
3445 {
3446 /* Delete the NHT structure if any, if we're toggling between
3447 * enabling/disabling import check. We deregister the route
3448 * from NHT to avoid overloading NHT and the process interaction
3449 */
3450 bgp_unlink_nexthop(new);
3451
3452 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3453 }
3454
3455 /* Aggregate address increment. */
3456 bgp_aggregate_increment (bgp, p, new, afi, safi);
3457
3458 /* Register new BGP information. */
3459 bgp_info_add (rn, new);
3460
3461 /* route_node_get lock */
3462 bgp_unlock_node (rn);
3463
3464 /* Process change. */
3465 bgp_process (bgp, rn, afi, safi);
3466
3467 /* Unintern original. */
3468 aspath_unintern (&attr.aspath);
3469 bgp_attr_extra_free (&attr);
3470 }
3471
3472 void
3473 bgp_static_update (struct bgp *bgp, struct prefix *p,
3474 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3475 {
3476 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3477 }
3478
3479 static void
3480 bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3481 safi_t safi, struct prefix_rd *prd, u_char *tag)
3482 {
3483 struct bgp_node *rn;
3484 struct bgp_info *new;
3485
3486 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3487
3488 /* Make new BGP info. */
3489 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
3490 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3491
3492 SET_FLAG (new->flags, BGP_INFO_VALID);
3493 new->extra = bgp_info_extra_new();
3494 memcpy (new->extra->tag, tag, 3);
3495
3496 /* Aggregate address increment. */
3497 bgp_aggregate_increment (bgp, p, new, afi, safi);
3498
3499 /* Register new BGP information. */
3500 bgp_info_add (rn, new);
3501
3502 /* route_node_get lock */
3503 bgp_unlock_node (rn);
3504
3505 /* Process change. */
3506 bgp_process (bgp, rn, afi, safi);
3507 }
3508
3509 void
3510 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3511 safi_t safi)
3512 {
3513 struct bgp_node *rn;
3514 struct bgp_info *ri;
3515
3516 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3517
3518 /* Check selected route and self inserted route. */
3519 for (ri = rn->info; ri; ri = ri->next)
3520 if (ri->peer == bgp->peer_self
3521 && ri->type == ZEBRA_ROUTE_BGP
3522 && ri->sub_type == BGP_ROUTE_STATIC)
3523 break;
3524
3525 /* Withdraw static BGP route from routing table. */
3526 if (ri)
3527 {
3528 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3529 bgp_unlink_nexthop(ri);
3530 bgp_info_delete (rn, ri);
3531 bgp_process (bgp, rn, afi, safi);
3532 }
3533
3534 /* Unlock bgp_node_lookup. */
3535 bgp_unlock_node (rn);
3536 }
3537
3538 static void
3539 bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3540 safi_t safi, struct prefix_rd *prd, u_char *tag)
3541 {
3542 struct bgp_node *rn;
3543 struct bgp_info *ri;
3544
3545 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3546
3547 /* Check selected route and self inserted route. */
3548 for (ri = rn->info; ri; ri = ri->next)
3549 if (ri->peer == bgp->peer_self
3550 && ri->type == ZEBRA_ROUTE_BGP
3551 && ri->sub_type == BGP_ROUTE_STATIC)
3552 break;
3553
3554 /* Withdraw static BGP route from routing table. */
3555 if (ri)
3556 {
3557 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3558 bgp_info_delete (rn, ri);
3559 bgp_process (bgp, rn, afi, safi);
3560 }
3561
3562 /* Unlock bgp_node_lookup. */
3563 bgp_unlock_node (rn);
3564 }
3565
3566 /* Configure static BGP network. When user don't run zebra, static
3567 route should be installed as valid. */
3568 static int
3569 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3570 afi_t afi, safi_t safi, const char *rmap, int backdoor)
3571 {
3572 int ret;
3573 struct prefix p;
3574 struct bgp_static *bgp_static;
3575 struct bgp_node *rn;
3576 u_char need_update = 0;
3577
3578 /* Convert IP prefix string to struct prefix. */
3579 ret = str2prefix (ip_str, &p);
3580 if (! ret)
3581 {
3582 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3583 return CMD_WARNING;
3584 }
3585 #ifdef HAVE_IPV6
3586 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3587 {
3588 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3589 VTY_NEWLINE);
3590 return CMD_WARNING;
3591 }
3592 #endif /* HAVE_IPV6 */
3593
3594 apply_mask (&p);
3595
3596 /* Set BGP static route configuration. */
3597 rn = bgp_node_get (bgp->route[afi][safi], &p);
3598
3599 if (rn->info)
3600 {
3601 /* Configuration change. */
3602 bgp_static = rn->info;
3603
3604 /* Check previous routes are installed into BGP. */
3605 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3606 need_update = 1;
3607
3608 bgp_static->backdoor = backdoor;
3609
3610 if (rmap)
3611 {
3612 if (bgp_static->rmap.name)
3613 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3614 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
3615 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3616 }
3617 else
3618 {
3619 if (bgp_static->rmap.name)
3620 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3621 bgp_static->rmap.name = NULL;
3622 bgp_static->rmap.map = NULL;
3623 bgp_static->valid = 0;
3624 }
3625 bgp_unlock_node (rn);
3626 }
3627 else
3628 {
3629 /* New configuration. */
3630 bgp_static = bgp_static_new ();
3631 bgp_static->backdoor = backdoor;
3632 bgp_static->valid = 0;
3633 bgp_static->igpmetric = 0;
3634 bgp_static->igpnexthop.s_addr = 0;
3635
3636 if (rmap)
3637 {
3638 if (bgp_static->rmap.name)
3639 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3640 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
3641 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3642 }
3643 rn->info = bgp_static;
3644 }
3645
3646 bgp_static->valid = 1;
3647 if (need_update)
3648 bgp_static_withdraw (bgp, &p, afi, safi);
3649
3650 if (! bgp_static->backdoor)
3651 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3652
3653 return CMD_SUCCESS;
3654 }
3655
3656 /* Configure static BGP network. */
3657 static int
3658 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
3659 afi_t afi, safi_t safi)
3660 {
3661 int ret;
3662 struct prefix p;
3663 struct bgp_static *bgp_static;
3664 struct bgp_node *rn;
3665
3666 /* Convert IP prefix string to struct prefix. */
3667 ret = str2prefix (ip_str, &p);
3668 if (! ret)
3669 {
3670 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3671 return CMD_WARNING;
3672 }
3673 #ifdef HAVE_IPV6
3674 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3675 {
3676 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3677 VTY_NEWLINE);
3678 return CMD_WARNING;
3679 }
3680 #endif /* HAVE_IPV6 */
3681
3682 apply_mask (&p);
3683
3684 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3685 if (! rn)
3686 {
3687 vty_out (vty, "%% Can't find specified static route configuration.%s",
3688 VTY_NEWLINE);
3689 return CMD_WARNING;
3690 }
3691
3692 bgp_static = rn->info;
3693
3694 /* Update BGP RIB. */
3695 if (! bgp_static->backdoor)
3696 bgp_static_withdraw (bgp, &p, afi, safi);
3697
3698 /* Clear configuration. */
3699 bgp_static_free (bgp_static);
3700 rn->info = NULL;
3701 bgp_unlock_node (rn);
3702 bgp_unlock_node (rn);
3703
3704 return CMD_SUCCESS;
3705 }
3706
3707 void
3708 bgp_static_add (struct bgp *bgp)
3709 {
3710 afi_t afi;
3711 safi_t safi;
3712 struct bgp_node *rn;
3713 struct bgp_node *rm;
3714 struct bgp_table *table;
3715 struct bgp_static *bgp_static;
3716
3717 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3718 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3719 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3720 if (rn->info != NULL)
3721 {
3722 if (safi == SAFI_MPLS_VPN)
3723 {
3724 table = rn->info;
3725
3726 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3727 {
3728 bgp_static = rn->info;
3729 bgp_static_update_vpnv4 (bgp, &rm->p,
3730 AFI_IP, SAFI_MPLS_VPN,
3731 (struct prefix_rd *)&rn->p,
3732 bgp_static->tag);
3733 }
3734 }
3735 else
3736 {
3737 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
3738 }
3739 }
3740 }
3741
3742 /* Called from bgp_delete(). Delete all static routes from the BGP
3743 instance. */
3744 void
3745 bgp_static_delete (struct bgp *bgp)
3746 {
3747 afi_t afi;
3748 safi_t safi;
3749 struct bgp_node *rn;
3750 struct bgp_node *rm;
3751 struct bgp_table *table;
3752 struct bgp_static *bgp_static;
3753
3754 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3755 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3756 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3757 if (rn->info != NULL)
3758 {
3759 if (safi == SAFI_MPLS_VPN)
3760 {
3761 table = rn->info;
3762
3763 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3764 {
3765 bgp_static = rn->info;
3766 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3767 AFI_IP, SAFI_MPLS_VPN,
3768 (struct prefix_rd *)&rn->p,
3769 bgp_static->tag);
3770 bgp_static_free (bgp_static);
3771 rn->info = NULL;
3772 bgp_unlock_node (rn);
3773 }
3774 }
3775 else
3776 {
3777 bgp_static = rn->info;
3778 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3779 bgp_static_free (bgp_static);
3780 rn->info = NULL;
3781 bgp_unlock_node (rn);
3782 }
3783 }
3784 }
3785
3786 void
3787 bgp_static_redo_import_check (struct bgp *bgp)
3788 {
3789 afi_t afi;
3790 safi_t safi;
3791 struct bgp_node *rn;
3792 struct bgp_static *bgp_static;
3793
3794 /* Use this flag to force reprocessing of the route */
3795 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3796 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3797 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3798 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3799 if (rn->info != NULL)
3800 {
3801 bgp_static = rn->info;
3802 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
3803 }
3804 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3805 }
3806
3807 static void
3808 bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
3809 {
3810 struct bgp_table *table;
3811 struct bgp_node *rn;
3812 struct bgp_info *ri;
3813
3814 table = bgp->rib[afi][safi];
3815 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3816 {
3817 for (ri = rn->info; ri; ri = ri->next)
3818 {
3819 if (ri->peer == bgp->peer_self &&
3820 ((ri->type == ZEBRA_ROUTE_BGP &&
3821 ri->sub_type == BGP_ROUTE_STATIC) ||
3822 (ri->type != ZEBRA_ROUTE_BGP &&
3823 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
3824 {
3825 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
3826 bgp_unlink_nexthop(ri);
3827 bgp_info_delete (rn, ri);
3828 bgp_process (bgp, rn, afi, safi);
3829 }
3830 }
3831 }
3832 }
3833
3834 /*
3835 * Purge all networks and redistributed routes from routing table.
3836 * Invoked upon the instance going down.
3837 */
3838 void
3839 bgp_purge_static_redist_routes (struct bgp *bgp)
3840 {
3841 afi_t afi;
3842 safi_t safi;
3843
3844 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3845 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3846 bgp_purge_af_static_redist_routes (bgp, afi, safi);
3847 }
3848
3849 int
3850 bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3851 const char *tag_str)
3852 {
3853 int ret;
3854 struct prefix p;
3855 struct prefix_rd prd;
3856 struct bgp *bgp;
3857 struct bgp_node *prn;
3858 struct bgp_node *rn;
3859 struct bgp_table *table;
3860 struct bgp_static *bgp_static;
3861 u_char tag[3];
3862
3863 bgp = vty->index;
3864
3865 ret = str2prefix (ip_str, &p);
3866 if (! ret)
3867 {
3868 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3869 return CMD_WARNING;
3870 }
3871 apply_mask (&p);
3872
3873 ret = str2prefix_rd (rd_str, &prd);
3874 if (! ret)
3875 {
3876 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3877 return CMD_WARNING;
3878 }
3879
3880 ret = str2tag (tag_str, tag);
3881 if (! ret)
3882 {
3883 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3884 return CMD_WARNING;
3885 }
3886
3887 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3888 (struct prefix *)&prd);
3889 if (prn->info == NULL)
3890 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3891 else
3892 bgp_unlock_node (prn);
3893 table = prn->info;
3894
3895 rn = bgp_node_get (table, &p);
3896
3897 if (rn->info)
3898 {
3899 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3900 bgp_unlock_node (rn);
3901 }
3902 else
3903 {
3904 /* New configuration. */
3905 bgp_static = bgp_static_new ();
3906 bgp_static->valid = 1;
3907 memcpy (bgp_static->tag, tag, 3);
3908 rn->info = bgp_static;
3909
3910 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3911 }
3912
3913 return CMD_SUCCESS;
3914 }
3915
3916 /* Configure static BGP network. */
3917 int
3918 bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3919 const char *rd_str, const char *tag_str)
3920 {
3921 int ret;
3922 struct bgp *bgp;
3923 struct prefix p;
3924 struct prefix_rd prd;
3925 struct bgp_node *prn;
3926 struct bgp_node *rn;
3927 struct bgp_table *table;
3928 struct bgp_static *bgp_static;
3929 u_char tag[3];
3930
3931 bgp = vty->index;
3932
3933 /* Convert IP prefix string to struct prefix. */
3934 ret = str2prefix (ip_str, &p);
3935 if (! ret)
3936 {
3937 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3938 return CMD_WARNING;
3939 }
3940 apply_mask (&p);
3941
3942 ret = str2prefix_rd (rd_str, &prd);
3943 if (! ret)
3944 {
3945 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3946 return CMD_WARNING;
3947 }
3948
3949 ret = str2tag (tag_str, tag);
3950 if (! ret)
3951 {
3952 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3953 return CMD_WARNING;
3954 }
3955
3956 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3957 (struct prefix *)&prd);
3958 if (prn->info == NULL)
3959 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3960 else
3961 bgp_unlock_node (prn);
3962 table = prn->info;
3963
3964 rn = bgp_node_lookup (table, &p);
3965
3966 if (rn)
3967 {
3968 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3969
3970 bgp_static = rn->info;
3971 bgp_static_free (bgp_static);
3972 rn->info = NULL;
3973 bgp_unlock_node (rn);
3974 bgp_unlock_node (rn);
3975 }
3976 else
3977 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3978
3979 return CMD_SUCCESS;
3980 }
3981
3982 static int
3983 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
3984 const char *rmap_name)
3985 {
3986 struct bgp_rmap *rmap;
3987
3988 rmap = &bgp->table_map[afi][safi];
3989 if (rmap_name)
3990 {
3991 if (rmap->name)
3992 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
3993 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
3994 rmap->map = route_map_lookup_by_name (rmap_name);
3995 }
3996 else
3997 {
3998 if (rmap->name)
3999 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4000 rmap->name = NULL;
4001 rmap->map = NULL;
4002 }
4003
4004 bgp_zebra_announce_table(bgp, afi, safi);
4005
4006 return CMD_SUCCESS;
4007 }
4008
4009 static int
4010 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4011 const char *rmap_name)
4012 {
4013 struct bgp_rmap *rmap;
4014
4015 rmap = &bgp->table_map[afi][safi];
4016 if (rmap->name)
4017 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4018 rmap->name = NULL;
4019 rmap->map = NULL;
4020
4021 bgp_zebra_announce_table(bgp, afi, safi);
4022
4023 return CMD_SUCCESS;
4024 }
4025
4026 int
4027 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4028 safi_t safi, int *write)
4029 {
4030 if (bgp->table_map[afi][safi].name)
4031 {
4032 bgp_config_write_family_header (vty, afi, safi, write);
4033 vty_out (vty, " table-map %s%s",
4034 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4035 }
4036
4037 return 0;
4038 }
4039
4040
4041 DEFUN (bgp_table_map,
4042 bgp_table_map_cmd,
4043 "table-map WORD",
4044 "BGP table to RIB route download filter\n"
4045 "Name of the route map\n")
4046 {
4047 return bgp_table_map_set (vty, vty->index,
4048 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4049 }
4050 DEFUN (no_bgp_table_map,
4051 no_bgp_table_map_cmd,
4052 "no table-map WORD",
4053 "BGP table to RIB route download filter\n"
4054 "Name of the route map\n")
4055 {
4056 return bgp_table_map_unset (vty, vty->index,
4057 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4058 }
4059
4060 DEFUN (bgp_network,
4061 bgp_network_cmd,
4062 "network A.B.C.D/M",
4063 "Specify a network to announce via BGP\n"
4064 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4065 {
4066 return bgp_static_set (vty, vty->index, argv[0],
4067 AFI_IP, bgp_node_safi (vty), NULL, 0);
4068 }
4069
4070 DEFUN (bgp_network_route_map,
4071 bgp_network_route_map_cmd,
4072 "network A.B.C.D/M route-map WORD",
4073 "Specify a network to announce via BGP\n"
4074 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4075 "Route-map to modify the attributes\n"
4076 "Name of the route map\n")
4077 {
4078 return bgp_static_set (vty, vty->index, argv[0],
4079 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4080 }
4081
4082 DEFUN (bgp_network_backdoor,
4083 bgp_network_backdoor_cmd,
4084 "network A.B.C.D/M backdoor",
4085 "Specify a network to announce via BGP\n"
4086 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4087 "Specify a BGP backdoor route\n")
4088 {
4089 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4090 NULL, 1);
4091 }
4092
4093 DEFUN (bgp_network_mask,
4094 bgp_network_mask_cmd,
4095 "network A.B.C.D mask A.B.C.D",
4096 "Specify a network to announce via BGP\n"
4097 "Network number\n"
4098 "Network mask\n"
4099 "Network mask\n")
4100 {
4101 int ret;
4102 char prefix_str[BUFSIZ];
4103
4104 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4105 if (! ret)
4106 {
4107 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4108 return CMD_WARNING;
4109 }
4110
4111 return bgp_static_set (vty, vty->index, prefix_str,
4112 AFI_IP, bgp_node_safi (vty), NULL, 0);
4113 }
4114
4115 DEFUN (bgp_network_mask_route_map,
4116 bgp_network_mask_route_map_cmd,
4117 "network A.B.C.D mask A.B.C.D route-map WORD",
4118 "Specify a network to announce via BGP\n"
4119 "Network number\n"
4120 "Network mask\n"
4121 "Network mask\n"
4122 "Route-map to modify the attributes\n"
4123 "Name of the route map\n")
4124 {
4125 int ret;
4126 char prefix_str[BUFSIZ];
4127
4128 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4129 if (! ret)
4130 {
4131 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4132 return CMD_WARNING;
4133 }
4134
4135 return bgp_static_set (vty, vty->index, prefix_str,
4136 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4137 }
4138
4139 DEFUN (bgp_network_mask_backdoor,
4140 bgp_network_mask_backdoor_cmd,
4141 "network A.B.C.D mask A.B.C.D backdoor",
4142 "Specify a network to announce via BGP\n"
4143 "Network number\n"
4144 "Network mask\n"
4145 "Network mask\n"
4146 "Specify a BGP backdoor route\n")
4147 {
4148 int ret;
4149 char prefix_str[BUFSIZ];
4150
4151 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4152 if (! ret)
4153 {
4154 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4155 return CMD_WARNING;
4156 }
4157
4158 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4159 NULL, 1);
4160 }
4161
4162 DEFUN (bgp_network_mask_natural,
4163 bgp_network_mask_natural_cmd,
4164 "network A.B.C.D",
4165 "Specify a network to announce via BGP\n"
4166 "Network number\n")
4167 {
4168 int ret;
4169 char prefix_str[BUFSIZ];
4170
4171 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4172 if (! ret)
4173 {
4174 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4175 return CMD_WARNING;
4176 }
4177
4178 return bgp_static_set (vty, vty->index, prefix_str,
4179 AFI_IP, bgp_node_safi (vty), NULL, 0);
4180 }
4181
4182 DEFUN (bgp_network_mask_natural_route_map,
4183 bgp_network_mask_natural_route_map_cmd,
4184 "network A.B.C.D route-map WORD",
4185 "Specify a network to announce via BGP\n"
4186 "Network number\n"
4187 "Route-map to modify the attributes\n"
4188 "Name of the route map\n")
4189 {
4190 int ret;
4191 char prefix_str[BUFSIZ];
4192
4193 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4194 if (! ret)
4195 {
4196 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4197 return CMD_WARNING;
4198 }
4199
4200 return bgp_static_set (vty, vty->index, prefix_str,
4201 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4202 }
4203
4204 DEFUN (bgp_network_mask_natural_backdoor,
4205 bgp_network_mask_natural_backdoor_cmd,
4206 "network A.B.C.D backdoor",
4207 "Specify a network to announce via BGP\n"
4208 "Network number\n"
4209 "Specify a BGP backdoor route\n")
4210 {
4211 int ret;
4212 char prefix_str[BUFSIZ];
4213
4214 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4215 if (! ret)
4216 {
4217 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4218 return CMD_WARNING;
4219 }
4220
4221 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4222 NULL, 1);
4223 }
4224
4225 DEFUN (no_bgp_network,
4226 no_bgp_network_cmd,
4227 "no network A.B.C.D/M",
4228 NO_STR
4229 "Specify a network to announce via BGP\n"
4230 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4231 {
4232 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4233 bgp_node_safi (vty));
4234 }
4235
4236 ALIAS (no_bgp_network,
4237 no_bgp_network_route_map_cmd,
4238 "no network A.B.C.D/M route-map WORD",
4239 NO_STR
4240 "Specify a network to announce via BGP\n"
4241 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4242 "Route-map to modify the attributes\n"
4243 "Name of the route map\n")
4244
4245 ALIAS (no_bgp_network,
4246 no_bgp_network_backdoor_cmd,
4247 "no network A.B.C.D/M backdoor",
4248 NO_STR
4249 "Specify a network to announce via BGP\n"
4250 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4251 "Specify a BGP backdoor route\n")
4252
4253 DEFUN (no_bgp_network_mask,
4254 no_bgp_network_mask_cmd,
4255 "no network A.B.C.D mask A.B.C.D",
4256 NO_STR
4257 "Specify a network to announce via BGP\n"
4258 "Network number\n"
4259 "Network mask\n"
4260 "Network mask\n")
4261 {
4262 int ret;
4263 char prefix_str[BUFSIZ];
4264
4265 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4266 if (! ret)
4267 {
4268 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4269 return CMD_WARNING;
4270 }
4271
4272 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4273 bgp_node_safi (vty));
4274 }
4275
4276 ALIAS (no_bgp_network_mask,
4277 no_bgp_network_mask_route_map_cmd,
4278 "no network A.B.C.D mask A.B.C.D route-map WORD",
4279 NO_STR
4280 "Specify a network to announce via BGP\n"
4281 "Network number\n"
4282 "Network mask\n"
4283 "Network mask\n"
4284 "Route-map to modify the attributes\n"
4285 "Name of the route map\n")
4286
4287 ALIAS (no_bgp_network_mask,
4288 no_bgp_network_mask_backdoor_cmd,
4289 "no network A.B.C.D mask A.B.C.D backdoor",
4290 NO_STR
4291 "Specify a network to announce via BGP\n"
4292 "Network number\n"
4293 "Network mask\n"
4294 "Network mask\n"
4295 "Specify a BGP backdoor route\n")
4296
4297 DEFUN (no_bgp_network_mask_natural,
4298 no_bgp_network_mask_natural_cmd,
4299 "no network A.B.C.D",
4300 NO_STR
4301 "Specify a network to announce via BGP\n"
4302 "Network number\n")
4303 {
4304 int ret;
4305 char prefix_str[BUFSIZ];
4306
4307 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4308 if (! ret)
4309 {
4310 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4311 return CMD_WARNING;
4312 }
4313
4314 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4315 bgp_node_safi (vty));
4316 }
4317
4318 ALIAS (no_bgp_network_mask_natural,
4319 no_bgp_network_mask_natural_route_map_cmd,
4320 "no network A.B.C.D route-map WORD",
4321 NO_STR
4322 "Specify a network to announce via BGP\n"
4323 "Network number\n"
4324 "Route-map to modify the attributes\n"
4325 "Name of the route map\n")
4326
4327 ALIAS (no_bgp_network_mask_natural,
4328 no_bgp_network_mask_natural_backdoor_cmd,
4329 "no network A.B.C.D backdoor",
4330 NO_STR
4331 "Specify a network to announce via BGP\n"
4332 "Network number\n"
4333 "Specify a BGP backdoor route\n")
4334
4335 #ifdef HAVE_IPV6
4336 DEFUN (ipv6_bgp_network,
4337 ipv6_bgp_network_cmd,
4338 "network X:X::X:X/M",
4339 "Specify a network to announce via BGP\n"
4340 "IPv6 prefix <network>/<length>\n")
4341 {
4342 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4343 NULL, 0);
4344 }
4345
4346 DEFUN (ipv6_bgp_network_route_map,
4347 ipv6_bgp_network_route_map_cmd,
4348 "network X:X::X:X/M route-map WORD",
4349 "Specify a network to announce via BGP\n"
4350 "IPv6 prefix <network>/<length>\n"
4351 "Route-map to modify the attributes\n"
4352 "Name of the route map\n")
4353 {
4354 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4355 bgp_node_safi (vty), argv[1], 0);
4356 }
4357
4358 DEFUN (no_ipv6_bgp_network,
4359 no_ipv6_bgp_network_cmd,
4360 "no network X:X::X:X/M",
4361 NO_STR
4362 "Specify a network to announce via BGP\n"
4363 "IPv6 prefix <network>/<length>\n")
4364 {
4365 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4366 }
4367
4368 ALIAS (no_ipv6_bgp_network,
4369 no_ipv6_bgp_network_route_map_cmd,
4370 "no network X:X::X:X/M route-map WORD",
4371 NO_STR
4372 "Specify a network to announce via BGP\n"
4373 "IPv6 prefix <network>/<length>\n"
4374 "Route-map to modify the attributes\n"
4375 "Name of the route map\n")
4376
4377 ALIAS (ipv6_bgp_network,
4378 old_ipv6_bgp_network_cmd,
4379 "ipv6 bgp network X:X::X:X/M",
4380 IPV6_STR
4381 BGP_STR
4382 "Specify a network to announce via BGP\n"
4383 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4384
4385 ALIAS (no_ipv6_bgp_network,
4386 old_no_ipv6_bgp_network_cmd,
4387 "no ipv6 bgp network X:X::X:X/M",
4388 NO_STR
4389 IPV6_STR
4390 BGP_STR
4391 "Specify a network to announce via BGP\n"
4392 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4393 #endif /* HAVE_IPV6 */
4394
4395 /* Aggreagete address:
4396
4397 advertise-map Set condition to advertise attribute
4398 as-set Generate AS set path information
4399 attribute-map Set attributes of aggregate
4400 route-map Set parameters of aggregate
4401 summary-only Filter more specific routes from updates
4402 suppress-map Conditionally filter more specific routes from updates
4403 <cr>
4404 */
4405 struct bgp_aggregate
4406 {
4407 /* Summary-only flag. */
4408 u_char summary_only;
4409
4410 /* AS set generation. */
4411 u_char as_set;
4412
4413 /* Route-map for aggregated route. */
4414 struct route_map *map;
4415
4416 /* Suppress-count. */
4417 unsigned long count;
4418
4419 /* SAFI configuration. */
4420 safi_t safi;
4421 };
4422
4423 static struct bgp_aggregate *
4424 bgp_aggregate_new (void)
4425 {
4426 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4427 }
4428
4429 static void
4430 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4431 {
4432 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4433 }
4434
4435 /* Update an aggregate as routes are added/removed from the BGP table */
4436 static void
4437 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4438 afi_t afi, safi_t safi, struct bgp_info *del,
4439 struct bgp_aggregate *aggregate)
4440 {
4441 struct bgp_table *table;
4442 struct bgp_node *top;
4443 struct bgp_node *rn;
4444 u_char origin;
4445 struct aspath *aspath = NULL;
4446 struct aspath *asmerge = NULL;
4447 struct community *community = NULL;
4448 struct community *commerge = NULL;
4449 #if defined(AGGREGATE_NEXTHOP_CHECK)
4450 struct in_addr nexthop;
4451 u_int32_t med = 0;
4452 #endif
4453 struct bgp_info *ri;
4454 struct bgp_info *new;
4455 int first = 1;
4456 unsigned long match = 0;
4457 u_char atomic_aggregate = 0;
4458
4459 /* Record adding route's nexthop and med. */
4460 if (rinew)
4461 {
4462 #if defined(AGGREGATE_NEXTHOP_CHECK)
4463 nexthop = rinew->attr->nexthop;
4464 med = rinew->attr->med;
4465 #endif
4466 }
4467
4468 /* ORIGIN attribute: If at least one route among routes that are
4469 aggregated has ORIGIN with the value INCOMPLETE, then the
4470 aggregated route must have the ORIGIN attribute with the value
4471 INCOMPLETE. Otherwise, if at least one route among routes that
4472 are aggregated has ORIGIN with the value EGP, then the aggregated
4473 route must have the origin attribute with the value EGP. In all
4474 other case the value of the ORIGIN attribute of the aggregated
4475 route is INTERNAL. */
4476 origin = BGP_ORIGIN_IGP;
4477
4478 table = bgp->rib[afi][safi];
4479
4480 top = bgp_node_get (table, p);
4481 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4482 if (rn->p.prefixlen > p->prefixlen)
4483 {
4484 match = 0;
4485
4486 for (ri = rn->info; ri; ri = ri->next)
4487 {
4488 if (BGP_INFO_HOLDDOWN (ri))
4489 continue;
4490
4491 if (del && ri == del)
4492 continue;
4493
4494 if (! rinew && first)
4495 {
4496 #if defined(AGGREGATE_NEXTHOP_CHECK)
4497 nexthop = ri->attr->nexthop;
4498 med = ri->attr->med;
4499 #endif
4500 first = 0;
4501 }
4502
4503 #ifdef AGGREGATE_NEXTHOP_CHECK
4504 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4505 || ri->attr->med != med)
4506 {
4507 if (aspath)
4508 aspath_free (aspath);
4509 if (community)
4510 community_free (community);
4511 bgp_unlock_node (rn);
4512 bgp_unlock_node (top);
4513 return;
4514 }
4515 #endif /* AGGREGATE_NEXTHOP_CHECK */
4516
4517 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4518 atomic_aggregate = 1;
4519
4520 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4521 {
4522 if (aggregate->summary_only)
4523 {
4524 (bgp_info_extra_get (ri))->suppress++;
4525 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4526 match++;
4527 }
4528
4529 aggregate->count++;
4530
4531 if (origin < ri->attr->origin)
4532 origin = ri->attr->origin;
4533
4534 if (aggregate->as_set)
4535 {
4536 if (aspath)
4537 {
4538 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4539 aspath_free (aspath);
4540 aspath = asmerge;
4541 }
4542 else
4543 aspath = aspath_dup (ri->attr->aspath);
4544
4545 if (ri->attr->community)
4546 {
4547 if (community)
4548 {
4549 commerge = community_merge (community,
4550 ri->attr->community);
4551 community = community_uniq_sort (commerge);
4552 community_free (commerge);
4553 }
4554 else
4555 community = community_dup (ri->attr->community);
4556 }
4557 }
4558 }
4559 }
4560 if (match)
4561 bgp_process (bgp, rn, afi, safi);
4562 }
4563 bgp_unlock_node (top);
4564
4565 if (rinew)
4566 {
4567 aggregate->count++;
4568
4569 if (aggregate->summary_only)
4570 (bgp_info_extra_get (rinew))->suppress++;
4571
4572 if (origin < rinew->attr->origin)
4573 origin = rinew->attr->origin;
4574
4575 if (aggregate->as_set)
4576 {
4577 if (aspath)
4578 {
4579 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4580 aspath_free (aspath);
4581 aspath = asmerge;
4582 }
4583 else
4584 aspath = aspath_dup (rinew->attr->aspath);
4585
4586 if (rinew->attr->community)
4587 {
4588 if (community)
4589 {
4590 commerge = community_merge (community,
4591 rinew->attr->community);
4592 community = community_uniq_sort (commerge);
4593 community_free (commerge);
4594 }
4595 else
4596 community = community_dup (rinew->attr->community);
4597 }
4598 }
4599 }
4600
4601 if (aggregate->count > 0)
4602 {
4603 rn = bgp_node_get (table, p);
4604 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
4605 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4606 aggregate->as_set,
4607 atomic_aggregate), rn);
4608 SET_FLAG (new->flags, BGP_INFO_VALID);
4609
4610 bgp_info_add (rn, new);
4611 bgp_unlock_node (rn);
4612 bgp_process (bgp, rn, afi, safi);
4613 }
4614 else
4615 {
4616 if (aspath)
4617 aspath_free (aspath);
4618 if (community)
4619 community_free (community);
4620 }
4621 }
4622
4623 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4624 struct bgp_aggregate *);
4625
4626 void
4627 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4628 struct bgp_info *ri, afi_t afi, safi_t safi)
4629 {
4630 struct bgp_node *child;
4631 struct bgp_node *rn;
4632 struct bgp_aggregate *aggregate;
4633 struct bgp_table *table;
4634
4635 /* MPLS-VPN aggregation is not yet supported. */
4636 if (safi == SAFI_MPLS_VPN)
4637 return;
4638
4639 table = bgp->aggregate[afi][safi];
4640
4641 /* No aggregates configured. */
4642 if (bgp_table_top_nolock (table) == NULL)
4643 return;
4644
4645 if (p->prefixlen == 0)
4646 return;
4647
4648 if (BGP_INFO_HOLDDOWN (ri))
4649 return;
4650
4651 child = bgp_node_get (table, p);
4652
4653 /* Aggregate address configuration check. */
4654 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
4655 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4656 {
4657 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4658 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
4659 }
4660 bgp_unlock_node (child);
4661 }
4662
4663 void
4664 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4665 struct bgp_info *del, afi_t afi, safi_t safi)
4666 {
4667 struct bgp_node *child;
4668 struct bgp_node *rn;
4669 struct bgp_aggregate *aggregate;
4670 struct bgp_table *table;
4671
4672 /* MPLS-VPN aggregation is not yet supported. */
4673 if (safi == SAFI_MPLS_VPN)
4674 return;
4675
4676 table = bgp->aggregate[afi][safi];
4677
4678 /* No aggregates configured. */
4679 if (bgp_table_top_nolock (table) == NULL)
4680 return;
4681
4682 if (p->prefixlen == 0)
4683 return;
4684
4685 child = bgp_node_get (table, p);
4686
4687 /* Aggregate address configuration check. */
4688 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
4689 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4690 {
4691 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4692 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
4693 }
4694 bgp_unlock_node (child);
4695 }
4696
4697 /* Called via bgp_aggregate_set when the user configures aggregate-address */
4698 static void
4699 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4700 struct bgp_aggregate *aggregate)
4701 {
4702 struct bgp_table *table;
4703 struct bgp_node *top;
4704 struct bgp_node *rn;
4705 struct bgp_info *new;
4706 struct bgp_info *ri;
4707 unsigned long match;
4708 u_char origin = BGP_ORIGIN_IGP;
4709 struct aspath *aspath = NULL;
4710 struct aspath *asmerge = NULL;
4711 struct community *community = NULL;
4712 struct community *commerge = NULL;
4713 u_char atomic_aggregate = 0;
4714
4715 table = bgp->rib[afi][safi];
4716
4717 /* Sanity check. */
4718 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4719 return;
4720 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4721 return;
4722
4723 /* If routes exists below this node, generate aggregate routes. */
4724 top = bgp_node_get (table, p);
4725 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4726 if (rn->p.prefixlen > p->prefixlen)
4727 {
4728 match = 0;
4729
4730 for (ri = rn->info; ri; ri = ri->next)
4731 {
4732 if (BGP_INFO_HOLDDOWN (ri))
4733 continue;
4734
4735 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4736 atomic_aggregate = 1;
4737
4738 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4739 {
4740 /* summary-only aggregate route suppress aggregated
4741 route announcement. */
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 /* If at least one route among routes that are aggregated has
4750 * ORIGIN with the value INCOMPLETE, then the aggregated route
4751 * MUST have the ORIGIN attribute with the value INCOMPLETE.
4752 * Otherwise, if at least one route among routes that are
4753 * aggregated has ORIGIN with the value EGP, then the aggregated
4754 * route MUST have the ORIGIN attribute with the value EGP.
4755 */
4756 if (origin < ri->attr->origin)
4757 origin = ri->attr->origin;
4758
4759 /* as-set aggregate route generate origin, as path,
4760 community aggregation. */
4761 if (aggregate->as_set)
4762 {
4763 if (aspath)
4764 {
4765 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4766 aspath_free (aspath);
4767 aspath = asmerge;
4768 }
4769 else
4770 aspath = aspath_dup (ri->attr->aspath);
4771
4772 if (ri->attr->community)
4773 {
4774 if (community)
4775 {
4776 commerge = community_merge (community,
4777 ri->attr->community);
4778 community = community_uniq_sort (commerge);
4779 community_free (commerge);
4780 }
4781 else
4782 community = community_dup (ri->attr->community);
4783 }
4784 }
4785 aggregate->count++;
4786 }
4787 }
4788
4789 /* If this node is suppressed, process the change. */
4790 if (match)
4791 bgp_process (bgp, rn, afi, safi);
4792 }
4793 bgp_unlock_node (top);
4794
4795 /* Add aggregate route to BGP table. */
4796 if (aggregate->count)
4797 {
4798 rn = bgp_node_get (table, p);
4799 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
4800 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4801 aggregate->as_set,
4802 atomic_aggregate), rn);
4803 SET_FLAG (new->flags, BGP_INFO_VALID);
4804
4805 bgp_info_add (rn, new);
4806 bgp_unlock_node (rn);
4807
4808 /* Process change. */
4809 bgp_process (bgp, rn, afi, safi);
4810 }
4811 else
4812 {
4813 if (aspath)
4814 aspath_free (aspath);
4815 if (community)
4816 community_free (community);
4817 }
4818 }
4819
4820 void
4821 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4822 safi_t safi, struct bgp_aggregate *aggregate)
4823 {
4824 struct bgp_table *table;
4825 struct bgp_node *top;
4826 struct bgp_node *rn;
4827 struct bgp_info *ri;
4828 unsigned long match;
4829
4830 table = bgp->rib[afi][safi];
4831
4832 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4833 return;
4834 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4835 return;
4836
4837 /* If routes exists below this node, generate aggregate routes. */
4838 top = bgp_node_get (table, p);
4839 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4840 if (rn->p.prefixlen > p->prefixlen)
4841 {
4842 match = 0;
4843
4844 for (ri = rn->info; ri; ri = ri->next)
4845 {
4846 if (BGP_INFO_HOLDDOWN (ri))
4847 continue;
4848
4849 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4850 {
4851 if (aggregate->summary_only && ri->extra)
4852 {
4853 ri->extra->suppress--;
4854
4855 if (ri->extra->suppress == 0)
4856 {
4857 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4858 match++;
4859 }
4860 }
4861 aggregate->count--;
4862 }
4863 }
4864
4865 /* If this node was suppressed, process the change. */
4866 if (match)
4867 bgp_process (bgp, rn, afi, safi);
4868 }
4869 bgp_unlock_node (top);
4870
4871 /* Delete aggregate route from BGP table. */
4872 rn = bgp_node_get (table, p);
4873
4874 for (ri = rn->info; ri; ri = ri->next)
4875 if (ri->peer == bgp->peer_self
4876 && ri->type == ZEBRA_ROUTE_BGP
4877 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4878 break;
4879
4880 /* Withdraw static BGP route from routing table. */
4881 if (ri)
4882 {
4883 bgp_info_delete (rn, ri);
4884 bgp_process (bgp, rn, afi, safi);
4885 }
4886
4887 /* Unlock bgp_node_lookup. */
4888 bgp_unlock_node (rn);
4889 }
4890
4891 /* Aggregate route attribute. */
4892 #define AGGREGATE_SUMMARY_ONLY 1
4893 #define AGGREGATE_AS_SET 1
4894
4895 static int
4896 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4897 afi_t afi, safi_t safi)
4898 {
4899 int ret;
4900 struct prefix p;
4901 struct bgp_node *rn;
4902 struct bgp *bgp;
4903 struct bgp_aggregate *aggregate;
4904
4905 /* Convert string to prefix structure. */
4906 ret = str2prefix (prefix_str, &p);
4907 if (!ret)
4908 {
4909 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4910 return CMD_WARNING;
4911 }
4912 apply_mask (&p);
4913
4914 /* Get BGP structure. */
4915 bgp = vty->index;
4916
4917 /* Old configuration check. */
4918 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4919 if (! rn)
4920 {
4921 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4922 VTY_NEWLINE);
4923 return CMD_WARNING;
4924 }
4925
4926 aggregate = rn->info;
4927 if (aggregate->safi & SAFI_UNICAST)
4928 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4929 if (aggregate->safi & SAFI_MULTICAST)
4930 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4931
4932 /* Unlock aggregate address configuration. */
4933 rn->info = NULL;
4934 bgp_aggregate_free (aggregate);
4935 bgp_unlock_node (rn);
4936 bgp_unlock_node (rn);
4937
4938 return CMD_SUCCESS;
4939 }
4940
4941 static int
4942 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4943 afi_t afi, safi_t safi,
4944 u_char summary_only, u_char as_set)
4945 {
4946 int ret;
4947 struct prefix p;
4948 struct bgp_node *rn;
4949 struct bgp *bgp;
4950 struct bgp_aggregate *aggregate;
4951
4952 /* Convert string to prefix structure. */
4953 ret = str2prefix (prefix_str, &p);
4954 if (!ret)
4955 {
4956 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4957 return CMD_WARNING;
4958 }
4959 apply_mask (&p);
4960
4961 /* Get BGP structure. */
4962 bgp = vty->index;
4963
4964 /* Old configuration check. */
4965 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4966
4967 if (rn->info)
4968 {
4969 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4970 /* try to remove the old entry */
4971 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4972 if (ret)
4973 {
4974 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4975 bgp_unlock_node (rn);
4976 return CMD_WARNING;
4977 }
4978 }
4979
4980 /* Make aggregate address structure. */
4981 aggregate = bgp_aggregate_new ();
4982 aggregate->summary_only = summary_only;
4983 aggregate->as_set = as_set;
4984 aggregate->safi = safi;
4985 rn->info = aggregate;
4986
4987 /* Aggregate address insert into BGP routing table. */
4988 if (safi & SAFI_UNICAST)
4989 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4990 if (safi & SAFI_MULTICAST)
4991 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4992
4993 return CMD_SUCCESS;
4994 }
4995
4996 DEFUN (aggregate_address,
4997 aggregate_address_cmd,
4998 "aggregate-address A.B.C.D/M",
4999 "Configure BGP aggregate entries\n"
5000 "Aggregate prefix\n")
5001 {
5002 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5003 }
5004
5005 DEFUN (aggregate_address_mask,
5006 aggregate_address_mask_cmd,
5007 "aggregate-address A.B.C.D A.B.C.D",
5008 "Configure BGP aggregate entries\n"
5009 "Aggregate address\n"
5010 "Aggregate mask\n")
5011 {
5012 int ret;
5013 char prefix_str[BUFSIZ];
5014
5015 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5016
5017 if (! ret)
5018 {
5019 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5020 return CMD_WARNING;
5021 }
5022
5023 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5024 0, 0);
5025 }
5026
5027 DEFUN (aggregate_address_summary_only,
5028 aggregate_address_summary_only_cmd,
5029 "aggregate-address A.B.C.D/M summary-only",
5030 "Configure BGP aggregate entries\n"
5031 "Aggregate prefix\n"
5032 "Filter more specific routes from updates\n")
5033 {
5034 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5035 AGGREGATE_SUMMARY_ONLY, 0);
5036 }
5037
5038 DEFUN (aggregate_address_mask_summary_only,
5039 aggregate_address_mask_summary_only_cmd,
5040 "aggregate-address A.B.C.D A.B.C.D summary-only",
5041 "Configure BGP aggregate entries\n"
5042 "Aggregate address\n"
5043 "Aggregate mask\n"
5044 "Filter more specific routes from updates\n")
5045 {
5046 int ret;
5047 char prefix_str[BUFSIZ];
5048
5049 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5050
5051 if (! ret)
5052 {
5053 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5054 return CMD_WARNING;
5055 }
5056
5057 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5058 AGGREGATE_SUMMARY_ONLY, 0);
5059 }
5060
5061 DEFUN (aggregate_address_as_set,
5062 aggregate_address_as_set_cmd,
5063 "aggregate-address A.B.C.D/M as-set",
5064 "Configure BGP aggregate entries\n"
5065 "Aggregate prefix\n"
5066 "Generate AS set path information\n")
5067 {
5068 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5069 0, AGGREGATE_AS_SET);
5070 }
5071
5072 DEFUN (aggregate_address_mask_as_set,
5073 aggregate_address_mask_as_set_cmd,
5074 "aggregate-address A.B.C.D A.B.C.D as-set",
5075 "Configure BGP aggregate entries\n"
5076 "Aggregate address\n"
5077 "Aggregate mask\n"
5078 "Generate AS set path information\n")
5079 {
5080 int ret;
5081 char prefix_str[BUFSIZ];
5082
5083 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5084
5085 if (! ret)
5086 {
5087 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5088 return CMD_WARNING;
5089 }
5090
5091 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5092 0, AGGREGATE_AS_SET);
5093 }
5094
5095
5096 DEFUN (aggregate_address_as_set_summary,
5097 aggregate_address_as_set_summary_cmd,
5098 "aggregate-address A.B.C.D/M as-set summary-only",
5099 "Configure BGP aggregate entries\n"
5100 "Aggregate prefix\n"
5101 "Generate AS set path information\n"
5102 "Filter more specific routes from updates\n")
5103 {
5104 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5105 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5106 }
5107
5108 ALIAS (aggregate_address_as_set_summary,
5109 aggregate_address_summary_as_set_cmd,
5110 "aggregate-address A.B.C.D/M summary-only as-set",
5111 "Configure BGP aggregate entries\n"
5112 "Aggregate prefix\n"
5113 "Filter more specific routes from updates\n"
5114 "Generate AS set path information\n")
5115
5116 DEFUN (aggregate_address_mask_as_set_summary,
5117 aggregate_address_mask_as_set_summary_cmd,
5118 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5119 "Configure BGP aggregate entries\n"
5120 "Aggregate address\n"
5121 "Aggregate mask\n"
5122 "Generate AS set path information\n"
5123 "Filter more specific routes from updates\n")
5124 {
5125 int ret;
5126 char prefix_str[BUFSIZ];
5127
5128 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5129
5130 if (! ret)
5131 {
5132 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5133 return CMD_WARNING;
5134 }
5135
5136 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5137 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5138 }
5139
5140 ALIAS (aggregate_address_mask_as_set_summary,
5141 aggregate_address_mask_summary_as_set_cmd,
5142 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5143 "Configure BGP aggregate entries\n"
5144 "Aggregate address\n"
5145 "Aggregate mask\n"
5146 "Filter more specific routes from updates\n"
5147 "Generate AS set path information\n")
5148
5149 DEFUN (no_aggregate_address,
5150 no_aggregate_address_cmd,
5151 "no aggregate-address A.B.C.D/M",
5152 NO_STR
5153 "Configure BGP aggregate entries\n"
5154 "Aggregate prefix\n")
5155 {
5156 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5157 }
5158
5159 ALIAS (no_aggregate_address,
5160 no_aggregate_address_summary_only_cmd,
5161 "no aggregate-address A.B.C.D/M summary-only",
5162 NO_STR
5163 "Configure BGP aggregate entries\n"
5164 "Aggregate prefix\n"
5165 "Filter more specific routes from updates\n")
5166
5167 ALIAS (no_aggregate_address,
5168 no_aggregate_address_as_set_cmd,
5169 "no aggregate-address A.B.C.D/M as-set",
5170 NO_STR
5171 "Configure BGP aggregate entries\n"
5172 "Aggregate prefix\n"
5173 "Generate AS set path information\n")
5174
5175 ALIAS (no_aggregate_address,
5176 no_aggregate_address_as_set_summary_cmd,
5177 "no aggregate-address A.B.C.D/M as-set summary-only",
5178 NO_STR
5179 "Configure BGP aggregate entries\n"
5180 "Aggregate prefix\n"
5181 "Generate AS set path information\n"
5182 "Filter more specific routes from updates\n")
5183
5184 ALIAS (no_aggregate_address,
5185 no_aggregate_address_summary_as_set_cmd,
5186 "no aggregate-address A.B.C.D/M summary-only as-set",
5187 NO_STR
5188 "Configure BGP aggregate entries\n"
5189 "Aggregate prefix\n"
5190 "Filter more specific routes from updates\n"
5191 "Generate AS set path information\n")
5192
5193 DEFUN (no_aggregate_address_mask,
5194 no_aggregate_address_mask_cmd,
5195 "no aggregate-address A.B.C.D A.B.C.D",
5196 NO_STR
5197 "Configure BGP aggregate entries\n"
5198 "Aggregate address\n"
5199 "Aggregate mask\n")
5200 {
5201 int ret;
5202 char prefix_str[BUFSIZ];
5203
5204 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5205
5206 if (! ret)
5207 {
5208 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5209 return CMD_WARNING;
5210 }
5211
5212 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5213 }
5214
5215 ALIAS (no_aggregate_address_mask,
5216 no_aggregate_address_mask_summary_only_cmd,
5217 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5218 NO_STR
5219 "Configure BGP aggregate entries\n"
5220 "Aggregate address\n"
5221 "Aggregate mask\n"
5222 "Filter more specific routes from updates\n")
5223
5224 ALIAS (no_aggregate_address_mask,
5225 no_aggregate_address_mask_as_set_cmd,
5226 "no aggregate-address A.B.C.D A.B.C.D as-set",
5227 NO_STR
5228 "Configure BGP aggregate entries\n"
5229 "Aggregate address\n"
5230 "Aggregate mask\n"
5231 "Generate AS set path information\n")
5232
5233 ALIAS (no_aggregate_address_mask,
5234 no_aggregate_address_mask_as_set_summary_cmd,
5235 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5236 NO_STR
5237 "Configure BGP aggregate entries\n"
5238 "Aggregate address\n"
5239 "Aggregate mask\n"
5240 "Generate AS set path information\n"
5241 "Filter more specific routes from updates\n")
5242
5243 ALIAS (no_aggregate_address_mask,
5244 no_aggregate_address_mask_summary_as_set_cmd,
5245 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5246 NO_STR
5247 "Configure BGP aggregate entries\n"
5248 "Aggregate address\n"
5249 "Aggregate mask\n"
5250 "Filter more specific routes from updates\n"
5251 "Generate AS set path information\n")
5252
5253 #ifdef HAVE_IPV6
5254 DEFUN (ipv6_aggregate_address,
5255 ipv6_aggregate_address_cmd,
5256 "aggregate-address X:X::X:X/M",
5257 "Configure BGP aggregate entries\n"
5258 "Aggregate prefix\n")
5259 {
5260 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5261 }
5262
5263 DEFUN (ipv6_aggregate_address_summary_only,
5264 ipv6_aggregate_address_summary_only_cmd,
5265 "aggregate-address X:X::X:X/M summary-only",
5266 "Configure BGP aggregate entries\n"
5267 "Aggregate prefix\n"
5268 "Filter more specific routes from updates\n")
5269 {
5270 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5271 AGGREGATE_SUMMARY_ONLY, 0);
5272 }
5273
5274 DEFUN (no_ipv6_aggregate_address,
5275 no_ipv6_aggregate_address_cmd,
5276 "no aggregate-address X:X::X:X/M",
5277 NO_STR
5278 "Configure BGP aggregate entries\n"
5279 "Aggregate prefix\n")
5280 {
5281 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5282 }
5283
5284 DEFUN (no_ipv6_aggregate_address_summary_only,
5285 no_ipv6_aggregate_address_summary_only_cmd,
5286 "no aggregate-address X:X::X:X/M summary-only",
5287 NO_STR
5288 "Configure BGP aggregate entries\n"
5289 "Aggregate prefix\n"
5290 "Filter more specific routes from updates\n")
5291 {
5292 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5293 }
5294
5295 ALIAS (ipv6_aggregate_address,
5296 old_ipv6_aggregate_address_cmd,
5297 "ipv6 bgp aggregate-address X:X::X:X/M",
5298 IPV6_STR
5299 BGP_STR
5300 "Configure BGP aggregate entries\n"
5301 "Aggregate prefix\n")
5302
5303 ALIAS (ipv6_aggregate_address_summary_only,
5304 old_ipv6_aggregate_address_summary_only_cmd,
5305 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5306 IPV6_STR
5307 BGP_STR
5308 "Configure BGP aggregate entries\n"
5309 "Aggregate prefix\n"
5310 "Filter more specific routes from updates\n")
5311
5312 ALIAS (no_ipv6_aggregate_address,
5313 old_no_ipv6_aggregate_address_cmd,
5314 "no ipv6 bgp aggregate-address X:X::X:X/M",
5315 NO_STR
5316 IPV6_STR
5317 BGP_STR
5318 "Configure BGP aggregate entries\n"
5319 "Aggregate prefix\n")
5320
5321 ALIAS (no_ipv6_aggregate_address_summary_only,
5322 old_no_ipv6_aggregate_address_summary_only_cmd,
5323 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5324 NO_STR
5325 IPV6_STR
5326 BGP_STR
5327 "Configure BGP aggregate entries\n"
5328 "Aggregate prefix\n"
5329 "Filter more specific routes from updates\n")
5330 #endif /* HAVE_IPV6 */
5331
5332 /* Redistribute route treatment. */
5333 void
5334 bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
5335 const struct in6_addr *nexthop6, unsigned int ifindex,
5336 u_int32_t metric, u_char type, u_short instance, u_short tag)
5337 {
5338 struct bgp_info *new;
5339 struct bgp_info *bi;
5340 struct bgp_info info;
5341 struct bgp_node *bn;
5342 struct attr attr;
5343 struct attr *new_attr;
5344 afi_t afi;
5345 int ret;
5346 struct bgp_redist *red;
5347
5348 /* Make default attribute. */
5349 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5350 if (nexthop)
5351 attr.nexthop = *nexthop;
5352 attr.nh_ifindex = ifindex;
5353
5354 #ifdef HAVE_IPV6
5355 if (nexthop6)
5356 {
5357 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5358 extra->mp_nexthop_global = *nexthop6;
5359 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
5360 }
5361 #endif
5362
5363 attr.med = metric;
5364 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5365 attr.extra->tag = tag;
5366
5367 afi = family2afi (p->family);
5368
5369 red = bgp_redist_lookup(bgp, afi, type, instance);
5370 if (red)
5371 {
5372 struct attr attr_new;
5373 struct attr_extra extra_new;
5374
5375 /* Copy attribute for modification. */
5376 attr_new.extra = &extra_new;
5377 bgp_attr_dup (&attr_new, &attr);
5378
5379 if (red->redist_metric_flag)
5380 attr_new.med = red->redist_metric;
5381
5382 /* Apply route-map. */
5383 if (red->rmap.name)
5384 {
5385 info.peer = bgp->peer_self;
5386 info.attr = &attr_new;
5387
5388 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5389
5390 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5391
5392 bgp->peer_self->rmap_type = 0;
5393
5394 if (ret == RMAP_DENYMATCH)
5395 {
5396 /* Free uninterned attribute. */
5397 bgp_attr_flush (&attr_new);
5398
5399 /* Unintern original. */
5400 aspath_unintern (&attr.aspath);
5401 bgp_attr_extra_free (&attr);
5402 bgp_redistribute_delete (bgp, p, type, instance);
5403 return;
5404 }
5405 }
5406
5407 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5408 afi, SAFI_UNICAST, p, NULL);
5409
5410 new_attr = bgp_attr_intern (&attr_new);
5411
5412 for (bi = bn->info; bi; bi = bi->next)
5413 if (bi->peer == bgp->peer_self
5414 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5415 break;
5416
5417 if (bi)
5418 {
5419 /* Ensure the (source route) type is updated. */
5420 bi->type = type;
5421 if (attrhash_cmp (bi->attr, new_attr) &&
5422 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5423 {
5424 bgp_attr_unintern (&new_attr);
5425 aspath_unintern (&attr.aspath);
5426 bgp_attr_extra_free (&attr);
5427 bgp_unlock_node (bn);
5428 return;
5429 }
5430 else
5431 {
5432 /* The attribute is changed. */
5433 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5434
5435 /* Rewrite BGP route information. */
5436 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5437 bgp_info_restore(bn, bi);
5438 else
5439 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5440 bgp_attr_unintern (&bi->attr);
5441 bi->attr = new_attr;
5442 bi->uptime = bgp_clock ();
5443
5444 /* Process change. */
5445 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5446 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5447 bgp_unlock_node (bn);
5448 aspath_unintern (&attr.aspath);
5449 bgp_attr_extra_free (&attr);
5450 return;
5451 }
5452 }
5453
5454 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5455 new_attr, bn);
5456 SET_FLAG (new->flags, BGP_INFO_VALID);
5457
5458 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5459 bgp_info_add (bn, new);
5460 bgp_unlock_node (bn);
5461 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5462 }
5463
5464 /* Unintern original. */
5465 aspath_unintern (&attr.aspath);
5466 bgp_attr_extra_free (&attr);
5467 }
5468
5469 void
5470 bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
5471 {
5472 afi_t afi;
5473 struct bgp_node *rn;
5474 struct bgp_info *ri;
5475 struct bgp_redist *red;
5476
5477 afi = family2afi (p->family);
5478
5479 red = bgp_redist_lookup(bgp, afi, type, instance);
5480 if (red)
5481 {
5482 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5483
5484 for (ri = rn->info; ri; ri = ri->next)
5485 if (ri->peer == bgp->peer_self
5486 && ri->type == type)
5487 break;
5488
5489 if (ri)
5490 {
5491 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5492 bgp_info_delete (rn, ri);
5493 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5494 }
5495 bgp_unlock_node (rn);
5496 }
5497 }
5498
5499 /* Withdraw specified route type's route. */
5500 void
5501 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
5502 {
5503 struct bgp_node *rn;
5504 struct bgp_info *ri;
5505 struct bgp_table *table;
5506
5507 table = bgp->rib[afi][SAFI_UNICAST];
5508
5509 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5510 {
5511 for (ri = rn->info; ri; ri = ri->next)
5512 if (ri->peer == bgp->peer_self
5513 && ri->type == type
5514 && ri->instance == instance)
5515 break;
5516
5517 if (ri)
5518 {
5519 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5520 bgp_info_delete (rn, ri);
5521 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5522 }
5523 }
5524 }
5525
5526 /* Static function to display route. */
5527 static void
5528 route_vty_out_route (struct prefix *p, struct vty *vty)
5529 {
5530 int len;
5531 u_int32_t destination;
5532 char buf[BUFSIZ];
5533
5534 if (p->family == AF_INET)
5535 {
5536 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5537 destination = ntohl (p->u.prefix4.s_addr);
5538
5539 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5540 || (IN_CLASSB (destination) && p->prefixlen == 16)
5541 || (IN_CLASSA (destination) && p->prefixlen == 8)
5542 || p->u.prefix4.s_addr == 0)
5543 {
5544 /* When mask is natural, mask is not displayed. */
5545 }
5546 else
5547 len += vty_out (vty, "/%d", p->prefixlen);
5548 }
5549 else
5550 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5551 p->prefixlen);
5552
5553 len = 17 - len;
5554 if (len < 1)
5555 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5556 else
5557 vty_out (vty, "%*s", len, " ");
5558 }
5559
5560 enum bgp_display_type
5561 {
5562 normal_list,
5563 };
5564
5565 /* Print the short form route status for a bgp_info */
5566 static void
5567 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
5568 json_object *json_path)
5569 {
5570 if (json_path)
5571 {
5572
5573 /* Route status display. */
5574 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5575 json_object_boolean_true_add(json_path, "removed");
5576
5577 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5578 json_object_boolean_true_add(json_path, "stale");
5579
5580 if (binfo->extra && binfo->extra->suppress)
5581 json_object_boolean_true_add(json_path, "suppressed");
5582
5583 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5584 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5585 json_object_boolean_true_add(json_path, "valid");
5586
5587 /* Selected */
5588 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5589 json_object_boolean_true_add(json_path, "history");
5590
5591 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5592 json_object_boolean_true_add(json_path, "damped");
5593
5594 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5595 json_object_boolean_true_add(json_path, "bestpath");
5596
5597 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5598 json_object_boolean_true_add(json_path, "multipath");
5599
5600 /* Internal route. */
5601 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5602 json_object_string_add(json_path, "pathFrom", "internal");
5603 else
5604 json_object_string_add(json_path, "pathFrom", "external");
5605
5606 return;
5607 }
5608
5609 /* Route status display. */
5610 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5611 vty_out (vty, "R");
5612 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5613 vty_out (vty, "S");
5614 else if (binfo->extra && binfo->extra->suppress)
5615 vty_out (vty, "s");
5616 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5617 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5618 vty_out (vty, "*");
5619 else
5620 vty_out (vty, " ");
5621
5622 /* Selected */
5623 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5624 vty_out (vty, "h");
5625 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5626 vty_out (vty, "d");
5627 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5628 vty_out (vty, ">");
5629 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5630 vty_out (vty, "=");
5631 else
5632 vty_out (vty, " ");
5633
5634 /* Internal route. */
5635 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5636 vty_out (vty, "i");
5637 else
5638 vty_out (vty, " ");
5639 }
5640
5641 /* called from terminal list command */
5642 void
5643 route_vty_out (struct vty *vty, struct prefix *p,
5644 struct bgp_info *binfo, int display, safi_t safi,
5645 json_object *json_paths)
5646 {
5647 struct attr *attr;
5648 json_object *json_path = NULL;
5649 json_object *json_nexthops = NULL;
5650 json_object *json_nexthop_global = NULL;
5651 json_object *json_nexthop_ll = NULL;
5652
5653 if (json_paths)
5654 json_path = json_object_new_object();
5655
5656 /* short status lead text */
5657 route_vty_short_status_out (vty, binfo, json_path);
5658
5659 if (!json_paths)
5660 {
5661 /* print prefix and mask */
5662 if (! display)
5663 route_vty_out_route (p, vty);
5664 else
5665 vty_out (vty, "%*s", 17, " ");
5666 }
5667
5668 /* Print attribute */
5669 attr = binfo->attr;
5670 if (attr)
5671 {
5672
5673 /* IPv4 Next Hop */
5674 if (p->family == AF_INET
5675 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5676 {
5677 if (json_paths)
5678 {
5679 json_nexthop_global = json_object_new_object();
5680
5681 if (safi == SAFI_MPLS_VPN)
5682 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
5683 else
5684 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
5685
5686 json_object_string_add(json_nexthop_global, "afi", "ipv4");
5687 json_object_boolean_true_add(json_nexthop_global, "used");
5688 }
5689 else
5690 {
5691 if (safi == SAFI_MPLS_VPN)
5692 vty_out (vty, "%-16s",
5693 inet_ntoa (attr->extra->mp_nexthop_global_in));
5694 else
5695 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5696 }
5697 }
5698
5699 #ifdef HAVE_IPV6
5700 /* IPv6 Next Hop */
5701 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5702 {
5703 int len;
5704 char buf[BUFSIZ];
5705
5706 if (json_paths)
5707 {
5708 json_nexthop_global = json_object_new_object();
5709 json_object_string_add(json_nexthop_global, "ip",
5710 inet_ntop (AF_INET6,
5711 &attr->extra->mp_nexthop_global,
5712 buf, BUFSIZ));
5713 json_object_string_add(json_nexthop_global, "afi", "ipv6");
5714 json_object_string_add(json_nexthop_global, "scope", "global");
5715
5716 /* We display both LL & GL if both have been received */
5717 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5718 {
5719 json_nexthop_ll = json_object_new_object();
5720 json_object_string_add(json_nexthop_ll, "ip",
5721 inet_ntop (AF_INET6,
5722 &attr->extra->mp_nexthop_local,
5723 buf, BUFSIZ));
5724 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
5725 json_object_string_add(json_nexthop_ll, "scope", "link-local");
5726
5727 if (IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
5728 &attr->extra->mp_nexthop_local) != 0)
5729 json_object_boolean_true_add(json_nexthop_ll, "used");
5730 else
5731 json_object_boolean_true_add(json_nexthop_global, "used");
5732 }
5733 else
5734 json_object_boolean_true_add(json_nexthop_global, "used");
5735 }
5736 else
5737 {
5738 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5739 {
5740 if (binfo->peer->conf_if)
5741 {
5742 len = vty_out (vty, "%s",
5743 binfo->peer->conf_if);
5744 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
5745
5746 if (len < 1)
5747 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
5748 else
5749 vty_out (vty, "%*s", len, " ");
5750 }
5751 else
5752 {
5753 len = vty_out (vty, "%s",
5754 inet_ntop (AF_INET6,
5755 &attr->extra->mp_nexthop_local,
5756 buf, BUFSIZ));
5757 len = 16 - len;
5758
5759 if (len < 1)
5760 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5761 else
5762 vty_out (vty, "%*s", len, " ");
5763 }
5764 }
5765 else
5766 {
5767 len = vty_out (vty, "%s",
5768 inet_ntop (AF_INET6,
5769 &attr->extra->mp_nexthop_global,
5770 buf, BUFSIZ));
5771 len = 16 - len;
5772
5773 if (len < 1)
5774 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5775 else
5776 vty_out (vty, "%*s", len, " ");
5777 }
5778 }
5779 }
5780 #endif /* HAVE_IPV6 */
5781
5782 /* MED/Metric */
5783 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5784 if (json_paths)
5785 json_object_int_add(json_path, "med", attr->med);
5786 else
5787 vty_out (vty, "%10u", attr->med);
5788 else
5789 if (!json_paths)
5790 vty_out (vty, " ");
5791
5792 /* Local Pref */
5793 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5794 if (json_paths)
5795 json_object_int_add(json_path, "localpref", attr->local_pref);
5796 else
5797 vty_out (vty, "%7u", attr->local_pref);
5798 else
5799 if (!json_paths)
5800 vty_out (vty, " ");
5801
5802 if (json_paths)
5803 {
5804 if (attr->extra)
5805 json_object_int_add(json_path, "weight", attr->extra->weight);
5806 else
5807 json_object_int_add(json_path, "weight", 0);
5808 }
5809 else
5810 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
5811
5812 /* Print aspath */
5813 if (attr->aspath)
5814 {
5815 if (json_paths)
5816 json_object_string_add(json_path, "aspath", attr->aspath->str);
5817 else
5818 aspath_print_vty (vty, "%s", attr->aspath, " ");
5819 }
5820
5821 /* Print origin */
5822 if (json_paths)
5823 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
5824 else
5825 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5826 }
5827 else
5828 {
5829 if (json_paths)
5830 json_object_string_add(json_path, "alert", "No attributes");
5831 else
5832 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
5833 }
5834
5835 if (json_paths)
5836 {
5837 if (json_nexthop_global || json_nexthop_ll)
5838 {
5839 json_nexthops = json_object_new_array();
5840
5841 if (json_nexthop_global)
5842 json_object_array_add(json_nexthops, json_nexthop_global);
5843
5844 if (json_nexthop_ll)
5845 json_object_array_add(json_nexthops, json_nexthop_ll);
5846
5847 json_object_object_add(json_path, "nexthops", json_nexthops);
5848 }
5849
5850 json_object_array_add(json_paths, json_path);
5851 }
5852 else
5853 vty_out (vty, "%s", VTY_NEWLINE);
5854 }
5855
5856 /* called from terminal list command */
5857 void
5858 route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
5859 u_char use_json, json_object *json_ar)
5860 {
5861 json_object *json_status = NULL;
5862 json_object *json_net = NULL;
5863 char buff[BUFSIZ];
5864 /* Route status display. */
5865 if (use_json)
5866 {
5867 json_status = json_object_new_object();
5868 json_net = json_object_new_object();
5869 }
5870 else
5871 {
5872 vty_out (vty, "*");
5873 vty_out (vty, ">");
5874 vty_out (vty, " ");
5875 }
5876
5877 /* print prefix and mask */
5878 if (use_json)
5879 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
5880 else
5881 route_vty_out_route (p, vty);
5882
5883 /* Print attribute */
5884 if (attr)
5885 {
5886 if (use_json)
5887 {
5888 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5889 {
5890 if (safi == SAFI_MPLS_VPN)
5891 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
5892 else
5893 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
5894 }
5895 #ifdef HAVE_IPV6
5896 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5897 {
5898 char buf[BUFSIZ];
5899
5900 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5901 buf, BUFSIZ));
5902 }
5903 #endif /* HAVE_IPV6 */
5904
5905 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5906 json_object_int_add(json_net, "metric", attr->med);
5907
5908 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5909 json_object_int_add(json_net, "localPref", attr->local_pref);
5910
5911 if (attr->extra)
5912 json_object_int_add(json_net, "weight", attr->extra->weight);
5913 else
5914 json_object_int_add(json_net, "weight", 0);
5915
5916 /* Print aspath */
5917 if (attr->aspath)
5918 json_object_string_add(json_net, "asPath", attr->aspath->str);
5919
5920 /* Print origin */
5921 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
5922 }
5923 else
5924 {
5925 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5926 {
5927 if (safi == SAFI_MPLS_VPN)
5928 vty_out (vty, "%-16s",
5929 inet_ntoa (attr->extra->mp_nexthop_global_in));
5930 else
5931 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5932 }
5933 #ifdef HAVE_IPV6
5934 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5935 {
5936 int len;
5937 char buf[BUFSIZ];
5938
5939 assert (attr->extra);
5940
5941 len = vty_out (vty, "%s",
5942 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5943 buf, BUFSIZ));
5944 len = 16 - len;
5945 if (len < 1)
5946 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5947 else
5948 vty_out (vty, "%*s", len, " ");
5949 }
5950 #endif /* HAVE_IPV6 */
5951 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5952 vty_out (vty, "%10u", attr->med);
5953 else
5954 vty_out (vty, " ");
5955
5956 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5957 vty_out (vty, "%7u", attr->local_pref);
5958 else
5959 vty_out (vty, " ");
5960
5961 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
5962
5963 /* Print aspath */
5964 if (attr->aspath)
5965 aspath_print_vty (vty, "%s", attr->aspath, " ");
5966
5967 /* Print origin */
5968 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5969 }
5970 }
5971 if (use_json)
5972 {
5973 json_object_boolean_true_add(json_status, "*");
5974 json_object_boolean_true_add(json_status, ">");
5975 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
5976 char buf_cut[BUFSIZ];
5977 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
5978 }
5979 else
5980 vty_out (vty, "%s", VTY_NEWLINE);
5981 }
5982
5983 void
5984 route_vty_out_tag (struct vty *vty, struct prefix *p,
5985 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
5986 {
5987 json_object *json_out = NULL;
5988 struct attr *attr;
5989 u_int32_t label = 0;
5990
5991 if (!binfo->extra)
5992 return;
5993
5994 if (json)
5995 json_out = json_object_new_object();
5996
5997 /* short status lead text */
5998 route_vty_short_status_out (vty, binfo, json_out);
5999
6000 /* print prefix and mask */
6001 if (json == NULL)
6002 {
6003 if (! display)
6004 route_vty_out_route (p, vty);
6005 else
6006 vty_out (vty, "%*s", 17, " ");
6007 }
6008
6009 /* Print attribute */
6010 attr = binfo->attr;
6011 if (attr)
6012 {
6013 if (p->family == AF_INET
6014 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6015 {
6016 if (safi == SAFI_MPLS_VPN)
6017 {
6018 if (json)
6019 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6020 else
6021 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6022 }
6023 else
6024 {
6025 if (json)
6026 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6027 else
6028 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6029 }
6030 }
6031 #ifdef HAVE_IPV6
6032 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6033 {
6034 assert (attr->extra);
6035 char buf_a[BUFSIZ];
6036 char buf_b[BUFSIZ];
6037 char buf_c[BUFSIZ];
6038 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
6039 {
6040 if (json)
6041 json_object_string_add(json_out, "mpNexthopGlobalIn",
6042 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6043 else
6044 vty_out (vty, "%s",
6045 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6046 buf_a, BUFSIZ));
6047 }
6048 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6049 {
6050 if (json)
6051 {
6052 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6053 buf_a, BUFSIZ);
6054 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6055 buf_b, BUFSIZ);
6056 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6057 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6058 }
6059 else
6060 vty_out (vty, "%s(%s)",
6061 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6062 buf_a, BUFSIZ),
6063 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6064 buf_b, BUFSIZ));
6065 }
6066
6067 }
6068 #endif /* HAVE_IPV6 */
6069 }
6070
6071 label = decode_label (binfo->extra->tag);
6072
6073 if (json)
6074 {
6075 if (label)
6076 json_object_int_add(json_out, "notag", label);
6077 json_object_array_add(json, json_out);
6078 }
6079 else
6080 {
6081 vty_out (vty, "notag/%d", label);
6082 vty_out (vty, "%s", VTY_NEWLINE);
6083 }
6084 }
6085
6086 /* dampening route */
6087 static void
6088 damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6089 int display, safi_t safi, u_char use_json, json_object *json)
6090 {
6091 struct attr *attr;
6092 int len;
6093 char timebuf[BGP_UPTIME_LEN];
6094
6095 /* short status lead text */
6096 route_vty_short_status_out (vty, binfo, json);
6097
6098 /* print prefix and mask */
6099 if (!use_json)
6100 {
6101 if (! display)
6102 route_vty_out_route (p, vty);
6103 else
6104 vty_out (vty, "%*s", 17, " ");
6105 }
6106
6107 len = vty_out (vty, "%s", binfo->peer->host);
6108 len = 17 - len;
6109 if (len < 1)
6110 {
6111 if (!use_json)
6112 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6113 }
6114 else
6115 {
6116 if (use_json)
6117 json_object_int_add(json, "peerHost", len);
6118 else
6119 vty_out (vty, "%*s", len, " ");
6120 }
6121
6122 if (use_json)
6123 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6124 else
6125 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6126
6127 /* Print attribute */
6128 attr = binfo->attr;
6129 if (attr)
6130 {
6131 /* Print aspath */
6132 if (attr->aspath)
6133 {
6134 if (use_json)
6135 json_object_string_add(json, "asPath", attr->aspath->str);
6136 else
6137 aspath_print_vty (vty, "%s", attr->aspath, " ");
6138 }
6139
6140 /* Print origin */
6141 if (use_json)
6142 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6143 else
6144 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6145 }
6146 if (!use_json)
6147 vty_out (vty, "%s", VTY_NEWLINE);
6148 }
6149
6150 /* flap route */
6151 static void
6152 flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6153 int display, safi_t safi, u_char use_json, json_object *json)
6154 {
6155 struct attr *attr;
6156 struct bgp_damp_info *bdi;
6157 char timebuf[BGP_UPTIME_LEN];
6158 int len;
6159
6160 if (!binfo->extra)
6161 return;
6162
6163 bdi = binfo->extra->damp_info;
6164
6165 /* short status lead text */
6166 route_vty_short_status_out (vty, binfo, json);
6167
6168 /* print prefix and mask */
6169 if (!use_json)
6170 {
6171 if (! display)
6172 route_vty_out_route (p, vty);
6173 else
6174 vty_out (vty, "%*s", 17, " ");
6175 }
6176
6177 len = vty_out (vty, "%s", binfo->peer->host);
6178 len = 16 - len;
6179 if (len < 1)
6180 {
6181 if (!use_json)
6182 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6183 }
6184 else
6185 {
6186 if (use_json)
6187 json_object_int_add(json, "peerHost", len);
6188 else
6189 vty_out (vty, "%*s", len, " ");
6190 }
6191
6192 len = vty_out (vty, "%d", bdi->flap);
6193 len = 5 - len;
6194 if (len < 1)
6195 {
6196 if (!use_json)
6197 vty_out (vty, " ");
6198 }
6199 else
6200 {
6201 if (use_json)
6202 json_object_int_add(json, "bdiFlap", len);
6203 else
6204 vty_out (vty, "%*s", len, " ");
6205 }
6206
6207 if (use_json)
6208 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6209 else
6210 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6211 timebuf, BGP_UPTIME_LEN, 0, NULL));
6212
6213 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6214 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6215 {
6216 if (use_json)
6217 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6218 else
6219 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6220 }
6221 else
6222 {
6223 if (!use_json)
6224 vty_out (vty, "%*s ", 8, " ");
6225 }
6226
6227 /* Print attribute */
6228 attr = binfo->attr;
6229 if (attr)
6230 {
6231 /* Print aspath */
6232 if (attr->aspath)
6233 {
6234 if (use_json)
6235 json_object_string_add(json, "asPath", attr->aspath->str);
6236 else
6237 aspath_print_vty (vty, "%s", attr->aspath, " ");
6238 }
6239
6240 /* Print origin */
6241 if (use_json)
6242 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6243 else
6244 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6245 }
6246 if (!use_json)
6247 vty_out (vty, "%s", VTY_NEWLINE);
6248 }
6249
6250 static void
6251 route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6252 const char *header, json_object *json_adv_to)
6253 {
6254 char buf1[INET6_ADDRSTRLEN];
6255 json_object *json_peer = NULL;
6256
6257 if (json_adv_to)
6258 {
6259 /* 'advertised-to' is a dictionary of peers we have advertised this
6260 * prefix too. The key is the peer's IP or swpX, the value is the
6261 * hostname if we know it and "" if not.
6262 */
6263 json_peer = json_object_new_object();
6264
6265 if (peer->hostname)
6266 json_object_string_add(json_peer, "hostname", peer->hostname);
6267
6268 if (peer->conf_if)
6269 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6270 else
6271 json_object_object_add(json_adv_to,
6272 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6273 json_peer);
6274 }
6275 else
6276 {
6277 if (*first)
6278 {
6279 vty_out (vty, "%s", header);
6280 *first = 0;
6281 }
6282
6283 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6284 {
6285 if (peer->conf_if)
6286 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6287 else
6288 vty_out (vty, " %s(%s)", peer->hostname,
6289 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6290 }
6291 else
6292 {
6293 if (peer->conf_if)
6294 vty_out (vty, " %s", peer->conf_if);
6295 else
6296 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6297 }
6298 }
6299 }
6300
6301 static void
6302 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6303 struct bgp_info *binfo, afi_t afi, safi_t safi,
6304 json_object *json_paths)
6305 {
6306 char buf[INET6_ADDRSTRLEN];
6307 char buf1[BUFSIZ];
6308 struct attr *attr;
6309 int sockunion_vty_out (struct vty *, union sockunion *);
6310 #ifdef HAVE_CLOCK_MONOTONIC
6311 time_t tbuf;
6312 #endif
6313 json_object *json_bestpath = NULL;
6314 json_object *json_cluster_list = NULL;
6315 json_object *json_cluster_list_list = NULL;
6316 json_object *json_ext_community = NULL;
6317 json_object *json_last_update = NULL;
6318 json_object *json_nexthop_global = NULL;
6319 json_object *json_nexthop_ll = NULL;
6320 json_object *json_nexthops = NULL;
6321 json_object *json_path = NULL;
6322 json_object *json_peer = NULL;
6323 json_object *json_string = NULL;
6324 json_object *json_adv_to = NULL;
6325 int first = 0;
6326 struct listnode *node, *nnode;
6327 struct peer *peer;
6328 int addpath_capable;
6329 int has_adj;
6330 int first_as;
6331
6332 if (json_paths)
6333 {
6334 json_path = json_object_new_object();
6335 json_peer = json_object_new_object();
6336 json_nexthop_global = json_object_new_object();
6337 }
6338
6339 attr = binfo->attr;
6340
6341 if (attr)
6342 {
6343 /* Line1 display AS-path, Aggregator */
6344 if (attr->aspath)
6345 {
6346 if (json_paths)
6347 {
6348 json_object_lock(attr->aspath->json);
6349 json_object_object_add(json_path, "aspath", attr->aspath->json);
6350 }
6351 else
6352 {
6353 if (attr->aspath->segments)
6354 aspath_print_vty (vty, " %s", attr->aspath, "");
6355 else
6356 vty_out (vty, " Local");
6357 }
6358 }
6359
6360 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6361 {
6362 if (json_paths)
6363 json_object_boolean_true_add(json_path, "removed");
6364 else
6365 vty_out (vty, ", (removed)");
6366 }
6367
6368 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6369 {
6370 if (json_paths)
6371 json_object_boolean_true_add(json_path, "stale");
6372 else
6373 vty_out (vty, ", (stale)");
6374 }
6375
6376 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6377 {
6378 if (json_paths)
6379 {
6380 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6381 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
6382 }
6383 else
6384 {
6385 vty_out (vty, ", (aggregated by %u %s)",
6386 attr->extra->aggregator_as,
6387 inet_ntoa (attr->extra->aggregator_addr));
6388 }
6389 }
6390
6391 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6392 {
6393 if (json_paths)
6394 json_object_boolean_true_add(json_path, "rxedFromRrClient");
6395 else
6396 vty_out (vty, ", (Received from a RR-client)");
6397 }
6398
6399 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6400 {
6401 if (json_paths)
6402 json_object_boolean_true_add(json_path, "rxedFromRsClient");
6403 else
6404 vty_out (vty, ", (Received from a RS-client)");
6405 }
6406
6407 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6408 {
6409 if (json_paths)
6410 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
6411 else
6412 vty_out (vty, ", (history entry)");
6413 }
6414 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6415 {
6416 if (json_paths)
6417 json_object_boolean_true_add(json_path, "dampeningSuppressed");
6418 else
6419 vty_out (vty, ", (suppressed due to dampening)");
6420 }
6421
6422 if (!json_paths)
6423 vty_out (vty, "%s", VTY_NEWLINE);
6424
6425 /* Line2 display Next-hop, Neighbor, Router-id */
6426 /* Display the nexthop */
6427 if (p->family == AF_INET
6428 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6429 {
6430 if (safi == SAFI_MPLS_VPN)
6431 {
6432 if (json_paths)
6433 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6434 else
6435 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6436 }
6437 else
6438 {
6439 if (json_paths)
6440 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6441 else
6442 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6443 }
6444
6445 if (json_paths)
6446 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6447 }
6448 #ifdef HAVE_IPV6
6449 else
6450 {
6451 assert (attr->extra);
6452 if (json_paths)
6453 {
6454 json_object_string_add(json_nexthop_global, "ip",
6455 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6456 buf, INET6_ADDRSTRLEN));
6457 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6458 json_object_string_add(json_nexthop_global, "scope", "global");
6459 }
6460 else
6461 {
6462 vty_out (vty, " %s",
6463 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6464 buf, INET6_ADDRSTRLEN));
6465 }
6466 }
6467 #endif /* HAVE_IPV6 */
6468
6469
6470 /* Display the IGP cost or 'inaccessible' */
6471 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6472 {
6473 if (json_paths)
6474 json_object_boolean_false_add(json_nexthop_global, "accessible");
6475 else
6476 vty_out (vty, " (inaccessible)");
6477 }
6478 else
6479 {
6480 if (binfo->extra && binfo->extra->igpmetric)
6481 {
6482 if (json_paths)
6483 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
6484 else
6485 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
6486 }
6487
6488 /* IGP cost is 0, display this only for json */
6489 else
6490 {
6491 if (json_paths)
6492 json_object_int_add(json_nexthop_global, "metric", 0);
6493 }
6494
6495 if (json_paths)
6496 json_object_boolean_true_add(json_nexthop_global, "accessible");
6497 }
6498
6499 /* Display peer "from" output */
6500 /* This path was originated locally */
6501 if (binfo->peer == bgp->peer_self)
6502 {
6503
6504 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6505 {
6506 if (json_paths)
6507 json_object_string_add(json_peer, "peerId", "0.0.0.0");
6508 else
6509 vty_out (vty, " from 0.0.0.0 ");
6510 }
6511 else
6512 {
6513 if (json_paths)
6514 json_object_string_add(json_peer, "peerId", "::");
6515 else
6516 vty_out (vty, " from :: ");
6517 }
6518
6519 if (json_paths)
6520 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
6521 else
6522 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6523 }
6524
6525 /* We RXed this path from one of our peers */
6526 else
6527 {
6528
6529 if (json_paths)
6530 {
6531 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6532 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6533
6534 if (binfo->peer->hostname)
6535 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
6536
6537 if (binfo->peer->domainname)
6538 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
6539
6540 if (binfo->peer->conf_if)
6541 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
6542 }
6543 else
6544 {
6545 if (binfo->peer->conf_if)
6546 {
6547 if (binfo->peer->hostname &&
6548 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6549 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6550 binfo->peer->conf_if);
6551 else
6552 vty_out (vty, " from %s", binfo->peer->conf_if);
6553 }
6554 else
6555 {
6556 if (binfo->peer->hostname &&
6557 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6558 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6559 binfo->peer->host);
6560 else
6561 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6562 }
6563
6564 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6565 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6566 else
6567 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6568 }
6569 }
6570
6571 if (!json_paths)
6572 vty_out (vty, "%s", VTY_NEWLINE);
6573
6574 #ifdef HAVE_IPV6
6575 /* display the link-local nexthop */
6576 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6577 {
6578 if (json_paths)
6579 {
6580 json_nexthop_ll = json_object_new_object();
6581 json_object_string_add(json_nexthop_ll, "ip",
6582 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6583 buf, INET6_ADDRSTRLEN));
6584 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6585 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6586
6587 json_object_boolean_true_add(json_nexthop_ll, "accessible");
6588 json_object_boolean_true_add(json_nexthop_ll, "used");
6589 }
6590 else
6591 {
6592 vty_out (vty, " (%s) (used)%s",
6593 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6594 buf, INET6_ADDRSTRLEN),
6595 VTY_NEWLINE);
6596 }
6597 }
6598 /* If we do not have a link-local nexthop then we must flag the global as "used" */
6599 else
6600 {
6601 if (json_paths)
6602 json_object_boolean_true_add(json_nexthop_global, "used");
6603 }
6604 #endif /* HAVE_IPV6 */
6605
6606 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
6607 if (json_paths)
6608 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6609 else
6610 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6611
6612 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6613 {
6614 if (json_paths)
6615 json_object_int_add(json_path, "med", attr->med);
6616 else
6617 vty_out (vty, ", metric %u", attr->med);
6618 }
6619
6620 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6621 {
6622 if (json_paths)
6623 json_object_int_add(json_path, "localpref", attr->local_pref);
6624 else
6625 vty_out (vty, ", localpref %u", attr->local_pref);
6626 }
6627 else
6628 {
6629 if (json_paths)
6630 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
6631 else
6632 vty_out (vty, ", localpref %u", bgp->default_local_pref);
6633 }
6634
6635 if (attr->extra && attr->extra->weight != 0)
6636 {
6637 if (json_paths)
6638 json_object_int_add(json_path, "weight", attr->extra->weight);
6639 else
6640 vty_out (vty, ", weight %u", attr->extra->weight);
6641 }
6642
6643 if (attr->extra && attr->extra->tag != 0)
6644 {
6645 if (json_paths)
6646 json_object_int_add(json_path, "tag", attr->extra->tag);
6647 else
6648 vty_out (vty, ", tag %d", attr->extra->tag);
6649 }
6650
6651 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6652 {
6653 if (json_paths)
6654 json_object_boolean_false_add(json_path, "valid");
6655 else
6656 vty_out (vty, ", invalid");
6657 }
6658 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6659 {
6660 if (json_paths)
6661 json_object_boolean_true_add(json_path, "valid");
6662 else
6663 vty_out (vty, ", valid");
6664 }
6665
6666 if (binfo->peer != bgp->peer_self)
6667 {
6668 if (binfo->peer->as == binfo->peer->local_as)
6669 {
6670 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
6671 {
6672 if (json_paths)
6673 json_object_string_add(json_peer, "type", "confed-internal");
6674 else
6675 vty_out (vty, ", confed-internal");
6676 }
6677 else
6678 {
6679 if (json_paths)
6680 json_object_string_add(json_peer, "type", "internal");
6681 else
6682 vty_out (vty, ", internal");
6683 }
6684 }
6685 else
6686 {
6687 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
6688 {
6689 if (json_paths)
6690 json_object_string_add(json_peer, "type", "confed-external");
6691 else
6692 vty_out (vty, ", confed-external");
6693 }
6694 else
6695 {
6696 if (json_paths)
6697 json_object_string_add(json_peer, "type", "external");
6698 else
6699 vty_out (vty, ", external");
6700 }
6701 }
6702 }
6703 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6704 {
6705 if (json_paths)
6706 {
6707 json_object_boolean_true_add(json_path, "aggregated");
6708 json_object_boolean_true_add(json_path, "local");
6709 }
6710 else
6711 {
6712 vty_out (vty, ", aggregated, local");
6713 }
6714 }
6715 else if (binfo->type != ZEBRA_ROUTE_BGP)
6716 {
6717 if (json_paths)
6718 json_object_boolean_true_add(json_path, "sourced");
6719 else
6720 vty_out (vty, ", sourced");
6721 }
6722 else
6723 {
6724 if (json_paths)
6725 {
6726 json_object_boolean_true_add(json_path, "sourced");
6727 json_object_boolean_true_add(json_path, "local");
6728 }
6729 else
6730 {
6731 vty_out (vty, ", sourced, local");
6732 }
6733 }
6734
6735 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6736 {
6737 if (json_paths)
6738 json_object_boolean_true_add(json_path, "atomicAggregate");
6739 else
6740 vty_out (vty, ", atomic-aggregate");
6741 }
6742
6743 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6744 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6745 bgp_info_mpath_count (binfo)))
6746 {
6747 if (json_paths)
6748 json_object_boolean_true_add(json_path, "multipath");
6749 else
6750 vty_out (vty, ", multipath");
6751 }
6752
6753 // Mark the bestpath(s)
6754 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
6755 {
6756 first_as = aspath_get_firstas(attr->aspath);
6757
6758 if (json_paths)
6759 {
6760 if (!json_bestpath)
6761 json_bestpath = json_object_new_object();
6762 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
6763 }
6764 else
6765 {
6766 if (first_as)
6767 vty_out (vty, ", bestpath-from-AS %d", first_as);
6768 else
6769 vty_out (vty, ", bestpath-from-AS Local");
6770 }
6771 }
6772
6773 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6774 {
6775 if (json_paths)
6776 {
6777 if (!json_bestpath)
6778 json_bestpath = json_object_new_object();
6779 json_object_boolean_true_add(json_bestpath, "overall");
6780 }
6781 else
6782 vty_out (vty, ", best");
6783 }
6784
6785 if (json_bestpath)
6786 json_object_object_add(json_path, "bestpath", json_bestpath);
6787
6788 if (!json_paths)
6789 vty_out (vty, "%s", VTY_NEWLINE);
6790
6791 /* Line 4 display Community */
6792 if (attr->community)
6793 {
6794 if (json_paths)
6795 {
6796 json_object_lock(attr->community->json);
6797 json_object_object_add(json_path, "community", attr->community->json);
6798 }
6799 else
6800 {
6801 vty_out (vty, " Community: %s%s", attr->community->str,
6802 VTY_NEWLINE);
6803 }
6804 }
6805
6806 /* Line 5 display Extended-community */
6807 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
6808 {
6809 if (json_paths)
6810 {
6811 json_ext_community = json_object_new_object();
6812 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
6813 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
6814 }
6815 else
6816 {
6817 vty_out (vty, " Extended Community: %s%s",
6818 attr->extra->ecommunity->str, VTY_NEWLINE);
6819 }
6820 }
6821
6822 /* Line 6 display Originator, Cluster-id */
6823 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6824 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6825 {
6826 assert (attr->extra);
6827 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6828 {
6829 if (json_paths)
6830 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
6831 else
6832 vty_out (vty, " Originator: %s",
6833 inet_ntoa (attr->extra->originator_id));
6834 }
6835
6836 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6837 {
6838 int i;
6839
6840 if (json_paths)
6841 {
6842 json_cluster_list = json_object_new_object();
6843 json_cluster_list_list = json_object_new_array();
6844
6845 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6846 {
6847 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
6848 json_object_array_add(json_cluster_list_list, json_string);
6849 }
6850
6851 /* struct cluster_list does not have "str" variable like
6852 * aspath and community do. Add this someday if someone
6853 * asks for it.
6854 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
6855 */
6856 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
6857 json_object_object_add(json_path, "clusterList", json_cluster_list);
6858 }
6859 else
6860 {
6861 vty_out (vty, ", Cluster list: ");
6862
6863 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6864 {
6865 vty_out (vty, "%s ",
6866 inet_ntoa (attr->extra->cluster->list[i]));
6867 }
6868 }
6869 }
6870
6871 if (!json_paths)
6872 vty_out (vty, "%s", VTY_NEWLINE);
6873 }
6874
6875 if (binfo->extra && binfo->extra->damp_info)
6876 bgp_damp_info_vty (vty, binfo, json_path);
6877
6878 /* Line 7 display Addpath IDs */
6879 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
6880 {
6881 if (json_paths)
6882 {
6883 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
6884 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
6885 }
6886 else
6887 {
6888 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
6889 binfo->addpath_rx_id, binfo->addpath_tx_id,
6890 VTY_NEWLINE);
6891 }
6892 }
6893
6894 /* If we used addpath to TX a non-bestpath we need to display
6895 * "Advertised to" on a path-by-path basis */
6896 if (bgp->addpath_tx_used[afi][safi])
6897 {
6898 first = 1;
6899
6900 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6901 {
6902 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
6903 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
6904
6905 if ((addpath_capable && has_adj) ||
6906 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
6907 {
6908 if (json_path && !json_adv_to)
6909 json_adv_to = json_object_new_object();
6910
6911 route_vty_out_advertised_to(vty, peer, &first,
6912 " Advertised to:",
6913 json_adv_to);
6914 }
6915 }
6916
6917 if (json_path)
6918 {
6919 if (json_adv_to)
6920 {
6921 json_object_object_add(json_path, "advertisedTo", json_adv_to);
6922 }
6923 }
6924 else
6925 {
6926 if (!first)
6927 {
6928 vty_out (vty, "%s", VTY_NEWLINE);
6929 }
6930 }
6931 }
6932
6933 /* Line 8 display Uptime */
6934 #ifdef HAVE_CLOCK_MONOTONIC
6935 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
6936 if (json_paths)
6937 {
6938 json_last_update = json_object_new_object();
6939 json_object_int_add(json_last_update, "epoch", tbuf);
6940 json_object_string_add(json_last_update, "string", ctime(&tbuf));
6941 json_object_object_add(json_path, "lastUpdate", json_last_update);
6942 }
6943 else
6944 vty_out (vty, " Last update: %s", ctime(&tbuf));
6945 #else
6946 if (json_paths)
6947 {
6948 json_last_update = json_object_new_object();
6949 json_object_int_add(json_last_update, "epoch", tbuf);
6950 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
6951 json_object_object_add(json_path, "lastUpdate", json_last_update);
6952 }
6953 else
6954 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6955 #endif /* HAVE_CLOCK_MONOTONIC */
6956 }
6957
6958 /* We've constructed the json object for this path, add it to the json
6959 * array of paths
6960 */
6961 if (json_paths)
6962 {
6963 if (json_nexthop_global || json_nexthop_ll)
6964 {
6965 json_nexthops = json_object_new_array();
6966
6967 if (json_nexthop_global)
6968 json_object_array_add(json_nexthops, json_nexthop_global);
6969
6970 if (json_nexthop_ll)
6971 json_object_array_add(json_nexthops, json_nexthop_ll);
6972
6973 json_object_object_add(json_path, "nexthops", json_nexthops);
6974 }
6975
6976 json_object_object_add(json_path, "peer", json_peer);
6977 json_object_array_add(json_paths, json_path);
6978 }
6979 else
6980 vty_out (vty, "%s", VTY_NEWLINE);
6981 }
6982
6983 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
6984 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6985 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6986
6987 enum bgp_show_type
6988 {
6989 bgp_show_type_normal,
6990 bgp_show_type_regexp,
6991 bgp_show_type_prefix_list,
6992 bgp_show_type_filter_list,
6993 bgp_show_type_route_map,
6994 bgp_show_type_neighbor,
6995 bgp_show_type_cidr_only,
6996 bgp_show_type_prefix_longer,
6997 bgp_show_type_community_all,
6998 bgp_show_type_community,
6999 bgp_show_type_community_exact,
7000 bgp_show_type_community_list,
7001 bgp_show_type_community_list_exact,
7002 bgp_show_type_flap_statistics,
7003 bgp_show_type_flap_address,
7004 bgp_show_type_flap_prefix,
7005 bgp_show_type_flap_cidr_only,
7006 bgp_show_type_flap_regexp,
7007 bgp_show_type_flap_filter_list,
7008 bgp_show_type_flap_prefix_list,
7009 bgp_show_type_flap_prefix_longer,
7010 bgp_show_type_flap_route_map,
7011 bgp_show_type_flap_neighbor,
7012 bgp_show_type_dampend_paths,
7013 bgp_show_type_damp_neighbor
7014 };
7015
7016 static int
7017 bgp_show_prefix_list (struct vty *vty, const char *name,
7018 const char *prefix_list_str, afi_t afi,
7019 safi_t safi, enum bgp_show_type type);
7020 static int
7021 bgp_show_filter_list (struct vty *vty, const char *name,
7022 const char *filter, afi_t afi,
7023 safi_t safi, enum bgp_show_type type);
7024 static int
7025 bgp_show_route_map (struct vty *vty, const char *name,
7026 const char *rmap_str, afi_t afi,
7027 safi_t safi, enum bgp_show_type type);
7028 static int
7029 bgp_show_community_list (struct vty *vty, const char *name,
7030 const char *com, int exact,
7031 afi_t afi, safi_t safi);
7032 static int
7033 bgp_show_prefix_longer (struct vty *vty, const char *name,
7034 const char *prefix, afi_t afi,
7035 safi_t safi, enum bgp_show_type type);
7036
7037 static int
7038 bgp_show_table (struct vty *vty, struct bgp_table *table,
7039 struct in_addr *router_id, enum bgp_show_type type,
7040 void *output_arg, u_char use_json, json_object *json)
7041 {
7042 struct bgp_info *ri;
7043 struct bgp_node *rn;
7044 int header = 1;
7045 int display;
7046 unsigned long output_count;
7047 struct prefix *p;
7048 char buf[BUFSIZ];
7049 char buf2[BUFSIZ];
7050 json_object *json_paths = NULL;
7051 json_object *json_routes = NULL;
7052
7053 if (use_json)
7054 {
7055 if (json == NULL)
7056 json = json_object_new_object();
7057
7058 json_object_int_add(json, "tableVersion", table->version);
7059 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
7060 json_routes = json_object_new_object();
7061 }
7062
7063 /* This is first entry point, so reset total line. */
7064 output_count = 0;
7065
7066 /* Start processing of routes. */
7067 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7068 if (rn->info != NULL)
7069 {
7070 display = 0;
7071
7072 if (use_json)
7073 json_paths = json_object_new_array();
7074 else
7075 json_paths = NULL;
7076
7077 for (ri = rn->info; ri; ri = ri->next)
7078 {
7079 if (type == bgp_show_type_flap_statistics
7080 || type == bgp_show_type_flap_address
7081 || type == bgp_show_type_flap_prefix
7082 || type == bgp_show_type_flap_cidr_only
7083 || type == bgp_show_type_flap_regexp
7084 || type == bgp_show_type_flap_filter_list
7085 || type == bgp_show_type_flap_prefix_list
7086 || type == bgp_show_type_flap_prefix_longer
7087 || type == bgp_show_type_flap_route_map
7088 || type == bgp_show_type_flap_neighbor
7089 || type == bgp_show_type_dampend_paths
7090 || type == bgp_show_type_damp_neighbor)
7091 {
7092 if (!(ri->extra && ri->extra->damp_info))
7093 continue;
7094 }
7095 if (type == bgp_show_type_regexp
7096 || type == bgp_show_type_flap_regexp)
7097 {
7098 regex_t *regex = output_arg;
7099
7100 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7101 continue;
7102 }
7103 if (type == bgp_show_type_prefix_list
7104 || type == bgp_show_type_flap_prefix_list)
7105 {
7106 struct prefix_list *plist = output_arg;
7107
7108 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7109 continue;
7110 }
7111 if (type == bgp_show_type_filter_list
7112 || type == bgp_show_type_flap_filter_list)
7113 {
7114 struct as_list *as_list = output_arg;
7115
7116 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7117 continue;
7118 }
7119 if (type == bgp_show_type_route_map
7120 || type == bgp_show_type_flap_route_map)
7121 {
7122 struct route_map *rmap = output_arg;
7123 struct bgp_info binfo;
7124 struct attr dummy_attr;
7125 struct attr_extra dummy_extra;
7126 int ret;
7127
7128 dummy_attr.extra = &dummy_extra;
7129 bgp_attr_dup (&dummy_attr, ri->attr);
7130
7131 binfo.peer = ri->peer;
7132 binfo.attr = &dummy_attr;
7133
7134 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7135 if (ret == RMAP_DENYMATCH)
7136 continue;
7137 }
7138 if (type == bgp_show_type_neighbor
7139 || type == bgp_show_type_flap_neighbor
7140 || type == bgp_show_type_damp_neighbor)
7141 {
7142 union sockunion *su = output_arg;
7143
7144 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7145 continue;
7146 }
7147 if (type == bgp_show_type_cidr_only
7148 || type == bgp_show_type_flap_cidr_only)
7149 {
7150 u_int32_t destination;
7151
7152 destination = ntohl (rn->p.u.prefix4.s_addr);
7153 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7154 continue;
7155 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7156 continue;
7157 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7158 continue;
7159 }
7160 if (type == bgp_show_type_prefix_longer
7161 || type == bgp_show_type_flap_prefix_longer)
7162 {
7163 struct prefix *p = output_arg;
7164
7165 if (! prefix_match (p, &rn->p))
7166 continue;
7167 }
7168 if (type == bgp_show_type_community_all)
7169 {
7170 if (! ri->attr->community)
7171 continue;
7172 }
7173 if (type == bgp_show_type_community)
7174 {
7175 struct community *com = output_arg;
7176
7177 if (! ri->attr->community ||
7178 ! community_match (ri->attr->community, com))
7179 continue;
7180 }
7181 if (type == bgp_show_type_community_exact)
7182 {
7183 struct community *com = output_arg;
7184
7185 if (! ri->attr->community ||
7186 ! community_cmp (ri->attr->community, com))
7187 continue;
7188 }
7189 if (type == bgp_show_type_community_list)
7190 {
7191 struct community_list *list = output_arg;
7192
7193 if (! community_list_match (ri->attr->community, list))
7194 continue;
7195 }
7196 if (type == bgp_show_type_community_list_exact)
7197 {
7198 struct community_list *list = output_arg;
7199
7200 if (! community_list_exact_match (ri->attr->community, list))
7201 continue;
7202 }
7203 if (type == bgp_show_type_flap_address
7204 || type == bgp_show_type_flap_prefix)
7205 {
7206 struct prefix *p = output_arg;
7207
7208 if (! prefix_match (&rn->p, p))
7209 continue;
7210
7211 if (type == bgp_show_type_flap_prefix)
7212 if (p->prefixlen != rn->p.prefixlen)
7213 continue;
7214 }
7215 if (type == bgp_show_type_dampend_paths
7216 || type == bgp_show_type_damp_neighbor)
7217 {
7218 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7219 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7220 continue;
7221 }
7222
7223 if (!use_json && header)
7224 {
7225 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
7226 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7227 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7228 if (type == bgp_show_type_dampend_paths
7229 || type == bgp_show_type_damp_neighbor)
7230 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7231 else if (type == bgp_show_type_flap_statistics
7232 || type == bgp_show_type_flap_address
7233 || type == bgp_show_type_flap_prefix
7234 || type == bgp_show_type_flap_cidr_only
7235 || type == bgp_show_type_flap_regexp
7236 || type == bgp_show_type_flap_filter_list
7237 || type == bgp_show_type_flap_prefix_list
7238 || type == bgp_show_type_flap_prefix_longer
7239 || type == bgp_show_type_flap_route_map
7240 || type == bgp_show_type_flap_neighbor)
7241 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7242 else
7243 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7244 header = 0;
7245 }
7246
7247 if (type == bgp_show_type_dampend_paths
7248 || type == bgp_show_type_damp_neighbor)
7249 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7250 else if (type == bgp_show_type_flap_statistics
7251 || type == bgp_show_type_flap_address
7252 || type == bgp_show_type_flap_prefix
7253 || type == bgp_show_type_flap_cidr_only
7254 || type == bgp_show_type_flap_regexp
7255 || type == bgp_show_type_flap_filter_list
7256 || type == bgp_show_type_flap_prefix_list
7257 || type == bgp_show_type_flap_prefix_longer
7258 || type == bgp_show_type_flap_route_map
7259 || type == bgp_show_type_flap_neighbor)
7260 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7261 else
7262 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7263 display++;
7264 }
7265
7266 if (display)
7267 {
7268 output_count++;
7269 if (use_json)
7270 {
7271 p = &rn->p;
7272 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7273 json_object_object_add(json_routes, buf2, json_paths);
7274 }
7275 }
7276 }
7277
7278 if (use_json)
7279 {
7280 json_object_object_add(json, "routes", json_routes);
7281 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7282 json_object_free(json);
7283 }
7284 else
7285 {
7286 /* No route is displayed */
7287 if (output_count == 0)
7288 {
7289 if (type == bgp_show_type_normal)
7290 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
7291 }
7292 else
7293 vty_out (vty, "%sTotal number of prefixes %ld%s",
7294 VTY_NEWLINE, output_count, VTY_NEWLINE);
7295 }
7296
7297 return CMD_SUCCESS;
7298 }
7299
7300 static int
7301 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
7302 enum bgp_show_type type, void *output_arg, u_char use_json)
7303 {
7304 struct bgp_table *table;
7305
7306 if (bgp == NULL)
7307 {
7308 bgp = bgp_get_default ();
7309 }
7310
7311 if (bgp == NULL)
7312 {
7313 if (!use_json)
7314 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7315 return CMD_WARNING;
7316 }
7317
7318 table = bgp->rib[afi][safi];
7319
7320 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg,
7321 use_json, NULL);
7322 }
7323
7324 static void
7325 bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7326 u_char use_json)
7327 {
7328 struct listnode *node, *nnode;
7329 struct bgp *bgp;
7330 struct bgp_table *table;
7331 json_object *json = NULL;
7332 int is_first = 1;
7333
7334 if (use_json)
7335 vty_out (vty, "{%s", VTY_NEWLINE);
7336
7337 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7338 {
7339 if (use_json)
7340 {
7341 if (!(json = json_object_new_object()))
7342 {
7343 zlog_err("Unable to allocate memory for JSON object");
7344 vty_out (vty,
7345 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
7346 VTY_NEWLINE);
7347 return;
7348 }
7349 json_object_int_add(json, "vrfId",
7350 (bgp->vrf_id == VRF_UNKNOWN)
7351 ? -1 : bgp->vrf_id);
7352 json_object_string_add(json, "vrfName",
7353 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7354 ? "Default" : bgp->name);
7355 if (! is_first)
7356 vty_out (vty, ",%s", VTY_NEWLINE);
7357 else
7358 is_first = 0;
7359
7360 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7361 ? "Default" : bgp->name);
7362 }
7363 else
7364 {
7365 vty_out (vty, "%sInstance %s:%s",
7366 VTY_NEWLINE,
7367 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7368 ? "Default" : bgp->name,
7369 VTY_NEWLINE);
7370 }
7371 table = bgp->rib[afi][safi];
7372 bgp_show_table (vty, table, &bgp->router_id,
7373 bgp_show_type_normal, NULL, use_json, json);
7374
7375 }
7376
7377 if (use_json)
7378 vty_out (vty, "}%s", VTY_NEWLINE);
7379 }
7380
7381 /* Header of detailed BGP route information */
7382 static void
7383 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7384 struct bgp_node *rn,
7385 struct prefix_rd *prd, afi_t afi, safi_t safi,
7386 json_object *json)
7387 {
7388 struct bgp_info *ri;
7389 struct prefix *p;
7390 struct peer *peer;
7391 struct listnode *node, *nnode;
7392 char buf1[INET6_ADDRSTRLEN];
7393 char buf2[INET6_ADDRSTRLEN];
7394 int count = 0;
7395 int best = 0;
7396 int suppress = 0;
7397 int no_export = 0;
7398 int no_advertise = 0;
7399 int local_as = 0;
7400 int first = 1;
7401 json_object *json_adv_to = NULL;
7402
7403 p = &rn->p;
7404
7405 if (json)
7406 {
7407 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7408 json_object_int_add(json, "prefixlen", p->prefixlen);
7409 }
7410 else
7411 {
7412 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7413 (safi == SAFI_MPLS_VPN ?
7414 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7415 safi == SAFI_MPLS_VPN ? ":" : "",
7416 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7417 p->prefixlen, VTY_NEWLINE);
7418 }
7419
7420 for (ri = rn->info; ri; ri = ri->next)
7421 {
7422 count++;
7423 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7424 {
7425 best = count;
7426 if (ri->extra && ri->extra->suppress)
7427 suppress = 1;
7428 if (ri->attr->community != NULL)
7429 {
7430 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7431 no_advertise = 1;
7432 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7433 no_export = 1;
7434 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7435 local_as = 1;
7436 }
7437 }
7438 }
7439
7440 if (!json)
7441 {
7442 vty_out (vty, "Paths: (%d available", count);
7443 if (best)
7444 {
7445 vty_out (vty, ", best #%d", best);
7446 if (safi == SAFI_UNICAST)
7447 vty_out (vty, ", table Default-IP-Routing-Table");
7448 }
7449 else
7450 vty_out (vty, ", no best path");
7451
7452 if (no_advertise)
7453 vty_out (vty, ", not advertised to any peer");
7454 else if (no_export)
7455 vty_out (vty, ", not advertised to EBGP peer");
7456 else if (local_as)
7457 vty_out (vty, ", not advertised outside local AS");
7458
7459 if (suppress)
7460 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7461 vty_out (vty, ")%s", VTY_NEWLINE);
7462 }
7463
7464 /* If we are not using addpath then we can display Advertised to and that will
7465 * show what peers we advertised the bestpath to. If we are using addpath
7466 * though then we must display Advertised to on a path-by-path basis. */
7467 if (!bgp->addpath_tx_used[afi][safi])
7468 {
7469 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7470 {
7471 if (bgp_adj_out_lookup (peer, rn, 0))
7472 {
7473 if (json && !json_adv_to)
7474 json_adv_to = json_object_new_object();
7475
7476 route_vty_out_advertised_to(vty, peer, &first,
7477 " Advertised to non peer-group peers:\n ",
7478 json_adv_to);
7479 }
7480 }
7481
7482 if (json)
7483 {
7484 if (json_adv_to)
7485 {
7486 json_object_object_add(json, "advertisedTo", json_adv_to);
7487 }
7488 }
7489 else
7490 {
7491 if (first)
7492 vty_out (vty, " Not advertised to any peer");
7493 vty_out (vty, "%s", VTY_NEWLINE);
7494 }
7495 }
7496 }
7497
7498 /* Display specified route of BGP table. */
7499 static int
7500 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
7501 struct bgp_table *rib, const char *ip_str,
7502 afi_t afi, safi_t safi, struct prefix_rd *prd,
7503 int prefix_check, enum bgp_path_type pathtype,
7504 u_char use_json)
7505 {
7506 int ret;
7507 int header;
7508 int display = 0;
7509 struct prefix match;
7510 struct bgp_node *rn;
7511 struct bgp_node *rm;
7512 struct bgp_info *ri;
7513 struct bgp_table *table;
7514 json_object *json = NULL;
7515 json_object *json_paths = NULL;
7516
7517 /* Check IP address argument. */
7518 ret = str2prefix (ip_str, &match);
7519 if (! ret)
7520 {
7521 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
7522 return CMD_WARNING;
7523 }
7524
7525 match.family = afi2family (afi);
7526
7527 if (use_json)
7528 {
7529 json = json_object_new_object();
7530 json_paths = json_object_new_array();
7531 }
7532
7533 if (safi == SAFI_MPLS_VPN)
7534 {
7535 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
7536 {
7537 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
7538 continue;
7539
7540 if ((table = rn->info) != NULL)
7541 {
7542 header = 1;
7543
7544 if ((rm = bgp_node_match (table, &match)) != NULL)
7545 {
7546 if (prefix_check && rm->p.prefixlen != match.prefixlen)
7547 {
7548 bgp_unlock_node (rm);
7549 continue;
7550 }
7551
7552 for (ri = rm->info; ri; ri = ri->next)
7553 {
7554 if (header)
7555 {
7556 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
7557 AFI_IP, SAFI_MPLS_VPN, json);
7558
7559 header = 0;
7560 }
7561 display++;
7562
7563 if (pathtype == BGP_PATH_ALL ||
7564 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7565 (pathtype == BGP_PATH_MULTIPATH &&
7566 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7567 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN, json_paths);
7568 }
7569
7570 bgp_unlock_node (rm);
7571 }
7572 }
7573 }
7574 }
7575 else
7576 {
7577 header = 1;
7578
7579 if ((rn = bgp_node_match (rib, &match)) != NULL)
7580 {
7581 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
7582 {
7583 for (ri = rn->info; ri; ri = ri->next)
7584 {
7585 if (header)
7586 {
7587 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
7588 header = 0;
7589 }
7590 display++;
7591
7592 if (pathtype == BGP_PATH_ALL ||
7593 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7594 (pathtype == BGP_PATH_MULTIPATH &&
7595 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7596 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
7597 }
7598 }
7599
7600 bgp_unlock_node (rn);
7601 }
7602 }
7603
7604 if (use_json)
7605 {
7606 if (display)
7607 json_object_object_add(json, "paths", json_paths);
7608
7609 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7610 json_object_free(json);
7611 }
7612 else
7613 {
7614 if (!display)
7615 {
7616 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7617 return CMD_WARNING;
7618 }
7619 }
7620
7621 return CMD_SUCCESS;
7622 }
7623
7624 /* Display specified route of Main RIB */
7625 static int
7626 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
7627 afi_t afi, safi_t safi, struct prefix_rd *prd,
7628 int prefix_check, enum bgp_path_type pathtype,
7629 u_char use_json)
7630 {
7631 struct bgp *bgp;
7632
7633 /* BGP structure lookup. */
7634 if (view_name)
7635 {
7636 bgp = bgp_lookup_by_name (view_name);
7637 if (bgp == NULL)
7638 {
7639 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
7640 return CMD_WARNING;
7641 }
7642 }
7643 else
7644 {
7645 bgp = bgp_get_default ();
7646 if (bgp == NULL)
7647 {
7648 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7649 return CMD_WARNING;
7650 }
7651 }
7652
7653 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
7654 afi, safi, prd, prefix_check, pathtype,
7655 use_json);
7656 }
7657
7658 /* BGP route print out function. */
7659 DEFUN (show_ip_bgp,
7660 show_ip_bgp_cmd,
7661 "show ip bgp {json}",
7662 SHOW_STR
7663 IP_STR
7664 BGP_STR
7665 "JavaScript Object Notation\n")
7666 {
7667 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
7668 }
7669
7670 DEFUN (show_ip_bgp_ipv4,
7671 show_ip_bgp_ipv4_cmd,
7672 "show ip bgp ipv4 (unicast|multicast) {json}",
7673 SHOW_STR
7674 IP_STR
7675 BGP_STR
7676 "Address family\n"
7677 "Address Family modifier\n"
7678 "Address Family modifier\n"
7679 "JavaScript Object Notation\n")
7680 {
7681 u_char uj = use_json(argc, argv);
7682
7683 if (strncmp (argv[0], "m", 1) == 0)
7684 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7685 NULL, uj);
7686
7687 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
7688 }
7689
7690 ALIAS (show_ip_bgp_ipv4,
7691 show_bgp_ipv4_safi_cmd,
7692 "show bgp ipv4 (unicast|multicast) {json}",
7693 SHOW_STR
7694 BGP_STR
7695 "Address family\n"
7696 "Address Family modifier\n"
7697 "Address Family modifier\n"
7698 "JavaScript Object Notation\n")
7699
7700 DEFUN (show_ip_bgp_route,
7701 show_ip_bgp_route_cmd,
7702 "show ip bgp A.B.C.D {json}",
7703 SHOW_STR
7704 IP_STR
7705 BGP_STR
7706 "Network in the BGP routing table to display\n"
7707 "JavaScript Object Notation\n")
7708 {
7709 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7710 }
7711
7712 DEFUN (show_ip_bgp_route_pathtype,
7713 show_ip_bgp_route_pathtype_cmd,
7714 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
7715 SHOW_STR
7716 IP_STR
7717 BGP_STR
7718 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7719 "Display only the bestpath\n"
7720 "Display only multipaths\n"
7721 "JavaScript Object Notation\n")
7722 {
7723 u_char uj = use_json(argc, argv);
7724
7725 if (strncmp (argv[1], "b", 1) == 0)
7726 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7727 else
7728 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7729 }
7730
7731 DEFUN (show_bgp_ipv4_safi_route_pathtype,
7732 show_bgp_ipv4_safi_route_pathtype_cmd,
7733 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
7734 SHOW_STR
7735 BGP_STR
7736 "Address family\n"
7737 "Address Family modifier\n"
7738 "Address Family modifier\n"
7739 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7740 "Display only the bestpath\n"
7741 "Display only multipaths\n"
7742 "JavaScript Object Notation\n")
7743 {
7744 u_char uj = use_json(argc, argv);
7745
7746 if (strncmp (argv[0], "m", 1) == 0)
7747 if (strncmp (argv[2], "b", 1) == 0)
7748 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7749 else
7750 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7751 else
7752 if (strncmp (argv[2], "b", 1) == 0)
7753 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7754 else
7755 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7756 }
7757
7758 DEFUN (show_ip_bgp_ipv4_route,
7759 show_ip_bgp_ipv4_route_cmd,
7760 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
7761 SHOW_STR
7762 IP_STR
7763 BGP_STR
7764 "Address family\n"
7765 "Address Family modifier\n"
7766 "Address Family modifier\n"
7767 "Network in the BGP routing table to display\n"
7768 "JavaScript Object Notation\n")
7769 {
7770 u_char uj = use_json(argc, argv);
7771
7772 if (strncmp (argv[0], "m", 1) == 0)
7773 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
7774
7775 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
7776 }
7777
7778 ALIAS (show_ip_bgp_ipv4_route,
7779 show_bgp_ipv4_safi_route_cmd,
7780 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
7781 SHOW_STR
7782 BGP_STR
7783 "Address family\n"
7784 "Address Family modifier\n"
7785 "Address Family modifier\n"
7786 "Network in the BGP routing table to display\n"
7787 "JavaScript Object Notation\n")
7788
7789 DEFUN (show_ip_bgp_vpnv4_all_route,
7790 show_ip_bgp_vpnv4_all_route_cmd,
7791 "show ip bgp vpnv4 all A.B.C.D {json}",
7792 SHOW_STR
7793 IP_STR
7794 BGP_STR
7795 "Display VPNv4 NLRI specific information\n"
7796 "Display information about all VPNv4 NLRIs\n"
7797 "Network in the BGP routing table to display\n"
7798 "JavaScript Object Notation\n")
7799 {
7800 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7801 }
7802
7803
7804 DEFUN (show_ip_bgp_vpnv4_rd_route,
7805 show_ip_bgp_vpnv4_rd_route_cmd,
7806 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
7807 SHOW_STR
7808 IP_STR
7809 BGP_STR
7810 "Display VPNv4 NLRI specific information\n"
7811 "Display information for a route distinguisher\n"
7812 "VPN Route Distinguisher\n"
7813 "Network in the BGP routing table to display\n"
7814 "JavaScript Object Notation\n")
7815 {
7816 int ret;
7817 struct prefix_rd prd;
7818 u_char uj= use_json(argc, argv);
7819
7820 ret = str2prefix_rd (argv[0], &prd);
7821 if (! ret)
7822 {
7823 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7824 return CMD_WARNING;
7825 }
7826 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj);
7827 }
7828
7829 DEFUN (show_ip_bgp_prefix,
7830 show_ip_bgp_prefix_cmd,
7831 "show ip bgp A.B.C.D/M {json}",
7832 SHOW_STR
7833 IP_STR
7834 BGP_STR
7835 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7836 "JavaScript Object Notation\n")
7837 {
7838 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
7839 }
7840
7841 DEFUN (show_ip_bgp_prefix_pathtype,
7842 show_ip_bgp_prefix_pathtype_cmd,
7843 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
7844 SHOW_STR
7845 IP_STR
7846 BGP_STR
7847 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7848 "Display only the bestpath\n"
7849 "Display only multipaths\n"
7850 "JavaScript Object Notation\n")
7851 {
7852 u_char uj = use_json(argc, argv);
7853 if (strncmp (argv[1], "b", 1) == 0)
7854 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
7855 else
7856 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
7857 }
7858
7859 DEFUN (show_ip_bgp_ipv4_prefix,
7860 show_ip_bgp_ipv4_prefix_cmd,
7861 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
7862 SHOW_STR
7863 IP_STR
7864 BGP_STR
7865 "Address family\n"
7866 "Address Family modifier\n"
7867 "Address Family modifier\n"
7868 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7869 "JavaScript Object Notation\n")
7870 {
7871 u_char uj = use_json(argc, argv);
7872
7873 if (strncmp (argv[0], "m", 1) == 0)
7874 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
7875
7876 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
7877 }
7878
7879 ALIAS (show_ip_bgp_ipv4_prefix,
7880 show_bgp_ipv4_safi_prefix_cmd,
7881 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
7882 SHOW_STR
7883 BGP_STR
7884 "Address family\n"
7885 "Address Family modifier\n"
7886 "Address Family modifier\n"
7887 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7888 "JavaScript Object Notation\n")
7889
7890 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7891 show_ip_bgp_ipv4_prefix_pathtype_cmd,
7892 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
7893 SHOW_STR
7894 IP_STR
7895 BGP_STR
7896 "Address family\n"
7897 "Address Family modifier\n"
7898 "Address Family modifier\n"
7899 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7900 "Display only the bestpath\n"
7901 "Display only multipaths\n"
7902 "JavaScript Object Notation\n")
7903 {
7904 u_char uj = use_json(argc, argv);
7905
7906 if (strncmp (argv[0], "m", 1) == 0)
7907 if (strncmp (argv[2], "b", 1) == 0)
7908 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
7909 else
7910 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
7911 else
7912 if (strncmp (argv[2], "b", 1) == 0)
7913 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
7914 else
7915 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
7916 }
7917
7918 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7919 show_bgp_ipv4_safi_prefix_pathtype_cmd,
7920 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
7921 SHOW_STR
7922 BGP_STR
7923 "Address family\n"
7924 "Address Family modifier\n"
7925 "Address Family modifier\n"
7926 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7927 "Display only the bestpath\n"
7928 "Display only multipaths\n"
7929 "JavaScript Object Notation\n")
7930
7931 DEFUN (show_ip_bgp_vpnv4_all_prefix,
7932 show_ip_bgp_vpnv4_all_prefix_cmd,
7933 "show ip bgp vpnv4 all A.B.C.D/M {json}",
7934 SHOW_STR
7935 IP_STR
7936 BGP_STR
7937 "Display VPNv4 NLRI specific information\n"
7938 "Display information about all VPNv4 NLRIs\n"
7939 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7940 "JavaScript Object Notation\n")
7941 {
7942 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
7943 }
7944
7945 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7946 show_ip_bgp_vpnv4_rd_prefix_cmd,
7947 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
7948 SHOW_STR
7949 IP_STR
7950 BGP_STR
7951 "Display VPNv4 NLRI specific information\n"
7952 "Display information for a route distinguisher\n"
7953 "VPN Route Distinguisher\n"
7954 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7955 "JavaScript Object Notation\n")
7956 {
7957 int ret;
7958 struct prefix_rd prd;
7959
7960 ret = str2prefix_rd (argv[0], &prd);
7961 if (! ret)
7962 {
7963 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7964 return CMD_WARNING;
7965 }
7966 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv));
7967 }
7968
7969 DEFUN (show_ip_bgp_view,
7970 show_ip_bgp_instance_cmd,
7971 "show ip bgp " BGP_INSTANCE_CMD " {json}",
7972 SHOW_STR
7973 IP_STR
7974 BGP_STR
7975 BGP_INSTANCE_HELP_STR
7976 "JavaScript Object Notation\n")
7977 {
7978 struct bgp *bgp;
7979
7980 /* BGP structure lookup. */
7981 bgp = bgp_lookup_by_name (argv[1]);
7982 if (bgp == NULL)
7983 {
7984 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
7985 return CMD_WARNING;
7986 }
7987
7988 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
7989 }
7990
7991 DEFUN (show_ip_bgp_instance_all,
7992 show_ip_bgp_instance_all_cmd,
7993 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
7994 SHOW_STR
7995 IP_STR
7996 BGP_STR
7997 BGP_INSTANCE_ALL_HELP_STR
7998 "JavaScript Object Notation\n")
7999 {
8000 u_char uj = use_json(argc, argv);
8001
8002 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8003 return CMD_SUCCESS;
8004 }
8005
8006 DEFUN (show_ip_bgp_instance_route,
8007 show_ip_bgp_instance_route_cmd,
8008 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
8009 SHOW_STR
8010 IP_STR
8011 BGP_STR
8012 BGP_INSTANCE_HELP_STR
8013 "Network in the BGP routing table to display\n"
8014 "JavaScript Object Notation\n")
8015 {
8016 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8017 }
8018
8019 DEFUN (show_ip_bgp_instance_route_pathtype,
8020 show_ip_bgp_instance_route_pathtype_cmd,
8021 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
8022 SHOW_STR
8023 IP_STR
8024 BGP_STR
8025 BGP_INSTANCE_HELP_STR
8026 "Network in the BGP routing table to display\n"
8027 "Display only the bestpath\n"
8028 "Display only multipaths\n"
8029 "JavaScript Object Notation\n")
8030 {
8031 u_char uj = use_json(argc, argv);
8032
8033 if (strncmp (argv[3], "b", 1) == 0)
8034 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8035 else
8036 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8037 }
8038
8039 DEFUN (show_ip_bgp_instance_prefix,
8040 show_ip_bgp_instance_prefix_cmd,
8041 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
8042 SHOW_STR
8043 IP_STR
8044 BGP_STR
8045 BGP_INSTANCE_HELP_STR
8046 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8047 "JavaScript Object Notation\n")
8048 {
8049 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8050 }
8051
8052 DEFUN (show_ip_bgp_instance_prefix_pathtype,
8053 show_ip_bgp_instance_prefix_pathtype_cmd,
8054 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
8055 SHOW_STR
8056 IP_STR
8057 BGP_STR
8058 BGP_INSTANCE_HELP_STR
8059 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8060 "Display only the bestpath\n"
8061 "Display only multipaths\n"
8062 "JavaScript Object Notation\n")
8063 {
8064 u_char uj = use_json(argc, argv);
8065 if (strncmp (argv[3], "b", 1) == 0)
8066 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8067 else
8068 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8069 }
8070
8071 #ifdef HAVE_IPV6
8072 DEFUN (show_bgp,
8073 show_bgp_cmd,
8074 "show bgp {json}",
8075 SHOW_STR
8076 BGP_STR
8077 "JavaScript Object Notation\n")
8078 {
8079 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8080 NULL, use_json(argc, argv));
8081 }
8082
8083 ALIAS (show_bgp,
8084 show_bgp_ipv6_cmd,
8085 "show bgp ipv6 {json}",
8086 SHOW_STR
8087 BGP_STR
8088 "Address family\n"
8089 "JavaScript Object Notation\n")
8090
8091 DEFUN (show_bgp_ipv6_safi,
8092 show_bgp_ipv6_safi_cmd,
8093 "show bgp ipv6 (unicast|multicast) {json}",
8094 SHOW_STR
8095 BGP_STR
8096 "Address family\n"
8097 "Address Family modifier\n"
8098 "Address Family modifier\n"
8099 "JavaScript Object Notation\n")
8100 {
8101 u_char uj = use_json(argc, argv);
8102 if (strncmp (argv[0], "m", 1) == 0)
8103 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8104 NULL, uj);
8105
8106 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
8107 }
8108
8109 static void
8110 bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8111 {
8112 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8113 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8114 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8115 }
8116
8117 /* old command */
8118 DEFUN (show_ipv6_bgp,
8119 show_ipv6_bgp_cmd,
8120 "show ipv6 bgp {json}",
8121 SHOW_STR
8122 IP_STR
8123 BGP_STR
8124 "JavaScript Object Notation\n")
8125 {
8126 bgp_show_ipv6_bgp_deprecate_warning(vty);
8127 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8128 NULL, use_json(argc, argv));
8129 }
8130
8131 DEFUN (show_bgp_route,
8132 show_bgp_route_cmd,
8133 "show bgp X:X::X:X {json}",
8134 SHOW_STR
8135 BGP_STR
8136 "Network in the BGP routing table to display\n"
8137 "JavaScript Object Notation\n")
8138 {
8139 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8140 }
8141
8142 ALIAS (show_bgp_route,
8143 show_bgp_ipv6_route_cmd,
8144 "show bgp ipv6 X:X::X:X {json}",
8145 SHOW_STR
8146 BGP_STR
8147 "Address family\n"
8148 "Network in the BGP routing table to display\n"
8149 "JavaScript Object Notation\n")
8150
8151 DEFUN (show_bgp_ipv6_safi_route,
8152 show_bgp_ipv6_safi_route_cmd,
8153 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
8154 SHOW_STR
8155 BGP_STR
8156 "Address family\n"
8157 "Address Family modifier\n"
8158 "Address Family modifier\n"
8159 "Network in the BGP routing table to display\n"
8160 "JavaScript Object Notation\n")
8161 {
8162 u_char uj = use_json(argc, argv);
8163 if (strncmp (argv[0], "m", 1) == 0)
8164 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
8165
8166 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
8167 }
8168
8169 DEFUN (show_bgp_route_pathtype,
8170 show_bgp_route_pathtype_cmd,
8171 "show bgp X:X::X:X (bestpath|multipath) {json}",
8172 SHOW_STR
8173 BGP_STR
8174 "Network in the BGP routing table to display\n"
8175 "Display only the bestpath\n"
8176 "Display only multipaths\n"
8177 "JavaScript Object Notation\n")
8178 {
8179 u_char uj = use_json(argc, argv);
8180 if (strncmp (argv[1], "b", 1) == 0)
8181 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8182 else
8183 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8184 }
8185
8186 ALIAS (show_bgp_route_pathtype,
8187 show_bgp_ipv6_route_pathtype_cmd,
8188 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
8189 SHOW_STR
8190 BGP_STR
8191 "Address family\n"
8192 "Network in the BGP routing table to display\n"
8193 "Display only the bestpath\n"
8194 "Display only multipaths\n"
8195 "JavaScript Object Notation\n")
8196
8197 DEFUN (show_bgp_ipv6_safi_route_pathtype,
8198 show_bgp_ipv6_safi_route_pathtype_cmd,
8199 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
8200 SHOW_STR
8201 BGP_STR
8202 "Address family\n"
8203 "Address Family modifier\n"
8204 "Address Family modifier\n"
8205 "Network in the BGP routing table to display\n"
8206 "Display only the bestpath\n"
8207 "Display only multipaths\n"
8208 "JavaScript Object Notation\n")
8209 {
8210 u_char uj = use_json(argc, argv);
8211 if (strncmp (argv[0], "m", 1) == 0)
8212 if (strncmp (argv[2], "b", 1) == 0)
8213 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8214 else
8215 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8216 else
8217 if (strncmp (argv[2], "b", 1) == 0)
8218 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8219 else
8220 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8221 }
8222
8223 /* old command */
8224 DEFUN (show_ipv6_bgp_route,
8225 show_ipv6_bgp_route_cmd,
8226 "show ipv6 bgp X:X::X:X {json}",
8227 SHOW_STR
8228 IP_STR
8229 BGP_STR
8230 "Network in the BGP routing table to display\n"
8231 "JavaScript Object Notation\n")
8232 {
8233 bgp_show_ipv6_bgp_deprecate_warning(vty);
8234 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8235 }
8236
8237 DEFUN (show_bgp_prefix,
8238 show_bgp_prefix_cmd,
8239 "show bgp X:X::X:X/M {json}",
8240 SHOW_STR
8241 BGP_STR
8242 "IPv6 prefix <network>/<length>\n"
8243 "JavaScript Object Notation\n")
8244 {
8245 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8246 }
8247
8248 ALIAS (show_bgp_prefix,
8249 show_bgp_ipv6_prefix_cmd,
8250 "show bgp ipv6 X:X::X:X/M {json}",
8251 SHOW_STR
8252 BGP_STR
8253 "Address family\n"
8254 "IPv6 prefix <network>/<length>\n"
8255 "JavaScript Object Notation\n")
8256
8257 DEFUN (show_bgp_ipv6_safi_prefix,
8258 show_bgp_ipv6_safi_prefix_cmd,
8259 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
8260 SHOW_STR
8261 BGP_STR
8262 "Address family\n"
8263 "Address Family modifier\n"
8264 "Address Family modifier\n"
8265 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8266 "JavaScript Object Notation\n")
8267 {
8268 u_char uj = use_json(argc, argv);
8269 if (strncmp (argv[0], "m", 1) == 0)
8270 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
8271
8272 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
8273 }
8274
8275 DEFUN (show_bgp_prefix_pathtype,
8276 show_bgp_prefix_pathtype_cmd,
8277 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
8278 SHOW_STR
8279 BGP_STR
8280 "IPv6 prefix <network>/<length>\n"
8281 "Display only the bestpath\n"
8282 "Display only multipaths\n"
8283 "JavaScript Object Notation\n")
8284 {
8285 u_char uj = use_json(argc, argv);
8286 if (strncmp (argv[1], "b", 1) == 0)
8287 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8288 else
8289 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8290 }
8291
8292 ALIAS (show_bgp_prefix_pathtype,
8293 show_bgp_ipv6_prefix_pathtype_cmd,
8294 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8295 SHOW_STR
8296 BGP_STR
8297 "Address family\n"
8298 "IPv6 prefix <network>/<length>\n"
8299 "Display only the bestpath\n"
8300 "Display only multipaths\n"
8301 "JavaScript Object Notation\n")
8302
8303 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8304 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8305 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
8306 SHOW_STR
8307 BGP_STR
8308 "Address family\n"
8309 "Address Family modifier\n"
8310 "Address Family modifier\n"
8311 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8312 "Display only the bestpath\n"
8313 "Display only multipaths\n"
8314 "JavaScript Object Notation\n")
8315 {
8316 u_char uj = use_json(argc, argv);
8317 if (strncmp (argv[0], "m", 1) == 0)
8318 if (strncmp (argv[2], "b", 1) == 0)
8319 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8320 else
8321 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8322 else
8323 if (strncmp (argv[2], "b", 1) == 0)
8324 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8325 else
8326 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8327 }
8328
8329 /* old command */
8330 DEFUN (show_ipv6_bgp_prefix,
8331 show_ipv6_bgp_prefix_cmd,
8332 "show ipv6 bgp X:X::X:X/M {json}",
8333 SHOW_STR
8334 IP_STR
8335 BGP_STR
8336 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8337 "JavaScript Object Notation\n")
8338 {
8339 bgp_show_ipv6_bgp_deprecate_warning(vty);
8340 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8341 }
8342
8343 DEFUN (show_bgp_view,
8344 show_bgp_instance_cmd,
8345 "show bgp " BGP_INSTANCE_CMD " {json}",
8346 SHOW_STR
8347 BGP_STR
8348 BGP_INSTANCE_HELP_STR
8349 "JavaScript Object Notation\n")
8350 {
8351 struct bgp *bgp;
8352
8353 /* BGP structure lookup. */
8354 bgp = bgp_lookup_by_name (argv[1]);
8355 if (bgp == NULL)
8356 {
8357 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8358 return CMD_WARNING;
8359 }
8360
8361 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8362 }
8363
8364 DEFUN (show_bgp_instance_all,
8365 show_bgp_instance_all_cmd,
8366 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
8367 SHOW_STR
8368 BGP_STR
8369 BGP_INSTANCE_ALL_HELP_STR
8370 "JavaScript Object Notation\n")
8371 {
8372 u_char uj = use_json(argc, argv);
8373
8374 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
8375 return CMD_SUCCESS;
8376 }
8377
8378 ALIAS (show_bgp_view,
8379 show_bgp_instance_ipv6_cmd,
8380 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
8381 SHOW_STR
8382 BGP_STR
8383 BGP_INSTANCE_HELP_STR
8384 "Address family\n"
8385 "JavaScript Object Notation\n")
8386
8387 DEFUN (show_bgp_instance_route,
8388 show_bgp_instance_route_cmd,
8389 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
8390 SHOW_STR
8391 BGP_STR
8392 BGP_INSTANCE_HELP_STR
8393 "Network in the BGP routing table to display\n"
8394 "JavaScript Object Notation\n")
8395 {
8396 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8397 }
8398
8399 ALIAS (show_bgp_instance_route,
8400 show_bgp_instance_ipv6_route_cmd,
8401 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
8402 SHOW_STR
8403 BGP_STR
8404 BGP_INSTANCE_HELP_STR
8405 "Address family\n"
8406 "Network in the BGP routing table to display\n"
8407 "JavaScript Object Notation\n")
8408
8409 DEFUN (show_bgp_instance_route_pathtype,
8410 show_bgp_instance_route_pathtype_cmd,
8411 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
8412 SHOW_STR
8413 BGP_STR
8414 BGP_INSTANCE_HELP_STR
8415 "Network in the BGP routing table to display\n"
8416 "Display only the bestpath\n"
8417 "Display only multipaths\n"
8418 "JavaScript Object Notation\n")
8419 {
8420 u_char uj = use_json(argc, argv);
8421 if (strncmp (argv[3], "b", 1) == 0)
8422 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8423 else
8424 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8425 }
8426
8427 ALIAS (show_bgp_instance_route_pathtype,
8428 show_bgp_instance_ipv6_route_pathtype_cmd,
8429 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
8430 SHOW_STR
8431 BGP_STR
8432 BGP_INSTANCE_HELP_STR
8433 "Address family\n"
8434 "Network in the BGP routing table to display\n"
8435 "Display only the bestpath\n"
8436 "Display only multipaths\n"
8437 "JavaScript Object Notation\n")
8438
8439 DEFUN (show_bgp_instance_prefix,
8440 show_bgp_instance_prefix_cmd,
8441 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
8442 SHOW_STR
8443 BGP_STR
8444 BGP_INSTANCE_HELP_STR
8445 "IPv6 prefix <network>/<length>\n"
8446 "JavaScript Object Notation\n")
8447 {
8448 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8449 }
8450
8451 ALIAS (show_bgp_instance_prefix,
8452 show_bgp_instance_ipv6_prefix_cmd,
8453 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
8454 SHOW_STR
8455 BGP_STR
8456 BGP_INSTANCE_HELP_STR
8457 "Address family\n"
8458 "IPv6 prefix <network>/<length>\n"
8459 "JavaScript Object Notation\n")
8460
8461 DEFUN (show_bgp_instance_prefix_pathtype,
8462 show_bgp_instance_prefix_pathtype_cmd,
8463 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
8464 SHOW_STR
8465 BGP_STR
8466 BGP_INSTANCE_HELP_STR
8467 "IPv6 prefix <network>/<length>\n"
8468 "Display only the bestpath\n"
8469 "Display only multipaths\n"
8470 "JavaScript Object Notation\n")
8471 {
8472 u_char uj = use_json(argc, argv);
8473 if (strncmp (argv[3], "b", 1) == 0)
8474 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8475 else
8476 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8477 }
8478
8479 ALIAS (show_bgp_instance_prefix_pathtype,
8480 show_bgp_instance_ipv6_prefix_pathtype_cmd,
8481 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8482 SHOW_STR
8483 BGP_STR
8484 BGP_INSTANCE_HELP_STR
8485 "Address family\n"
8486 "IPv6 prefix <network>/<length>\n"
8487 "Display only the bestpath\n"
8488 "Display only multipaths\n"
8489 "JavaScript Object Notation\n")
8490
8491 DEFUN (show_bgp_instance_prefix_list,
8492 show_bgp_instance_prefix_list_cmd,
8493 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
8494 SHOW_STR
8495 BGP_STR
8496 BGP_INSTANCE_HELP_STR
8497 "Display routes conforming to the prefix-list\n"
8498 "IPv6 prefix-list name\n")
8499 {
8500 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8501 bgp_show_type_prefix_list);
8502 }
8503
8504 ALIAS (show_bgp_instance_prefix_list,
8505 show_bgp_instance_ipv6_prefix_list_cmd,
8506 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
8507 SHOW_STR
8508 BGP_STR
8509 BGP_INSTANCE_HELP_STR
8510 "Address family\n"
8511 "Display routes conforming to the prefix-list\n"
8512 "IPv6 prefix-list name\n")
8513
8514 DEFUN (show_bgp_instance_filter_list,
8515 show_bgp_instance_filter_list_cmd,
8516 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
8517 SHOW_STR
8518 BGP_STR
8519 BGP_INSTANCE_HELP_STR
8520 "Display routes conforming to the filter-list\n"
8521 "Regular expression access list name\n")
8522 {
8523 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8524 bgp_show_type_filter_list);
8525 }
8526
8527 ALIAS (show_bgp_instance_filter_list,
8528 show_bgp_instance_ipv6_filter_list_cmd,
8529 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
8530 SHOW_STR
8531 BGP_STR
8532 BGP_INSTANCE_HELP_STR
8533 "Address family\n"
8534 "Display routes conforming to the filter-list\n"
8535 "Regular expression access list name\n")
8536
8537 DEFUN (show_bgp_instance_route_map,
8538 show_bgp_instance_route_map_cmd,
8539 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
8540 SHOW_STR
8541 BGP_STR
8542 BGP_INSTANCE_HELP_STR
8543 "Display routes matching the route-map\n"
8544 "A route-map to match on\n")
8545 {
8546 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8547 bgp_show_type_route_map);
8548 }
8549
8550 ALIAS (show_bgp_instance_route_map,
8551 show_bgp_instance_ipv6_route_map_cmd,
8552 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
8553 SHOW_STR
8554 BGP_STR
8555 BGP_INSTANCE_HELP_STR
8556 "Address family\n"
8557 "Display routes matching the route-map\n"
8558 "A route-map to match on\n")
8559
8560 DEFUN (show_bgp_instance_community_list,
8561 show_bgp_instance_community_list_cmd,
8562 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
8563 SHOW_STR
8564 BGP_STR
8565 BGP_INSTANCE_HELP_STR
8566 "Display routes matching the community-list\n"
8567 "community-list number\n"
8568 "community-list name\n")
8569 {
8570 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
8571 }
8572
8573 ALIAS (show_bgp_instance_community_list,
8574 show_bgp_instance_ipv6_community_list_cmd,
8575 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
8576 SHOW_STR
8577 BGP_STR
8578 BGP_INSTANCE_HELP_STR
8579 "Address family\n"
8580 "Display routes matching the community-list\n"
8581 "community-list number\n"
8582 "community-list name\n")
8583
8584 DEFUN (show_bgp_instance_prefix_longer,
8585 show_bgp_instance_prefix_longer_cmd,
8586 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
8587 SHOW_STR
8588 BGP_STR
8589 BGP_INSTANCE_HELP_STR
8590 "IPv6 prefix <network>/<length>\n"
8591 "Display route and more specific routes\n")
8592 {
8593 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8594 bgp_show_type_prefix_longer);
8595 }
8596
8597 ALIAS (show_bgp_instance_prefix_longer,
8598 show_bgp_instance_ipv6_prefix_longer_cmd,
8599 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
8600 SHOW_STR
8601 BGP_STR
8602 BGP_INSTANCE_HELP_STR
8603 "Address family\n"
8604 "IPv6 prefix <network>/<length>\n"
8605 "Display route and more specific routes\n")
8606
8607 /* old command */
8608 DEFUN (show_ipv6_mbgp,
8609 show_ipv6_mbgp_cmd,
8610 "show ipv6 mbgp {json}",
8611 SHOW_STR
8612 IP_STR
8613 MBGP_STR
8614 "JavaScript Object Notation\n")
8615 {
8616 bgp_show_ipv6_bgp_deprecate_warning(vty);
8617 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8618 NULL, use_json(argc, argv));
8619 }
8620
8621 /* old command */
8622 DEFUN (show_ipv6_mbgp_route,
8623 show_ipv6_mbgp_route_cmd,
8624 "show ipv6 mbgp X:X::X:X {json}",
8625 SHOW_STR
8626 IP_STR
8627 MBGP_STR
8628 "Network in the MBGP routing table to display\n"
8629 "JavaScript Object Notation\n")
8630 {
8631 bgp_show_ipv6_bgp_deprecate_warning(vty);
8632 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8633 }
8634
8635 /* old command */
8636 DEFUN (show_ipv6_mbgp_prefix,
8637 show_ipv6_mbgp_prefix_cmd,
8638 "show ipv6 mbgp X:X::X:X/M {json}",
8639 SHOW_STR
8640 IP_STR
8641 MBGP_STR
8642 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8643 "JavaScript Object Notation\n")
8644 {
8645 bgp_show_ipv6_bgp_deprecate_warning(vty);
8646 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8647 }
8648 #endif
8649
8650
8651 static int
8652 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
8653 safi_t safi, enum bgp_show_type type)
8654 {
8655 int i;
8656 struct buffer *b;
8657 char *regstr;
8658 int first;
8659 regex_t *regex;
8660 int rc;
8661
8662 first = 0;
8663 b = buffer_new (1024);
8664 for (i = 0; i < argc; i++)
8665 {
8666 if (first)
8667 buffer_putc (b, ' ');
8668 else
8669 {
8670 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8671 continue;
8672 first = 1;
8673 }
8674
8675 buffer_putstr (b, argv[i]);
8676 }
8677 buffer_putc (b, '\0');
8678
8679 regstr = buffer_getstr (b);
8680 buffer_free (b);
8681
8682 regex = bgp_regcomp (regstr);
8683 XFREE(MTYPE_TMP, regstr);
8684 if (! regex)
8685 {
8686 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8687 VTY_NEWLINE);
8688 return CMD_WARNING;
8689 }
8690
8691 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
8692 bgp_regex_free (regex);
8693 return rc;
8694 }
8695
8696 DEFUN (show_ip_bgp_regexp,
8697 show_ip_bgp_regexp_cmd,
8698 "show ip bgp regexp .LINE",
8699 SHOW_STR
8700 IP_STR
8701 BGP_STR
8702 "Display routes matching the AS path regular expression\n"
8703 "A regular-expression to match the BGP AS paths\n")
8704 {
8705 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8706 bgp_show_type_regexp);
8707 }
8708
8709 DEFUN (show_ip_bgp_flap_regexp,
8710 show_ip_bgp_flap_regexp_cmd,
8711 "show ip bgp flap-statistics regexp .LINE",
8712 SHOW_STR
8713 IP_STR
8714 BGP_STR
8715 "Display flap statistics of routes\n"
8716 "Display routes matching the AS path regular expression\n"
8717 "A regular-expression to match the BGP AS paths\n")
8718 {
8719 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8720 bgp_show_type_flap_regexp);
8721 }
8722
8723 ALIAS (show_ip_bgp_flap_regexp,
8724 show_ip_bgp_damp_flap_regexp_cmd,
8725 "show ip bgp dampening flap-statistics regexp .LINE",
8726 SHOW_STR
8727 IP_STR
8728 BGP_STR
8729 "Display detailed information about dampening\n"
8730 "Display flap statistics of routes\n"
8731 "Display routes matching the AS path regular expression\n"
8732 "A regular-expression to match the BGP AS paths\n")
8733
8734 DEFUN (show_ip_bgp_ipv4_regexp,
8735 show_ip_bgp_ipv4_regexp_cmd,
8736 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8737 SHOW_STR
8738 IP_STR
8739 BGP_STR
8740 "Address family\n"
8741 "Address Family modifier\n"
8742 "Address Family modifier\n"
8743 "Display routes matching the AS path regular expression\n"
8744 "A regular-expression to match the BGP AS paths\n")
8745 {
8746 if (strncmp (argv[0], "m", 1) == 0)
8747 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8748 bgp_show_type_regexp);
8749
8750 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8751 bgp_show_type_regexp);
8752 }
8753
8754 #ifdef HAVE_IPV6
8755 DEFUN (show_bgp_regexp,
8756 show_bgp_regexp_cmd,
8757 "show bgp regexp .LINE",
8758 SHOW_STR
8759 BGP_STR
8760 "Display routes matching the AS path regular expression\n"
8761 "A regular-expression to match the BGP AS paths\n")
8762 {
8763 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8764 bgp_show_type_regexp);
8765 }
8766
8767 ALIAS (show_bgp_regexp,
8768 show_bgp_ipv6_regexp_cmd,
8769 "show bgp ipv6 regexp .LINE",
8770 SHOW_STR
8771 BGP_STR
8772 "Address family\n"
8773 "Display routes matching the AS path regular expression\n"
8774 "A regular-expression to match the BGP AS paths\n")
8775
8776 /* old command */
8777 DEFUN (show_ipv6_bgp_regexp,
8778 show_ipv6_bgp_regexp_cmd,
8779 "show ipv6 bgp regexp .LINE",
8780 SHOW_STR
8781 IP_STR
8782 BGP_STR
8783 "Display routes matching the AS path regular expression\n"
8784 "A regular-expression to match the BGP AS paths\n")
8785 {
8786 bgp_show_ipv6_bgp_deprecate_warning(vty);
8787 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8788 bgp_show_type_regexp);
8789 }
8790
8791 /* old command */
8792 DEFUN (show_ipv6_mbgp_regexp,
8793 show_ipv6_mbgp_regexp_cmd,
8794 "show ipv6 mbgp regexp .LINE",
8795 SHOW_STR
8796 IP_STR
8797 BGP_STR
8798 "Display routes matching the AS path regular expression\n"
8799 "A regular-expression to match the MBGP AS paths\n")
8800 {
8801 bgp_show_ipv6_bgp_deprecate_warning(vty);
8802 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8803 bgp_show_type_regexp);
8804 }
8805 #endif /* HAVE_IPV6 */
8806
8807 static int
8808 bgp_show_prefix_list (struct vty *vty, const char *name,
8809 const char *prefix_list_str, afi_t afi,
8810 safi_t safi, enum bgp_show_type type)
8811 {
8812 struct prefix_list *plist;
8813 struct bgp *bgp = NULL;
8814
8815 if (name && !(bgp = bgp_lookup_by_name(name)))
8816 {
8817 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
8818 return CMD_WARNING;
8819 }
8820
8821 plist = prefix_list_lookup (afi, prefix_list_str);
8822 if (plist == NULL)
8823 {
8824 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8825 prefix_list_str, VTY_NEWLINE);
8826 return CMD_WARNING;
8827 }
8828
8829 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
8830 }
8831
8832 DEFUN (show_ip_bgp_prefix_list,
8833 show_ip_bgp_prefix_list_cmd,
8834 "show ip bgp prefix-list WORD",
8835 SHOW_STR
8836 IP_STR
8837 BGP_STR
8838 "Display routes conforming to the prefix-list\n"
8839 "IP prefix-list name\n")
8840 {
8841 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
8842 bgp_show_type_prefix_list);
8843 }
8844
8845 DEFUN (show_ip_bgp_instance_prefix_list,
8846 show_ip_bgp_instance_prefix_list_cmd,
8847 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
8848 SHOW_STR
8849 IP_STR
8850 BGP_STR
8851 BGP_INSTANCE_HELP_STR
8852 "Display routes conforming to the prefix-list\n"
8853 "IP prefix-list name\n")
8854 {
8855 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
8856 bgp_show_type_prefix_list);
8857 }
8858
8859 DEFUN (show_ip_bgp_flap_prefix_list,
8860 show_ip_bgp_flap_prefix_list_cmd,
8861 "show ip bgp flap-statistics prefix-list WORD",
8862 SHOW_STR
8863 IP_STR
8864 BGP_STR
8865 "Display flap statistics of routes\n"
8866 "Display routes conforming to the prefix-list\n"
8867 "IP prefix-list name\n")
8868 {
8869 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
8870 bgp_show_type_flap_prefix_list);
8871 }
8872
8873 ALIAS (show_ip_bgp_flap_prefix_list,
8874 show_ip_bgp_damp_flap_prefix_list_cmd,
8875 "show ip bgp dampening flap-statistics prefix-list WORD",
8876 SHOW_STR
8877 IP_STR
8878 BGP_STR
8879 "Display detailed information about dampening\n"
8880 "Display flap statistics of routes\n"
8881 "Display routes conforming to the prefix-list\n"
8882 "IP prefix-list name\n")
8883
8884 DEFUN (show_ip_bgp_ipv4_prefix_list,
8885 show_ip_bgp_ipv4_prefix_list_cmd,
8886 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8887 SHOW_STR
8888 IP_STR
8889 BGP_STR
8890 "Address family\n"
8891 "Address Family modifier\n"
8892 "Address Family modifier\n"
8893 "Display routes conforming to the prefix-list\n"
8894 "IP prefix-list name\n")
8895 {
8896 if (strncmp (argv[0], "m", 1) == 0)
8897 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
8898 bgp_show_type_prefix_list);
8899
8900 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
8901 bgp_show_type_prefix_list);
8902 }
8903
8904 #ifdef HAVE_IPV6
8905 DEFUN (show_bgp_prefix_list,
8906 show_bgp_prefix_list_cmd,
8907 "show bgp prefix-list WORD",
8908 SHOW_STR
8909 BGP_STR
8910 "Display routes conforming to the prefix-list\n"
8911 "IPv6 prefix-list name\n")
8912 {
8913 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
8914 bgp_show_type_prefix_list);
8915 }
8916
8917 ALIAS (show_bgp_prefix_list,
8918 show_bgp_ipv6_prefix_list_cmd,
8919 "show bgp ipv6 prefix-list WORD",
8920 SHOW_STR
8921 BGP_STR
8922 "Address family\n"
8923 "Display routes conforming to the prefix-list\n"
8924 "IPv6 prefix-list name\n")
8925
8926 /* old command */
8927 DEFUN (show_ipv6_bgp_prefix_list,
8928 show_ipv6_bgp_prefix_list_cmd,
8929 "show ipv6 bgp prefix-list WORD",
8930 SHOW_STR
8931 IPV6_STR
8932 BGP_STR
8933 "Display routes matching the prefix-list\n"
8934 "IPv6 prefix-list name\n")
8935 {
8936 bgp_show_ipv6_bgp_deprecate_warning(vty);
8937 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
8938 bgp_show_type_prefix_list);
8939 }
8940
8941 /* old command */
8942 DEFUN (show_ipv6_mbgp_prefix_list,
8943 show_ipv6_mbgp_prefix_list_cmd,
8944 "show ipv6 mbgp prefix-list WORD",
8945 SHOW_STR
8946 IPV6_STR
8947 MBGP_STR
8948 "Display routes matching the prefix-list\n"
8949 "IPv6 prefix-list name\n")
8950 {
8951 bgp_show_ipv6_bgp_deprecate_warning(vty);
8952 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
8953 bgp_show_type_prefix_list);
8954 }
8955 #endif /* HAVE_IPV6 */
8956
8957 static int
8958 bgp_show_filter_list (struct vty *vty, const char *name,
8959 const char *filter, afi_t afi,
8960 safi_t safi, enum bgp_show_type type)
8961 {
8962 struct as_list *as_list;
8963 struct bgp *bgp = NULL;
8964
8965 if (name && !(bgp = bgp_lookup_by_name(name)))
8966 {
8967 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
8968 return CMD_WARNING;
8969 }
8970
8971 as_list = as_list_lookup (filter);
8972 if (as_list == NULL)
8973 {
8974 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8975 return CMD_WARNING;
8976 }
8977
8978 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
8979 }
8980
8981 DEFUN (show_ip_bgp_filter_list,
8982 show_ip_bgp_filter_list_cmd,
8983 "show ip bgp filter-list WORD",
8984 SHOW_STR
8985 IP_STR
8986 BGP_STR
8987 "Display routes conforming to the filter-list\n"
8988 "Regular expression access list name\n")
8989 {
8990 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
8991 bgp_show_type_filter_list);
8992 }
8993
8994 DEFUN (show_ip_bgp_instance_filter_list,
8995 show_ip_bgp_instance_filter_list_cmd,
8996 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
8997 SHOW_STR
8998 IP_STR
8999 BGP_STR
9000 BGP_INSTANCE_HELP_STR
9001 "Display routes conforming to the filter-list\n"
9002 "Regular expression access list name\n")
9003 {
9004 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9005 bgp_show_type_filter_list);
9006 }
9007
9008 DEFUN (show_ip_bgp_flap_filter_list,
9009 show_ip_bgp_flap_filter_list_cmd,
9010 "show ip bgp flap-statistics filter-list WORD",
9011 SHOW_STR
9012 IP_STR
9013 BGP_STR
9014 "Display flap statistics of routes\n"
9015 "Display routes conforming to the filter-list\n"
9016 "Regular expression access list name\n")
9017 {
9018 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9019 bgp_show_type_flap_filter_list);
9020 }
9021
9022 ALIAS (show_ip_bgp_flap_filter_list,
9023 show_ip_bgp_damp_flap_filter_list_cmd,
9024 "show ip bgp dampening flap-statistics filter-list WORD",
9025 SHOW_STR
9026 IP_STR
9027 BGP_STR
9028 "Display detailed information about dampening\n"
9029 "Display flap statistics of routes\n"
9030 "Display routes conforming to the filter-list\n"
9031 "Regular expression access list name\n")
9032
9033 DEFUN (show_ip_bgp_ipv4_filter_list,
9034 show_ip_bgp_ipv4_filter_list_cmd,
9035 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9036 SHOW_STR
9037 IP_STR
9038 BGP_STR
9039 "Address family\n"
9040 "Address Family modifier\n"
9041 "Address Family modifier\n"
9042 "Display routes conforming to the filter-list\n"
9043 "Regular expression access list name\n")
9044 {
9045 if (strncmp (argv[0], "m", 1) == 0)
9046 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9047 bgp_show_type_filter_list);
9048
9049 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9050 bgp_show_type_filter_list);
9051 }
9052
9053 #ifdef HAVE_IPV6
9054 DEFUN (show_bgp_filter_list,
9055 show_bgp_filter_list_cmd,
9056 "show bgp filter-list WORD",
9057 SHOW_STR
9058 BGP_STR
9059 "Display routes conforming to the filter-list\n"
9060 "Regular expression access list name\n")
9061 {
9062 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9063 bgp_show_type_filter_list);
9064 }
9065
9066 ALIAS (show_bgp_filter_list,
9067 show_bgp_ipv6_filter_list_cmd,
9068 "show bgp ipv6 filter-list WORD",
9069 SHOW_STR
9070 BGP_STR
9071 "Address family\n"
9072 "Display routes conforming to the filter-list\n"
9073 "Regular expression access list name\n")
9074
9075 /* old command */
9076 DEFUN (show_ipv6_bgp_filter_list,
9077 show_ipv6_bgp_filter_list_cmd,
9078 "show ipv6 bgp filter-list WORD",
9079 SHOW_STR
9080 IPV6_STR
9081 BGP_STR
9082 "Display routes conforming to the filter-list\n"
9083 "Regular expression access list name\n")
9084 {
9085 bgp_show_ipv6_bgp_deprecate_warning(vty);
9086 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9087 bgp_show_type_filter_list);
9088 }
9089
9090 /* old command */
9091 DEFUN (show_ipv6_mbgp_filter_list,
9092 show_ipv6_mbgp_filter_list_cmd,
9093 "show ipv6 mbgp filter-list WORD",
9094 SHOW_STR
9095 IPV6_STR
9096 MBGP_STR
9097 "Display routes conforming to the filter-list\n"
9098 "Regular expression access list name\n")
9099 {
9100 bgp_show_ipv6_bgp_deprecate_warning(vty);
9101 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9102 bgp_show_type_filter_list);
9103 }
9104 #endif /* HAVE_IPV6 */
9105
9106 DEFUN (show_ip_bgp_dampening_info,
9107 show_ip_bgp_dampening_params_cmd,
9108 "show ip bgp dampening parameters",
9109 SHOW_STR
9110 IP_STR
9111 BGP_STR
9112 "Display detailed information about dampening\n"
9113 "Display detail of configured dampening parameters\n")
9114 {
9115 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9116 }
9117
9118 static int
9119 bgp_show_route_map (struct vty *vty, const char *name,
9120 const char *rmap_str, afi_t afi,
9121 safi_t safi, enum bgp_show_type type)
9122 {
9123 struct route_map *rmap;
9124 struct bgp *bgp = NULL;
9125
9126 if (name && !(bgp = bgp_lookup_by_name(name)))
9127 {
9128 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9129 return CMD_WARNING;
9130 }
9131
9132 rmap = route_map_lookup_by_name (rmap_str);
9133 if (! rmap)
9134 {
9135 vty_out (vty, "%% %s is not a valid route-map name%s",
9136 rmap_str, VTY_NEWLINE);
9137 return CMD_WARNING;
9138 }
9139
9140 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
9141 }
9142
9143 DEFUN (show_ip_bgp_route_map,
9144 show_ip_bgp_route_map_cmd,
9145 "show ip bgp route-map WORD",
9146 SHOW_STR
9147 IP_STR
9148 BGP_STR
9149 "Display routes matching the route-map\n"
9150 "A route-map to match on\n")
9151 {
9152 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9153 bgp_show_type_route_map);
9154 }
9155
9156 DEFUN (show_ip_bgp_instance_route_map,
9157 show_ip_bgp_instance_route_map_cmd,
9158 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
9159 SHOW_STR
9160 IP_STR
9161 BGP_STR
9162 BGP_INSTANCE_HELP_STR
9163 "Display routes matching the route-map\n"
9164 "A route-map to match on\n")
9165 {
9166 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9167 bgp_show_type_route_map);
9168 }
9169
9170 DEFUN (show_ip_bgp_flap_route_map,
9171 show_ip_bgp_flap_route_map_cmd,
9172 "show ip bgp flap-statistics route-map WORD",
9173 SHOW_STR
9174 IP_STR
9175 BGP_STR
9176 "Display flap statistics of routes\n"
9177 "Display routes matching the route-map\n"
9178 "A route-map to match on\n")
9179 {
9180 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9181 bgp_show_type_flap_route_map);
9182 }
9183
9184 ALIAS (show_ip_bgp_flap_route_map,
9185 show_ip_bgp_damp_flap_route_map_cmd,
9186 "show ip bgp dampening flap-statistics route-map WORD",
9187 SHOW_STR
9188 IP_STR
9189 BGP_STR
9190 "Display detailed information about dampening\n"
9191 "Display flap statistics of routes\n"
9192 "Display routes matching the route-map\n"
9193 "A route-map to match on\n")
9194
9195 DEFUN (show_ip_bgp_ipv4_route_map,
9196 show_ip_bgp_ipv4_route_map_cmd,
9197 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9198 SHOW_STR
9199 IP_STR
9200 BGP_STR
9201 "Address family\n"
9202 "Address Family modifier\n"
9203 "Address Family modifier\n"
9204 "Display routes matching the route-map\n"
9205 "A route-map to match on\n")
9206 {
9207 if (strncmp (argv[0], "m", 1) == 0)
9208 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9209 bgp_show_type_route_map);
9210
9211 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9212 bgp_show_type_route_map);
9213 }
9214
9215 DEFUN (show_bgp_route_map,
9216 show_bgp_route_map_cmd,
9217 "show bgp route-map WORD",
9218 SHOW_STR
9219 BGP_STR
9220 "Display routes matching the route-map\n"
9221 "A route-map to match on\n")
9222 {
9223 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9224 bgp_show_type_route_map);
9225 }
9226
9227 ALIAS (show_bgp_route_map,
9228 show_bgp_ipv6_route_map_cmd,
9229 "show bgp ipv6 route-map WORD",
9230 SHOW_STR
9231 BGP_STR
9232 "Address family\n"
9233 "Display routes matching the route-map\n"
9234 "A route-map to match on\n")
9235
9236 DEFUN (show_ip_bgp_cidr_only,
9237 show_ip_bgp_cidr_only_cmd,
9238 "show ip bgp cidr-only",
9239 SHOW_STR
9240 IP_STR
9241 BGP_STR
9242 "Display only routes with non-natural netmasks\n")
9243 {
9244 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9245 bgp_show_type_cidr_only, NULL, 0);
9246 }
9247
9248 DEFUN (show_ip_bgp_flap_cidr_only,
9249 show_ip_bgp_flap_cidr_only_cmd,
9250 "show ip bgp flap-statistics cidr-only",
9251 SHOW_STR
9252 IP_STR
9253 BGP_STR
9254 "Display flap statistics of routes\n"
9255 "Display only routes with non-natural netmasks\n")
9256 {
9257 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9258 bgp_show_type_flap_cidr_only, NULL, 0);
9259 }
9260
9261 ALIAS (show_ip_bgp_flap_cidr_only,
9262 show_ip_bgp_damp_flap_cidr_only_cmd,
9263 "show ip bgp dampening flap-statistics cidr-only",
9264 SHOW_STR
9265 IP_STR
9266 BGP_STR
9267 "Display detailed information about dampening\n"
9268 "Display flap statistics of routes\n"
9269 "Display only routes with non-natural netmasks\n")
9270
9271 DEFUN (show_ip_bgp_ipv4_cidr_only,
9272 show_ip_bgp_ipv4_cidr_only_cmd,
9273 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9274 SHOW_STR
9275 IP_STR
9276 BGP_STR
9277 "Address family\n"
9278 "Address Family modifier\n"
9279 "Address Family modifier\n"
9280 "Display only routes with non-natural netmasks\n")
9281 {
9282 if (strncmp (argv[0], "m", 1) == 0)
9283 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9284 bgp_show_type_cidr_only, NULL, 0);
9285
9286 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9287 bgp_show_type_cidr_only, NULL, 0);
9288 }
9289
9290 DEFUN (show_ip_bgp_community_all,
9291 show_ip_bgp_community_all_cmd,
9292 "show ip bgp community",
9293 SHOW_STR
9294 IP_STR
9295 BGP_STR
9296 "Display routes matching the communities\n")
9297 {
9298 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9299 bgp_show_type_community_all, NULL, 0);
9300 }
9301
9302 DEFUN (show_ip_bgp_ipv4_community_all,
9303 show_ip_bgp_ipv4_community_all_cmd,
9304 "show ip bgp ipv4 (unicast|multicast) community",
9305 SHOW_STR
9306 IP_STR
9307 BGP_STR
9308 "Address family\n"
9309 "Address Family modifier\n"
9310 "Address Family modifier\n"
9311 "Display routes matching the communities\n")
9312 {
9313 if (strncmp (argv[0], "m", 1) == 0)
9314 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9315 bgp_show_type_community_all, NULL, 0);
9316
9317 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9318 bgp_show_type_community_all, NULL, 0);
9319 }
9320
9321 #ifdef HAVE_IPV6
9322 DEFUN (show_bgp_community_all,
9323 show_bgp_community_all_cmd,
9324 "show bgp community",
9325 SHOW_STR
9326 BGP_STR
9327 "Display routes matching the communities\n")
9328 {
9329 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9330 bgp_show_type_community_all, NULL, 0);
9331 }
9332
9333 ALIAS (show_bgp_community_all,
9334 show_bgp_ipv6_community_all_cmd,
9335 "show bgp ipv6 community",
9336 SHOW_STR
9337 BGP_STR
9338 "Address family\n"
9339 "Display routes matching the communities\n")
9340
9341 /* old command */
9342 DEFUN (show_ipv6_bgp_community_all,
9343 show_ipv6_bgp_community_all_cmd,
9344 "show ipv6 bgp community",
9345 SHOW_STR
9346 IPV6_STR
9347 BGP_STR
9348 "Display routes matching the communities\n")
9349 {
9350 bgp_show_ipv6_bgp_deprecate_warning(vty);
9351 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9352 bgp_show_type_community_all, NULL, 0);
9353 }
9354
9355 /* old command */
9356 DEFUN (show_ipv6_mbgp_community_all,
9357 show_ipv6_mbgp_community_all_cmd,
9358 "show ipv6 mbgp community",
9359 SHOW_STR
9360 IPV6_STR
9361 MBGP_STR
9362 "Display routes matching the communities\n")
9363 {
9364 bgp_show_ipv6_bgp_deprecate_warning(vty);
9365 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9366 bgp_show_type_community_all, NULL, 0);
9367 }
9368 #endif /* HAVE_IPV6 */
9369
9370 static int
9371 bgp_show_community (struct vty *vty, const char *view_name, int argc,
9372 const char **argv, int exact, afi_t afi, safi_t safi)
9373 {
9374 struct community *com;
9375 struct buffer *b;
9376 struct bgp *bgp;
9377 int i;
9378 char *str;
9379 int first = 0;
9380
9381 /* BGP structure lookup */
9382 if (view_name)
9383 {
9384 bgp = bgp_lookup_by_name (view_name);
9385 if (bgp == NULL)
9386 {
9387 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
9388 return CMD_WARNING;
9389 }
9390 }
9391 else
9392 {
9393 bgp = bgp_get_default ();
9394 if (bgp == NULL)
9395 {
9396 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9397 return CMD_WARNING;
9398 }
9399 }
9400
9401 b = buffer_new (1024);
9402 for (i = 0; i < argc; i++)
9403 {
9404 if (first)
9405 buffer_putc (b, ' ');
9406 else
9407 {
9408 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9409 continue;
9410 first = 1;
9411 }
9412
9413 buffer_putstr (b, argv[i]);
9414 }
9415 buffer_putc (b, '\0');
9416
9417 str = buffer_getstr (b);
9418 buffer_free (b);
9419
9420 com = community_str2com (str);
9421 XFREE (MTYPE_TMP, str);
9422 if (! com)
9423 {
9424 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9425 return CMD_WARNING;
9426 }
9427
9428 return bgp_show (vty, bgp, afi, safi,
9429 (exact ? bgp_show_type_community_exact :
9430 bgp_show_type_community), com, 0);
9431 }
9432
9433 DEFUN (show_ip_bgp_community,
9434 show_ip_bgp_community_cmd,
9435 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9436 SHOW_STR
9437 IP_STR
9438 BGP_STR
9439 "Display routes matching the communities\n"
9440 COMMUNITY_AANN_STR
9441 "Do not send outside local AS (well-known community)\n"
9442 "Do not advertise to any peer (well-known community)\n"
9443 "Do not export to next AS (well-known community)\n")
9444 {
9445 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9446 }
9447
9448 ALIAS (show_ip_bgp_community,
9449 show_ip_bgp_community2_cmd,
9450 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9451 SHOW_STR
9452 IP_STR
9453 BGP_STR
9454 "Display routes matching the communities\n"
9455 COMMUNITY_AANN_STR
9456 "Do not send outside local AS (well-known community)\n"
9457 "Do not advertise to any peer (well-known community)\n"
9458 "Do not export to next AS (well-known community)\n"
9459 COMMUNITY_AANN_STR
9460 "Do not send outside local AS (well-known community)\n"
9461 "Do not advertise to any peer (well-known community)\n"
9462 "Do not export to next AS (well-known community)\n")
9463
9464 ALIAS (show_ip_bgp_community,
9465 show_ip_bgp_community3_cmd,
9466 "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)",
9467 SHOW_STR
9468 IP_STR
9469 BGP_STR
9470 "Display routes matching the communities\n"
9471 COMMUNITY_AANN_STR
9472 "Do not send outside local AS (well-known community)\n"
9473 "Do not advertise to any peer (well-known community)\n"
9474 "Do not export to next AS (well-known community)\n"
9475 COMMUNITY_AANN_STR
9476 "Do not send outside local AS (well-known community)\n"
9477 "Do not advertise to any peer (well-known community)\n"
9478 "Do not export to next AS (well-known community)\n"
9479 COMMUNITY_AANN_STR
9480 "Do not send outside local AS (well-known community)\n"
9481 "Do not advertise to any peer (well-known community)\n"
9482 "Do not export to next AS (well-known community)\n")
9483
9484 ALIAS (show_ip_bgp_community,
9485 show_ip_bgp_community4_cmd,
9486 "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)",
9487 SHOW_STR
9488 IP_STR
9489 BGP_STR
9490 "Display routes matching the communities\n"
9491 COMMUNITY_AANN_STR
9492 "Do not send outside local AS (well-known community)\n"
9493 "Do not advertise to any peer (well-known community)\n"
9494 "Do not export to next AS (well-known community)\n"
9495 COMMUNITY_AANN_STR
9496 "Do not send outside local AS (well-known community)\n"
9497 "Do not advertise to any peer (well-known community)\n"
9498 "Do not export to next AS (well-known community)\n"
9499 COMMUNITY_AANN_STR
9500 "Do not send outside local AS (well-known community)\n"
9501 "Do not advertise to any peer (well-known community)\n"
9502 "Do not export to next AS (well-known community)\n"
9503 COMMUNITY_AANN_STR
9504 "Do not send outside local AS (well-known community)\n"
9505 "Do not advertise to any peer (well-known community)\n"
9506 "Do not export to next AS (well-known community)\n")
9507
9508 DEFUN (show_ip_bgp_ipv4_community,
9509 show_ip_bgp_ipv4_community_cmd,
9510 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9511 SHOW_STR
9512 IP_STR
9513 BGP_STR
9514 "Address family\n"
9515 "Address Family modifier\n"
9516 "Address Family modifier\n"
9517 "Display routes matching the communities\n"
9518 COMMUNITY_AANN_STR
9519 "Do not send outside local AS (well-known community)\n"
9520 "Do not advertise to any peer (well-known community)\n"
9521 "Do not export to next AS (well-known community)\n")
9522 {
9523 if (strncmp (argv[0], "m", 1) == 0)
9524 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9525
9526 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9527 }
9528
9529 ALIAS (show_ip_bgp_ipv4_community,
9530 show_ip_bgp_ipv4_community2_cmd,
9531 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9532 SHOW_STR
9533 IP_STR
9534 BGP_STR
9535 "Address family\n"
9536 "Address Family modifier\n"
9537 "Address Family modifier\n"
9538 "Display routes matching the communities\n"
9539 COMMUNITY_AANN_STR
9540 "Do not send outside local AS (well-known community)\n"
9541 "Do not advertise to any peer (well-known community)\n"
9542 "Do not export to next AS (well-known community)\n"
9543 COMMUNITY_AANN_STR
9544 "Do not send outside local AS (well-known community)\n"
9545 "Do not advertise to any peer (well-known community)\n"
9546 "Do not export to next AS (well-known community)\n")
9547
9548 ALIAS (show_ip_bgp_ipv4_community,
9549 show_ip_bgp_ipv4_community3_cmd,
9550 "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)",
9551 SHOW_STR
9552 IP_STR
9553 BGP_STR
9554 "Address family\n"
9555 "Address Family modifier\n"
9556 "Address Family modifier\n"
9557 "Display routes matching the communities\n"
9558 COMMUNITY_AANN_STR
9559 "Do not send outside local AS (well-known community)\n"
9560 "Do not advertise to any peer (well-known community)\n"
9561 "Do not export to next AS (well-known community)\n"
9562 COMMUNITY_AANN_STR
9563 "Do not send outside local AS (well-known community)\n"
9564 "Do not advertise to any peer (well-known community)\n"
9565 "Do not export to next AS (well-known community)\n"
9566 COMMUNITY_AANN_STR
9567 "Do not send outside local AS (well-known community)\n"
9568 "Do not advertise to any peer (well-known community)\n"
9569 "Do not export to next AS (well-known community)\n")
9570
9571 ALIAS (show_ip_bgp_ipv4_community,
9572 show_ip_bgp_ipv4_community4_cmd,
9573 "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)",
9574 SHOW_STR
9575 IP_STR
9576 BGP_STR
9577 "Address family\n"
9578 "Address Family modifier\n"
9579 "Address Family modifier\n"
9580 "Display routes matching the communities\n"
9581 COMMUNITY_AANN_STR
9582 "Do not send outside local AS (well-known community)\n"
9583 "Do not advertise to any peer (well-known community)\n"
9584 "Do not export to next AS (well-known community)\n"
9585 COMMUNITY_AANN_STR
9586 "Do not send outside local AS (well-known community)\n"
9587 "Do not advertise to any peer (well-known community)\n"
9588 "Do not export to next AS (well-known community)\n"
9589 COMMUNITY_AANN_STR
9590 "Do not send outside local AS (well-known community)\n"
9591 "Do not advertise to any peer (well-known community)\n"
9592 "Do not export to next AS (well-known community)\n"
9593 COMMUNITY_AANN_STR
9594 "Do not send outside local AS (well-known community)\n"
9595 "Do not advertise to any peer (well-known community)\n"
9596 "Do not export to next AS (well-known community)\n")
9597
9598 DEFUN (show_bgp_instance_afi_safi_community_all,
9599 show_bgp_instance_afi_safi_community_all_cmd,
9600 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
9601 SHOW_STR
9602 BGP_STR
9603 BGP_INSTANCE_HELP_STR
9604 "Address family\n"
9605 "Address family\n"
9606 "Address Family modifier\n"
9607 "Address Family modifier\n"
9608 "Display routes matching the communities\n")
9609 {
9610 int afi;
9611 int safi;
9612 struct bgp *bgp;
9613
9614 /* BGP structure lookup. */
9615 bgp = bgp_lookup_by_name (argv[1]);
9616 if (bgp == NULL)
9617 {
9618 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
9619 return CMD_WARNING;
9620 }
9621
9622 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9623 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9624 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
9625 }
9626
9627 DEFUN (show_bgp_instance_afi_safi_community,
9628 show_bgp_instance_afi_safi_community_cmd,
9629 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9630 SHOW_STR
9631 BGP_STR
9632 BGP_INSTANCE_HELP_STR
9633 "Address family\n"
9634 "Address family\n"
9635 "Address family modifier\n"
9636 "Address family modifier\n"
9637 "Display routes matching the communities\n"
9638 COMMUNITY_AANN_STR
9639 "Do not send outside local AS (well-known community)\n"
9640 "Do not advertise to any peer (well-known community)\n"
9641 "Do not export to next AS (well-known community)\n")
9642 {
9643 int afi;
9644 int safi;
9645
9646 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9647 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9648 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
9649 }
9650
9651 ALIAS (show_bgp_instance_afi_safi_community,
9652 show_bgp_instance_afi_safi_community2_cmd,
9653 "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)",
9654 SHOW_STR
9655 BGP_STR
9656 BGP_INSTANCE_HELP_STR
9657 "Address family\n"
9658 "Address family\n"
9659 "Address family modifier\n"
9660 "Address family modifier\n"
9661 "Display routes matching the communities\n"
9662 COMMUNITY_AANN_STR
9663 "Do not send outside local AS (well-known community)\n"
9664 "Do not advertise to any peer (well-known community)\n"
9665 "Do not export to next AS (well-known community)\n"
9666 COMMUNITY_AANN_STR
9667 "Do not send outside local AS (well-known community)\n"
9668 "Do not advertise to any peer (well-known community)\n"
9669 "Do not export to next AS (well-known community)\n")
9670
9671 ALIAS (show_bgp_instance_afi_safi_community,
9672 show_bgp_instance_afi_safi_community3_cmd,
9673 "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)",
9674 SHOW_STR
9675 BGP_STR
9676 BGP_INSTANCE_HELP_STR
9677 "Address family\n"
9678 "Address family\n"
9679 "Address family modifier\n"
9680 "Address family modifier\n"
9681 "Display routes matching the communities\n"
9682 COMMUNITY_AANN_STR
9683 "Do not send outside local AS (well-known community)\n"
9684 "Do not advertise to any peer (well-known community)\n"
9685 "Do not export to next AS (well-known community)\n"
9686 COMMUNITY_AANN_STR
9687 "Do not send outside local AS (well-known community)\n"
9688 "Do not advertise to any peer (well-known community)\n"
9689 "Do not export to next AS (well-known community)\n"
9690 COMMUNITY_AANN_STR
9691 "Do not send outside local AS (well-known community)\n"
9692 "Do not advertise to any peer (well-known community)\n"
9693 "Do not export to next AS (well-known community)\n")
9694
9695 ALIAS (show_bgp_instance_afi_safi_community,
9696 show_bgp_instance_afi_safi_community4_cmd,
9697 "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)",
9698 SHOW_STR
9699 BGP_STR
9700 BGP_INSTANCE_HELP_STR
9701 "Address family\n"
9702 "Address family\n"
9703 "Address family modifier\n"
9704 "Address family modifier\n"
9705 "Display routes matching the communities\n"
9706 COMMUNITY_AANN_STR
9707 "Do not send outside local AS (well-known community)\n"
9708 "Do not advertise to any peer (well-known community)\n"
9709 "Do not export to next AS (well-known community)\n"
9710 COMMUNITY_AANN_STR
9711 "Do not send outside local AS (well-known community)\n"
9712 "Do not advertise to any peer (well-known community)\n"
9713 "Do not export to next AS (well-known community)\n"
9714 COMMUNITY_AANN_STR
9715 "Do not send outside local AS (well-known community)\n"
9716 "Do not advertise to any peer (well-known community)\n"
9717 "Do not export to next AS (well-known community)\n"
9718 COMMUNITY_AANN_STR
9719 "Do not send outside local AS (well-known community)\n"
9720 "Do not advertise to any peer (well-known community)\n"
9721 "Do not export to next AS (well-known community)\n")
9722
9723 DEFUN (show_ip_bgp_community_exact,
9724 show_ip_bgp_community_exact_cmd,
9725 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9726 SHOW_STR
9727 IP_STR
9728 BGP_STR
9729 "Display routes matching the communities\n"
9730 COMMUNITY_AANN_STR
9731 "Do not send outside local AS (well-known community)\n"
9732 "Do not advertise to any peer (well-known community)\n"
9733 "Do not export to next AS (well-known community)\n"
9734 "Exact match of the communities")
9735 {
9736 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9737 }
9738
9739 ALIAS (show_ip_bgp_community_exact,
9740 show_ip_bgp_community2_exact_cmd,
9741 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9742 SHOW_STR
9743 IP_STR
9744 BGP_STR
9745 "Display routes matching the communities\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 COMMUNITY_AANN_STR
9751 "Do not send outside local AS (well-known community)\n"
9752 "Do not advertise to any peer (well-known community)\n"
9753 "Do not export to next AS (well-known community)\n"
9754 "Exact match of the communities")
9755
9756 ALIAS (show_ip_bgp_community_exact,
9757 show_ip_bgp_community3_exact_cmd,
9758 "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",
9759 SHOW_STR
9760 IP_STR
9761 BGP_STR
9762 "Display routes matching the communities\n"
9763 COMMUNITY_AANN_STR
9764 "Do not send outside local AS (well-known community)\n"
9765 "Do not advertise to any peer (well-known community)\n"
9766 "Do not export to next AS (well-known community)\n"
9767 COMMUNITY_AANN_STR
9768 "Do not send outside local AS (well-known community)\n"
9769 "Do not advertise to any peer (well-known community)\n"
9770 "Do not export to next AS (well-known community)\n"
9771 COMMUNITY_AANN_STR
9772 "Do not send outside local AS (well-known community)\n"
9773 "Do not advertise to any peer (well-known community)\n"
9774 "Do not export to next AS (well-known community)\n"
9775 "Exact match of the communities")
9776
9777 ALIAS (show_ip_bgp_community_exact,
9778 show_ip_bgp_community4_exact_cmd,
9779 "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",
9780 SHOW_STR
9781 IP_STR
9782 BGP_STR
9783 "Display routes matching the communities\n"
9784 COMMUNITY_AANN_STR
9785 "Do not send outside local AS (well-known community)\n"
9786 "Do not advertise to any peer (well-known community)\n"
9787 "Do not export to next AS (well-known community)\n"
9788 COMMUNITY_AANN_STR
9789 "Do not send outside local AS (well-known community)\n"
9790 "Do not advertise to any peer (well-known community)\n"
9791 "Do not export to next AS (well-known community)\n"
9792 COMMUNITY_AANN_STR
9793 "Do not send outside local AS (well-known community)\n"
9794 "Do not advertise to any peer (well-known community)\n"
9795 "Do not export to next AS (well-known community)\n"
9796 COMMUNITY_AANN_STR
9797 "Do not send outside local AS (well-known community)\n"
9798 "Do not advertise to any peer (well-known community)\n"
9799 "Do not export to next AS (well-known community)\n"
9800 "Exact match of the communities")
9801
9802 DEFUN (show_ip_bgp_ipv4_community_exact,
9803 show_ip_bgp_ipv4_community_exact_cmd,
9804 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9805 SHOW_STR
9806 IP_STR
9807 BGP_STR
9808 "Address family\n"
9809 "Address Family modifier\n"
9810 "Address Family modifier\n"
9811 "Display routes matching the communities\n"
9812 COMMUNITY_AANN_STR
9813 "Do not send outside local AS (well-known community)\n"
9814 "Do not advertise to any peer (well-known community)\n"
9815 "Do not export to next AS (well-known community)\n"
9816 "Exact match of the communities")
9817 {
9818 if (strncmp (argv[0], "m", 1) == 0)
9819 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9820
9821 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9822 }
9823
9824 ALIAS (show_ip_bgp_ipv4_community_exact,
9825 show_ip_bgp_ipv4_community2_exact_cmd,
9826 "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",
9827 SHOW_STR
9828 IP_STR
9829 BGP_STR
9830 "Address family\n"
9831 "Address Family modifier\n"
9832 "Address Family modifier\n"
9833 "Display routes matching the communities\n"
9834 COMMUNITY_AANN_STR
9835 "Do not send outside local AS (well-known community)\n"
9836 "Do not advertise to any peer (well-known community)\n"
9837 "Do not export to next AS (well-known community)\n"
9838 COMMUNITY_AANN_STR
9839 "Do not send outside local AS (well-known community)\n"
9840 "Do not advertise to any peer (well-known community)\n"
9841 "Do not export to next AS (well-known community)\n"
9842 "Exact match of the communities")
9843
9844 ALIAS (show_ip_bgp_ipv4_community_exact,
9845 show_ip_bgp_ipv4_community3_exact_cmd,
9846 "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",
9847 SHOW_STR
9848 IP_STR
9849 BGP_STR
9850 "Address family\n"
9851 "Address Family modifier\n"
9852 "Address Family modifier\n"
9853 "Display routes matching the communities\n"
9854 COMMUNITY_AANN_STR
9855 "Do not send outside local AS (well-known community)\n"
9856 "Do not advertise to any peer (well-known community)\n"
9857 "Do not export to next AS (well-known community)\n"
9858 COMMUNITY_AANN_STR
9859 "Do not send outside local AS (well-known community)\n"
9860 "Do not advertise to any peer (well-known community)\n"
9861 "Do not export to next AS (well-known community)\n"
9862 COMMUNITY_AANN_STR
9863 "Do not send outside local AS (well-known community)\n"
9864 "Do not advertise to any peer (well-known community)\n"
9865 "Do not export to next AS (well-known community)\n"
9866 "Exact match of the communities")
9867
9868 ALIAS (show_ip_bgp_ipv4_community_exact,
9869 show_ip_bgp_ipv4_community4_exact_cmd,
9870 "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",
9871 SHOW_STR
9872 IP_STR
9873 BGP_STR
9874 "Address family\n"
9875 "Address Family modifier\n"
9876 "Address Family modifier\n"
9877 "Display routes matching the communities\n"
9878 COMMUNITY_AANN_STR
9879 "Do not send outside local AS (well-known community)\n"
9880 "Do not advertise to any peer (well-known community)\n"
9881 "Do not export to next AS (well-known community)\n"
9882 COMMUNITY_AANN_STR
9883 "Do not send outside local AS (well-known community)\n"
9884 "Do not advertise to any peer (well-known community)\n"
9885 "Do not export to next AS (well-known community)\n"
9886 COMMUNITY_AANN_STR
9887 "Do not send outside local AS (well-known community)\n"
9888 "Do not advertise to any peer (well-known community)\n"
9889 "Do not export to next AS (well-known community)\n"
9890 COMMUNITY_AANN_STR
9891 "Do not send outside local AS (well-known community)\n"
9892 "Do not advertise to any peer (well-known community)\n"
9893 "Do not export to next AS (well-known community)\n"
9894 "Exact match of the communities")
9895
9896 #ifdef HAVE_IPV6
9897 DEFUN (show_bgp_community,
9898 show_bgp_community_cmd,
9899 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9900 SHOW_STR
9901 BGP_STR
9902 "Display routes matching the communities\n"
9903 COMMUNITY_AANN_STR
9904 "Do not send outside local AS (well-known community)\n"
9905 "Do not advertise to any peer (well-known community)\n"
9906 "Do not export to next AS (well-known community)\n")
9907 {
9908 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9909 }
9910
9911 ALIAS (show_bgp_community,
9912 show_bgp_ipv6_community_cmd,
9913 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9914 SHOW_STR
9915 BGP_STR
9916 "Address family\n"
9917 "Display routes matching the communities\n"
9918 COMMUNITY_AANN_STR
9919 "Do not send outside local AS (well-known community)\n"
9920 "Do not advertise to any peer (well-known community)\n"
9921 "Do not export to next AS (well-known community)\n")
9922
9923 ALIAS (show_bgp_community,
9924 show_bgp_community2_cmd,
9925 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9926 SHOW_STR
9927 BGP_STR
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_community,
9939 show_bgp_ipv6_community2_cmd,
9940 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9941 SHOW_STR
9942 BGP_STR
9943 "Address family\n"
9944 "Display routes matching the communities\n"
9945 COMMUNITY_AANN_STR
9946 "Do not send outside local AS (well-known community)\n"
9947 "Do not advertise to any peer (well-known community)\n"
9948 "Do not export to next AS (well-known community)\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
9954 ALIAS (show_bgp_community,
9955 show_bgp_community3_cmd,
9956 "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)",
9957 SHOW_STR
9958 BGP_STR
9959 "Display routes matching the communities\n"
9960 COMMUNITY_AANN_STR
9961 "Do not send outside local AS (well-known community)\n"
9962 "Do not advertise to any peer (well-known community)\n"
9963 "Do not export to next AS (well-known community)\n"
9964 COMMUNITY_AANN_STR
9965 "Do not send outside local AS (well-known community)\n"
9966 "Do not advertise to any peer (well-known community)\n"
9967 "Do not export to next AS (well-known community)\n"
9968 COMMUNITY_AANN_STR
9969 "Do not send outside local AS (well-known community)\n"
9970 "Do not advertise to any peer (well-known community)\n"
9971 "Do not export to next AS (well-known community)\n")
9972
9973 ALIAS (show_bgp_community,
9974 show_bgp_ipv6_community3_cmd,
9975 "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)",
9976 SHOW_STR
9977 BGP_STR
9978 "Address family\n"
9979 "Display routes matching the communities\n"
9980 COMMUNITY_AANN_STR
9981 "Do not send outside local AS (well-known community)\n"
9982 "Do not advertise to any peer (well-known community)\n"
9983 "Do not export to next AS (well-known community)\n"
9984 COMMUNITY_AANN_STR
9985 "Do not send outside local AS (well-known community)\n"
9986 "Do not advertise to any peer (well-known community)\n"
9987 "Do not export to next AS (well-known community)\n"
9988 COMMUNITY_AANN_STR
9989 "Do not send outside local AS (well-known community)\n"
9990 "Do not advertise to any peer (well-known community)\n"
9991 "Do not export to next AS (well-known community)\n")
9992
9993 ALIAS (show_bgp_community,
9994 show_bgp_community4_cmd,
9995 "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)",
9996 SHOW_STR
9997 BGP_STR
9998 "Display routes matching the communities\n"
9999 COMMUNITY_AANN_STR
10000 "Do not send outside local AS (well-known community)\n"
10001 "Do not advertise to any peer (well-known community)\n"
10002 "Do not export to next AS (well-known community)\n"
10003 COMMUNITY_AANN_STR
10004 "Do not send outside local AS (well-known community)\n"
10005 "Do not advertise to any peer (well-known community)\n"
10006 "Do not export to next AS (well-known community)\n"
10007 COMMUNITY_AANN_STR
10008 "Do not send outside local AS (well-known community)\n"
10009 "Do not advertise to any peer (well-known community)\n"
10010 "Do not export to next AS (well-known community)\n"
10011 COMMUNITY_AANN_STR
10012 "Do not send outside local AS (well-known community)\n"
10013 "Do not advertise to any peer (well-known community)\n"
10014 "Do not export to next AS (well-known community)\n")
10015
10016 ALIAS (show_bgp_community,
10017 show_bgp_ipv6_community4_cmd,
10018 "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)",
10019 SHOW_STR
10020 BGP_STR
10021 "Address family\n"
10022 "Display routes matching the communities\n"
10023 COMMUNITY_AANN_STR
10024 "Do not send outside local AS (well-known community)\n"
10025 "Do not advertise to any peer (well-known community)\n"
10026 "Do not export to next AS (well-known community)\n"
10027 COMMUNITY_AANN_STR
10028 "Do not send outside local AS (well-known community)\n"
10029 "Do not advertise to any peer (well-known community)\n"
10030 "Do not export to next AS (well-known community)\n"
10031 COMMUNITY_AANN_STR
10032 "Do not send outside local AS (well-known community)\n"
10033 "Do not advertise to any peer (well-known community)\n"
10034 "Do not export to next AS (well-known community)\n"
10035 COMMUNITY_AANN_STR
10036 "Do not send outside local AS (well-known community)\n"
10037 "Do not advertise to any peer (well-known community)\n"
10038 "Do not export to next AS (well-known community)\n")
10039
10040 /* old command */
10041 DEFUN (show_ipv6_bgp_community,
10042 show_ipv6_bgp_community_cmd,
10043 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10044 SHOW_STR
10045 IPV6_STR
10046 BGP_STR
10047 "Display routes matching the communities\n"
10048 COMMUNITY_AANN_STR
10049 "Do not send outside local AS (well-known community)\n"
10050 "Do not advertise to any peer (well-known community)\n"
10051 "Do not export to next AS (well-known community)\n")
10052 {
10053 bgp_show_ipv6_bgp_deprecate_warning(vty);
10054 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10055 }
10056
10057 /* old command */
10058 ALIAS (show_ipv6_bgp_community,
10059 show_ipv6_bgp_community2_cmd,
10060 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10061 SHOW_STR
10062 IPV6_STR
10063 BGP_STR
10064 "Display routes matching the communities\n"
10065 COMMUNITY_AANN_STR
10066 "Do not send outside local AS (well-known community)\n"
10067 "Do not advertise to any peer (well-known community)\n"
10068 "Do not export to next AS (well-known community)\n"
10069 COMMUNITY_AANN_STR
10070 "Do not send outside local AS (well-known community)\n"
10071 "Do not advertise to any peer (well-known community)\n"
10072 "Do not export to next AS (well-known community)\n")
10073
10074 /* old command */
10075 ALIAS (show_ipv6_bgp_community,
10076 show_ipv6_bgp_community3_cmd,
10077 "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)",
10078 SHOW_STR
10079 IPV6_STR
10080 BGP_STR
10081 "Display routes matching the communities\n"
10082 COMMUNITY_AANN_STR
10083 "Do not send outside local AS (well-known community)\n"
10084 "Do not advertise to any peer (well-known community)\n"
10085 "Do not export to next AS (well-known community)\n"
10086 COMMUNITY_AANN_STR
10087 "Do not send outside local AS (well-known community)\n"
10088 "Do not advertise to any peer (well-known community)\n"
10089 "Do not export to next AS (well-known community)\n"
10090 COMMUNITY_AANN_STR
10091 "Do not send outside local AS (well-known community)\n"
10092 "Do not advertise to any peer (well-known community)\n"
10093 "Do not export to next AS (well-known community)\n")
10094
10095 /* old command */
10096 ALIAS (show_ipv6_bgp_community,
10097 show_ipv6_bgp_community4_cmd,
10098 "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)",
10099 SHOW_STR
10100 IPV6_STR
10101 BGP_STR
10102 "Display routes matching the communities\n"
10103 COMMUNITY_AANN_STR
10104 "Do not send outside local AS (well-known community)\n"
10105 "Do not advertise to any peer (well-known community)\n"
10106 "Do not export to next AS (well-known community)\n"
10107 COMMUNITY_AANN_STR
10108 "Do not send outside local AS (well-known community)\n"
10109 "Do not advertise to any peer (well-known community)\n"
10110 "Do not export to next AS (well-known community)\n"
10111 COMMUNITY_AANN_STR
10112 "Do not send outside local AS (well-known community)\n"
10113 "Do not advertise to any peer (well-known community)\n"
10114 "Do not export to next AS (well-known community)\n"
10115 COMMUNITY_AANN_STR
10116 "Do not send outside local AS (well-known community)\n"
10117 "Do not advertise to any peer (well-known community)\n"
10118 "Do not export to next AS (well-known community)\n")
10119
10120 DEFUN (show_bgp_community_exact,
10121 show_bgp_community_exact_cmd,
10122 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10123 SHOW_STR
10124 BGP_STR
10125 "Display routes matching the communities\n"
10126 COMMUNITY_AANN_STR
10127 "Do not send outside local AS (well-known community)\n"
10128 "Do not advertise to any peer (well-known community)\n"
10129 "Do not export to next AS (well-known community)\n"
10130 "Exact match of the communities")
10131 {
10132 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10133 }
10134
10135 ALIAS (show_bgp_community_exact,
10136 show_bgp_ipv6_community_exact_cmd,
10137 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10138 SHOW_STR
10139 BGP_STR
10140 "Address family\n"
10141 "Display routes matching the communities\n"
10142 COMMUNITY_AANN_STR
10143 "Do not send outside local AS (well-known community)\n"
10144 "Do not advertise to any peer (well-known community)\n"
10145 "Do not export to next AS (well-known community)\n"
10146 "Exact match of the communities")
10147
10148 ALIAS (show_bgp_community_exact,
10149 show_bgp_community2_exact_cmd,
10150 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10151 SHOW_STR
10152 BGP_STR
10153 "Display routes matching the communities\n"
10154 COMMUNITY_AANN_STR
10155 "Do not send outside local AS (well-known community)\n"
10156 "Do not advertise to any peer (well-known community)\n"
10157 "Do not export to next AS (well-known community)\n"
10158 COMMUNITY_AANN_STR
10159 "Do not send outside local AS (well-known community)\n"
10160 "Do not advertise to any peer (well-known community)\n"
10161 "Do not export to next AS (well-known community)\n"
10162 "Exact match of the communities")
10163
10164 ALIAS (show_bgp_community_exact,
10165 show_bgp_ipv6_community2_exact_cmd,
10166 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10167 SHOW_STR
10168 BGP_STR
10169 "Address family\n"
10170 "Display routes matching the communities\n"
10171 COMMUNITY_AANN_STR
10172 "Do not send outside local AS (well-known community)\n"
10173 "Do not advertise to any peer (well-known community)\n"
10174 "Do not export to next AS (well-known community)\n"
10175 COMMUNITY_AANN_STR
10176 "Do not send outside local AS (well-known community)\n"
10177 "Do not advertise to any peer (well-known community)\n"
10178 "Do not export to next AS (well-known community)\n"
10179 "Exact match of the communities")
10180
10181 ALIAS (show_bgp_community_exact,
10182 show_bgp_community3_exact_cmd,
10183 "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",
10184 SHOW_STR
10185 BGP_STR
10186 "Display routes matching the communities\n"
10187 COMMUNITY_AANN_STR
10188 "Do not send outside local AS (well-known community)\n"
10189 "Do not advertise to any peer (well-known community)\n"
10190 "Do not export to next AS (well-known community)\n"
10191 COMMUNITY_AANN_STR
10192 "Do not send outside local AS (well-known community)\n"
10193 "Do not advertise to any peer (well-known community)\n"
10194 "Do not export to next AS (well-known community)\n"
10195 COMMUNITY_AANN_STR
10196 "Do not send outside local AS (well-known community)\n"
10197 "Do not advertise to any peer (well-known community)\n"
10198 "Do not export to next AS (well-known community)\n"
10199 "Exact match of the communities")
10200
10201 ALIAS (show_bgp_community_exact,
10202 show_bgp_ipv6_community3_exact_cmd,
10203 "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",
10204 SHOW_STR
10205 BGP_STR
10206 "Address family\n"
10207 "Display routes matching the communities\n"
10208 COMMUNITY_AANN_STR
10209 "Do not send outside local AS (well-known community)\n"
10210 "Do not advertise to any peer (well-known community)\n"
10211 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10221
10222 ALIAS (show_bgp_community_exact,
10223 show_bgp_community4_exact_cmd,
10224 "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",
10225 SHOW_STR
10226 BGP_STR
10227 "Display routes matching the communities\n"
10228 COMMUNITY_AANN_STR
10229 "Do not send outside local AS (well-known community)\n"
10230 "Do not advertise to any peer (well-known community)\n"
10231 "Do not export to next AS (well-known community)\n"
10232 COMMUNITY_AANN_STR
10233 "Do not send outside local AS (well-known community)\n"
10234 "Do not advertise to any peer (well-known community)\n"
10235 "Do not export to next AS (well-known community)\n"
10236 COMMUNITY_AANN_STR
10237 "Do not send outside local AS (well-known community)\n"
10238 "Do not advertise to any peer (well-known community)\n"
10239 "Do not export to next AS (well-known community)\n"
10240 COMMUNITY_AANN_STR
10241 "Do not send outside local AS (well-known community)\n"
10242 "Do not advertise to any peer (well-known community)\n"
10243 "Do not export to next AS (well-known community)\n"
10244 "Exact match of the communities")
10245
10246 ALIAS (show_bgp_community_exact,
10247 show_bgp_ipv6_community4_exact_cmd,
10248 "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",
10249 SHOW_STR
10250 BGP_STR
10251 "Address family\n"
10252 "Display routes matching the communities\n"
10253 COMMUNITY_AANN_STR
10254 "Do not send outside local AS (well-known community)\n"
10255 "Do not advertise to any peer (well-known community)\n"
10256 "Do not export to next AS (well-known community)\n"
10257 COMMUNITY_AANN_STR
10258 "Do not send outside local AS (well-known community)\n"
10259 "Do not advertise to any peer (well-known community)\n"
10260 "Do not export to next AS (well-known community)\n"
10261 COMMUNITY_AANN_STR
10262 "Do not send outside local AS (well-known community)\n"
10263 "Do not advertise to any peer (well-known community)\n"
10264 "Do not export to next AS (well-known community)\n"
10265 COMMUNITY_AANN_STR
10266 "Do not send outside local AS (well-known community)\n"
10267 "Do not advertise to any peer (well-known community)\n"
10268 "Do not export to next AS (well-known community)\n"
10269 "Exact match of the communities")
10270
10271 /* old command */
10272 DEFUN (show_ipv6_bgp_community_exact,
10273 show_ipv6_bgp_community_exact_cmd,
10274 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10275 SHOW_STR
10276 IPV6_STR
10277 BGP_STR
10278 "Display routes matching the communities\n"
10279 COMMUNITY_AANN_STR
10280 "Do not send outside local AS (well-known community)\n"
10281 "Do not advertise to any peer (well-known community)\n"
10282 "Do not export to next AS (well-known community)\n"
10283 "Exact match of the communities")
10284 {
10285 bgp_show_ipv6_bgp_deprecate_warning(vty);
10286 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10287 }
10288
10289 /* old command */
10290 ALIAS (show_ipv6_bgp_community_exact,
10291 show_ipv6_bgp_community2_exact_cmd,
10292 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10293 SHOW_STR
10294 IPV6_STR
10295 BGP_STR
10296 "Display routes matching the communities\n"
10297 COMMUNITY_AANN_STR
10298 "Do not send outside local AS (well-known community)\n"
10299 "Do not advertise to any peer (well-known community)\n"
10300 "Do not export to next AS (well-known community)\n"
10301 COMMUNITY_AANN_STR
10302 "Do not send outside local AS (well-known community)\n"
10303 "Do not advertise to any peer (well-known community)\n"
10304 "Do not export to next AS (well-known community)\n"
10305 "Exact match of the communities")
10306
10307 /* old command */
10308 ALIAS (show_ipv6_bgp_community_exact,
10309 show_ipv6_bgp_community3_exact_cmd,
10310 "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",
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 COMMUNITY_AANN_STR
10320 "Do not send outside local AS (well-known community)\n"
10321 "Do not advertise to any peer (well-known community)\n"
10322 "Do not export to next AS (well-known community)\n"
10323 COMMUNITY_AANN_STR
10324 "Do not send outside local AS (well-known community)\n"
10325 "Do not advertise to any peer (well-known community)\n"
10326 "Do not export to next AS (well-known community)\n"
10327 "Exact match of the communities")
10328
10329 /* old command */
10330 ALIAS (show_ipv6_bgp_community_exact,
10331 show_ipv6_bgp_community4_exact_cmd,
10332 "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",
10333 SHOW_STR
10334 IPV6_STR
10335 BGP_STR
10336 "Display routes matching the communities\n"
10337 COMMUNITY_AANN_STR
10338 "Do not send outside local AS (well-known community)\n"
10339 "Do not advertise to any peer (well-known community)\n"
10340 "Do not export to next AS (well-known community)\n"
10341 COMMUNITY_AANN_STR
10342 "Do not send outside local AS (well-known community)\n"
10343 "Do not advertise to any peer (well-known community)\n"
10344 "Do not export to next AS (well-known community)\n"
10345 COMMUNITY_AANN_STR
10346 "Do not send outside local AS (well-known community)\n"
10347 "Do not advertise to any peer (well-known community)\n"
10348 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10354
10355 /* old command */
10356 DEFUN (show_ipv6_mbgp_community,
10357 show_ipv6_mbgp_community_cmd,
10358 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10359 SHOW_STR
10360 IPV6_STR
10361 MBGP_STR
10362 "Display routes matching the communities\n"
10363 COMMUNITY_AANN_STR
10364 "Do not send outside local AS (well-known community)\n"
10365 "Do not advertise to any peer (well-known community)\n"
10366 "Do not export to next AS (well-known community)\n")
10367 {
10368 bgp_show_ipv6_bgp_deprecate_warning(vty);
10369 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10370 }
10371
10372 /* old command */
10373 ALIAS (show_ipv6_mbgp_community,
10374 show_ipv6_mbgp_community2_cmd,
10375 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10376 SHOW_STR
10377 IPV6_STR
10378 MBGP_STR
10379 "Display routes matching the communities\n"
10380 COMMUNITY_AANN_STR
10381 "Do not send outside local AS (well-known community)\n"
10382 "Do not advertise to any peer (well-known community)\n"
10383 "Do not export to next AS (well-known community)\n"
10384 COMMUNITY_AANN_STR
10385 "Do not send outside local AS (well-known community)\n"
10386 "Do not advertise to any peer (well-known community)\n"
10387 "Do not export to next AS (well-known community)\n")
10388
10389 /* old command */
10390 ALIAS (show_ipv6_mbgp_community,
10391 show_ipv6_mbgp_community3_cmd,
10392 "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)",
10393 SHOW_STR
10394 IPV6_STR
10395 MBGP_STR
10396 "Display routes matching the communities\n"
10397 COMMUNITY_AANN_STR
10398 "Do not send outside local AS (well-known community)\n"
10399 "Do not advertise to any peer (well-known community)\n"
10400 "Do not export to next AS (well-known community)\n"
10401 COMMUNITY_AANN_STR
10402 "Do not send outside local AS (well-known community)\n"
10403 "Do not advertise to any peer (well-known community)\n"
10404 "Do not export to next AS (well-known community)\n"
10405 COMMUNITY_AANN_STR
10406 "Do not send outside local AS (well-known community)\n"
10407 "Do not advertise to any peer (well-known community)\n"
10408 "Do not export to next AS (well-known community)\n")
10409
10410 /* old command */
10411 ALIAS (show_ipv6_mbgp_community,
10412 show_ipv6_mbgp_community4_cmd,
10413 "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)",
10414 SHOW_STR
10415 IPV6_STR
10416 MBGP_STR
10417 "Display routes matching the communities\n"
10418 COMMUNITY_AANN_STR
10419 "Do not send outside local AS (well-known community)\n"
10420 "Do not advertise to any peer (well-known community)\n"
10421 "Do not export to next AS (well-known community)\n"
10422 COMMUNITY_AANN_STR
10423 "Do not send outside local AS (well-known community)\n"
10424 "Do not advertise to any peer (well-known community)\n"
10425 "Do not export to next AS (well-known community)\n"
10426 COMMUNITY_AANN_STR
10427 "Do not send outside local AS (well-known community)\n"
10428 "Do not advertise to any peer (well-known community)\n"
10429 "Do not export to next AS (well-known community)\n"
10430 COMMUNITY_AANN_STR
10431 "Do not send outside local AS (well-known community)\n"
10432 "Do not advertise to any peer (well-known community)\n"
10433 "Do not export to next AS (well-known community)\n")
10434
10435 /* old command */
10436 DEFUN (show_ipv6_mbgp_community_exact,
10437 show_ipv6_mbgp_community_exact_cmd,
10438 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10439 SHOW_STR
10440 IPV6_STR
10441 MBGP_STR
10442 "Display routes matching the communities\n"
10443 COMMUNITY_AANN_STR
10444 "Do not send outside local AS (well-known community)\n"
10445 "Do not advertise to any peer (well-known community)\n"
10446 "Do not export to next AS (well-known community)\n"
10447 "Exact match of the communities")
10448 {
10449 bgp_show_ipv6_bgp_deprecate_warning(vty);
10450 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10451 }
10452
10453 /* old command */
10454 ALIAS (show_ipv6_mbgp_community_exact,
10455 show_ipv6_mbgp_community2_exact_cmd,
10456 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10457 SHOW_STR
10458 IPV6_STR
10459 MBGP_STR
10460 "Display routes matching the communities\n"
10461 COMMUNITY_AANN_STR
10462 "Do not send outside local AS (well-known community)\n"
10463 "Do not advertise to any peer (well-known community)\n"
10464 "Do not export to next AS (well-known community)\n"
10465 COMMUNITY_AANN_STR
10466 "Do not send outside local AS (well-known community)\n"
10467 "Do not advertise to any peer (well-known community)\n"
10468 "Do not export to next AS (well-known community)\n"
10469 "Exact match of the communities")
10470
10471 /* old command */
10472 ALIAS (show_ipv6_mbgp_community_exact,
10473 show_ipv6_mbgp_community3_exact_cmd,
10474 "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",
10475 SHOW_STR
10476 IPV6_STR
10477 MBGP_STR
10478 "Display routes matching the communities\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 COMMUNITY_AANN_STR
10488 "Do not send outside local AS (well-known community)\n"
10489 "Do not advertise to any peer (well-known community)\n"
10490 "Do not export to next AS (well-known community)\n"
10491 "Exact match of the communities")
10492
10493 /* old command */
10494 ALIAS (show_ipv6_mbgp_community_exact,
10495 show_ipv6_mbgp_community4_exact_cmd,
10496 "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",
10497 SHOW_STR
10498 IPV6_STR
10499 MBGP_STR
10500 "Display routes matching the communities\n"
10501 COMMUNITY_AANN_STR
10502 "Do not send outside local AS (well-known community)\n"
10503 "Do not advertise to any peer (well-known community)\n"
10504 "Do not export to next AS (well-known community)\n"
10505 COMMUNITY_AANN_STR
10506 "Do not send outside local AS (well-known community)\n"
10507 "Do not advertise to any peer (well-known community)\n"
10508 "Do not export to next AS (well-known community)\n"
10509 COMMUNITY_AANN_STR
10510 "Do not send outside local AS (well-known community)\n"
10511 "Do not advertise to any peer (well-known community)\n"
10512 "Do not export to next AS (well-known community)\n"
10513 COMMUNITY_AANN_STR
10514 "Do not send outside local AS (well-known community)\n"
10515 "Do not advertise to any peer (well-known community)\n"
10516 "Do not export to next AS (well-known community)\n"
10517 "Exact match of the communities")
10518 #endif /* HAVE_IPV6 */
10519
10520 static int
10521 bgp_show_community_list (struct vty *vty, const char *name,
10522 const char *com, int exact,
10523 afi_t afi, safi_t safi)
10524 {
10525 struct community_list *list;
10526 struct bgp *bgp = NULL;
10527
10528 if (name && !(bgp = bgp_lookup_by_name(name)))
10529 {
10530 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
10531 return CMD_WARNING;
10532 }
10533
10534 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
10535 if (list == NULL)
10536 {
10537 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10538 VTY_NEWLINE);
10539 return CMD_WARNING;
10540 }
10541
10542 return bgp_show (vty, bgp, afi, safi,
10543 (exact ? bgp_show_type_community_list_exact :
10544 bgp_show_type_community_list), list, 0);
10545 }
10546
10547 DEFUN (show_ip_bgp_community_list,
10548 show_ip_bgp_community_list_cmd,
10549 "show ip bgp community-list (<1-500>|WORD)",
10550 SHOW_STR
10551 IP_STR
10552 BGP_STR
10553 "Display routes matching the community-list\n"
10554 "community-list number\n"
10555 "community-list name\n")
10556 {
10557 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
10558 }
10559
10560 DEFUN (show_ip_bgp_instance_community_list,
10561 show_ip_bgp_instance_community_list_cmd,
10562 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
10563 SHOW_STR
10564 IP_STR
10565 BGP_STR
10566 BGP_INSTANCE_HELP_STR
10567 "Display routes matching the community-list\n"
10568 "community-list number\n"
10569 "community-list name\n")
10570 {
10571 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
10572 }
10573
10574 DEFUN (show_ip_bgp_ipv4_community_list,
10575 show_ip_bgp_ipv4_community_list_cmd,
10576 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
10577 SHOW_STR
10578 IP_STR
10579 BGP_STR
10580 "Address family\n"
10581 "Address Family modifier\n"
10582 "Address Family modifier\n"
10583 "Display routes matching the community-list\n"
10584 "community-list number\n"
10585 "community-list name\n")
10586 {
10587 if (strncmp (argv[0], "m", 1) == 0)
10588 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10589
10590 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_UNICAST);
10591 }
10592
10593 DEFUN (show_ip_bgp_community_list_exact,
10594 show_ip_bgp_community_list_exact_cmd,
10595 "show ip bgp community-list (<1-500>|WORD) exact-match",
10596 SHOW_STR
10597 IP_STR
10598 BGP_STR
10599 "Display routes matching the community-list\n"
10600 "community-list number\n"
10601 "community-list name\n"
10602 "Exact match of the communities\n")
10603 {
10604 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
10605 }
10606
10607 DEFUN (show_ip_bgp_ipv4_community_list_exact,
10608 show_ip_bgp_ipv4_community_list_exact_cmd,
10609 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
10610 SHOW_STR
10611 IP_STR
10612 BGP_STR
10613 "Address family\n"
10614 "Address Family modifier\n"
10615 "Address Family modifier\n"
10616 "Display routes matching the community-list\n"
10617 "community-list number\n"
10618 "community-list name\n"
10619 "Exact match of the communities\n")
10620 {
10621 if (strncmp (argv[0], "m", 1) == 0)
10622 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10623
10624 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_UNICAST);
10625 }
10626
10627 #ifdef HAVE_IPV6
10628 DEFUN (show_bgp_community_list,
10629 show_bgp_community_list_cmd,
10630 "show bgp community-list (<1-500>|WORD)",
10631 SHOW_STR
10632 BGP_STR
10633 "Display routes matching the community-list\n"
10634 "community-list number\n"
10635 "community-list name\n")
10636 {
10637 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10638 }
10639
10640 ALIAS (show_bgp_community_list,
10641 show_bgp_ipv6_community_list_cmd,
10642 "show bgp ipv6 community-list (<1-500>|WORD)",
10643 SHOW_STR
10644 BGP_STR
10645 "Address family\n"
10646 "Display routes matching the community-list\n"
10647 "community-list number\n"
10648 "community-list name\n")
10649
10650 /* old command */
10651 DEFUN (show_ipv6_bgp_community_list,
10652 show_ipv6_bgp_community_list_cmd,
10653 "show ipv6 bgp community-list WORD",
10654 SHOW_STR
10655 IPV6_STR
10656 BGP_STR
10657 "Display routes matching the community-list\n"
10658 "community-list name\n")
10659 {
10660 bgp_show_ipv6_bgp_deprecate_warning(vty);
10661 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10662 }
10663
10664 /* old command */
10665 DEFUN (show_ipv6_mbgp_community_list,
10666 show_ipv6_mbgp_community_list_cmd,
10667 "show ipv6 mbgp community-list WORD",
10668 SHOW_STR
10669 IPV6_STR
10670 MBGP_STR
10671 "Display routes matching the community-list\n"
10672 "community-list name\n")
10673 {
10674 bgp_show_ipv6_bgp_deprecate_warning(vty);
10675 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10676 }
10677
10678 DEFUN (show_bgp_community_list_exact,
10679 show_bgp_community_list_exact_cmd,
10680 "show bgp community-list (<1-500>|WORD) exact-match",
10681 SHOW_STR
10682 BGP_STR
10683 "Display routes matching the community-list\n"
10684 "community-list number\n"
10685 "community-list name\n"
10686 "Exact match of the communities\n")
10687 {
10688 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10689 }
10690
10691 ALIAS (show_bgp_community_list_exact,
10692 show_bgp_ipv6_community_list_exact_cmd,
10693 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
10694 SHOW_STR
10695 BGP_STR
10696 "Address family\n"
10697 "Display routes matching the community-list\n"
10698 "community-list number\n"
10699 "community-list name\n"
10700 "Exact match of the communities\n")
10701
10702 /* old command */
10703 DEFUN (show_ipv6_bgp_community_list_exact,
10704 show_ipv6_bgp_community_list_exact_cmd,
10705 "show ipv6 bgp community-list WORD exact-match",
10706 SHOW_STR
10707 IPV6_STR
10708 BGP_STR
10709 "Display routes matching the community-list\n"
10710 "community-list name\n"
10711 "Exact match of the communities\n")
10712 {
10713 bgp_show_ipv6_bgp_deprecate_warning(vty);
10714 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10715 }
10716
10717 /* old command */
10718 DEFUN (show_ipv6_mbgp_community_list_exact,
10719 show_ipv6_mbgp_community_list_exact_cmd,
10720 "show ipv6 mbgp community-list WORD exact-match",
10721 SHOW_STR
10722 IPV6_STR
10723 MBGP_STR
10724 "Display routes matching the community-list\n"
10725 "community-list name\n"
10726 "Exact match of the communities\n")
10727 {
10728 bgp_show_ipv6_bgp_deprecate_warning(vty);
10729 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
10730 }
10731 #endif /* HAVE_IPV6 */
10732
10733 static int
10734 bgp_show_prefix_longer (struct vty *vty, const char *name,
10735 const char *prefix, afi_t afi,
10736 safi_t safi, enum bgp_show_type type)
10737 {
10738 int ret;
10739 struct prefix *p;
10740 struct bgp *bgp = NULL;
10741
10742 if (name && !(bgp = bgp_lookup_by_name(name)))
10743 {
10744 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
10745 return CMD_WARNING;
10746 }
10747
10748 p = prefix_new();
10749
10750 ret = str2prefix (prefix, p);
10751 if (! ret)
10752 {
10753 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
10754 return CMD_WARNING;
10755 }
10756
10757 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
10758 prefix_free(p);
10759 return ret;
10760 }
10761
10762 DEFUN (show_ip_bgp_prefix_longer,
10763 show_ip_bgp_prefix_longer_cmd,
10764 "show ip bgp A.B.C.D/M longer-prefixes",
10765 SHOW_STR
10766 IP_STR
10767 BGP_STR
10768 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10769 "Display route and more specific routes\n")
10770 {
10771 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10772 bgp_show_type_prefix_longer);
10773 }
10774
10775 DEFUN (show_ip_bgp_instance_prefix_longer,
10776 show_ip_bgp_instance_prefix_longer_cmd,
10777 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
10778 SHOW_STR
10779 IP_STR
10780 BGP_STR
10781 BGP_INSTANCE_HELP_STR
10782 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10783 "Display route and more specific routes\n")
10784 {
10785 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
10786 bgp_show_type_prefix_longer);
10787 }
10788
10789 DEFUN (show_ip_bgp_flap_prefix_longer,
10790 show_ip_bgp_flap_prefix_longer_cmd,
10791 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
10792 SHOW_STR
10793 IP_STR
10794 BGP_STR
10795 "Display flap statistics of routes\n"
10796 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10797 "Display route and more specific routes\n")
10798 {
10799 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10800 bgp_show_type_flap_prefix_longer);
10801 }
10802
10803 ALIAS (show_ip_bgp_flap_prefix_longer,
10804 show_ip_bgp_damp_flap_prefix_longer_cmd,
10805 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
10806 SHOW_STR
10807 IP_STR
10808 BGP_STR
10809 "Display detailed information about dampening\n"
10810 "Display flap statistics of routes\n"
10811 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10812 "Display route and more specific routes\n")
10813
10814 DEFUN (show_ip_bgp_ipv4_prefix_longer,
10815 show_ip_bgp_ipv4_prefix_longer_cmd,
10816 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
10817 SHOW_STR
10818 IP_STR
10819 BGP_STR
10820 "Address family\n"
10821 "Address Family modifier\n"
10822 "Address Family modifier\n"
10823 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10824 "Display route and more specific routes\n")
10825 {
10826 if (strncmp (argv[0], "m", 1) == 0)
10827 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
10828 bgp_show_type_prefix_longer);
10829
10830 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
10831 bgp_show_type_prefix_longer);
10832 }
10833
10834 DEFUN (show_ip_bgp_flap_address,
10835 show_ip_bgp_flap_address_cmd,
10836 "show ip bgp flap-statistics A.B.C.D",
10837 SHOW_STR
10838 IP_STR
10839 BGP_STR
10840 "Display flap statistics of routes\n"
10841 "Network in the BGP routing table to display\n")
10842 {
10843 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10844 bgp_show_type_flap_address);
10845 }
10846
10847 ALIAS (show_ip_bgp_flap_address,
10848 show_ip_bgp_damp_flap_address_cmd,
10849 "show ip bgp dampening flap-statistics A.B.C.D",
10850 SHOW_STR
10851 IP_STR
10852 BGP_STR
10853 "Display detailed information about dampening\n"
10854 "Display flap statistics of routes\n"
10855 "Network in the BGP routing table to display\n")
10856
10857 DEFUN (show_ip_bgp_flap_prefix,
10858 show_ip_bgp_flap_prefix_cmd,
10859 "show ip bgp flap-statistics A.B.C.D/M",
10860 SHOW_STR
10861 IP_STR
10862 BGP_STR
10863 "Display flap statistics of routes\n"
10864 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10865 {
10866 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10867 bgp_show_type_flap_prefix);
10868 }
10869
10870 ALIAS (show_ip_bgp_flap_prefix,
10871 show_ip_bgp_damp_flap_prefix_cmd,
10872 "show ip bgp dampening flap-statistics A.B.C.D/M",
10873 SHOW_STR
10874 IP_STR
10875 BGP_STR
10876 "Display detailed information about dampening\n"
10877 "Display flap statistics of routes\n"
10878 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10879
10880 #ifdef HAVE_IPV6
10881 DEFUN (show_bgp_prefix_longer,
10882 show_bgp_prefix_longer_cmd,
10883 "show bgp X:X::X:X/M longer-prefixes",
10884 SHOW_STR
10885 BGP_STR
10886 "IPv6 prefix <network>/<length>\n"
10887 "Display route and more specific routes\n")
10888 {
10889 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
10890 bgp_show_type_prefix_longer);
10891 }
10892
10893 ALIAS (show_bgp_prefix_longer,
10894 show_bgp_ipv6_prefix_longer_cmd,
10895 "show bgp ipv6 X:X::X:X/M longer-prefixes",
10896 SHOW_STR
10897 BGP_STR
10898 "Address family\n"
10899 "IPv6 prefix <network>/<length>\n"
10900 "Display route and more specific routes\n")
10901
10902 /* old command */
10903 DEFUN (show_ipv6_bgp_prefix_longer,
10904 show_ipv6_bgp_prefix_longer_cmd,
10905 "show ipv6 bgp X:X::X:X/M longer-prefixes",
10906 SHOW_STR
10907 IPV6_STR
10908 BGP_STR
10909 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
10910 "Display route and more specific routes\n")
10911 {
10912 bgp_show_ipv6_bgp_deprecate_warning(vty);
10913 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
10914 bgp_show_type_prefix_longer);
10915 }
10916
10917 /* old command */
10918 DEFUN (show_ipv6_mbgp_prefix_longer,
10919 show_ipv6_mbgp_prefix_longer_cmd,
10920 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
10921 SHOW_STR
10922 IPV6_STR
10923 MBGP_STR
10924 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
10925 "Display route and more specific routes\n")
10926 {
10927 bgp_show_ipv6_bgp_deprecate_warning(vty);
10928 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
10929 bgp_show_type_prefix_longer);
10930 }
10931 #endif /* HAVE_IPV6 */
10932
10933 static struct peer *
10934 peer_lookup_in_view (struct vty *vty, const char *view_name,
10935 const char *ip_str, u_char use_json)
10936 {
10937 int ret;
10938 struct bgp *bgp;
10939 struct peer *peer;
10940 union sockunion su;
10941
10942 /* BGP structure lookup. */
10943 if (view_name)
10944 {
10945 bgp = bgp_lookup_by_name (view_name);
10946 if (! bgp)
10947 {
10948 if (use_json)
10949 {
10950 json_object *json_no = NULL;
10951 json_no = json_object_new_object();
10952 json_object_string_add(json_no, "warning", "Can't find BGP view");
10953 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10954 json_object_free(json_no);
10955 }
10956 else
10957 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
10958 return NULL;
10959 }
10960 }
10961 else
10962 {
10963 bgp = bgp_get_default ();
10964 if (! bgp)
10965 {
10966 if (use_json)
10967 {
10968 json_object *json_no = NULL;
10969 json_no = json_object_new_object();
10970 json_object_string_add(json_no, "warning", "No BGP process configured");
10971 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10972 json_object_free(json_no);
10973 }
10974 else
10975 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10976 return NULL;
10977 }
10978 }
10979
10980 /* Get peer sockunion. */
10981 ret = str2sockunion (ip_str, &su);
10982 if (ret < 0)
10983 {
10984 peer = peer_lookup_by_conf_if (bgp, ip_str);
10985 if (!peer)
10986 {
10987 peer = peer_lookup_by_hostname(bgp, ip_str);
10988
10989 if (!peer)
10990 {
10991 if (use_json)
10992 {
10993 json_object *json_no = NULL;
10994 json_no = json_object_new_object();
10995 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
10996 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10997 json_object_free(json_no);
10998 }
10999 else
11000 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11001 return NULL;
11002 }
11003 }
11004 return peer;
11005 }
11006
11007 /* Peer structure lookup. */
11008 peer = peer_lookup (bgp, &su);
11009 if (! peer)
11010 {
11011 if (use_json)
11012 {
11013 json_object *json_no = NULL;
11014 json_no = json_object_new_object();
11015 json_object_string_add(json_no, "warning","No such neighbor");
11016 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11017 json_object_free(json_no);
11018 }
11019 else
11020 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11021 return NULL;
11022 }
11023
11024 return peer;
11025 }
11026
11027 enum bgp_stats
11028 {
11029 BGP_STATS_MAXBITLEN = 0,
11030 BGP_STATS_RIB,
11031 BGP_STATS_PREFIXES,
11032 BGP_STATS_TOTPLEN,
11033 BGP_STATS_UNAGGREGATEABLE,
11034 BGP_STATS_MAX_AGGREGATEABLE,
11035 BGP_STATS_AGGREGATES,
11036 BGP_STATS_SPACE,
11037 BGP_STATS_ASPATH_COUNT,
11038 BGP_STATS_ASPATH_MAXHOPS,
11039 BGP_STATS_ASPATH_TOTHOPS,
11040 BGP_STATS_ASPATH_MAXSIZE,
11041 BGP_STATS_ASPATH_TOTSIZE,
11042 BGP_STATS_ASN_HIGHEST,
11043 BGP_STATS_MAX,
11044 };
11045
11046 static const char *table_stats_strs[] =
11047 {
11048 [BGP_STATS_PREFIXES] = "Total Prefixes",
11049 [BGP_STATS_TOTPLEN] = "Average prefix length",
11050 [BGP_STATS_RIB] = "Total Advertisements",
11051 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11052 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11053 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11054 [BGP_STATS_SPACE] = "Address space advertised",
11055 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11056 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11057 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11058 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11059 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11060 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11061 [BGP_STATS_MAX] = NULL,
11062 };
11063
11064 struct bgp_table_stats
11065 {
11066 struct bgp_table *table;
11067 unsigned long long counts[BGP_STATS_MAX];
11068 };
11069
11070 #if 0
11071 #define TALLY_SIGFIG 100000
11072 static unsigned long
11073 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11074 {
11075 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11076 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11077 unsigned long ret = newtot / count;
11078
11079 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11080 return ret + 1;
11081 else
11082 return ret;
11083 }
11084 #endif
11085
11086 static int
11087 bgp_table_stats_walker (struct thread *t)
11088 {
11089 struct bgp_node *rn;
11090 struct bgp_node *top;
11091 struct bgp_table_stats *ts = THREAD_ARG (t);
11092 unsigned int space = 0;
11093
11094 if (!(top = bgp_table_top (ts->table)))
11095 return 0;
11096
11097 switch (top->p.family)
11098 {
11099 case AF_INET:
11100 space = IPV4_MAX_BITLEN;
11101 break;
11102 case AF_INET6:
11103 space = IPV6_MAX_BITLEN;
11104 break;
11105 }
11106
11107 ts->counts[BGP_STATS_MAXBITLEN] = space;
11108
11109 for (rn = top; rn; rn = bgp_route_next (rn))
11110 {
11111 struct bgp_info *ri;
11112 struct bgp_node *prn = bgp_node_parent_nolock (rn);
11113 unsigned int rinum = 0;
11114
11115 if (rn == top)
11116 continue;
11117
11118 if (!rn->info)
11119 continue;
11120
11121 ts->counts[BGP_STATS_PREFIXES]++;
11122 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11123
11124 #if 0
11125 ts->counts[BGP_STATS_AVGPLEN]
11126 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11127 ts->counts[BGP_STATS_AVGPLEN],
11128 rn->p.prefixlen);
11129 #endif
11130
11131 /* check if the prefix is included by any other announcements */
11132 while (prn && !prn->info)
11133 prn = bgp_node_parent_nolock (prn);
11134
11135 if (prn == NULL || prn == top)
11136 {
11137 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11138 /* announced address space */
11139 if (space)
11140 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11141 }
11142 else if (prn->info)
11143 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11144
11145 for (ri = rn->info; ri; ri = ri->next)
11146 {
11147 rinum++;
11148 ts->counts[BGP_STATS_RIB]++;
11149
11150 if (ri->attr &&
11151 (CHECK_FLAG (ri->attr->flag,
11152 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11153 ts->counts[BGP_STATS_AGGREGATES]++;
11154
11155 /* as-path stats */
11156 if (ri->attr && ri->attr->aspath)
11157 {
11158 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11159 unsigned int size = aspath_size (ri->attr->aspath);
11160 as_t highest = aspath_highest (ri->attr->aspath);
11161
11162 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11163
11164 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11165 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11166
11167 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11168 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11169
11170 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11171 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11172 #if 0
11173 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11174 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11175 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11176 hops);
11177 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11178 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11179 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11180 size);
11181 #endif
11182 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11183 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11184 }
11185 }
11186 }
11187 return 0;
11188 }
11189
11190 static int
11191 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11192 {
11193 struct bgp_table_stats ts;
11194 unsigned int i;
11195
11196 if (!bgp->rib[afi][safi])
11197 {
11198 vty_out (vty, "%% No RIB exist's for the AFI(%d)/SAFI(%d)%s",
11199 afi, safi, VTY_NEWLINE);
11200 return CMD_WARNING;
11201 }
11202
11203 memset (&ts, 0, sizeof (ts));
11204 ts.table = bgp->rib[afi][safi];
11205 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11206
11207 vty_out (vty, "BGP %s RIB statistics%s%s",
11208 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11209
11210 for (i = 0; i < BGP_STATS_MAX; i++)
11211 {
11212 if (!table_stats_strs[i])
11213 continue;
11214
11215 switch (i)
11216 {
11217 #if 0
11218 case BGP_STATS_ASPATH_AVGHOPS:
11219 case BGP_STATS_ASPATH_AVGSIZE:
11220 case BGP_STATS_AVGPLEN:
11221 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11222 vty_out (vty, "%12.2f",
11223 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11224 break;
11225 #endif
11226 case BGP_STATS_ASPATH_TOTHOPS:
11227 case BGP_STATS_ASPATH_TOTSIZE:
11228 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11229 vty_out (vty, "%12.2f",
11230 ts.counts[i] ?
11231 (float)ts.counts[i] /
11232 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11233 : 0);
11234 break;
11235 case BGP_STATS_TOTPLEN:
11236 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11237 vty_out (vty, "%12.2f",
11238 ts.counts[i] ?
11239 (float)ts.counts[i] /
11240 (float)ts.counts[BGP_STATS_PREFIXES]
11241 : 0);
11242 break;
11243 case BGP_STATS_SPACE:
11244 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11245 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11246 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11247 break;
11248 vty_out (vty, "%30s: ", "%% announced ");
11249 vty_out (vty, "%12.2f%s",
11250 100 * (float)ts.counts[BGP_STATS_SPACE] /
11251 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
11252 VTY_NEWLINE);
11253 vty_out (vty, "%30s: ", "/8 equivalent ");
11254 vty_out (vty, "%12.2f%s",
11255 (float)ts.counts[BGP_STATS_SPACE] /
11256 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11257 VTY_NEWLINE);
11258 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11259 break;
11260 vty_out (vty, "%30s: ", "/24 equivalent ");
11261 vty_out (vty, "%12.2f",
11262 (float)ts.counts[BGP_STATS_SPACE] /
11263 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11264 break;
11265 default:
11266 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11267 vty_out (vty, "%12llu", ts.counts[i]);
11268 }
11269
11270 vty_out (vty, "%s", VTY_NEWLINE);
11271 }
11272 return CMD_SUCCESS;
11273 }
11274
11275 static int
11276 bgp_table_stats_vty (struct vty *vty, const char *name,
11277 const char *afi_str, const char *safi_str)
11278 {
11279 struct bgp *bgp;
11280 afi_t afi;
11281 safi_t safi;
11282
11283 if (name)
11284 bgp = bgp_lookup_by_name (name);
11285 else
11286 bgp = bgp_get_default ();
11287
11288 if (!bgp)
11289 {
11290 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
11291 return CMD_WARNING;
11292 }
11293 if (strncmp (afi_str, "ipv", 3) == 0)
11294 {
11295 if (strncmp (afi_str, "ipv4", 4) == 0)
11296 afi = AFI_IP;
11297 else if (strncmp (afi_str, "ipv6", 4) == 0)
11298 afi = AFI_IP6;
11299 else
11300 {
11301 vty_out (vty, "%% Invalid address family %s%s",
11302 afi_str, VTY_NEWLINE);
11303 return CMD_WARNING;
11304 }
11305 if (strncmp (safi_str, "m", 1) == 0)
11306 safi = SAFI_MULTICAST;
11307 else if (strncmp (safi_str, "u", 1) == 0)
11308 safi = SAFI_UNICAST;
11309 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
11310 safi = SAFI_MPLS_VPN;
11311 else
11312 {
11313 vty_out (vty, "%% Invalid subsequent address family %s%s",
11314 safi_str, VTY_NEWLINE);
11315 return CMD_WARNING;
11316 }
11317 }
11318 else
11319 {
11320 vty_out (vty, "%% Invalid address family %s%s",
11321 afi_str, VTY_NEWLINE);
11322 return CMD_WARNING;
11323 }
11324
11325 return bgp_table_stats (vty, bgp, afi, safi);
11326 }
11327
11328 DEFUN (show_bgp_statistics,
11329 show_bgp_statistics_cmd,
11330 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
11331 SHOW_STR
11332 BGP_STR
11333 "Address family\n"
11334 "Address family\n"
11335 "Address Family modifier\n"
11336 "Address Family modifier\n"
11337 "BGP RIB advertisement statistics\n")
11338 {
11339 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11340 }
11341
11342 ALIAS (show_bgp_statistics,
11343 show_bgp_statistics_vpnv4_cmd,
11344 "show bgp (ipv4) (vpnv4) statistics",
11345 SHOW_STR
11346 BGP_STR
11347 "Address family\n"
11348 "Address Family modifier\n"
11349 "BGP RIB advertisement statistics\n")
11350
11351 DEFUN (show_bgp_statistics_view,
11352 show_bgp_statistics_view_cmd,
11353 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) statistics",
11354 SHOW_STR
11355 BGP_STR
11356 BGP_INSTANCE_HELP_STR
11357 "Address family\n"
11358 "Address family\n"
11359 "Address Family modifier\n"
11360 "Address Family modifier\n"
11361 "BGP RIB advertisement statistics\n")
11362 {
11363 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
11364 }
11365
11366 ALIAS (show_bgp_statistics_view,
11367 show_bgp_statistics_view_vpnv4_cmd,
11368 "show bgp " BGP_INSTANCE_CMD " (ipv4) (vpnv4) statistics",
11369 SHOW_STR
11370 BGP_STR
11371 BGP_INSTANCE_HELP_STR
11372 "Address family\n"
11373 "Address Family modifier\n"
11374 "BGP RIB advertisement statistics\n")
11375
11376 enum bgp_pcounts
11377 {
11378 PCOUNT_ADJ_IN = 0,
11379 PCOUNT_DAMPED,
11380 PCOUNT_REMOVED,
11381 PCOUNT_HISTORY,
11382 PCOUNT_STALE,
11383 PCOUNT_VALID,
11384 PCOUNT_ALL,
11385 PCOUNT_COUNTED,
11386 PCOUNT_PFCNT, /* the figure we display to users */
11387 PCOUNT_MAX,
11388 };
11389
11390 static const char *pcount_strs[] =
11391 {
11392 [PCOUNT_ADJ_IN] = "Adj-in",
11393 [PCOUNT_DAMPED] = "Damped",
11394 [PCOUNT_REMOVED] = "Removed",
11395 [PCOUNT_HISTORY] = "History",
11396 [PCOUNT_STALE] = "Stale",
11397 [PCOUNT_VALID] = "Valid",
11398 [PCOUNT_ALL] = "All RIB",
11399 [PCOUNT_COUNTED] = "PfxCt counted",
11400 [PCOUNT_PFCNT] = "Useable",
11401 [PCOUNT_MAX] = NULL,
11402 };
11403
11404 struct peer_pcounts
11405 {
11406 unsigned int count[PCOUNT_MAX];
11407 const struct peer *peer;
11408 const struct bgp_table *table;
11409 };
11410
11411 static int
11412 bgp_peer_count_walker (struct thread *t)
11413 {
11414 struct bgp_node *rn;
11415 struct peer_pcounts *pc = THREAD_ARG (t);
11416 const struct peer *peer = pc->peer;
11417
11418 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
11419 {
11420 struct bgp_adj_in *ain;
11421 struct bgp_info *ri;
11422
11423 for (ain = rn->adj_in; ain; ain = ain->next)
11424 if (ain->peer == peer)
11425 pc->count[PCOUNT_ADJ_IN]++;
11426
11427 for (ri = rn->info; ri; ri = ri->next)
11428 {
11429 char buf[SU_ADDRSTRLEN];
11430
11431 if (ri->peer != peer)
11432 continue;
11433
11434 pc->count[PCOUNT_ALL]++;
11435
11436 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
11437 pc->count[PCOUNT_DAMPED]++;
11438 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
11439 pc->count[PCOUNT_HISTORY]++;
11440 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
11441 pc->count[PCOUNT_REMOVED]++;
11442 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
11443 pc->count[PCOUNT_STALE]++;
11444 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
11445 pc->count[PCOUNT_VALID]++;
11446 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11447 pc->count[PCOUNT_PFCNT]++;
11448
11449 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11450 {
11451 pc->count[PCOUNT_COUNTED]++;
11452 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11453 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
11454 peer->host,
11455 inet_ntop(rn->p.family, &rn->p.u.prefix,
11456 buf, SU_ADDRSTRLEN),
11457 rn->p.prefixlen,
11458 ri->flags);
11459 }
11460 else
11461 {
11462 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11463 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
11464 peer->host,
11465 inet_ntop(rn->p.family, &rn->p.u.prefix,
11466 buf, SU_ADDRSTRLEN),
11467 rn->p.prefixlen,
11468 ri->flags);
11469 }
11470 }
11471 }
11472 return 0;
11473 }
11474
11475 static int
11476 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
11477 {
11478 struct peer_pcounts pcounts = { .peer = peer };
11479 unsigned int i;
11480 json_object *json = NULL;
11481 json_object *json_loop = NULL;
11482
11483 if (use_json)
11484 {
11485 json = json_object_new_object();
11486 json_loop = json_object_new_object();
11487 }
11488
11489 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11490 || !peer->bgp->rib[afi][safi])
11491 {
11492 if (use_json)
11493 {
11494 json_object_string_add(json, "warning", "No such neighbor or address family");
11495 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11496 json_object_free(json);
11497 }
11498 else
11499 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11500
11501 return CMD_WARNING;
11502 }
11503
11504 memset (&pcounts, 0, sizeof(pcounts));
11505 pcounts.peer = peer;
11506 pcounts.table = peer->bgp->rib[afi][safi];
11507
11508 /* in-place call via thread subsystem so as to record execution time
11509 * * stats for the thread-walk (i.e. ensure this can't be blamed on
11510 * * on just vty_read()).
11511 * */
11512 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
11513
11514 if (use_json)
11515 {
11516 json_object_string_add(json, "prefixCountsFor", peer->host);
11517 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
11518 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
11519
11520 for (i = 0; i < PCOUNT_MAX; i++)
11521 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
11522
11523 json_object_object_add(json, "ribTableWalkCounters", json_loop);
11524
11525 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11526 {
11527 json_object_string_add(json, "pfxctDriftFor", peer->host);
11528 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
11529 }
11530 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11531 json_object_free(json);
11532 }
11533 else
11534 {
11535
11536 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
11537 {
11538 vty_out (vty, "Prefix counts for %s/%s, %s%s",
11539 peer->hostname, peer->host, afi_safi_print (afi, safi),
11540 VTY_NEWLINE);
11541 }
11542 else
11543 {
11544 vty_out (vty, "Prefix counts for %s, %s%s",
11545 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
11546 }
11547
11548 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
11549 vty_out (vty, "%sCounts from RIB table walk:%s%s",
11550 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
11551
11552 for (i = 0; i < PCOUNT_MAX; i++)
11553 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
11554
11555 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11556 {
11557 vty_out (vty, "%s [pcount] PfxCt drift!%s",
11558 peer->host, VTY_NEWLINE);
11559 vty_out (vty, "Please report this bug, with the above command output%s",
11560 VTY_NEWLINE);
11561 }
11562 }
11563
11564 return CMD_SUCCESS;
11565 }
11566
11567 DEFUN (show_ip_bgp_neighbor_prefix_counts,
11568 show_ip_bgp_neighbor_prefix_counts_cmd,
11569 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11570 SHOW_STR
11571 IP_STR
11572 BGP_STR
11573 "Detailed information on TCP and BGP neighbor connections\n"
11574 "Neighbor to display information about\n"
11575 "Neighbor to display information about\n"
11576 "Neighbor on bgp configured interface\n"
11577 "Display detailed prefix count information\n"
11578 "JavaScript Object Notation\n")
11579 {
11580 struct peer *peer;
11581 u_char uj = use_json(argc, argv);
11582
11583 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11584 if (! peer)
11585 return CMD_WARNING;
11586
11587 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11588 }
11589
11590 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
11591 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
11592 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11593 SHOW_STR
11594 IP_STR
11595 BGP_STR
11596 BGP_INSTANCE_HELP_STR
11597 "Detailed information on TCP and BGP neighbor connections\n"
11598 "Neighbor to display information about\n"
11599 "Neighbor to display information about\n"
11600 "Neighbor on bgp configured interface\n"
11601 "Display detailed prefix count information\n"
11602 "JavaScript Object Notation\n")
11603 {
11604 struct peer *peer;
11605 u_char uj = use_json(argc, argv);
11606
11607 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11608 if (! peer)
11609 return CMD_WARNING;
11610
11611 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11612 }
11613
11614 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
11615 show_bgp_ipv6_neighbor_prefix_counts_cmd,
11616 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11617 SHOW_STR
11618 BGP_STR
11619 "Address family\n"
11620 "Detailed information on TCP and BGP neighbor connections\n"
11621 "Neighbor to display information about\n"
11622 "Neighbor to display information about\n"
11623 "Neighbor on bgp configured interface\n"
11624 "Display detailed prefix count information\n"
11625 "JavaScript Object Notation\n")
11626 {
11627 struct peer *peer;
11628 u_char uj = use_json(argc, argv);
11629
11630 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11631 if (! peer)
11632 return CMD_WARNING;
11633
11634 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
11635 }
11636
11637 DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
11638 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
11639 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11640 SHOW_STR
11641 BGP_STR
11642 BGP_INSTANCE_HELP_STR
11643 "Address family\n"
11644 "Detailed information on TCP and BGP neighbor connections\n"
11645 "Neighbor to display information about\n"
11646 "Neighbor to display information about\n"
11647 "Neighbor on bgp configured interface\n"
11648 "Display detailed prefix count information\n"
11649 "JavaScript Object Notation\n")
11650 {
11651 struct peer *peer;
11652 u_char uj = use_json(argc, argv);
11653
11654 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11655 if (! peer)
11656 return CMD_WARNING;
11657
11658 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
11659 }
11660
11661 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
11662 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
11663 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11664 SHOW_STR
11665 IP_STR
11666 BGP_STR
11667 "Address family\n"
11668 "Address Family modifier\n"
11669 "Address Family modifier\n"
11670 "Detailed information on TCP and BGP neighbor connections\n"
11671 "Neighbor to display information about\n"
11672 "Neighbor to display information about\n"
11673 "Neighbor on bgp configured interface\n"
11674 "Display detailed prefix count information\n"
11675 "JavaScript Object Notation\n")
11676 {
11677 struct peer *peer;
11678 u_char uj = use_json(argc, argv);
11679
11680 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
11681 if (! peer)
11682 return CMD_WARNING;
11683
11684 if (strncmp (argv[0], "m", 1) == 0)
11685 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj);
11686
11687 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11688 }
11689
11690 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
11691 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
11692 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11693 SHOW_STR
11694 IP_STR
11695 BGP_STR
11696 "Address family\n"
11697 "Address Family modifier\n"
11698 "Address Family modifier\n"
11699 "Detailed information on TCP and BGP neighbor connections\n"
11700 "Neighbor to display information about\n"
11701 "Neighbor to display information about\n"
11702 "Neighbor on bgp configured interface\n"
11703 "Display detailed prefix count information\n"
11704 "JavaScript Object Notation\n")
11705 {
11706 struct peer *peer;
11707 u_char uj = use_json(argc, argv);
11708
11709 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11710 if (! peer)
11711 return CMD_WARNING;
11712
11713 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
11714 }
11715
11716 static void
11717 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
11718 int in, const char *rmap_name, u_char use_json, json_object *json)
11719 {
11720 struct bgp_table *table;
11721 struct bgp_adj_in *ain;
11722 struct bgp_adj_out *adj;
11723 unsigned long output_count;
11724 unsigned long filtered_count;
11725 struct bgp_node *rn;
11726 int header1 = 1;
11727 struct bgp *bgp;
11728 int header2 = 1;
11729 struct attr attr;
11730 struct attr_extra extra;
11731 int ret;
11732 struct update_subgroup *subgrp;
11733 json_object *json_scode = NULL;
11734 json_object *json_ocode = NULL;
11735 json_object *json_ar = NULL;
11736 struct peer_af *paf;
11737
11738 if (use_json)
11739 {
11740 json_scode = json_object_new_object();
11741 json_ocode = json_object_new_object();
11742 json_ar = json_object_new_object();
11743
11744 json_object_string_add(json_scode, "suppressed", "s");
11745 json_object_string_add(json_scode, "damped", "d");
11746 json_object_string_add(json_scode, "history", "h");
11747 json_object_string_add(json_scode, "valid", "*");
11748 json_object_string_add(json_scode, "best", ">");
11749 json_object_string_add(json_scode, "multipath", "=");
11750 json_object_string_add(json_scode, "internal", "i");
11751 json_object_string_add(json_scode, "ribFailure", "r");
11752 json_object_string_add(json_scode, "stale", "S");
11753 json_object_string_add(json_scode, "removed", "R");
11754
11755 json_object_string_add(json_ocode, "igp", "i");
11756 json_object_string_add(json_ocode, "egp", "e");
11757 json_object_string_add(json_ocode, "incomplete", "?");
11758 }
11759
11760 bgp = peer->bgp;
11761
11762 if (! bgp)
11763 {
11764 if (use_json)
11765 {
11766 json_object_string_add(json, "alert", "no BGP");
11767 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11768 json_object_free(json);
11769 }
11770 else
11771 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
11772 return;
11773 }
11774
11775 table = bgp->rib[afi][safi];
11776
11777 output_count = filtered_count = 0;
11778 subgrp = peer_subgroup(peer, afi, safi);
11779
11780 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
11781 {
11782 if (use_json)
11783 {
11784 json_object_int_add(json, "bgpTableVersion", table->version);
11785 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11786 json_object_object_add(json, "bgpStatusCodes", json_scode);
11787 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11788 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
11789 }
11790 else
11791 {
11792 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
11793 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11794 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11795
11796 vty_out (vty, "Originating default network 0.0.0.0%s%s",
11797 VTY_NEWLINE, VTY_NEWLINE);
11798 }
11799 header1 = 0;
11800 }
11801
11802 attr.extra = &extra;
11803 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11804 {
11805 if (in)
11806 {
11807 for (ain = rn->adj_in; ain; ain = ain->next)
11808 {
11809 if (ain->peer == peer)
11810 {
11811 if (header1)
11812 {
11813 if (use_json)
11814 {
11815 json_object_int_add(json, "bgpTableVersion", 0);
11816 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11817 json_object_object_add(json, "bgpStatusCodes", json_scode);
11818 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11819 }
11820 else
11821 {
11822 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
11823 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11824 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11825 }
11826 header1 = 0;
11827 }
11828 if (header2)
11829 {
11830 if (!use_json)
11831 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
11832 header2 = 0;
11833 }
11834 if (ain->attr)
11835 {
11836 bgp_attr_dup(&attr, ain->attr);
11837 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
11838 {
11839 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
11840 output_count++;
11841 }
11842 else
11843 filtered_count++;
11844 }
11845 }
11846 }
11847 }
11848 else
11849 {
11850 for (adj = rn->adj_out; adj; adj = adj->next)
11851 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
11852 if (paf->peer == peer)
11853 {
11854 if (header1)
11855 {
11856 if (use_json)
11857 {
11858 json_object_int_add(json, "bgpTableVersion", table->version);
11859 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11860 json_object_object_add(json, "bgpStatusCodes", json_scode);
11861 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11862 }
11863 else
11864 {
11865 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
11866 inet_ntoa (bgp->router_id), VTY_NEWLINE);
11867 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11868 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11869 }
11870 header1 = 0;
11871 }
11872
11873 if (header2)
11874 {
11875 if (!use_json)
11876 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
11877 header2 = 0;
11878 }
11879
11880 if (adj->attr)
11881 {
11882 bgp_attr_dup(&attr, adj->attr);
11883 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
11884 if (ret != RMAP_DENY)
11885 {
11886 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
11887 output_count++;
11888 }
11889 else
11890 filtered_count++;
11891 }
11892 }
11893 }
11894 }
11895 if (use_json)
11896 json_object_object_add(json, "advertisedRoutes", json_ar);
11897
11898 if (output_count != 0)
11899 {
11900 if (use_json)
11901 json_object_int_add(json, "totalPrefixCounter", output_count);
11902 else
11903 vty_out (vty, "%sTotal number of prefixes %ld%s",
11904 VTY_NEWLINE, output_count, VTY_NEWLINE);
11905 }
11906 if (use_json)
11907 {
11908 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11909 json_object_free(json);
11910 }
11911
11912 }
11913
11914 static int
11915 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
11916 int in, const char *rmap_name, u_char use_json)
11917 {
11918 json_object *json = NULL;
11919
11920 if (use_json)
11921 json = json_object_new_object();
11922
11923 if (!peer || !peer->afc[afi][safi])
11924 {
11925 if (use_json)
11926 {
11927 json_object_string_add(json, "warning", "No such neighbor or address family");
11928 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11929 json_object_free(json);
11930 }
11931 else
11932 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11933
11934 return CMD_WARNING;
11935 }
11936
11937 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11938 {
11939 if (use_json)
11940 {
11941 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
11942 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11943 json_object_free(json);
11944 }
11945 else
11946 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
11947
11948 return CMD_WARNING;
11949 }
11950
11951 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
11952
11953 return CMD_SUCCESS;
11954 }
11955
11956 DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
11957 show_ip_bgp_instance_neighbor_advertised_route_cmd,
11958 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11959 SHOW_STR
11960 IP_STR
11961 BGP_STR
11962 BGP_INSTANCE_HELP_STR
11963 "Detailed information on TCP and BGP neighbor connections\n"
11964 "Neighbor to display information about\n"
11965 "Neighbor to display information about\n"
11966 "Display the routes advertised to a BGP neighbor\n"
11967 "JavaScript Object Notation\n")
11968 {
11969 struct peer *peer;
11970 u_char uj = use_json(argc, argv);
11971
11972 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
11973 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11974 else
11975 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
11976
11977 if (! peer)
11978 return CMD_WARNING;
11979
11980 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
11981 }
11982
11983 DEFUN (show_ip_bgp_neighbor_advertised_route,
11984 show_ip_bgp_neighbor_advertised_route_cmd,
11985 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11986 SHOW_STR
11987 IP_STR
11988 BGP_STR
11989 "Detailed information on TCP and BGP neighbor connections\n"
11990 "Neighbor to display information about\n"
11991 "Neighbor to display information about\n"
11992 "Neighbor on bgp configured interface\n"
11993 "Display the routes advertised to a BGP neighbor\n"
11994 "JavaScript Object Notation\n")
11995
11996 {
11997 struct peer *peer;
11998 const char *rmap_name = NULL;
11999 u_char uj = use_json(argc, argv);
12000
12001 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12002
12003 if (! peer)
12004 return CMD_WARNING;
12005
12006 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12007 || (argc == 3))
12008 rmap_name = argv[1];
12009
12010 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12011 }
12012
12013 ALIAS (show_ip_bgp_neighbor_advertised_route,
12014 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
12015 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12016 SHOW_STR
12017 IP_STR
12018 BGP_STR
12019 "Detailed information on TCP and BGP neighbor connections\n"
12020 "Neighbor to display information about\n"
12021 "Neighbor to display information about\n"
12022 "Neighbor on bgp configured interface\n"
12023 "Display the routes advertised to a BGP neighbor\n"
12024 "JavaScript Object Notation\n")
12025
12026 ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12027 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12028 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12029 SHOW_STR
12030 IP_STR
12031 BGP_STR
12032 BGP_INSTANCE_HELP_STR
12033 "Detailed information on TCP and BGP neighbor connections\n"
12034 "Neighbor to display information about\n"
12035 "Neighbor to display information about\n"
12036 "Neighbor on bgp configured interface\n"
12037 "Display the routes advertised to a BGP neighbor\n"
12038 "JavaScript Object Notation\n")
12039 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12040 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12041 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12042 SHOW_STR
12043 IP_STR
12044 BGP_STR
12045 "Address family\n"
12046 "Address Family modifier\n"
12047 "Address Family modifier\n"
12048 "Detailed information on TCP and BGP neighbor connections\n"
12049 "Neighbor to display information about\n"
12050 "Neighbor to display information about\n"
12051 "Neighbor on bgp configured interface\n"
12052 "Display the routes advertised to a BGP neighbor\n"
12053 "JavaScript Object Notation\n")
12054 {
12055 struct peer *peer;
12056 const char *rmap_name = NULL;
12057 u_char uj = use_json(argc, argv);
12058
12059 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12060 if (! peer)
12061 return CMD_WARNING;
12062
12063 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12064 rmap_name = argv[2];
12065
12066 if (strncmp (argv[0], "m", 1) == 0)
12067 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj);
12068 else
12069 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12070 }
12071
12072 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12073 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
12074 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12075 SHOW_STR
12076 IP_STR
12077 BGP_STR
12078 "Address family\n"
12079 "Address Family modifier\n"
12080 "Address Family modifier\n"
12081 "Detailed information on TCP and BGP neighbor connections\n"
12082 "Neighbor to display information about\n"
12083 "Neighbor to display information about\n"
12084 "Neighbor on bgp configured interface\n"
12085 "Display the routes advertised to a BGP neighbor\n"
12086 "Route-map to control what is displayed\n"
12087 "JavaScript Object Notation\n")
12088
12089 #ifdef HAVE_IPV6
12090 DEFUN (show_bgp_instance_neighbor_advertised_route,
12091 show_bgp_instance_neighbor_advertised_route_cmd,
12092 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12093 SHOW_STR
12094 BGP_STR
12095 BGP_INSTANCE_HELP_STR
12096 "Detailed information on TCP and BGP neighbor connections\n"
12097 "Neighbor to display information about\n"
12098 "Neighbor to display information about\n"
12099 "Neighbor on bgp configured interface\n"
12100 "Display the routes advertised to a BGP neighbor\n"
12101 "JavaScript Object Notation\n")
12102 {
12103 struct peer *peer;
12104 u_char uj = use_json(argc, argv);
12105
12106 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12107 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12108 else
12109 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12110
12111 if (! peer)
12112 return CMD_WARNING;
12113
12114 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
12115 }
12116
12117 ALIAS (show_bgp_instance_neighbor_advertised_route,
12118 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12119 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12120 SHOW_STR
12121 BGP_STR
12122 BGP_INSTANCE_HELP_STR
12123 "Address family\n"
12124 "Detailed information on TCP and BGP neighbor connections\n"
12125 "Neighbor to display information about\n"
12126 "Neighbor to display information about\n"
12127 "Neighbor on bgp configured interface\n"
12128 "Display the routes advertised to a BGP neighbor\n"
12129 "JavaScript Object Notation\n")
12130
12131 DEFUN (show_bgp_neighbor_advertised_route,
12132 show_bgp_neighbor_advertised_route_cmd,
12133 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12134 SHOW_STR
12135 BGP_STR
12136 "Detailed information on TCP and BGP neighbor connections\n"
12137 "Neighbor to display information about\n"
12138 "Neighbor to display information about\n"
12139 "Neighbor on bgp configured interface\n"
12140 "Display the routes advertised to a BGP neighbor\n"
12141 "JavaScript Object Notation\n")
12142
12143 {
12144 struct peer *peer;
12145 const char *rmap_name = NULL;
12146 u_char uj = use_json(argc, argv);
12147
12148 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12149
12150 if (!peer)
12151 return CMD_WARNING;
12152
12153 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12154 rmap_name = argv[1];
12155
12156 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
12157 }
12158
12159 ALIAS (show_bgp_neighbor_advertised_route,
12160 show_bgp_ipv6_neighbor_advertised_route_cmd,
12161 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12162 SHOW_STR
12163 BGP_STR
12164 "Address family\n"
12165 "Detailed information on TCP and BGP neighbor connections\n"
12166 "Neighbor to display information about\n"
12167 "Neighbor to display information about\n"
12168 "Neighbor on bgp configured interface\n"
12169 "Display the routes advertised to a BGP neighbor\n"
12170 "JavaScript Object Notation\n")
12171
12172 /* old command */
12173 ALIAS (show_bgp_neighbor_advertised_route,
12174 ipv6_bgp_neighbor_advertised_route_cmd,
12175 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12176 SHOW_STR
12177 IPV6_STR
12178 BGP_STR
12179 "Detailed information on TCP and BGP neighbor connections\n"
12180 "Neighbor to display information about\n"
12181 "Neighbor to display information about\n"
12182 "Neighbor on bgp configured interface\n"
12183 "Display the routes advertised to a BGP neighbor\n"
12184 "JavaScript Object Notation\n")
12185
12186 /* old command */
12187 DEFUN (ipv6_mbgp_neighbor_advertised_route,
12188 ipv6_mbgp_neighbor_advertised_route_cmd,
12189 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12190 SHOW_STR
12191 IPV6_STR
12192 MBGP_STR
12193 "Detailed information on TCP and BGP neighbor connections\n"
12194 "Neighbor to display information about\n"
12195 "Neighbor to display information about\n"
12196 "Neighbor on bgp configured interface\n"
12197 "Neighbor on bgp configured interface\n"
12198 "Display the routes advertised to a BGP neighbor\n"
12199 "JavaScript Object Notation\n")
12200 {
12201 struct peer *peer;
12202 u_char uj = use_json(argc, argv);
12203
12204 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12205 if (! peer)
12206 return CMD_WARNING;
12207
12208 bgp_show_ipv6_bgp_deprecate_warning(vty);
12209 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
12210 }
12211 #endif /* HAVE_IPV6 */
12212
12213 DEFUN (show_bgp_instance_neighbor_received_routes,
12214 show_bgp_instance_neighbor_received_routes_cmd,
12215 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12216 SHOW_STR
12217 BGP_STR
12218 BGP_INSTANCE_HELP_STR
12219 "Detailed information on TCP and BGP neighbor connections\n"
12220 "Neighbor to display information about\n"
12221 "Neighbor to display information about\n"
12222 "Neighbor on bgp configured interface\n"
12223 "Display the received routes from neighbor\n"
12224 "JavaScript Object Notation\n")
12225 {
12226 struct peer *peer;
12227 u_char uj = use_json(argc, argv);
12228
12229 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12230 if (! peer)
12231 return CMD_WARNING;
12232
12233 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
12234 }
12235
12236 DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12237 show_ip_bgp_instance_neighbor_received_routes_cmd,
12238 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12239 SHOW_STR
12240 IP_STR
12241 BGP_STR
12242 BGP_INSTANCE_HELP_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 received routes from neighbor\n"
12248 "JavaScript Object Notation\n")
12249 {
12250 struct peer *peer;
12251 u_char uj = use_json(argc, argv);
12252
12253 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12254 if (! peer)
12255 return CMD_WARNING;
12256
12257 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
12258 }
12259
12260 ALIAS (show_bgp_instance_neighbor_received_routes,
12261 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12262 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12263 SHOW_STR
12264 BGP_STR
12265 BGP_INSTANCE_HELP_STR
12266 "Address family\n"
12267 "Detailed information on TCP and BGP neighbor connections\n"
12268 "Neighbor to display information about\n"
12269 "Neighbor to display information about\n"
12270 "Neighbor on bgp configured interface\n"
12271 "Display the received routes from neighbor\n"
12272 "JavaScript Object Notation\n")
12273
12274 DEFUN (show_ip_bgp_neighbor_received_routes,
12275 show_ip_bgp_neighbor_received_routes_cmd,
12276 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12277 SHOW_STR
12278 IP_STR
12279 BGP_STR
12280 "Detailed information on TCP and BGP neighbor connections\n"
12281 "Neighbor to display information about\n"
12282 "Neighbor to display information about\n"
12283 "Neighbor on bgp configured interface\n"
12284 "Display the received routes from neighbor\n"
12285 "JavaScript Object Notation\n")
12286
12287 {
12288 struct peer *peer;
12289 const char *rmap_name = NULL;
12290 u_char uj = use_json(argc, argv);
12291
12292 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12293
12294 if (! peer)
12295 return CMD_WARNING;
12296
12297 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12298 rmap_name = argv[1];
12299
12300 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12301 }
12302
12303 ALIAS (show_ip_bgp_neighbor_received_routes,
12304 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12305 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12306 SHOW_STR
12307 IP_STR
12308 BGP_STR
12309 "Detailed information on TCP and BGP neighbor connections\n"
12310 "Neighbor to display information about\n"
12311 "Neighbor to display information about\n"
12312 "Neighbor on bgp configured interface\n"
12313 "Display the received routes from neighbor\n"
12314 "JavaScript Object Notation\n")
12315
12316 ALIAS (show_ip_bgp_instance_neighbor_received_routes,
12317 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
12318 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12319 SHOW_STR
12320 IP_STR
12321 BGP_STR
12322 BGP_INSTANCE_HELP_STR
12323 "Detailed information on TCP and BGP neighbor connections\n"
12324 "Neighbor to display information about\n"
12325 "Neighbor to display information about\n"
12326 "Neighbor on bgp configured interface\n"
12327 "Display the received routes from neighbor\n"
12328 "JavaScript Object Notation\n")
12329
12330 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12331 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12332 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12333 SHOW_STR
12334 IP_STR
12335 BGP_STR
12336 "Address family\n"
12337 "Address Family modifier\n"
12338 "Address Family modifier\n"
12339 "Detailed information on TCP and BGP neighbor connections\n"
12340 "Neighbor to display information about\n"
12341 "Neighbor to display information about\n"
12342 "Neighbor on bgp configured interface\n"
12343 "Display the received routes from neighbor\n"
12344 "JavaScript Object Notation\n")
12345 {
12346 struct peer *peer;
12347 const char *rmap_name = NULL;
12348 u_char uj = use_json(argc, argv);
12349
12350 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12351 if (! peer)
12352 return CMD_WARNING;
12353
12354 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12355 rmap_name = argv[2];
12356
12357 if (strncmp (argv[0], "m", 1) == 0)
12358 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj);
12359 else
12360 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12361 }
12362
12363 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12364 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
12365 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12366 SHOW_STR
12367 IP_STR
12368 BGP_STR
12369 "Address family\n"
12370 "Address Family modifier\n"
12371 "Address Family modifier\n"
12372 "Detailed information on TCP and BGP neighbor connections\n"
12373 "Neighbor to display information about\n"
12374 "Neighbor to display information about\n"
12375 "Neighbor on bgp configured interface\n"
12376 "Display the received routes from neighbor\n"
12377 "JavaScript Object Notation\n")
12378
12379 DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12380 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
12381 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
12382 SHOW_STR
12383 BGP_STR
12384 BGP_INSTANCE_HELP_STR
12385 "Address family\n"
12386 "Address family\n"
12387 "Address family modifier\n"
12388 "Address family modifier\n"
12389 "Detailed information on TCP and BGP neighbor connections\n"
12390 "Neighbor to display information about\n"
12391 "Neighbor to display information about\n"
12392 "Neighbor on bgp configured interface\n"
12393 "Display the advertised routes to neighbor\n"
12394 "Display the received routes from neighbor\n"
12395 "JavaScript Object Notation\n")
12396 {
12397 int afi;
12398 int safi;
12399 int in;
12400 struct peer *peer;
12401 u_char uj = use_json(argc, argv);
12402
12403 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
12404
12405 if (! peer)
12406 return CMD_WARNING;
12407
12408 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12409 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12410 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
12411
12412 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
12413 }
12414
12415 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12416 show_ip_bgp_neighbor_received_prefix_filter_cmd,
12417 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12418 SHOW_STR
12419 IP_STR
12420 BGP_STR
12421 "Detailed information on TCP and BGP neighbor connections\n"
12422 "Neighbor to display information about\n"
12423 "Neighbor to display information about\n"
12424 "Neighbor on bgp configured interface\n"
12425 "Display information received from a BGP neighbor\n"
12426 "Display the prefixlist filter\n"
12427 "JavaScript Object Notation\n")
12428 {
12429 char name[BUFSIZ];
12430 union sockunion su;
12431 struct peer *peer;
12432 int count, ret;
12433 u_char uj = use_json(argc, argv);
12434
12435 ret = str2sockunion (argv[0], &su);
12436 if (ret < 0)
12437 {
12438 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12439 if (! peer)
12440 {
12441 if (uj)
12442 {
12443 json_object *json_no = NULL;
12444 json_object *json_sub = NULL;
12445 json_no = json_object_new_object();
12446 json_sub = json_object_new_object();
12447 json_object_string_add(json_no, "warning", "Malformed address or name");
12448 json_object_string_add(json_sub, "warningCause", argv[0]);
12449 json_object_object_add(json_no, "detail", json_sub);
12450 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12451 json_object_free(json_no);
12452 }
12453 else
12454 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12455 return CMD_WARNING;
12456 }
12457 }
12458 else
12459 {
12460 peer = peer_lookup (NULL, &su);
12461 if (! peer)
12462 {
12463 if (uj)
12464 {
12465 json_object *json_no = NULL;
12466 json_no = json_object_new_object();
12467 json_object_string_add(json_no, "warning", "Peer not found");
12468 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12469 json_object_free(json_no);
12470 }
12471 else
12472 vty_out (vty, "No peer%s", VTY_NEWLINE);
12473 return CMD_WARNING;
12474 }
12475 }
12476
12477 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12478 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12479 if (count)
12480 {
12481 if (!uj)
12482 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12483 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12484 }
12485 else
12486 {
12487 if (uj)
12488 {
12489 json_object *json_no = NULL;
12490 json_no = json_object_new_object();
12491 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12492 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12493 json_object_free(json_no);
12494 }
12495 else
12496 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12497 }
12498
12499 return CMD_SUCCESS;
12500 }
12501
12502 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12503 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
12504 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12505 SHOW_STR
12506 IP_STR
12507 BGP_STR
12508 "Address family\n"
12509 "Address Family modifier\n"
12510 "Address Family modifier\n"
12511 "Detailed information on TCP and BGP neighbor connections\n"
12512 "Neighbor to display information about\n"
12513 "Neighbor to display information about\n"
12514 "Neighbor on bgp configured interface\n"
12515 "Display information received from a BGP neighbor\n"
12516 "Display the prefixlist filter\n"
12517 "JavaScript Object Notation\n")
12518 {
12519 char name[BUFSIZ];
12520 union sockunion su;
12521 struct peer *peer;
12522 int count, ret;
12523 u_char uj = use_json(argc, argv);
12524
12525 ret = str2sockunion (argv[1], &su);
12526 if (ret < 0)
12527 {
12528 peer = peer_lookup_by_conf_if (NULL, argv[1]);
12529 if (! peer)
12530 {
12531 if (uj)
12532 {
12533 json_object *json_no = NULL;
12534 json_object *json_sub = NULL;
12535 json_no = json_object_new_object();
12536 json_sub = json_object_new_object();
12537 json_object_string_add(json_no, "warning", "Malformed address or name");
12538 json_object_string_add(json_sub, "warningCause", argv[1]);
12539 json_object_object_add(json_no, "detail", json_sub);
12540 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12541 json_object_free(json_no);
12542 }
12543 else
12544 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12545 return CMD_WARNING;
12546 }
12547 }
12548 else
12549 {
12550 peer = peer_lookup (NULL, &su);
12551 if (! peer)
12552 {
12553 if (uj)
12554 {
12555 json_object *json_no = NULL;
12556 json_no = json_object_new_object();
12557 json_object_string_add(json_no, "warning", "Peer not found");
12558 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12559 json_object_free(json_no);
12560 }
12561 else
12562 vty_out (vty, "No peer%s", VTY_NEWLINE);
12563 return CMD_WARNING;
12564 }
12565 }
12566
12567 if (strncmp (argv[0], "m", 1) == 0)
12568 {
12569 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
12570 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12571 if (count)
12572 {
12573 if (!uj)
12574 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
12575 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12576 }
12577 else
12578 {
12579 if (uj)
12580 {
12581 json_object *json_no = NULL;
12582 json_no = json_object_new_object();
12583 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12584 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12585 json_object_free(json_no);
12586 }
12587 else
12588 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12589 }
12590 }
12591 else
12592 {
12593 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12594 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12595 if (count)
12596 {
12597 if (!uj)
12598 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12599 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12600 }
12601 else
12602 {
12603 if (uj)
12604 {
12605 json_object *json_no = NULL;
12606 json_no = json_object_new_object();
12607 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12608 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12609 json_object_free(json_no);
12610 }
12611 else
12612 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12613 }
12614 }
12615
12616 return CMD_SUCCESS;
12617 }
12618 #ifdef HAVE_IPV6
12619 DEFUN (show_bgp_neighbor_received_routes,
12620 show_bgp_neighbor_received_routes_cmd,
12621 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12622 SHOW_STR
12623 BGP_STR
12624 "Detailed information on TCP and BGP neighbor connections\n"
12625 "Neighbor to display information about\n"
12626 "Neighbor to display information about\n"
12627 "Neighbor on bgp configured interface\n"
12628 "Display the received routes from neighbor\n"
12629 "JavaScript Object Notation\n")
12630 {
12631 struct peer *peer;
12632 const char *rmap_name = NULL;
12633 u_char uj = use_json(argc, argv);
12634
12635 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12636
12637 if (! peer)
12638 return CMD_WARNING;
12639
12640 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12641 rmap_name = argv[1];
12642
12643 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
12644 }
12645
12646 ALIAS (show_bgp_neighbor_received_routes,
12647 show_bgp_ipv6_neighbor_received_routes_cmd,
12648 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12649 SHOW_STR
12650 BGP_STR
12651 "Address family\n"
12652 "Detailed information on TCP and BGP neighbor connections\n"
12653 "Neighbor to display information about\n"
12654 "Neighbor to display information about\n"
12655 "Neighbor on bgp configured interface\n"
12656 "Display the received routes from neighbor\n"
12657 "JavaScript Object Notation\n")
12658
12659 DEFUN (show_bgp_neighbor_received_prefix_filter,
12660 show_bgp_neighbor_received_prefix_filter_cmd,
12661 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12662 SHOW_STR
12663 BGP_STR
12664 "Detailed information on TCP and BGP neighbor connections\n"
12665 "Neighbor to display information about\n"
12666 "Neighbor to display information about\n"
12667 "Neighbor on bgp configured interface\n"
12668 "Display information received from a BGP neighbor\n"
12669 "Display the prefixlist filter\n"
12670 "JavaScript Object Notation\n")
12671 {
12672 char name[BUFSIZ];
12673 union sockunion su;
12674 struct peer *peer;
12675 int count, ret;
12676 u_char uj = use_json(argc, argv);
12677
12678 ret = str2sockunion (argv[0], &su);
12679 if (ret < 0)
12680 {
12681 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12682 if (! peer)
12683 {
12684 if (uj)
12685 {
12686 json_object *json_no = NULL;
12687 json_object *json_sub = NULL;
12688 json_no = json_object_new_object();
12689 json_sub = json_object_new_object();
12690 json_object_string_add(json_no, "warning", "Malformed address or name");
12691 json_object_string_add(json_sub, "warningCause", argv[0]);
12692 json_object_object_add(json_no, "detail", json_sub);
12693 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12694 json_object_free(json_no);
12695 }
12696 else
12697 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12698 return CMD_WARNING;
12699 }
12700 }
12701 else
12702 {
12703 peer = peer_lookup (NULL, &su);
12704 if (! peer)
12705 {
12706 if (uj)
12707 {
12708 json_object *json_no = NULL;
12709 json_no = json_object_new_object();
12710 json_object_string_add(json_no, "warning", "No Peer");
12711 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12712 json_object_free(json_no);
12713 }
12714 else
12715 vty_out (vty, "No peer%s", VTY_NEWLINE);
12716 return CMD_WARNING;
12717 }
12718 }
12719
12720 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12721 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
12722 if (count)
12723 {
12724 if (!uj)
12725 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12726 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
12727 }
12728 else
12729 {
12730 if (uj)
12731 {
12732 json_object *json_no = NULL;
12733 json_no = json_object_new_object();
12734 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12735 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12736 json_object_free(json_no);
12737 }
12738 else
12739 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12740 }
12741
12742 return CMD_SUCCESS;
12743 }
12744
12745 ALIAS (show_bgp_neighbor_received_prefix_filter,
12746 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
12747 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12748 SHOW_STR
12749 BGP_STR
12750 "Address family\n"
12751 "Detailed information on TCP and BGP neighbor connections\n"
12752 "Neighbor to display information about\n"
12753 "Neighbor to display information about\n"
12754 "Neighbor on bgp configured interface\n"
12755 "Display information received from a BGP neighbor\n"
12756 "Display the prefixlist filter\n"
12757 "JavaScript Object Notation\n")
12758
12759 /* old command */
12760 ALIAS (show_bgp_neighbor_received_routes,
12761 ipv6_bgp_neighbor_received_routes_cmd,
12762 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12763 SHOW_STR
12764 IPV6_STR
12765 BGP_STR
12766 "Detailed information on TCP and BGP neighbor connections\n"
12767 "Neighbor to display information about\n"
12768 "Neighbor to display information about\n"
12769 "Neighbor on bgp configured interface\n"
12770 "Display the received routes from neighbor\n"
12771 "JavaScript Object Notation\n")
12772
12773 /* old command */
12774 DEFUN (ipv6_mbgp_neighbor_received_routes,
12775 ipv6_mbgp_neighbor_received_routes_cmd,
12776 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12777 SHOW_STR
12778 IPV6_STR
12779 MBGP_STR
12780 "Detailed information on TCP and BGP neighbor connections\n"
12781 "Neighbor to display information about\n"
12782 "Neighbor to display information about\n"
12783 "Neighbor on bgp configured interface\n"
12784 "Display the received routes from neighbor\n"
12785 "JavaScript Object Notation\n")
12786 {
12787 struct peer *peer;
12788 u_char uj = use_json(argc, argv);
12789
12790 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12791 if (! peer)
12792 return CMD_WARNING;
12793
12794 bgp_show_ipv6_bgp_deprecate_warning(vty);
12795 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
12796 }
12797
12798 DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
12799 show_bgp_instance_neighbor_received_prefix_filter_cmd,
12800 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12801 SHOW_STR
12802 BGP_STR
12803 BGP_INSTANCE_HELP_STR
12804 "Detailed information on TCP and BGP neighbor connections\n"
12805 "Neighbor to display information about\n"
12806 "Neighbor to display information about\n"
12807 "Neighbor on bgp configured interface\n"
12808 "Display information received from a BGP neighbor\n"
12809 "Display the prefixlist filter\n"
12810 "JavaScript Object Notation\n")
12811 {
12812 char name[BUFSIZ];
12813 union sockunion su;
12814 struct peer *peer;
12815 struct bgp *bgp;
12816 int count, ret;
12817 u_char uj = use_json(argc, argv);
12818
12819 /* BGP structure lookup. */
12820 bgp = bgp_lookup_by_name (argv[1]);
12821 if (bgp == NULL)
12822 {
12823 if (uj)
12824 {
12825 json_object *json_no = NULL;
12826 json_no = json_object_new_object();
12827 json_object_string_add(json_no, "warning", "Can't find BGP view");
12828 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12829 json_object_free(json_no);
12830 }
12831 else
12832 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
12833 return CMD_WARNING;
12834 }
12835
12836 ret = str2sockunion (argv[2], &su);
12837 if (ret < 0)
12838 {
12839 peer = peer_lookup_by_conf_if (bgp, argv[2]);
12840 if (! peer)
12841 {
12842 if (uj)
12843 {
12844 json_object *json_no = NULL;
12845 json_object *json_sub = NULL;
12846 json_no = json_object_new_object();
12847 json_sub = json_object_new_object();
12848 json_object_string_add(json_no, "warning", "Malformed address or name");
12849 json_object_string_add(json_sub, "warningCause", argv[2]);
12850 json_object_object_add(json_no, "detail", json_sub);
12851 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12852 json_object_free(json_no);
12853 }
12854 else
12855 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
12856 return CMD_WARNING;
12857 }
12858 }
12859 else
12860 {
12861 peer = peer_lookup (bgp, &su);
12862 if (! peer)
12863 {
12864 if (uj)
12865 {
12866 json_object *json_no = NULL;
12867 json_no = json_object_new_object();
12868 json_object_boolean_true_add(json_no, "noPeer");
12869 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12870 json_object_free(json_no);
12871 }
12872 else
12873 vty_out (vty, "No peer%s", VTY_NEWLINE);
12874 return CMD_WARNING;
12875 }
12876
12877 }
12878
12879 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12880 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
12881 if (count)
12882 {
12883 if (!uj)
12884 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12885 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
12886 }
12887
12888 return CMD_SUCCESS;
12889 }
12890 ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
12891 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
12892 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12893 SHOW_STR
12894 BGP_STR
12895 BGP_INSTANCE_HELP_STR
12896 "Address family\n"
12897 "Detailed information on TCP and BGP neighbor connections\n"
12898 "Neighbor to display information about\n"
12899 "Neighbor to display information about\n"
12900 "Neighbor on bgp configured interface\n"
12901 "Display information received from a BGP neighbor\n"
12902 "Display the prefixlist filter\n"
12903 "JavaScript Object NOtation\n")
12904 #endif /* HAVE_IPV6 */
12905
12906 static int
12907 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
12908 safi_t safi, enum bgp_show_type type, u_char use_json)
12909 {
12910 if (! peer || ! peer->afc[afi][safi])
12911 {
12912 if (use_json)
12913 {
12914 json_object *json_no = NULL;
12915 json_no = json_object_new_object();
12916 json_object_string_add(json_no, "warning", "No such neighbor or address family");
12917 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12918 json_object_free(json_no);
12919 }
12920 else
12921 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12922 return CMD_WARNING;
12923 }
12924
12925 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
12926 }
12927
12928 DEFUN (show_ip_bgp_neighbor_routes,
12929 show_ip_bgp_neighbor_routes_cmd,
12930 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12931 SHOW_STR
12932 IP_STR
12933 BGP_STR
12934 "Detailed information on TCP and BGP neighbor connections\n"
12935 "Neighbor to display information about\n"
12936 "Neighbor to display information about\n"
12937 "Neighbor on bgp configured interface\n"
12938 "Display routes learned from neighbor\n"
12939 "JavaScript Object Notation\n")
12940 {
12941 struct peer *peer;
12942 u_char uj = use_json(argc, argv);
12943
12944 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12945 if (! peer)
12946 return CMD_WARNING;
12947
12948 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12949 bgp_show_type_neighbor, uj);
12950 }
12951
12952 DEFUN (show_ip_bgp_instance_neighbor_routes,
12953 show_ip_bgp_instance_neighbor_routes_cmd,
12954 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12955 SHOW_STR
12956 IP_STR
12957 BGP_STR
12958 BGP_INSTANCE_HELP_STR
12959 "Detailed information on TCP and BGP neighbor connections\n"
12960 "Neighbor to display information about\n"
12961 "Neighbor to display information about\n"
12962 "Neighbor on bgp configured interface\n"
12963 "Display routes learned from neighbor\n"
12964 "JavaScript Object Notation\n")
12965 {
12966 struct peer *peer;
12967 u_char uj = use_json(argc, argv);
12968
12969 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12970 if (! peer)
12971 return CMD_WARNING;
12972
12973 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12974 bgp_show_type_neighbor, uj);
12975 }
12976
12977 DEFUN (show_ip_bgp_neighbor_flap,
12978 show_ip_bgp_neighbor_flap_cmd,
12979 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
12980 SHOW_STR
12981 IP_STR
12982 BGP_STR
12983 "Detailed information on TCP and BGP neighbor connections\n"
12984 "Neighbor to display information about\n"
12985 "Neighbor to display information about\n"
12986 "Neighbor on bgp configured interface\n"
12987 "Display flap statistics of the routes learned from neighbor\n"
12988 "JavaScript Object Notation\n")
12989 {
12990 struct peer *peer;
12991 u_char uj = use_json(argc, argv);
12992
12993 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12994 if (! peer)
12995 return CMD_WARNING;
12996
12997 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12998 bgp_show_type_flap_neighbor, uj);
12999 }
13000
13001 DEFUN (show_ip_bgp_neighbor_damp,
13002 show_ip_bgp_neighbor_damp_cmd,
13003 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13004 SHOW_STR
13005 IP_STR
13006 BGP_STR
13007 "Detailed information on TCP and BGP neighbor connections\n"
13008 "Neighbor to display information about\n"
13009 "Neighbor to display information about\n"
13010 "Neighbor on bgp configured interface\n"
13011 "Display the dampened routes received from neighbor\n"
13012 "JavaScript Object Notation\n")
13013 {
13014 struct peer *peer;
13015 u_char uj = use_json(argc, argv);
13016
13017 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13018 if (! peer)
13019 return CMD_WARNING;
13020
13021 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13022 bgp_show_type_damp_neighbor, uj);
13023 }
13024
13025 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13026 show_ip_bgp_ipv4_neighbor_routes_cmd,
13027 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13028 SHOW_STR
13029 IP_STR
13030 BGP_STR
13031 "Address family\n"
13032 "Address Family modifier\n"
13033 "Address Family modifier\n"
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 routes learned 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[1], uj);
13045 if (! peer)
13046 return CMD_WARNING;
13047
13048 if (strncmp (argv[0], "m", 1) == 0)
13049 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13050 bgp_show_type_neighbor, uj);
13051
13052 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13053 bgp_show_type_neighbor, uj);
13054 }
13055
13056 #ifdef HAVE_IPV6
13057 DEFUN (show_bgp_instance_neighbor_routes,
13058 show_bgp_instance_neighbor_routes_cmd,
13059 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13060 SHOW_STR
13061 BGP_STR
13062 BGP_INSTANCE_HELP_STR
13063 "Detailed information on TCP and BGP neighbor connections\n"
13064 "Neighbor to display information about\n"
13065 "Neighbor to display information about\n"
13066 "Neighbor on bgp configured interface\n"
13067 "Display routes learned from neighbor\n"
13068 "JavaScript Object Notation\n")
13069 {
13070 struct peer *peer;
13071 u_char uj = use_json(argc, argv);
13072
13073 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13074 if (! peer)
13075 return CMD_WARNING;
13076
13077 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13078 bgp_show_type_neighbor, uj);
13079 }
13080
13081 ALIAS (show_bgp_instance_neighbor_routes,
13082 show_bgp_instance_ipv6_neighbor_routes_cmd,
13083 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13084 SHOW_STR
13085 BGP_STR
13086 BGP_INSTANCE_HELP_STR
13087 "Address family\n"
13088 "Detailed information on TCP and BGP neighbor connections\n"
13089 "Neighbor to display information about\n"
13090 "Neighbor to display information about\n"
13091 "Neighbor on bgp configured interface\n"
13092 "Display routes learned from neighbor\n"
13093 "JavaScript Object Notation\n")
13094
13095 DEFUN (show_bgp_instance_neighbor_damp,
13096 show_bgp_instance_neighbor_damp_cmd,
13097 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13098 SHOW_STR
13099 BGP_STR
13100 BGP_INSTANCE_HELP_STR
13101 "Detailed information on TCP and BGP neighbor connections\n"
13102 "Neighbor to display information about\n"
13103 "Neighbor to display information about\n"
13104 "Neighbor on bgp configured interface\n"
13105 "Display the dampened routes received from neighbor\n"
13106 "JavaScript Object Notation\n")
13107 {
13108 struct peer *peer;
13109 u_char uj = use_json(argc, argv);
13110
13111 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13112 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13113 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13114 else
13115 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13116
13117 if (! peer)
13118 return CMD_WARNING;
13119
13120 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13121 bgp_show_type_damp_neighbor, uj);
13122 }
13123
13124 ALIAS (show_bgp_instance_neighbor_damp,
13125 show_bgp_instance_ipv6_neighbor_damp_cmd,
13126 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13127 SHOW_STR
13128 BGP_STR
13129 BGP_INSTANCE_HELP_STR
13130 "Address family\n"
13131 "Detailed information on TCP and BGP neighbor connections\n"
13132 "Neighbor to display information about\n"
13133 "Neighbor to display information about\n"
13134 "Neighbor on bgp configured interface\n"
13135 "Display the dampened routes received from neighbor\n"
13136 "JavaScript Object Notation\n")
13137
13138 DEFUN (show_bgp_instance_neighbor_flap,
13139 show_bgp_instance_neighbor_flap_cmd,
13140 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13141 SHOW_STR
13142 BGP_STR
13143 BGP_INSTANCE_HELP_STR
13144 "Detailed information on TCP and BGP neighbor connections\n"
13145 "Neighbor to display information about\n"
13146 "Neighbor to display information about\n"
13147 "Neighbor on bgp configured interface\n"
13148 "Display flap statistics of the routes learned from neighbor\n"
13149 "JavaScript Object Notation\n")
13150 {
13151 struct peer *peer;
13152 u_char uj = use_json(argc, argv);
13153
13154 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13155 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13156 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13157 else
13158 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13159
13160 if (! peer)
13161 return CMD_WARNING;
13162
13163 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13164 bgp_show_type_flap_neighbor, uj);
13165 }
13166
13167 ALIAS (show_bgp_instance_neighbor_flap,
13168 show_bgp_instance_ipv6_neighbor_flap_cmd,
13169 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13170 SHOW_STR
13171 BGP_STR
13172 BGP_INSTANCE_HELP_STR
13173 "Address family\n"
13174 "Detailed information on TCP and BGP neighbor connections\n"
13175 "Neighbor to display information about\n"
13176 "Neighbor to display information about\n"
13177 "Neighbor on bgp configured interface\n"
13178 "Display flap statistics of the routes learned from neighbor\n"
13179 "JavaScript Object Notation\n")
13180
13181 DEFUN (show_bgp_neighbor_routes,
13182 show_bgp_neighbor_routes_cmd,
13183 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13184 SHOW_STR
13185 BGP_STR
13186 "Detailed information on TCP and BGP neighbor connections\n"
13187 "Neighbor to display information about\n"
13188 "Neighbor to display information about\n"
13189 "Neighbor on bgp configured interface\n"
13190 "Display routes learned from neighbor\n"
13191 "JavaScript Object Notation\n")
13192 {
13193 struct peer *peer;
13194 u_char uj = use_json(argc, argv);
13195
13196 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13197 if (! peer)
13198 return CMD_WARNING;
13199
13200 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13201 bgp_show_type_neighbor, uj);
13202 }
13203
13204
13205 ALIAS (show_bgp_neighbor_routes,
13206 show_bgp_ipv6_neighbor_routes_cmd,
13207 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13208 SHOW_STR
13209 BGP_STR
13210 "Address family\n"
13211 "Detailed information on TCP and BGP neighbor connections\n"
13212 "Neighbor to display information about\n"
13213 "Neighbor to display information about\n"
13214 "Neighbor on bgp configured interface\n"
13215 "Display routes learned from neighbor\n"
13216 "JavaScript Object Notation\n")
13217
13218 /* old command */
13219 ALIAS (show_bgp_neighbor_routes,
13220 ipv6_bgp_neighbor_routes_cmd,
13221 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13222 SHOW_STR
13223 IPV6_STR
13224 BGP_STR
13225 "Detailed information on TCP and BGP neighbor connections\n"
13226 "Neighbor to display information about\n"
13227 "Neighbor to display information about\n"
13228 "Neighbor on bgp configured interface\n"
13229 "Display routes learned from neighbor\n"
13230 "JavaScript Object Notation\n")
13231
13232 /* old command */
13233 DEFUN (ipv6_mbgp_neighbor_routes,
13234 ipv6_mbgp_neighbor_routes_cmd,
13235 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13236 SHOW_STR
13237 IPV6_STR
13238 MBGP_STR
13239 "Detailed information on TCP and BGP neighbor connections\n"
13240 "Neighbor to display information about\n"
13241 "Neighbor to display information about\n"
13242 "Neighbor on bgp configured interface\n"
13243 "Display routes learned from neighbor\n"
13244 "JavaScript Object Notation\n")
13245 {
13246 struct peer *peer;
13247 u_char uj = use_json(argc, argv);
13248
13249 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13250 if (! peer)
13251 return CMD_WARNING;
13252
13253 bgp_show_ipv6_bgp_deprecate_warning(vty);
13254 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
13255 bgp_show_type_neighbor, uj);
13256 }
13257
13258 ALIAS (show_bgp_instance_neighbor_flap,
13259 show_bgp_neighbor_flap_cmd,
13260 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13261 SHOW_STR
13262 BGP_STR
13263 "Detailed information on TCP and BGP neighbor connections\n"
13264 "Neighbor to display information about\n"
13265 "Neighbor to display information about\n"
13266 "Neighbor on bgp configured interface\n"
13267 "Display flap statistics of the routes learned from neighbor\n"
13268 "JavaScript Object Notation\n")
13269
13270 ALIAS (show_bgp_instance_neighbor_flap,
13271 show_bgp_ipv6_neighbor_flap_cmd,
13272 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13273 SHOW_STR
13274 BGP_STR
13275 "Address family\n"
13276 "Detailed information on TCP and BGP neighbor connections\n"
13277 "Neighbor to display information about\n"
13278 "Neighbor to display information about\n"
13279 "Neighbor on bgp configured interface\n"
13280 "Display flap statistics of the routes learned from neighbor\n"
13281 "JavaScript Object Notation\n")
13282
13283 ALIAS (show_bgp_instance_neighbor_damp,
13284 show_bgp_neighbor_damp_cmd,
13285 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13286 SHOW_STR
13287 BGP_STR
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 the dampened routes received from neighbor\n"
13293 "JavaScript Object Notation\n")
13294
13295 ALIAS (show_bgp_instance_neighbor_damp,
13296 show_bgp_ipv6_neighbor_damp_cmd,
13297 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13298 SHOW_STR
13299 BGP_STR
13300 "Address family\n"
13301 "Detailed information on TCP and BGP neighbor connections\n"
13302 "Neighbor to display information about\n"
13303 "Neighbor to display information about\n"
13304 "Neighbor on bgp configured interface\n"
13305 "Display the dampened routes received from neighbor\n"
13306 "JavaScript Object Notation\n")
13307
13308 #endif /* HAVE_IPV6 */
13309
13310 struct bgp_table *bgp_distance_table;
13311
13312 struct bgp_distance
13313 {
13314 /* Distance value for the IP source prefix. */
13315 u_char distance;
13316
13317 /* Name of the access-list to be matched. */
13318 char *access_list;
13319 };
13320
13321 static struct bgp_distance *
13322 bgp_distance_new (void)
13323 {
13324 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
13325 }
13326
13327 static void
13328 bgp_distance_free (struct bgp_distance *bdistance)
13329 {
13330 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13331 }
13332
13333 static int
13334 bgp_distance_set (struct vty *vty, const char *distance_str,
13335 const char *ip_str, const char *access_list_str)
13336 {
13337 int ret;
13338 struct prefix_ipv4 p;
13339 u_char distance;
13340 struct bgp_node *rn;
13341 struct bgp_distance *bdistance;
13342
13343 ret = str2prefix_ipv4 (ip_str, &p);
13344 if (ret == 0)
13345 {
13346 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13347 return CMD_WARNING;
13348 }
13349
13350 distance = atoi (distance_str);
13351
13352 /* Get BGP distance node. */
13353 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
13354 if (rn->info)
13355 {
13356 bdistance = rn->info;
13357 bgp_unlock_node (rn);
13358 }
13359 else
13360 {
13361 bdistance = bgp_distance_new ();
13362 rn->info = bdistance;
13363 }
13364
13365 /* Set distance value. */
13366 bdistance->distance = distance;
13367
13368 /* Reset access-list configuration. */
13369 if (bdistance->access_list)
13370 {
13371 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13372 bdistance->access_list = NULL;
13373 }
13374 if (access_list_str)
13375 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
13376
13377 return CMD_SUCCESS;
13378 }
13379
13380 static int
13381 bgp_distance_unset (struct vty *vty, const char *distance_str,
13382 const char *ip_str, const char *access_list_str)
13383 {
13384 int ret;
13385 int distance;
13386 struct prefix_ipv4 p;
13387 struct bgp_node *rn;
13388 struct bgp_distance *bdistance;
13389
13390 ret = str2prefix_ipv4 (ip_str, &p);
13391 if (ret == 0)
13392 {
13393 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13394 return CMD_WARNING;
13395 }
13396
13397 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
13398 if (! rn)
13399 {
13400 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13401 return CMD_WARNING;
13402 }
13403
13404 bdistance = rn->info;
13405 distance = atoi(distance_str);
13406
13407 if (bdistance->distance != distance)
13408 {
13409 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
13410 return CMD_WARNING;
13411 }
13412
13413 if (bdistance->access_list)
13414 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13415 bgp_distance_free (bdistance);
13416
13417 rn->info = NULL;
13418 bgp_unlock_node (rn);
13419 bgp_unlock_node (rn);
13420
13421 return CMD_SUCCESS;
13422 }
13423
13424 /* Apply BGP information to distance method. */
13425 u_char
13426 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
13427 {
13428 struct bgp_node *rn;
13429 struct prefix_ipv4 q;
13430 struct peer *peer;
13431 struct bgp_distance *bdistance;
13432 struct access_list *alist;
13433 struct bgp_static *bgp_static;
13434
13435 if (! bgp)
13436 return 0;
13437
13438 if (p->family != AF_INET)
13439 return 0;
13440
13441 peer = rinfo->peer;
13442
13443 if (peer->su.sa.sa_family != AF_INET)
13444 return 0;
13445
13446 memset (&q, 0, sizeof (struct prefix_ipv4));
13447 q.family = AF_INET;
13448 q.prefix = peer->su.sin.sin_addr;
13449 q.prefixlen = IPV4_MAX_BITLEN;
13450
13451 /* Check source address. */
13452 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
13453 if (rn)
13454 {
13455 bdistance = rn->info;
13456 bgp_unlock_node (rn);
13457
13458 if (bdistance->access_list)
13459 {
13460 alist = access_list_lookup (AFI_IP, bdistance->access_list);
13461 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13462 return bdistance->distance;
13463 }
13464 else
13465 return bdistance->distance;
13466 }
13467
13468 /* Backdoor check. */
13469 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
13470 if (rn)
13471 {
13472 bgp_static = rn->info;
13473 bgp_unlock_node (rn);
13474
13475 if (bgp_static->backdoor)
13476 {
13477 if (bgp->distance_local)
13478 return bgp->distance_local;
13479 else
13480 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13481 }
13482 }
13483
13484 if (peer->sort == BGP_PEER_EBGP)
13485 {
13486 if (bgp->distance_ebgp)
13487 return bgp->distance_ebgp;
13488 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13489 }
13490 else
13491 {
13492 if (bgp->distance_ibgp)
13493 return bgp->distance_ibgp;
13494 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13495 }
13496 }
13497
13498 DEFUN (bgp_distance,
13499 bgp_distance_cmd,
13500 "distance bgp <1-255> <1-255> <1-255>",
13501 "Define an administrative distance\n"
13502 "BGP distance\n"
13503 "Distance for routes external to the AS\n"
13504 "Distance for routes internal to the AS\n"
13505 "Distance for local routes\n")
13506 {
13507 struct bgp *bgp;
13508
13509 bgp = vty->index;
13510
13511 bgp->distance_ebgp = atoi (argv[0]);
13512 bgp->distance_ibgp = atoi (argv[1]);
13513 bgp->distance_local = atoi (argv[2]);
13514 return CMD_SUCCESS;
13515 }
13516
13517 DEFUN (no_bgp_distance,
13518 no_bgp_distance_cmd,
13519 "no distance bgp <1-255> <1-255> <1-255>",
13520 NO_STR
13521 "Define an administrative distance\n"
13522 "BGP distance\n"
13523 "Distance for routes external to the AS\n"
13524 "Distance for routes internal to the AS\n"
13525 "Distance for local routes\n")
13526 {
13527 struct bgp *bgp;
13528
13529 bgp = vty->index;
13530
13531 bgp->distance_ebgp= 0;
13532 bgp->distance_ibgp = 0;
13533 bgp->distance_local = 0;
13534 return CMD_SUCCESS;
13535 }
13536
13537 ALIAS (no_bgp_distance,
13538 no_bgp_distance2_cmd,
13539 "no distance bgp",
13540 NO_STR
13541 "Define an administrative distance\n"
13542 "BGP distance\n")
13543
13544 DEFUN (bgp_distance_source,
13545 bgp_distance_source_cmd,
13546 "distance <1-255> A.B.C.D/M",
13547 "Define an administrative distance\n"
13548 "Administrative distance\n"
13549 "IP source prefix\n")
13550 {
13551 bgp_distance_set (vty, argv[0], argv[1], NULL);
13552 return CMD_SUCCESS;
13553 }
13554
13555 DEFUN (no_bgp_distance_source,
13556 no_bgp_distance_source_cmd,
13557 "no distance <1-255> A.B.C.D/M",
13558 NO_STR
13559 "Define an administrative distance\n"
13560 "Administrative distance\n"
13561 "IP source prefix\n")
13562 {
13563 bgp_distance_unset (vty, argv[0], argv[1], NULL);
13564 return CMD_SUCCESS;
13565 }
13566
13567 DEFUN (bgp_distance_source_access_list,
13568 bgp_distance_source_access_list_cmd,
13569 "distance <1-255> A.B.C.D/M WORD",
13570 "Define an administrative distance\n"
13571 "Administrative distance\n"
13572 "IP source prefix\n"
13573 "Access list name\n")
13574 {
13575 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
13576 return CMD_SUCCESS;
13577 }
13578
13579 DEFUN (no_bgp_distance_source_access_list,
13580 no_bgp_distance_source_access_list_cmd,
13581 "no distance <1-255> A.B.C.D/M WORD",
13582 NO_STR
13583 "Define an administrative distance\n"
13584 "Administrative distance\n"
13585 "IP source prefix\n"
13586 "Access list name\n")
13587 {
13588 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
13589 return CMD_SUCCESS;
13590 }
13591
13592 DEFUN (bgp_damp_set,
13593 bgp_damp_set_cmd,
13594 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13595 "BGP Specific commands\n"
13596 "Enable route-flap dampening\n"
13597 "Half-life time for the penalty\n"
13598 "Value to start reusing a route\n"
13599 "Value to start suppressing a route\n"
13600 "Maximum duration to suppress a stable route\n")
13601 {
13602 struct bgp *bgp;
13603 int half = DEFAULT_HALF_LIFE * 60;
13604 int reuse = DEFAULT_REUSE;
13605 int suppress = DEFAULT_SUPPRESS;
13606 int max = 4 * half;
13607
13608 if (argc == 4)
13609 {
13610 half = atoi (argv[0]) * 60;
13611 reuse = atoi (argv[1]);
13612 suppress = atoi (argv[2]);
13613 max = atoi (argv[3]) * 60;
13614 }
13615 else if (argc == 1)
13616 {
13617 half = atoi (argv[0]) * 60;
13618 max = 4 * half;
13619 }
13620
13621 bgp = vty->index;
13622
13623 if (suppress < reuse)
13624 {
13625 vty_out (vty, "Suppress value cannot be less than reuse value %s",
13626 VTY_NEWLINE);
13627 return 0;
13628 }
13629
13630 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
13631 half, reuse, suppress, max);
13632 }
13633
13634 ALIAS (bgp_damp_set,
13635 bgp_damp_set2_cmd,
13636 "bgp dampening <1-45>",
13637 "BGP Specific commands\n"
13638 "Enable route-flap dampening\n"
13639 "Half-life time for the penalty\n")
13640
13641 ALIAS (bgp_damp_set,
13642 bgp_damp_set3_cmd,
13643 "bgp dampening",
13644 "BGP Specific commands\n"
13645 "Enable route-flap dampening\n")
13646
13647 DEFUN (bgp_damp_unset,
13648 bgp_damp_unset_cmd,
13649 "no bgp dampening",
13650 NO_STR
13651 "BGP Specific commands\n"
13652 "Enable route-flap dampening\n")
13653 {
13654 struct bgp *bgp;
13655
13656 bgp = vty->index;
13657 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
13658 }
13659
13660 ALIAS (bgp_damp_unset,
13661 bgp_damp_unset2_cmd,
13662 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13663 NO_STR
13664 "BGP Specific commands\n"
13665 "Enable route-flap dampening\n"
13666 "Half-life time for the penalty\n"
13667 "Value to start reusing a route\n"
13668 "Value to start suppressing a route\n"
13669 "Maximum duration to suppress a stable route\n")
13670
13671 ALIAS (bgp_damp_unset,
13672 bgp_damp_unset3_cmd,
13673 "no bgp dampening <1-45>",
13674 NO_STR
13675 "BGP Specific commands\n"
13676 "Enable route-flap dampening\n"
13677 "Half-life time for the penalty\n")
13678
13679 DEFUN (show_ip_bgp_dampened_paths,
13680 show_ip_bgp_dampened_paths_cmd,
13681 "show ip bgp dampened-paths",
13682 SHOW_STR
13683 IP_STR
13684 BGP_STR
13685 "Display paths suppressed due to dampening\n")
13686 {
13687 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
13688 NULL, 0);
13689 }
13690
13691 ALIAS (show_ip_bgp_dampened_paths,
13692 show_ip_bgp_damp_dampened_paths_cmd,
13693 "show ip bgp dampening dampened-paths",
13694 SHOW_STR
13695 IP_STR
13696 BGP_STR
13697 "Display detailed information about dampening\n"
13698 "Display paths suppressed due to dampening\n")
13699
13700 DEFUN (show_ip_bgp_flap_statistics,
13701 show_ip_bgp_flap_statistics_cmd,
13702 "show ip bgp flap-statistics",
13703 SHOW_STR
13704 IP_STR
13705 BGP_STR
13706 "Display flap statistics of routes\n")
13707 {
13708 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
13709 bgp_show_type_flap_statistics, NULL, 0);
13710 }
13711
13712 ALIAS (show_ip_bgp_flap_statistics,
13713 show_ip_bgp_damp_flap_statistics_cmd,
13714 "show ip bgp dampening flap-statistics",
13715 SHOW_STR
13716 IP_STR
13717 BGP_STR
13718 "Display detailed information about dampening\n"
13719 "Display flap statistics of routes\n")
13720
13721 /* Display specified route of BGP table. */
13722 static int
13723 bgp_clear_damp_route (struct vty *vty, const char *view_name,
13724 const char *ip_str, afi_t afi, safi_t safi,
13725 struct prefix_rd *prd, int prefix_check)
13726 {
13727 int ret;
13728 struct prefix match;
13729 struct bgp_node *rn;
13730 struct bgp_node *rm;
13731 struct bgp_info *ri;
13732 struct bgp_info *ri_temp;
13733 struct bgp *bgp;
13734 struct bgp_table *table;
13735
13736 /* BGP structure lookup. */
13737 if (view_name)
13738 {
13739 bgp = bgp_lookup_by_name (view_name);
13740 if (bgp == NULL)
13741 {
13742 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
13743 return CMD_WARNING;
13744 }
13745 }
13746 else
13747 {
13748 bgp = bgp_get_default ();
13749 if (bgp == NULL)
13750 {
13751 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
13752 return CMD_WARNING;
13753 }
13754 }
13755
13756 /* Check IP address argument. */
13757 ret = str2prefix (ip_str, &match);
13758 if (! ret)
13759 {
13760 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
13761 return CMD_WARNING;
13762 }
13763
13764 match.family = afi2family (afi);
13765
13766 if (safi == SAFI_MPLS_VPN)
13767 {
13768 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
13769 {
13770 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
13771 continue;
13772
13773 if ((table = rn->info) != NULL)
13774 if ((rm = bgp_node_match (table, &match)) != NULL)
13775 {
13776 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
13777 {
13778 ri = rm->info;
13779 while (ri)
13780 {
13781 if (ri->extra && ri->extra->damp_info)
13782 {
13783 ri_temp = ri->next;
13784 bgp_damp_info_free (ri->extra->damp_info, 1);
13785 ri = ri_temp;
13786 }
13787 else
13788 ri = ri->next;
13789 }
13790 }
13791
13792 bgp_unlock_node (rm);
13793 }
13794 }
13795 }
13796 else
13797 {
13798 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
13799 {
13800 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
13801 {
13802 ri = rn->info;
13803 while (ri)
13804 {
13805 if (ri->extra && ri->extra->damp_info)
13806 {
13807 ri_temp = ri->next;
13808 bgp_damp_info_free (ri->extra->damp_info, 1);
13809 ri = ri_temp;
13810 }
13811 else
13812 ri = ri->next;
13813 }
13814 }
13815
13816 bgp_unlock_node (rn);
13817 }
13818 }
13819
13820 return CMD_SUCCESS;
13821 }
13822
13823 DEFUN (clear_ip_bgp_dampening,
13824 clear_ip_bgp_dampening_cmd,
13825 "clear ip bgp dampening",
13826 CLEAR_STR
13827 IP_STR
13828 BGP_STR
13829 "Clear route flap dampening information\n")
13830 {
13831 bgp_damp_info_clean ();
13832 return CMD_SUCCESS;
13833 }
13834
13835 DEFUN (clear_ip_bgp_dampening_prefix,
13836 clear_ip_bgp_dampening_prefix_cmd,
13837 "clear ip bgp dampening A.B.C.D/M",
13838 CLEAR_STR
13839 IP_STR
13840 BGP_STR
13841 "Clear route flap dampening information\n"
13842 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13843 {
13844 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13845 SAFI_UNICAST, NULL, 1);
13846 }
13847
13848 DEFUN (clear_ip_bgp_dampening_address,
13849 clear_ip_bgp_dampening_address_cmd,
13850 "clear ip bgp dampening A.B.C.D",
13851 CLEAR_STR
13852 IP_STR
13853 BGP_STR
13854 "Clear route flap dampening information\n"
13855 "Network to clear damping information\n")
13856 {
13857 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13858 SAFI_UNICAST, NULL, 0);
13859 }
13860
13861 DEFUN (clear_ip_bgp_dampening_address_mask,
13862 clear_ip_bgp_dampening_address_mask_cmd,
13863 "clear ip bgp dampening A.B.C.D A.B.C.D",
13864 CLEAR_STR
13865 IP_STR
13866 BGP_STR
13867 "Clear route flap dampening information\n"
13868 "Network to clear damping information\n"
13869 "Network mask\n")
13870 {
13871 int ret;
13872 char prefix_str[BUFSIZ];
13873
13874 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
13875 if (! ret)
13876 {
13877 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
13878 return CMD_WARNING;
13879 }
13880
13881 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
13882 SAFI_UNICAST, NULL, 0);
13883 }
13884
13885 static int
13886 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
13887 afi_t afi, safi_t safi, int *write)
13888 {
13889 struct bgp_node *prn;
13890 struct bgp_node *rn;
13891 struct bgp_table *table;
13892 struct prefix *p;
13893 struct prefix_rd *prd;
13894 struct bgp_static *bgp_static;
13895 u_int32_t label;
13896 char buf[SU_ADDRSTRLEN];
13897 char rdbuf[RD_ADDRSTRLEN];
13898
13899 /* Network configuration. */
13900 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
13901 if ((table = prn->info) != NULL)
13902 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
13903 if ((bgp_static = rn->info) != NULL)
13904 {
13905 p = &rn->p;
13906 prd = (struct prefix_rd *) &prn->p;
13907
13908 /* "address-family" display. */
13909 bgp_config_write_family_header (vty, afi, safi, write);
13910
13911 /* "network" configuration display. */
13912 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
13913 label = decode_label (bgp_static->tag);
13914
13915 vty_out (vty, " network %s/%d rd %s tag %d",
13916 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13917 p->prefixlen,
13918 rdbuf, label);
13919 vty_out (vty, "%s", VTY_NEWLINE);
13920 }
13921 return 0;
13922 }
13923
13924 /* Configuration of static route announcement and aggregate
13925 information. */
13926 int
13927 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
13928 afi_t afi, safi_t safi, int *write)
13929 {
13930 struct bgp_node *rn;
13931 struct prefix *p;
13932 struct bgp_static *bgp_static;
13933 struct bgp_aggregate *bgp_aggregate;
13934 char buf[SU_ADDRSTRLEN];
13935
13936 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
13937 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
13938
13939 /* Network configuration. */
13940 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
13941 if ((bgp_static = rn->info) != NULL)
13942 {
13943 p = &rn->p;
13944
13945 /* "address-family" display. */
13946 bgp_config_write_family_header (vty, afi, safi, write);
13947
13948 /* "network" configuration display. */
13949 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13950 {
13951 u_int32_t destination;
13952 struct in_addr netmask;
13953
13954 destination = ntohl (p->u.prefix4.s_addr);
13955 masklen2ip (p->prefixlen, &netmask);
13956 vty_out (vty, " network %s",
13957 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
13958
13959 if ((IN_CLASSC (destination) && p->prefixlen == 24)
13960 || (IN_CLASSB (destination) && p->prefixlen == 16)
13961 || (IN_CLASSA (destination) && p->prefixlen == 8)
13962 || p->u.prefix4.s_addr == 0)
13963 {
13964 /* Natural mask is not display. */
13965 }
13966 else
13967 vty_out (vty, " mask %s", inet_ntoa (netmask));
13968 }
13969 else
13970 {
13971 vty_out (vty, " network %s/%d",
13972 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13973 p->prefixlen);
13974 }
13975
13976 if (bgp_static->rmap.name)
13977 vty_out (vty, " route-map %s", bgp_static->rmap.name);
13978 else
13979 {
13980 if (bgp_static->backdoor)
13981 vty_out (vty, " backdoor");
13982 }
13983
13984 vty_out (vty, "%s", VTY_NEWLINE);
13985 }
13986
13987 /* Aggregate-address configuration. */
13988 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
13989 if ((bgp_aggregate = rn->info) != NULL)
13990 {
13991 p = &rn->p;
13992
13993 /* "address-family" display. */
13994 bgp_config_write_family_header (vty, afi, safi, write);
13995
13996 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13997 {
13998 struct in_addr netmask;
13999
14000 masklen2ip (p->prefixlen, &netmask);
14001 vty_out (vty, " aggregate-address %s %s",
14002 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14003 inet_ntoa (netmask));
14004 }
14005 else
14006 {
14007 vty_out (vty, " aggregate-address %s/%d",
14008 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14009 p->prefixlen);
14010 }
14011
14012 if (bgp_aggregate->as_set)
14013 vty_out (vty, " as-set");
14014
14015 if (bgp_aggregate->summary_only)
14016 vty_out (vty, " summary-only");
14017
14018 vty_out (vty, "%s", VTY_NEWLINE);
14019 }
14020
14021 return 0;
14022 }
14023
14024 int
14025 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
14026 {
14027 struct bgp_node *rn;
14028 struct bgp_distance *bdistance;
14029
14030 /* Distance configuration. */
14031 if (bgp->distance_ebgp
14032 && bgp->distance_ibgp
14033 && bgp->distance_local
14034 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
14035 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
14036 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
14037 vty_out (vty, " distance bgp %d %d %d%s",
14038 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
14039 VTY_NEWLINE);
14040
14041 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
14042 if ((bdistance = rn->info) != NULL)
14043 {
14044 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
14045 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
14046 bdistance->access_list ? bdistance->access_list : "",
14047 VTY_NEWLINE);
14048 }
14049
14050 return 0;
14051 }
14052
14053 /* Allocate routing table structure and install commands. */
14054 void
14055 bgp_route_init (void)
14056 {
14057 /* Init BGP distance table. */
14058 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
14059
14060 /* IPv4 BGP commands. */
14061 install_element (BGP_NODE, &bgp_table_map_cmd);
14062 install_element (BGP_NODE, &bgp_network_cmd);
14063 install_element (BGP_NODE, &bgp_network_mask_cmd);
14064 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14065 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14066 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14067 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14068 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14069 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14070 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
14071 install_element (BGP_NODE, &no_bgp_table_map_cmd);
14072 install_element (BGP_NODE, &no_bgp_network_cmd);
14073 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14074 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14075 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14076 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14077 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14078 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14079 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14080 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14081
14082 install_element (BGP_NODE, &aggregate_address_cmd);
14083 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14084 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14085 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14086 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14087 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14088 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14089 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14090 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14091 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14092 install_element (BGP_NODE, &no_aggregate_address_cmd);
14093 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14094 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14095 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14096 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14097 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14098 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14099 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14100 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14101 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14102
14103 /* IPv4 unicast configuration. */
14104 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
14105 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14106 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14107 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14108 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14109 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14110 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
14111 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
14112 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
14113 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14114 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14115 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14116 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14117 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14118
14119 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14120 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14121 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14122 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14123 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14124 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14125 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14126 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14127 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14128 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14129 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14130 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14131 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14132 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14133 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14134 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14135 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14136 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14137 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14138 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14139
14140 /* IPv4 multicast configuration. */
14141 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
14142 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14143 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14144 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14145 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14146 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14147 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
14148 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
14149 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14150 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14151 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14152 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14153 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14154 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14155 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14156 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14157 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14158 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14159 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14160 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14161 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14162 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14163 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14164 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14165 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14166 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14167 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14168 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14169 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14170 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14171 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14172 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14173 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14174 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14175
14176 install_element (VIEW_NODE, &show_ip_bgp_cmd);
14177 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
14178 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
14179 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
14180 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
14181 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
14182 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
14183 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14184 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14185 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14186 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
14187 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
14188 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14189 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14190 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14191 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
14192 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14193 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14194 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14195 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14196 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14197 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14198 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14199 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14200
14201 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14202 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14203 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14204 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14205 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14206 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14207 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
14208 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14209 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14210 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
14211 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14212 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14213 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14214 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14215 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14216 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14217 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14218 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14219 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14220 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14221 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14222 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14223 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
14224 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14225 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14226 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14227 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14228 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14229 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14230 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14231 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14232 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14233 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14234 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14235 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14236 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14237 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14238 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
14239 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14240 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14241 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14242 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14243 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14244 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14245 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14246 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14247 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14248 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14249 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14250 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14251 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14252 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14253 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14254 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14255 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14256 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14257 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14258 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
14259 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14260 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14261 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14262 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14263 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
14264 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14265 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
14266 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14267 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
14268 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14269 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
14270 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14271 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14272 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
14273 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14274 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14275 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
14276 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14277 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14278 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14279 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
14280 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14281 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
14282 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14283 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
14284
14285 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
14286 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
14287 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14288 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
14289 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14290 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14291 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
14292 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
14293 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14294 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
14295 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
14296 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14297 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14298 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14299 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14300 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14301 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14302 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14303 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14304 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14305 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
14306 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
14307 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
14308 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
14309 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
14310 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
14311 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
14312 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
14313 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
14314 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14315 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_cmd);
14316 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14317 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14318 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14319 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
14320 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
14321 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
14322 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
14323 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14324 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14325 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14326 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14327
14328 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
14329 install_element (ENABLE_NODE, &show_ip_bgp_instance_cmd);
14330 install_element (ENABLE_NODE, &show_ip_bgp_instance_all_cmd);
14331 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
14332 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
14333 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
14334 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_cmd);
14335 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
14336 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14337 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14338 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
14339 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
14340 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14341 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14342 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
14343 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_cmd);
14344 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14345 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14346 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14347 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14348 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14349 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14350 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14351 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14352
14353 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
14354 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14355 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
14356 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14357 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14358 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
14359 install_element (ENABLE_NODE, &show_ip_bgp_instance_filter_list_cmd);
14360 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14361 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
14362 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_map_cmd);
14363 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14364 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
14365 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14366 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
14367 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14368 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
14369 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
14370 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
14371 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
14372 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
14373 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
14374 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
14375 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
14376 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14377 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_cmd);
14378 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14379 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14380 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14381 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
14382 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
14383 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
14384 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
14385 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14386 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14387 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14388 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14389 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
14390 install_element (ENABLE_NODE, &show_ip_bgp_instance_community_list_cmd);
14391 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14392 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
14393 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14394 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
14395 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14396 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14397 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14398 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14399 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14400 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14401 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14402 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14403 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14404 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14405 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14406 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14407 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14408 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14409 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14410 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
14411 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14412 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14413 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14414 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14415 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
14416 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
14417 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
14418 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
14419 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
14420 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
14421 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
14422 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
14423 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14424 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
14425 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
14426 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
14427 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
14428 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
14429 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14430 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14431 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14432 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14433 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
14434 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
14435 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
14436 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
14437 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
14438
14439 /* BGP dampening clear commands */
14440 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14441 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14442 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14443 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14444
14445 /* prefix count */
14446 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14447 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
14448 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14449 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
14450 #ifdef HAVE_IPV6
14451 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14452 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
14453
14454 /* New config IPv6 BGP commands. */
14455 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
14456 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14457 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
14458 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
14459 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14460 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14461
14462 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14463 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14464 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14465 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
14466
14467 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14468 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
14469
14470 /* Old config IPv6 BGP commands. */
14471 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14472 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14473
14474 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14475 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14476 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14477 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14478
14479 install_element (VIEW_NODE, &show_bgp_cmd);
14480 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
14481 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
14482 install_element (VIEW_NODE, &show_bgp_route_cmd);
14483 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
14484 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
14485 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14486 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14487 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14488 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14489 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
14490 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14491 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14492 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14493 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14494 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14495 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14496 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14497 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14498 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14499 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14500 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14501 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14502 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14503 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14504 install_element (VIEW_NODE, &show_bgp_community_cmd);
14505 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14506 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14507 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14508 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14509 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14510 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14511 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14512 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14513 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14514 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14515 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14516 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14517 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14518 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14519 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14520 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14521 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14522 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14523 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14524 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14525 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14526 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14527 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14528 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14529 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14530 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14531 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14532 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14533 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14534 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14535 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14536 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14537 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14538 install_element (VIEW_NODE, &show_bgp_instance_cmd);
14539 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
14540 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
14541 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
14542 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
14543 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
14544 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14545 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
14546 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14547 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14548 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14549 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
14550 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14551 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
14552 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14553 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
14554 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14555 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
14556 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14557 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
14558 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14559 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14560 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14561 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14562 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14563 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
14564 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14565 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14566 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14567 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
14568 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14569 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
14570 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
14571
14572 /* Restricted:
14573 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
14574 */
14575 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
14576 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
14577 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
14578 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
14579 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14580 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14581 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
14582 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
14583 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14584 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
14585 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14586 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14587 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
14588 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
14589 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
14590 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
14591 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
14592 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
14593 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
14594 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
14595 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
14596 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
14597 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
14598 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
14599 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
14600 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
14601 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
14602 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
14603 install_element (RESTRICTED_NODE, &show_bgp_instance_route_cmd);
14604 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_cmd);
14605 install_element (RESTRICTED_NODE, &show_bgp_instance_route_pathtype_cmd);
14606 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14607 install_element (RESTRICTED_NODE, &show_bgp_instance_prefix_cmd);
14608 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14609 install_element (RESTRICTED_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14610 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14611
14612 install_element (ENABLE_NODE, &show_bgp_cmd);
14613 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
14614 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
14615 install_element (ENABLE_NODE, &show_bgp_route_cmd);
14616 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
14617 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
14618 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
14619 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14620 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14621 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
14622 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
14623 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14624 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14625 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
14626 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14627 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
14628 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
14629 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
14630 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
14631 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
14632 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
14633 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
14634 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
14635 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
14636 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
14637 install_element (ENABLE_NODE, &show_bgp_community_cmd);
14638 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
14639 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
14640 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
14641 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
14642 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
14643 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
14644 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
14645 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
14646 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
14647 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
14648 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
14649 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
14650 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
14651 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
14652 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
14653 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
14654 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
14655 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
14656 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14657 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
14658 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14659 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
14660 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14661 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
14662 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14663 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
14664 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14665 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14666 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14667 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
14668 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14669 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
14670 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14671 install_element (ENABLE_NODE, &show_bgp_instance_cmd);
14672 install_element (ENABLE_NODE, &show_bgp_instance_all_cmd);
14673 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_cmd);
14674 install_element (ENABLE_NODE, &show_bgp_instance_route_cmd);
14675 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_cmd);
14676 install_element (ENABLE_NODE, &show_bgp_instance_route_pathtype_cmd);
14677 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14678 install_element (ENABLE_NODE, &show_bgp_instance_prefix_cmd);
14679 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14680 install_element (ENABLE_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14681 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14682 install_element (ENABLE_NODE, &show_bgp_instance_prefix_list_cmd);
14683 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14684 install_element (ENABLE_NODE, &show_bgp_instance_filter_list_cmd);
14685 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14686 install_element (ENABLE_NODE, &show_bgp_instance_route_map_cmd);
14687 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14688 install_element (ENABLE_NODE, &show_bgp_instance_community_list_cmd);
14689 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14690 install_element (ENABLE_NODE, &show_bgp_instance_prefix_longer_cmd);
14691 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14692 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14693 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14694 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14695 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14696 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_routes_cmd);
14697 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14698 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14699 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14700 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_flap_cmd);
14701 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14702 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_damp_cmd);
14703 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
14704
14705 /* Statistics */
14706 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
14707 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
14708 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
14709 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
14710
14711 /* old command */
14712 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14713 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14714 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
14715 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
14716 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
14717 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
14718 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
14719 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
14720 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
14721 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
14722 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
14723 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
14724 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
14725 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
14726 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
14727 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
14728 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14729 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14730 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
14731 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
14732 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
14733 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
14734 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14735 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
14736 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
14737 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
14738 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
14739 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
14740 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
14741 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
14742 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14743 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14744 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14745 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
14746 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14747 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14748
14749 /* old command */
14750 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
14751 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
14752 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
14753 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
14754 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
14755 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
14756 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
14757 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
14758 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
14759 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
14760 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
14761 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
14762 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
14763 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
14764 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
14765 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
14766 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14767 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14768 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
14769 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
14770 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
14771 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
14772 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14773 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
14774 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
14775 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
14776 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
14777 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
14778 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
14779 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
14780 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14781 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14782 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14783 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
14784 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14785 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14786
14787 /* old command */
14788 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14789 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14790 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14791 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14792
14793 /* old command */
14794 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14795 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14796 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14797 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14798
14799 /* old command */
14800 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
14801 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
14802 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14803 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14804 #endif /* HAVE_IPV6 */
14805
14806 install_element (BGP_NODE, &bgp_distance_cmd);
14807 install_element (BGP_NODE, &no_bgp_distance_cmd);
14808 install_element (BGP_NODE, &no_bgp_distance2_cmd);
14809 install_element (BGP_NODE, &bgp_distance_source_cmd);
14810 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
14811 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
14812 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
14813
14814 install_element (BGP_NODE, &bgp_damp_set_cmd);
14815 install_element (BGP_NODE, &bgp_damp_set2_cmd);
14816 install_element (BGP_NODE, &bgp_damp_set3_cmd);
14817 install_element (BGP_NODE, &bgp_damp_unset_cmd);
14818 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
14819 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
14820 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
14821 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
14822 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
14823 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
14824 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
14825 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
14826 }
14827
14828 void
14829 bgp_route_finish (void)
14830 {
14831 bgp_table_unlock (bgp_distance_table);
14832 bgp_distance_table = NULL;
14833 }