]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
d745dfdfd8dc013c756e158204cdcdea45dcbdd4
[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 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
807
808 if (ret == 1)
809 {
810 if (debug)
811 zlog_debug("%s: %s loses to %s due to Neighor IP comparison",
812 pfx_buf, new_buf, exist_buf);
813 return 0;
814 }
815
816 if (ret == -1)
817 {
818 if (debug)
819 zlog_debug("%s: %s wins over %s due to Neighor IP comparison",
820 pfx_buf, new_buf, exist_buf);
821 return 1;
822 }
823
824 if (debug)
825 zlog_debug("%s: %s wins over %s due to nothing left to compare",
826 pfx_buf, new_buf, exist_buf);
827
828 return 1;
829 }
830
831 static enum filter_type
832 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
833 afi_t afi, safi_t safi)
834 {
835 struct bgp_filter *filter;
836
837 filter = &peer->filter[afi][safi];
838
839 #define FILTER_EXIST_WARN(F,f,filter) \
840 if (BGP_DEBUG (update, UPDATE_IN) \
841 && !(F ## _IN (filter))) \
842 zlog_warn ("%s: Could not find configured input %s-list %s!", \
843 peer->host, #f, F ## _IN_NAME(filter));
844
845 if (DISTRIBUTE_IN_NAME (filter)) {
846 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
847
848 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
849 return FILTER_DENY;
850 }
851
852 if (PREFIX_LIST_IN_NAME (filter)) {
853 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
854
855 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
856 return FILTER_DENY;
857 }
858
859 if (FILTER_LIST_IN_NAME (filter)) {
860 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
861
862 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
863 return FILTER_DENY;
864 }
865
866 return FILTER_PERMIT;
867 #undef FILTER_EXIST_WARN
868 }
869
870 static enum filter_type
871 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
872 afi_t afi, safi_t safi)
873 {
874 struct bgp_filter *filter;
875
876 filter = &peer->filter[afi][safi];
877
878 #define FILTER_EXIST_WARN(F,f,filter) \
879 if (BGP_DEBUG (update, UPDATE_OUT) \
880 && !(F ## _OUT (filter))) \
881 zlog_warn ("%s: Could not find configured output %s-list %s!", \
882 peer->host, #f, F ## _OUT_NAME(filter));
883
884 if (DISTRIBUTE_OUT_NAME (filter)) {
885 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
886
887 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
888 return FILTER_DENY;
889 }
890
891 if (PREFIX_LIST_OUT_NAME (filter)) {
892 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
893
894 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
895 return FILTER_DENY;
896 }
897
898 if (FILTER_LIST_OUT_NAME (filter)) {
899 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
900
901 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
902 return FILTER_DENY;
903 }
904
905 return FILTER_PERMIT;
906 #undef FILTER_EXIST_WARN
907 }
908
909 /* If community attribute includes no_export then return 1. */
910 static int
911 bgp_community_filter (struct peer *peer, struct attr *attr)
912 {
913 if (attr->community)
914 {
915 /* NO_ADVERTISE check. */
916 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
917 return 1;
918
919 /* NO_EXPORT check. */
920 if (peer->sort == BGP_PEER_EBGP &&
921 community_include (attr->community, COMMUNITY_NO_EXPORT))
922 return 1;
923
924 /* NO_EXPORT_SUBCONFED check. */
925 if (peer->sort == BGP_PEER_EBGP
926 || peer->sort == BGP_PEER_CONFED)
927 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
928 return 1;
929 }
930 return 0;
931 }
932
933 /* Route reflection loop check. */
934 static int
935 bgp_cluster_filter (struct peer *peer, struct attr *attr)
936 {
937 struct in_addr cluster_id;
938
939 if (attr->extra && attr->extra->cluster)
940 {
941 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
942 cluster_id = peer->bgp->cluster_id;
943 else
944 cluster_id = peer->bgp->router_id;
945
946 if (cluster_loop_check (attr->extra->cluster, cluster_id))
947 return 1;
948 }
949 return 0;
950 }
951
952 static int
953 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
954 afi_t afi, safi_t safi, const char *rmap_name)
955 {
956 struct bgp_filter *filter;
957 struct bgp_info info;
958 route_map_result_t ret;
959 struct route_map *rmap = NULL;
960
961 filter = &peer->filter[afi][safi];
962
963 /* Apply default weight value. */
964 if (peer->weight)
965 (bgp_attr_extra_get (attr))->weight = peer->weight;
966
967 if (rmap_name)
968 {
969 rmap = route_map_lookup_by_name(rmap_name);
970
971 if (rmap == NULL)
972 return RMAP_DENY;
973 }
974 else
975 {
976 if (ROUTE_MAP_IN_NAME(filter))
977 {
978 rmap = ROUTE_MAP_IN (filter);
979
980 if (rmap == NULL)
981 return RMAP_DENY;
982 }
983 }
984
985 /* Route map apply. */
986 if (rmap)
987 {
988 /* Duplicate current value to new strucutre for modification. */
989 info.peer = peer;
990 info.attr = attr;
991
992 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
993
994 /* Apply BGP route map to the attribute. */
995 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
996
997 peer->rmap_type = 0;
998
999 if (ret == RMAP_DENYMATCH)
1000 {
1001 /* Free newly generated AS path and community by route-map. */
1002 bgp_attr_flush (attr);
1003 return RMAP_DENY;
1004 }
1005 }
1006 return RMAP_PERMIT;
1007 }
1008
1009 static int
1010 bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1011 afi_t afi, safi_t safi, const char *rmap_name)
1012 {
1013 struct bgp_filter *filter;
1014 struct bgp_info info;
1015 route_map_result_t ret;
1016 struct route_map *rmap = NULL;
1017
1018 filter = &peer->filter[afi][safi];
1019
1020 /* Apply default weight value. */
1021 if (peer->weight)
1022 (bgp_attr_extra_get (attr))->weight = peer->weight;
1023
1024 if (rmap_name)
1025 {
1026 rmap = route_map_lookup_by_name(rmap_name);
1027
1028 if (rmap == NULL)
1029 return RMAP_DENY;
1030 }
1031 else
1032 {
1033 if (ROUTE_MAP_OUT_NAME(filter))
1034 {
1035 rmap = ROUTE_MAP_OUT (filter);
1036
1037 if (rmap == NULL)
1038 return RMAP_DENY;
1039 }
1040 }
1041
1042 /* Route map apply. */
1043 if (rmap)
1044 {
1045 /* Duplicate current value to new strucutre for modification. */
1046 info.peer = peer;
1047 info.attr = attr;
1048
1049 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1050
1051 /* Apply BGP route map to the attribute. */
1052 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1053
1054 peer->rmap_type = 0;
1055
1056 if (ret == RMAP_DENYMATCH)
1057 /* caller has multiple error paths with bgp_attr_flush() */
1058 return RMAP_DENY;
1059 }
1060 return RMAP_PERMIT;
1061 }
1062
1063 /* If this is an EBGP peer with remove-private-AS */
1064 static void
1065 bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1066 struct peer *peer, struct attr *attr)
1067 {
1068 if (peer->sort == BGP_PEER_EBGP &&
1069 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1070 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1071 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1072 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
1073 {
1074 // Take action on the entire aspath
1075 if (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_ALL))
1077 {
1078 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
1079 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1080
1081 // The entire aspath consists of private ASNs so create an empty aspath
1082 else if (aspath_private_as_check (attr->aspath))
1083 attr->aspath = aspath_empty_get ();
1084
1085 // There are some public and some private ASNs, remove the private ASNs
1086 else
1087 attr->aspath = aspath_remove_private_asns (attr->aspath);
1088 }
1089
1090 // 'all' was not specified so the entire aspath must be private ASNs
1091 // for us to do anything
1092 else if (aspath_private_as_check (attr->aspath))
1093 {
1094 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1095 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1096 else
1097 attr->aspath = aspath_empty_get ();
1098 }
1099 }
1100 }
1101
1102 /* If this is an EBGP peer with as-override */
1103 static void
1104 bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1105 struct peer *peer, struct attr *attr)
1106 {
1107 if (peer->sort == BGP_PEER_EBGP &&
1108 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1109 {
1110 if (aspath_single_asn_check (attr->aspath, peer->as))
1111 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1112 }
1113 }
1114
1115 static void
1116 subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1117 {
1118 if (family == AF_INET)
1119 attr->nexthop.s_addr = 0;
1120 #ifdef HAVE_IPV6
1121 if (family == AF_INET6)
1122 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1123 #endif
1124 }
1125
1126 int
1127 subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1128 struct prefix *p, struct attr *attr)
1129 {
1130 struct bgp_filter *filter;
1131 struct peer *from;
1132 struct peer *peer;
1133 struct peer *onlypeer;
1134 struct bgp *bgp;
1135 struct attr *riattr;
1136 struct peer_af *paf;
1137 char buf[SU_ADDRSTRLEN];
1138 int ret;
1139 int transparent;
1140 int reflect;
1141 afi_t afi;
1142 safi_t safi;
1143
1144 if (DISABLE_BGP_ANNOUNCE)
1145 return 0;
1146
1147 afi = SUBGRP_AFI(subgrp);
1148 safi = SUBGRP_SAFI(subgrp);
1149 peer = SUBGRP_PEER(subgrp);
1150 onlypeer = NULL;
1151 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1152 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1153
1154 from = ri->peer;
1155 filter = &peer->filter[afi][safi];
1156 bgp = SUBGRP_INST(subgrp);
1157 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1158
1159 /* With addpath we may be asked to TX all kinds of paths so make sure
1160 * ri is valid */
1161 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1162 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1163 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1164 {
1165 return 0;
1166 }
1167
1168 /* If this is not the bestpath then check to see if there is an enabled addpath
1169 * feature that requires us to advertise it */
1170 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1171 {
1172 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1173 {
1174 return 0;
1175 }
1176 }
1177
1178 /* Aggregate-address suppress check. */
1179 if (ri->extra && ri->extra->suppress)
1180 if (! UNSUPPRESS_MAP_NAME (filter))
1181 {
1182 return 0;
1183 }
1184
1185 /* Do not send back route to sender. */
1186 if (onlypeer && from == onlypeer)
1187 {
1188 return 0;
1189 }
1190
1191 /* Do not send the default route in the BGP table if the neighbor is
1192 * configured for default-originate */
1193 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1194 {
1195 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1196 return 0;
1197 #ifdef HAVE_IPV6
1198 else if (p->family == AF_INET6 && p->prefixlen == 0)
1199 return 0;
1200 #endif /* HAVE_IPV6 */
1201 }
1202
1203 /* Transparency check. */
1204 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1205 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1206 transparent = 1;
1207 else
1208 transparent = 0;
1209
1210 /* If community is not disabled check the no-export and local. */
1211 if (! transparent && bgp_community_filter (peer, riattr))
1212 {
1213 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1214 zlog_debug ("subgrpannouncecheck: community filter check fail");
1215 return 0;
1216 }
1217
1218 /* If the attribute has originator-id and it is same as remote
1219 peer's id. */
1220 if (onlypeer &&
1221 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1222 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1223 {
1224 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1225 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1226 "remote router-id",
1227 onlypeer->host,
1228 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1229 p->prefixlen);
1230 return 0;
1231 }
1232
1233 /* ORF prefix-list filter check */
1234 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1235 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1236 || CHECK_FLAG (peer->af_cap[afi][safi],
1237 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1238 if (peer->orf_plist[afi][safi])
1239 {
1240 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1241 {
1242 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1243 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1244 peer->host,
1245 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1246 p->prefixlen);
1247 return 0;
1248 }
1249 }
1250
1251 /* Output filter check. */
1252 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1253 {
1254 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1255 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1256 peer->host,
1257 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1258 p->prefixlen);
1259 return 0;
1260 }
1261
1262 #ifdef BGP_SEND_ASPATH_CHECK
1263 /* AS path loop check. */
1264 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1265 {
1266 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1267 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1268 "that is part of AS path.",
1269 onlypeer->host, onlypeer->as);
1270 return 0;
1271 }
1272 #endif /* BGP_SEND_ASPATH_CHECK */
1273
1274 /* If we're a CONFED we need to loop check the CONFED ID too */
1275 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1276 {
1277 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1278 {
1279 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1280 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1281 " is AS path.",
1282 peer->host,
1283 bgp->confed_id);
1284 return 0;
1285 }
1286 }
1287
1288 /* Route-Reflect check. */
1289 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1290 reflect = 1;
1291 else
1292 reflect = 0;
1293
1294 /* IBGP reflection check. */
1295 if (reflect)
1296 {
1297 /* A route from a Client peer. */
1298 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1299 {
1300 /* Reflect to all the Non-Client peers and also to the
1301 Client peers other than the originator. Originator check
1302 is already done. So there is noting to do. */
1303 /* no bgp client-to-client reflection check. */
1304 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1305 if (CHECK_FLAG (peer->af_flags[afi][safi],
1306 PEER_FLAG_REFLECTOR_CLIENT))
1307 return 0;
1308 }
1309 else
1310 {
1311 /* A route from a Non-client peer. Reflect to all other
1312 clients. */
1313 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1314 PEER_FLAG_REFLECTOR_CLIENT))
1315 return 0;
1316 }
1317 }
1318
1319 /* For modify attribute, copy it to temporary structure. */
1320 bgp_attr_dup (attr, riattr);
1321
1322 /* If local-preference is not set. */
1323 if ((peer->sort == BGP_PEER_IBGP
1324 || peer->sort == BGP_PEER_CONFED)
1325 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1326 {
1327 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1328 attr->local_pref = bgp->default_local_pref;
1329 }
1330
1331 /* If originator-id is not set and the route is to be reflected,
1332 set the originator id */
1333 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1334 {
1335 attr->extra = bgp_attr_extra_get(attr);
1336 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1337 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1338 }
1339
1340 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1341 if (peer->sort == BGP_PEER_EBGP
1342 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1343 {
1344 if (from != bgp->peer_self && ! transparent
1345 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1346 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1347 }
1348
1349 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1350 * in announce check, only certain flags and length (or number of nexthops
1351 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1352 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1353 * Typically, the source nexthop in the attribute is preserved but in the
1354 * scenarios where we know it will always be overwritten, we reset the
1355 * nexthop to "0" in an attempt to achieve better Update packing. An
1356 * example of this is when a prefix from each of 2 IBGP peers needs to be
1357 * announced to an EBGP peer (and they have the same attributes barring
1358 * their nexthop).
1359 */
1360 if (reflect)
1361 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1362
1363 #ifdef HAVE_IPV6
1364 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1365 * the peer (group) is configured to receive link-local nexthop unchanged
1366 * and it is available in the prefix OR we're not reflecting the route and
1367 * the peer (group) to whom we're going to announce is on a shared network
1368 * and this is either a self-originated route or the peer is EBGP.
1369 */
1370 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1371 {
1372 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
1373 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1374 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1375 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1376 (!reflect && peer->shared_network &&
1377 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
1378 {
1379 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
1380 }
1381
1382 /* Clear off link-local nexthop in source, whenever it is not needed to
1383 * ensure more prefixes share the same attribute for announcement.
1384 */
1385 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1386 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1387 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1388 }
1389 #endif /* HAVE_IPV6 */
1390
1391 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1392 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1393
1394 /* Route map & unsuppress-map apply. */
1395 if (ROUTE_MAP_OUT_NAME (filter)
1396 || (ri->extra && ri->extra->suppress) )
1397 {
1398 struct bgp_info info;
1399 struct attr dummy_attr;
1400 struct attr_extra dummy_extra;
1401
1402 dummy_attr.extra = &dummy_extra;
1403
1404 info.peer = peer;
1405 info.attr = attr;
1406 /* don't confuse inbound and outbound setting */
1407 RESET_FLAG(attr->rmap_change_flags);
1408
1409 /*
1410 * The route reflector is not allowed to modify the attributes
1411 * of the reflected IBGP routes unless explicitly allowed.
1412 */
1413 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1414 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1415 {
1416 bgp_attr_dup (&dummy_attr, attr);
1417 info.attr = &dummy_attr;
1418 }
1419
1420 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1421
1422 if (ri->extra && ri->extra->suppress)
1423 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1424 else
1425 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1426
1427 peer->rmap_type = 0;
1428
1429 if (ret == RMAP_DENYMATCH)
1430 {
1431 bgp_attr_flush (attr);
1432 return 0;
1433 }
1434 }
1435
1436 /* After route-map has been applied, we check to see if the nexthop to
1437 * be carried in the attribute (that is used for the announcement) can
1438 * be cleared off or not. We do this in all cases where we would be
1439 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1440 * the global nexthop here; the link-local nexthop would have been cleared
1441 * already, and if not, it is required by the update formation code.
1442 * Also see earlier comments in this function.
1443 */
1444 /*
1445 * If route-map has performed some operation on the nexthop or the peer
1446 * configuration says to pass it unchanged, we cannot reset the nexthop
1447 * here, so only attempt to do it if these aren't true. Note that the
1448 * route-map handler itself might have cleared the nexthop, if for example,
1449 * it is configured as 'peer-address'.
1450 */
1451 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1452 riattr->rmap_change_flags) &&
1453 !transparent &&
1454 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
1455 {
1456 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
1457 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1458 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
1459 {
1460 if (!reflect ||
1461 CHECK_FLAG (peer->af_flags[afi][safi],
1462 PEER_FLAG_FORCE_NEXTHOP_SELF))
1463 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1464 AF_INET6 : p->family), attr);
1465 }
1466 else if (peer->sort == BGP_PEER_EBGP)
1467 {
1468 /* Can also reset the nexthop if announcing to EBGP, but only if
1469 * no peer in the subgroup is on a shared subnet.
1470 * Note: 3rd party nexthop currently implemented for IPv4 only.
1471 */
1472 SUBGRP_FOREACH_PEER (subgrp, paf)
1473 {
1474 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1475 break;
1476 }
1477 if (!paf)
1478 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
1479 }
1480 /* If IPv6/MP and nexthop does not have any override and happens to
1481 * be a link-local address, reset it so that we don't pass along the
1482 * source's link-local IPv6 address to recipients who may not be on
1483 * the same interface.
1484 */
1485 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1486 {
1487 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1488 subgroup_announce_reset_nhop (AF_INET6, attr);
1489 }
1490 }
1491
1492 return 1;
1493 }
1494
1495 struct bgp_info_pair
1496 {
1497 struct bgp_info *old;
1498 struct bgp_info *new;
1499 };
1500
1501 static void
1502 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1503 struct bgp_maxpaths_cfg *mpath_cfg,
1504 struct bgp_info_pair *result)
1505 {
1506 struct bgp_info *new_select;
1507 struct bgp_info *old_select;
1508 struct bgp_info *ri;
1509 struct bgp_info *ri1;
1510 struct bgp_info *ri2;
1511 struct bgp_info *nextri = NULL;
1512 int paths_eq, do_mpath, debug;
1513 struct list mp_list;
1514 char pfx_buf[PREFIX2STR_BUFFER];
1515 char path_buf[PATH_ADDPATH_STR_BUFFER];
1516
1517 bgp_mp_list_init (&mp_list);
1518 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
1519
1520 debug = bgp_debug_bestpath(&rn->p);
1521
1522 if (debug)
1523 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1524
1525 /* bgp deterministic-med */
1526 new_select = NULL;
1527 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1528 {
1529
1530 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1531 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1532 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1533
1534 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1535 {
1536 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1537 continue;
1538 if (BGP_INFO_HOLDDOWN (ri1))
1539 continue;
1540 if (ri1->peer && ri1->peer != bgp->peer_self)
1541 if (ri1->peer->status != Established)
1542 continue;
1543
1544 new_select = ri1;
1545 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
1546 if (ri1->next)
1547 {
1548 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1549 {
1550 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1551 continue;
1552 if (BGP_INFO_HOLDDOWN (ri2))
1553 continue;
1554 if (ri2->peer &&
1555 ri2->peer != bgp->peer_self &&
1556 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1557 if (ri2->peer->status != Established)
1558 continue;
1559
1560 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1561 || aspath_cmp_left_confed (ri1->attr->aspath,
1562 ri2->attr->aspath))
1563 {
1564 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1565 old_select = ri2;
1566 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1567 mpath_cfg, debug, pfx_buf))
1568 {
1569 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1570 new_select = ri2;
1571 }
1572
1573 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1574 }
1575 }
1576 }
1577 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1578 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1579
1580 if (debug)
1581 {
1582 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1583 zlog_debug("%s: %s is the bestpath from AS %d",
1584 pfx_buf, path_buf, aspath_get_firstas(new_select->attr->aspath));
1585 }
1586 }
1587 }
1588
1589 /* Check old selected route and new selected route. */
1590 old_select = NULL;
1591 new_select = NULL;
1592 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1593 {
1594 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1595 old_select = ri;
1596
1597 if (BGP_INFO_HOLDDOWN (ri))
1598 {
1599 /* reap REMOVED routes, if needs be
1600 * selected route must stay for a while longer though
1601 */
1602 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1603 && (ri != old_select))
1604 bgp_info_reap (rn, ri);
1605
1606 continue;
1607 }
1608
1609 if (ri->peer &&
1610 ri->peer != bgp->peer_self &&
1611 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1612 if (ri->peer->status != Established)
1613 continue;
1614
1615 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1616 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1617 {
1618 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1619 continue;
1620 }
1621
1622 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1623
1624 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
1625 {
1626 new_select = ri;
1627 }
1628 }
1629
1630 /* Now that we know which path is the bestpath see if any of the other paths
1631 * qualify as multipaths
1632 */
1633 if (do_mpath && new_select)
1634 {
1635 if (debug)
1636 {
1637 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1638 zlog_debug("%s: %s is the bestpath, now find multipaths", pfx_buf, path_buf);
1639 }
1640
1641 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1642 {
1643
1644 if (debug)
1645 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1646
1647 if (ri == new_select)
1648 {
1649 if (debug)
1650 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1651 pfx_buf, path_buf);
1652 bgp_mp_list_add (&mp_list, ri);
1653 continue;
1654 }
1655
1656 if (BGP_INFO_HOLDDOWN (ri))
1657 continue;
1658
1659 if (ri->peer &&
1660 ri->peer != bgp->peer_self &&
1661 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1662 if (ri->peer->status != Established)
1663 continue;
1664
1665 if (!bgp_info_nexthop_cmp (ri, new_select))
1666 {
1667 if (debug)
1668 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1669 pfx_buf, path_buf);
1670 continue;
1671 }
1672
1673 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
1674
1675 if (paths_eq)
1676 {
1677 if (debug)
1678 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1679 pfx_buf, path_buf);
1680 bgp_mp_list_add (&mp_list, ri);
1681 }
1682 }
1683 }
1684
1685 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1686 bgp_info_mpath_aggregate_update (new_select, old_select);
1687 bgp_mp_list_clear (&mp_list);
1688
1689 result->old = old_select;
1690 result->new = new_select;
1691
1692 return;
1693 }
1694
1695 /*
1696 * A new route/change in bestpath of an existing route. Evaluate the path
1697 * for advertisement to the subgroup.
1698 */
1699 int
1700 subgroup_process_announce_selected (struct update_subgroup *subgrp,
1701 struct bgp_info *selected,
1702 struct bgp_node *rn,
1703 u_int32_t addpath_tx_id)
1704 {
1705 struct prefix *p;
1706 struct peer *onlypeer;
1707 struct attr attr;
1708 struct attr_extra extra;
1709 afi_t afi;
1710 safi_t safi;
1711
1712 p = &rn->p;
1713 afi = SUBGRP_AFI(subgrp);
1714 safi = SUBGRP_SAFI(subgrp);
1715 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1716 (SUBGRP_PFIRST(subgrp))->peer : NULL);
1717
1718 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1719 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1720 PEER_STATUS_ORF_WAIT_REFRESH))
1721 return 0;
1722
1723 /* It's initialized in bgp_announce_check() */
1724 attr.extra = &extra;
1725
1726 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1727 if (selected)
1728 {
1729 if (subgroup_announce_check(selected, subgrp, p, &attr))
1730 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1731 else
1732 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1733 }
1734
1735 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1736 else
1737 {
1738 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
1739 }
1740
1741 return 0;
1742 }
1743
1744 struct bgp_process_queue
1745 {
1746 struct bgp *bgp;
1747 struct bgp_node *rn;
1748 afi_t afi;
1749 safi_t safi;
1750 };
1751
1752 static wq_item_status
1753 bgp_process_main (struct work_queue *wq, void *data)
1754 {
1755 struct bgp_process_queue *pq = data;
1756 struct bgp *bgp = pq->bgp;
1757 struct bgp_node *rn = pq->rn;
1758 afi_t afi = pq->afi;
1759 safi_t safi = pq->safi;
1760 struct prefix *p = &rn->p;
1761 struct bgp_info *new_select;
1762 struct bgp_info *old_select;
1763 struct bgp_info_pair old_and_new;
1764
1765 /* Is it end of initial update? (after startup) */
1766 if (!rn)
1767 {
1768 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1769 sizeof(bgp->update_delay_zebra_resume_time));
1770
1771 bgp->main_zebra_update_hold = 0;
1772 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1773 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1774 {
1775 bgp_zebra_announce_table(bgp, afi, safi);
1776 }
1777 bgp->main_peers_update_hold = 0;
1778
1779 bgp_start_routeadv(bgp);
1780 return WQ_SUCCESS;
1781 }
1782
1783 /* Best path selection. */
1784 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1785 old_select = old_and_new.old;
1786 new_select = old_and_new.new;
1787
1788 /* Nothing to do. */
1789 if (old_select && old_select == new_select &&
1790 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1791 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1792 !bgp->addpath_tx_used[afi][safi])
1793 {
1794 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1795 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
1796 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1797
1798 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1799 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1800 return WQ_SUCCESS;
1801 }
1802
1803 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1804 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1805
1806 /* bestpath has changed; bump version */
1807 if (old_select || new_select)
1808 {
1809 bgp_bump_version(rn);
1810
1811 if (!bgp->t_rmap_def_originate_eval)
1812 {
1813 bgp_lock (bgp);
1814 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
1815 update_group_refresh_default_originate_route_map,
1816 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1817 }
1818 }
1819
1820 if (old_select)
1821 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1822 if (new_select)
1823 {
1824 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1825 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1826 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1827 }
1828
1829 group_announce_route(bgp, afi, safi, rn, new_select);
1830
1831 /* FIB update. */
1832 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) &&
1833 (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) &&
1834 !bgp_option_check (BGP_OPT_NO_FIB))
1835 {
1836 if (new_select
1837 && new_select->type == ZEBRA_ROUTE_BGP
1838 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1839 new_select->sub_type == BGP_ROUTE_AGGREGATE))
1840 bgp_zebra_announce (p, new_select, bgp, afi, safi);
1841 else
1842 {
1843 /* Withdraw the route from the kernel. */
1844 if (old_select
1845 && old_select->type == ZEBRA_ROUTE_BGP
1846 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
1847 old_select->sub_type == BGP_ROUTE_AGGREGATE))
1848 bgp_zebra_withdraw (p, old_select, safi);
1849 }
1850 }
1851
1852 /* Reap old select bgp_info, if it has been removed */
1853 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1854 bgp_info_reap (rn, old_select);
1855
1856 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1857 return WQ_SUCCESS;
1858 }
1859
1860 static void
1861 bgp_processq_del (struct work_queue *wq, void *data)
1862 {
1863 struct bgp_process_queue *pq = data;
1864 struct bgp_table *table;
1865
1866 bgp_unlock (pq->bgp);
1867 if (pq->rn)
1868 {
1869 table = bgp_node_table (pq->rn);
1870 bgp_unlock_node (pq->rn);
1871 bgp_table_unlock (table);
1872 }
1873 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1874 }
1875
1876 void
1877 bgp_process_queue_init (void)
1878 {
1879 if (!bm->process_main_queue)
1880 {
1881 bm->process_main_queue
1882 = work_queue_new (bm->master, "process_main_queue");
1883
1884 if ( !bm->process_main_queue)
1885 {
1886 zlog_err ("%s: Failed to allocate work queue", __func__);
1887 exit (1);
1888 }
1889 }
1890
1891 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1892 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1893 bm->process_main_queue->spec.max_retries = 0;
1894 bm->process_main_queue->spec.hold = 50;
1895 /* Use a higher yield value of 50ms for main queue processing */
1896 bm->process_main_queue->spec.yield = 50 * 1000L;
1897 }
1898
1899 void
1900 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1901 {
1902 struct bgp_process_queue *pqnode;
1903
1904 /* already scheduled for processing? */
1905 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1906 return;
1907
1908 if (bm->process_main_queue == NULL)
1909 bgp_process_queue_init ();
1910
1911 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1912 sizeof (struct bgp_process_queue));
1913 if (!pqnode)
1914 return;
1915
1916 /* all unlocked in bgp_processq_del */
1917 bgp_table_lock (bgp_node_table (rn));
1918 pqnode->rn = bgp_lock_node (rn);
1919 pqnode->bgp = bgp;
1920 bgp_lock (bgp);
1921 pqnode->afi = afi;
1922 pqnode->safi = safi;
1923 work_queue_add (bm->process_main_queue, pqnode);
1924 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1925 return;
1926 }
1927
1928 void
1929 bgp_add_eoiu_mark (struct bgp *bgp)
1930 {
1931 struct bgp_process_queue *pqnode;
1932
1933 if (bm->process_main_queue == NULL)
1934 bgp_process_queue_init ();
1935
1936 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1937 sizeof (struct bgp_process_queue));
1938 if (!pqnode)
1939 return;
1940
1941 pqnode->rn = NULL;
1942 pqnode->bgp = bgp;
1943 bgp_lock (bgp);
1944 work_queue_add (bm->process_main_queue, pqnode);
1945 }
1946
1947 static int
1948 bgp_maximum_prefix_restart_timer (struct thread *thread)
1949 {
1950 struct peer *peer;
1951
1952 peer = THREAD_ARG (thread);
1953 peer->t_pmax_restart = NULL;
1954
1955 if (bgp_debug_neighbor_events(peer))
1956 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1957 peer->host);
1958
1959 peer_clear (peer, NULL);
1960
1961 return 0;
1962 }
1963
1964 int
1965 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1966 safi_t safi, int always)
1967 {
1968 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1969 return 0;
1970
1971 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
1972 {
1973 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1974 && ! always)
1975 return 0;
1976
1977 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1978 "limit %ld", afi_safi_print (afi, safi), peer->host,
1979 peer->pcount[afi][safi], peer->pmax[afi][safi]);
1980 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1981
1982 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1983 return 0;
1984
1985 {
1986 u_int8_t ndata[7];
1987
1988 if (safi == SAFI_MPLS_VPN)
1989 safi = SAFI_MPLS_LABELED_VPN;
1990
1991 ndata[0] = (afi >> 8);
1992 ndata[1] = afi;
1993 ndata[2] = safi;
1994 ndata[3] = (peer->pmax[afi][safi] >> 24);
1995 ndata[4] = (peer->pmax[afi][safi] >> 16);
1996 ndata[5] = (peer->pmax[afi][safi] >> 8);
1997 ndata[6] = (peer->pmax[afi][safi]);
1998
1999 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2000 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2001 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2002 }
2003
2004 /* Dynamic peers will just close their connection. */
2005 if (peer_dynamic_neighbor (peer))
2006 return 1;
2007
2008 /* restart timer start */
2009 if (peer->pmax_restart[afi][safi])
2010 {
2011 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2012
2013 if (bgp_debug_neighbor_events(peer))
2014 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2015 peer->host, peer->v_pmax_restart);
2016
2017 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2018 peer->v_pmax_restart);
2019 }
2020
2021 return 1;
2022 }
2023 else
2024 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2025
2026 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2027 {
2028 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2029 && ! always)
2030 return 0;
2031
2032 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2033 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2034 peer->pmax[afi][safi]);
2035 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2036 }
2037 else
2038 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2039 return 0;
2040 }
2041
2042 /* Unconditionally remove the route from the RIB, without taking
2043 * damping into consideration (eg, because the session went down)
2044 */
2045 static void
2046 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2047 afi_t afi, safi_t safi)
2048 {
2049 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2050
2051 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2052 bgp_info_delete (rn, ri); /* keep historical info */
2053
2054 bgp_process (peer->bgp, rn, afi, safi);
2055 }
2056
2057 static void
2058 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2059 afi_t afi, safi_t safi)
2060 {
2061 int status = BGP_DAMP_NONE;
2062
2063 /* apply dampening, if result is suppressed, we'll be retaining
2064 * the bgp_info in the RIB for historical reference.
2065 */
2066 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2067 && peer->sort == BGP_PEER_EBGP)
2068 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2069 == BGP_DAMP_SUPPRESSED)
2070 {
2071 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2072 return;
2073 }
2074
2075 bgp_rib_remove (rn, ri, peer, afi, safi);
2076 }
2077
2078 static struct bgp_info *
2079 info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
2080 struct bgp_node *rn)
2081 {
2082 struct bgp_info *new;
2083
2084 /* Make new BGP info. */
2085 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2086 new->type = type;
2087 new->instance = instance;
2088 new->sub_type = sub_type;
2089 new->peer = peer;
2090 new->attr = attr;
2091 new->uptime = bgp_clock ();
2092 new->net = rn;
2093 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
2094 return new;
2095 }
2096
2097 static void
2098 bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
2099 {
2100 if (addpath_id)
2101 sprintf(buf, " with addpath ID %d", addpath_id);
2102 }
2103
2104
2105 /* Check if received nexthop is valid or not. */
2106 static int
2107 bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
2108 {
2109 struct attr_extra *attre = attr->extra;
2110 int ret = 0;
2111
2112 /* Only validated for unicast and multicast currently. */
2113 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2114 return 0;
2115
2116 /* If NEXT_HOP is present, validate it. */
2117 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2118 {
2119 if (attr->nexthop.s_addr == 0 ||
2120 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2121 bgp_nexthop_self (bgp, attr))
2122 ret = 1;
2123 }
2124
2125 /* If MP_NEXTHOP is present, validate it. */
2126 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2127 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2128 * it is not an IPv6 link-local address.
2129 */
2130 if (attre && attre->mp_nexthop_len)
2131 {
2132 switch (attre->mp_nexthop_len)
2133 {
2134 case BGP_ATTR_NHLEN_IPV4:
2135 case BGP_ATTR_NHLEN_VPNV4:
2136 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2137 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2138 break;
2139
2140 #ifdef HAVE_IPV6
2141 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2142 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2143 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2144 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2145 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2146 break;
2147 #endif /* HAVE_IPV6 */
2148
2149 default:
2150 ret = 1;
2151 break;
2152 }
2153 }
2154
2155 return ret;
2156 }
2157
2158 int
2159 bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2160 struct attr *attr, afi_t afi, safi_t safi, int type,
2161 int sub_type, struct prefix_rd *prd, u_char *tag,
2162 int soft_reconfig)
2163 {
2164 int ret;
2165 int aspath_loop_count = 0;
2166 struct bgp_node *rn;
2167 struct bgp *bgp;
2168 struct attr new_attr;
2169 struct attr_extra new_extra;
2170 struct attr *attr_new;
2171 struct bgp_info *ri;
2172 struct bgp_info *new;
2173 const char *reason;
2174 char buf[SU_ADDRSTRLEN];
2175 char buf2[30];
2176 int connected = 0;
2177
2178 bgp = peer->bgp;
2179 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2180
2181 /* When peer's soft reconfiguration enabled. Record input packet in
2182 Adj-RIBs-In. */
2183 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2184 && peer != bgp->peer_self)
2185 bgp_adj_in_set (rn, peer, attr, addpath_id);
2186
2187 /* Check previously received route. */
2188 for (ri = rn->info; ri; ri = ri->next)
2189 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2190 ri->addpath_rx_id == addpath_id)
2191 break;
2192
2193 /* AS path local-as loop check. */
2194 if (peer->change_local_as)
2195 {
2196 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2197 aspath_loop_count = 1;
2198
2199 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2200 {
2201 reason = "as-path contains our own AS;";
2202 goto filtered;
2203 }
2204 }
2205
2206 /* AS path loop check. */
2207 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2208 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2209 && aspath_loop_check(attr->aspath, bgp->confed_id)
2210 > peer->allowas_in[afi][safi]))
2211 {
2212 reason = "as-path contains our own AS;";
2213 goto filtered;
2214 }
2215
2216 /* Route reflector originator ID check. */
2217 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2218 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2219 {
2220 reason = "originator is us;";
2221 goto filtered;
2222 }
2223
2224 /* Route reflector cluster ID check. */
2225 if (bgp_cluster_filter (peer, attr))
2226 {
2227 reason = "reflected from the same cluster;";
2228 goto filtered;
2229 }
2230
2231 /* Apply incoming filter. */
2232 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2233 {
2234 reason = "filter;";
2235 goto filtered;
2236 }
2237
2238 new_attr.extra = &new_extra;
2239 bgp_attr_dup (&new_attr, attr);
2240
2241 /* Apply incoming route-map.
2242 * NB: new_attr may now contain newly allocated values from route-map "set"
2243 * commands, so we need bgp_attr_flush in the error paths, until we intern
2244 * the attr (which takes over the memory references) */
2245 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2246 {
2247 reason = "route-map;";
2248 bgp_attr_flush (&new_attr);
2249 goto filtered;
2250 }
2251
2252 /* next hop check. */
2253 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
2254 {
2255 reason = "martian or self next-hop;";
2256 bgp_attr_flush (&new_attr);
2257 goto filtered;
2258 }
2259
2260 attr_new = bgp_attr_intern (&new_attr);
2261
2262 /* If the update is implicit withdraw. */
2263 if (ri)
2264 {
2265 ri->uptime = bgp_clock ();
2266
2267 /* Same attribute comes in. */
2268 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2269 && attrhash_cmp (ri->attr, attr_new))
2270 {
2271 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2272 && peer->sort == BGP_PEER_EBGP
2273 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2274 {
2275 if (bgp_debug_update(peer, p, NULL, 1))
2276 {
2277 bgp_info_addpath_rx_str(addpath_id, buf2);
2278 zlog_debug ("%s rcvd %s/%d%s",
2279 peer->host,
2280 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2281 p->prefixlen, buf2);
2282 }
2283
2284 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2285 {
2286 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2287 bgp_process (bgp, rn, afi, safi);
2288 }
2289 }
2290 else /* Duplicate - odd */
2291 {
2292 if (bgp_debug_update(peer, p, NULL, 1))
2293 {
2294 if (!peer->rcvd_attr_printed)
2295 {
2296 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2297 peer->rcvd_attr_printed = 1;
2298 }
2299
2300 bgp_info_addpath_rx_str(addpath_id, buf2);
2301 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
2302 peer->host,
2303 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2304 p->prefixlen, buf2);
2305 }
2306
2307 /* graceful restart STALE flag unset. */
2308 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2309 {
2310 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2311 bgp_process (bgp, rn, afi, safi);
2312 }
2313 }
2314
2315 bgp_unlock_node (rn);
2316 bgp_attr_unintern (&attr_new);
2317
2318 return 0;
2319 }
2320
2321 /* Withdraw/Announce before we fully processed the withdraw */
2322 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2323 {
2324 if (bgp_debug_update(peer, p, NULL, 1))
2325 {
2326 bgp_info_addpath_rx_str(addpath_id, buf2);
2327 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2328 peer->host,
2329 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2330 p->prefixlen, buf2);
2331 }
2332 bgp_info_restore (rn, ri);
2333 }
2334
2335 /* Received Logging. */
2336 if (bgp_debug_update(peer, p, NULL, 1))
2337 {
2338 bgp_info_addpath_rx_str(addpath_id, buf2);
2339 zlog_debug ("%s rcvd %s/%d%s",
2340 peer->host,
2341 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2342 p->prefixlen, buf2);
2343 }
2344
2345 /* graceful restart STALE flag unset. */
2346 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2347 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2348
2349 /* The attribute is changed. */
2350 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2351
2352 /* implicit withdraw, decrement aggregate and pcount here.
2353 * only if update is accepted, they'll increment below.
2354 */
2355 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2356
2357 /* Update bgp route dampening information. */
2358 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2359 && peer->sort == BGP_PEER_EBGP)
2360 {
2361 /* This is implicit withdraw so we should update dampening
2362 information. */
2363 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2364 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2365 }
2366
2367 /* Update to new attribute. */
2368 bgp_attr_unintern (&ri->attr);
2369 ri->attr = attr_new;
2370
2371 /* Update MPLS tag. */
2372 if (safi == SAFI_MPLS_VPN)
2373 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2374
2375 /* Update bgp route dampening information. */
2376 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2377 && peer->sort == BGP_PEER_EBGP)
2378 {
2379 /* Now we do normal update dampening. */
2380 ret = bgp_damp_update (ri, rn, afi, safi);
2381 if (ret == BGP_DAMP_SUPPRESSED)
2382 {
2383 bgp_unlock_node (rn);
2384 return 0;
2385 }
2386 }
2387
2388 /* Nexthop reachability check. */
2389 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2390 {
2391 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2392 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2393 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2394 connected = 1;
2395 else
2396 connected = 0;
2397
2398 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
2399 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2400 else
2401 {
2402 if (BGP_DEBUG(nht, NHT))
2403 {
2404 char buf1[INET6_ADDRSTRLEN];
2405 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2406 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2407 }
2408 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2409 }
2410 }
2411 else
2412 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2413
2414 /* Process change. */
2415 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2416
2417 bgp_process (bgp, rn, afi, safi);
2418 bgp_unlock_node (rn);
2419
2420 return 0;
2421 } // End of implicit withdraw
2422
2423 /* Received Logging. */
2424 if (bgp_debug_update(peer, p, NULL, 1))
2425 {
2426 if (!peer->rcvd_attr_printed)
2427 {
2428 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2429 peer->rcvd_attr_printed = 1;
2430 }
2431
2432 bgp_info_addpath_rx_str(addpath_id, buf2);
2433 zlog_debug ("%s rcvd %s/%d%s",
2434 peer->host,
2435 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2436 p->prefixlen, buf2);
2437 }
2438
2439 /* Make new BGP info. */
2440 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2441
2442 /* Update MPLS tag. */
2443 if (safi == SAFI_MPLS_VPN)
2444 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2445
2446 /* Nexthop reachability check. */
2447 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2448 {
2449 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2450 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2451 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2452 connected = 1;
2453 else
2454 connected = 0;
2455
2456 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
2457 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2458 else
2459 {
2460 if (BGP_DEBUG(nht, NHT))
2461 {
2462 char buf1[INET6_ADDRSTRLEN];
2463 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2464 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2465 }
2466 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2467 }
2468 }
2469 else
2470 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2471
2472 /* Addpath ID */
2473 new->addpath_rx_id = addpath_id;
2474
2475 /* Increment prefix */
2476 bgp_aggregate_increment (bgp, p, new, afi, safi);
2477
2478 /* Register new BGP information. */
2479 bgp_info_add (rn, new);
2480
2481 /* route_node_get lock */
2482 bgp_unlock_node (rn);
2483
2484 /* If maximum prefix count is configured and current prefix
2485 count exeed it. */
2486 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2487 return -1;
2488
2489 /* Process change. */
2490 bgp_process (bgp, rn, afi, safi);
2491
2492 return 0;
2493
2494 /* This BGP update is filtered. Log the reason then update BGP
2495 entry. */
2496 filtered:
2497 if (bgp_debug_update(peer, p, NULL, 1))
2498 {
2499 if (!peer->rcvd_attr_printed)
2500 {
2501 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2502 peer->rcvd_attr_printed = 1;
2503 }
2504
2505 bgp_info_addpath_rx_str(addpath_id, buf2);
2506 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
2507 peer->host,
2508 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2509 p->prefixlen, buf2, reason);
2510 }
2511
2512 if (ri)
2513 bgp_rib_remove (rn, ri, peer, afi, safi);
2514
2515 bgp_unlock_node (rn);
2516
2517 return 0;
2518 }
2519
2520 int
2521 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2522 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2523 struct prefix_rd *prd, u_char *tag)
2524 {
2525 struct bgp *bgp;
2526 char buf[SU_ADDRSTRLEN];
2527 char buf2[30];
2528 struct bgp_node *rn;
2529 struct bgp_info *ri;
2530
2531 bgp = peer->bgp;
2532
2533 /* Lookup node. */
2534 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2535
2536 /* If peer is soft reconfiguration enabled. Record input packet for
2537 further calculation. */
2538 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2539 && peer != bgp->peer_self)
2540 bgp_adj_in_unset (rn, peer, addpath_id);
2541
2542 /* Lookup withdrawn route. */
2543 for (ri = rn->info; ri; ri = ri->next)
2544 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2545 ri->addpath_rx_id == addpath_id)
2546 break;
2547
2548 /* Logging. */
2549 if (bgp_debug_update(peer, p, NULL, 1))
2550 {
2551 bgp_info_addpath_rx_str(addpath_id, buf2);
2552 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2553 peer->host,
2554 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2555 p->prefixlen, buf2);
2556 }
2557
2558 /* Withdraw specified route from routing table. */
2559 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2560 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2561 else if (bgp_debug_update(peer, p, NULL, 1))
2562 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2563 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2564 p->prefixlen);
2565
2566 /* Unlock bgp_node_get() lock. */
2567 bgp_unlock_node (rn);
2568
2569 return 0;
2570 }
2571
2572 void
2573 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2574 {
2575 struct update_subgroup *subgrp;
2576 subgrp = peer_subgroup(peer, afi, safi);
2577 subgroup_default_originate(subgrp, withdraw);
2578 }
2579
2580
2581 /*
2582 * bgp_stop_announce_route_timer
2583 */
2584 void
2585 bgp_stop_announce_route_timer (struct peer_af *paf)
2586 {
2587 if (!paf->t_announce_route)
2588 return;
2589
2590 THREAD_TIMER_OFF (paf->t_announce_route);
2591 }
2592
2593 /*
2594 * bgp_announce_route_timer_expired
2595 *
2596 * Callback that is invoked when the route announcement timer for a
2597 * peer_af expires.
2598 */
2599 static int
2600 bgp_announce_route_timer_expired (struct thread *t)
2601 {
2602 struct peer_af *paf;
2603 struct peer *peer;
2604
2605
2606 paf = THREAD_ARG (t);
2607 peer = paf->peer;
2608
2609 assert (paf->t_announce_route);
2610 paf->t_announce_route = NULL;
2611
2612 if (peer->status != Established)
2613 return 0;
2614
2615 if (!peer->afc_nego[paf->afi][paf->safi])
2616 return 0;
2617
2618 peer_af_announce_route (paf, 1);
2619 return 0;
2620 }
2621
2622 /*
2623 * bgp_announce_route
2624 *
2625 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2626 */
2627 void
2628 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2629 {
2630 struct peer_af *paf;
2631 struct update_subgroup *subgrp;
2632
2633 paf = peer_af_find (peer, afi, safi);
2634 if (!paf)
2635 return;
2636 subgrp = PAF_SUBGRP(paf);
2637
2638 /*
2639 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2640 * or a refresh has already been triggered.
2641 */
2642 if (!subgrp || paf->t_announce_route)
2643 return;
2644
2645 /*
2646 * Start a timer to stagger/delay the announce. This serves
2647 * two purposes - announcement can potentially be combined for
2648 * multiple peers and the announcement doesn't happen in the
2649 * vty context.
2650 */
2651 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
2652 bgp_announce_route_timer_expired, paf,
2653 (subgrp->peer_count == 1) ?
2654 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2655 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2656 }
2657
2658 /*
2659 * Announce routes from all AF tables to a peer.
2660 *
2661 * This should ONLY be called when there is a need to refresh the
2662 * routes to the peer based on a policy change for this peer alone
2663 * or a route refresh request received from the peer.
2664 * The operation will result in splitting the peer from its existing
2665 * subgroups and putting it in new subgroups.
2666 */
2667 void
2668 bgp_announce_route_all (struct peer *peer)
2669 {
2670 afi_t afi;
2671 safi_t safi;
2672
2673 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2674 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2675 bgp_announce_route (peer, afi, safi);
2676 }
2677
2678 static void
2679 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2680 struct bgp_table *table, struct prefix_rd *prd)
2681 {
2682 int ret;
2683 struct bgp_node *rn;
2684 struct bgp_adj_in *ain;
2685
2686 if (! table)
2687 table = peer->bgp->rib[afi][safi];
2688
2689 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2690 for (ain = rn->adj_in; ain; ain = ain->next)
2691 {
2692 if (ain->peer == peer)
2693 {
2694 struct bgp_info *ri = rn->info;
2695 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2696
2697 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
2698 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2699 prd, tag, 1);
2700
2701 if (ret < 0)
2702 {
2703 bgp_unlock_node (rn);
2704 return;
2705 }
2706 }
2707 }
2708 }
2709
2710 void
2711 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2712 {
2713 struct bgp_node *rn;
2714 struct bgp_table *table;
2715
2716 if (peer->status != Established)
2717 return;
2718
2719 if (safi != SAFI_MPLS_VPN)
2720 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
2721 else
2722 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2723 rn = bgp_route_next (rn))
2724 if ((table = rn->info) != NULL)
2725 {
2726 struct prefix_rd prd;
2727 prd.family = AF_UNSPEC;
2728 prd.prefixlen = 64;
2729 memcpy(&prd.val, rn->p.u.val, 8);
2730
2731 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2732 }
2733 }
2734
2735
2736 struct bgp_clear_node_queue
2737 {
2738 struct bgp_node *rn;
2739 };
2740
2741 static wq_item_status
2742 bgp_clear_route_node (struct work_queue *wq, void *data)
2743 {
2744 struct bgp_clear_node_queue *cnq = data;
2745 struct bgp_node *rn = cnq->rn;
2746 struct peer *peer = wq->spec.data;
2747 struct bgp_info *ri;
2748 afi_t afi = bgp_node_table (rn)->afi;
2749 safi_t safi = bgp_node_table (rn)->safi;
2750
2751 assert (rn && peer);
2752
2753 /* It is possible that we have multiple paths for a prefix from a peer
2754 * if that peer is using AddPath.
2755 */
2756 for (ri = rn->info; ri; ri = ri->next)
2757 if (ri->peer == peer)
2758 {
2759 /* graceful restart STALE flag set. */
2760 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2761 && peer->nsf[afi][safi]
2762 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2763 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2764 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
2765 else
2766 bgp_rib_remove (rn, ri, peer, afi, safi);
2767 }
2768 return WQ_SUCCESS;
2769 }
2770
2771 static void
2772 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
2773 {
2774 struct bgp_clear_node_queue *cnq = data;
2775 struct bgp_node *rn = cnq->rn;
2776 struct bgp_table *table = bgp_node_table (rn);
2777
2778 bgp_unlock_node (rn);
2779 bgp_table_unlock (table);
2780 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
2781 }
2782
2783 static void
2784 bgp_clear_node_complete (struct work_queue *wq)
2785 {
2786 struct peer *peer = wq->spec.data;
2787
2788 /* Tickle FSM to start moving again */
2789 BGP_EVENT_ADD (peer, Clearing_Completed);
2790
2791 peer_unlock (peer); /* bgp_clear_route */
2792 }
2793
2794 static void
2795 bgp_clear_node_queue_init (struct peer *peer)
2796 {
2797 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
2798
2799 snprintf (wname, sizeof(wname), "clear %s", peer->host);
2800 #undef CLEAR_QUEUE_NAME_LEN
2801
2802 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
2803 {
2804 zlog_err ("%s: Failed to allocate work queue", __func__);
2805 exit (1);
2806 }
2807 peer->clear_node_queue->spec.hold = 10;
2808 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2809 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2810 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2811 peer->clear_node_queue->spec.max_retries = 0;
2812
2813 /* we only 'lock' this peer reference when the queue is actually active */
2814 peer->clear_node_queue->spec.data = peer;
2815 }
2816
2817 static void
2818 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2819 struct bgp_table *table)
2820 {
2821 struct bgp_node *rn;
2822
2823
2824 if (! table)
2825 table = peer->bgp->rib[afi][safi];
2826
2827 /* If still no table => afi/safi isn't configured at all or smth. */
2828 if (! table)
2829 return;
2830
2831 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2832 {
2833 struct bgp_info *ri;
2834 struct bgp_adj_in *ain;
2835 struct bgp_adj_in *ain_next;
2836
2837 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2838 * queued for every clearing peer, regardless of whether it is
2839 * relevant to the peer at hand.
2840 *
2841 * Overview: There are 3 different indices which need to be
2842 * scrubbed, potentially, when a peer is removed:
2843 *
2844 * 1 peer's routes visible via the RIB (ie accepted routes)
2845 * 2 peer's routes visible by the (optional) peer's adj-in index
2846 * 3 other routes visible by the peer's adj-out index
2847 *
2848 * 3 there is no hurry in scrubbing, once the struct peer is
2849 * removed from bgp->peer, we could just GC such deleted peer's
2850 * adj-outs at our leisure.
2851 *
2852 * 1 and 2 must be 'scrubbed' in some way, at least made
2853 * invisible via RIB index before peer session is allowed to be
2854 * brought back up. So one needs to know when such a 'search' is
2855 * complete.
2856 *
2857 * Ideally:
2858 *
2859 * - there'd be a single global queue or a single RIB walker
2860 * - rather than tracking which route_nodes still need to be
2861 * examined on a peer basis, we'd track which peers still
2862 * aren't cleared
2863 *
2864 * Given that our per-peer prefix-counts now should be reliable,
2865 * this may actually be achievable. It doesn't seem to be a huge
2866 * problem at this time,
2867 *
2868 * It is possible that we have multiple paths for a prefix from a peer
2869 * if that peer is using AddPath.
2870 */
2871 ain = rn->adj_in;
2872 while (ain)
2873 {
2874 ain_next = ain->next;
2875
2876 if (ain->peer == peer)
2877 {
2878 bgp_adj_in_remove (rn, ain);
2879 bgp_unlock_node (rn);
2880 }
2881
2882 ain = ain_next;
2883 }
2884
2885 for (ri = rn->info; ri; ri = ri->next)
2886 if (ri->peer == peer)
2887 {
2888 struct bgp_clear_node_queue *cnq;
2889
2890 /* both unlocked in bgp_clear_node_queue_del */
2891 bgp_table_lock (bgp_node_table (rn));
2892 bgp_lock_node (rn);
2893 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2894 sizeof (struct bgp_clear_node_queue));
2895 cnq->rn = rn;
2896 work_queue_add (peer->clear_node_queue, cnq);
2897 break;
2898 }
2899 }
2900 return;
2901 }
2902
2903 void
2904 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2905 {
2906 struct bgp_node *rn;
2907 struct bgp_table *table;
2908
2909 if (peer->clear_node_queue == NULL)
2910 bgp_clear_node_queue_init (peer);
2911
2912 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2913 * Idle until it receives a Clearing_Completed event. This protects
2914 * against peers which flap faster than we can we clear, which could
2915 * lead to:
2916 *
2917 * a) race with routes from the new session being installed before
2918 * clear_route_node visits the node (to delete the route of that
2919 * peer)
2920 * b) resource exhaustion, clear_route_node likely leads to an entry
2921 * on the process_main queue. Fast-flapping could cause that queue
2922 * to grow and grow.
2923 */
2924
2925 /* lock peer in assumption that clear-node-queue will get nodes; if so,
2926 * the unlock will happen upon work-queue completion; other wise, the
2927 * unlock happens at the end of this function.
2928 */
2929 if (!peer->clear_node_queue->thread)
2930 peer_lock (peer);
2931
2932 if (safi != SAFI_MPLS_VPN)
2933 bgp_clear_route_table (peer, afi, safi, NULL);
2934 else
2935 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2936 rn = bgp_route_next (rn))
2937 if ((table = rn->info) != NULL)
2938 bgp_clear_route_table (peer, afi, safi, table);
2939
2940 /* unlock if no nodes got added to the clear-node-queue. */
2941 if (!peer->clear_node_queue->thread)
2942 peer_unlock (peer);
2943
2944 }
2945
2946 void
2947 bgp_clear_route_all (struct peer *peer)
2948 {
2949 afi_t afi;
2950 safi_t safi;
2951
2952 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2953 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2954 bgp_clear_route (peer, afi, safi);
2955 }
2956
2957 void
2958 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2959 {
2960 struct bgp_table *table;
2961 struct bgp_node *rn;
2962 struct bgp_adj_in *ain;
2963 struct bgp_adj_in *ain_next;
2964
2965 table = peer->bgp->rib[afi][safi];
2966
2967 /* It is possible that we have multiple paths for a prefix from a peer
2968 * if that peer is using AddPath.
2969 */
2970 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2971 {
2972 ain = rn->adj_in;
2973
2974 while (ain)
2975 {
2976 ain_next = ain->next;
2977
2978 if (ain->peer == peer)
2979 {
2980 bgp_adj_in_remove (rn, ain);
2981 bgp_unlock_node (rn);
2982 }
2983
2984 ain = ain_next;
2985 }
2986 }
2987 }
2988
2989 void
2990 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2991 {
2992 struct bgp_node *rn;
2993 struct bgp_info *ri;
2994 struct bgp_table *table;
2995
2996 table = peer->bgp->rib[afi][safi];
2997
2998 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2999 {
3000 for (ri = rn->info; ri; ri = ri->next)
3001 if (ri->peer == peer)
3002 {
3003 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3004 bgp_rib_remove (rn, ri, peer, afi, safi);
3005 break;
3006 }
3007 }
3008 }
3009
3010 /* Delete all kernel routes. */
3011 void
3012 bgp_cleanup_routes (void)
3013 {
3014 struct bgp *bgp;
3015 struct listnode *node, *nnode;
3016 struct bgp_node *rn;
3017 struct bgp_table *table;
3018 struct bgp_info *ri;
3019
3020 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
3021 {
3022 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3023
3024 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3025 for (ri = rn->info; ri; ri = ri->next)
3026 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3027 && ri->type == ZEBRA_ROUTE_BGP
3028 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3029 ri->sub_type == BGP_ROUTE_AGGREGATE))
3030 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
3031
3032 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3033
3034 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3035 for (ri = rn->info; ri; ri = ri->next)
3036 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3037 && ri->type == ZEBRA_ROUTE_BGP
3038 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3039 ri->sub_type == BGP_ROUTE_AGGREGATE))
3040 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
3041 }
3042 }
3043
3044 void
3045 bgp_reset (void)
3046 {
3047 vty_reset ();
3048 bgp_zclient_reset ();
3049 access_list_reset ();
3050 prefix_list_reset ();
3051 }
3052
3053 static int
3054 bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3055 {
3056 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3057 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3058 }
3059
3060 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3061 value. */
3062 int
3063 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3064 {
3065 u_char *pnt;
3066 u_char *lim;
3067 struct prefix p;
3068 int psize;
3069 int ret;
3070 afi_t afi;
3071 safi_t safi;
3072 int addpath_encoded;
3073 u_int32_t addpath_id;
3074
3075 /* Check peer status. */
3076 if (peer->status != Established)
3077 return 0;
3078
3079 pnt = packet->nlri;
3080 lim = pnt + packet->length;
3081 afi = packet->afi;
3082 safi = packet->safi;
3083 addpath_id = 0;
3084 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3085
3086 for (; pnt < lim; pnt += psize)
3087 {
3088 /* Clear prefix structure. */
3089 memset (&p, 0, sizeof (struct prefix));
3090
3091 if (addpath_encoded)
3092 {
3093
3094 /* When packet overflow occurs return immediately. */
3095 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3096 return -1;
3097
3098 addpath_id = ntohl(*((uint32_t*) pnt));
3099 pnt += BGP_ADDPATH_ID_LEN;
3100 }
3101
3102 /* Fetch prefix length. */
3103 p.prefixlen = *pnt++;
3104 p.family = afi2family (afi);
3105
3106 /* Already checked in nlri_sanity_check(). We do double check
3107 here. */
3108 if ((afi == AFI_IP && p.prefixlen > 32)
3109 || (afi == AFI_IP6 && p.prefixlen > 128))
3110 return -1;
3111
3112 /* Packet size overflow check. */
3113 psize = PSIZE (p.prefixlen);
3114
3115 /* When packet overflow occur return immediately. */
3116 if (pnt + psize > lim)
3117 return -1;
3118
3119 /* Fetch prefix from NLRI packet. */
3120 memcpy (&p.u.prefix, pnt, psize);
3121
3122 /* Check address. */
3123 if (afi == AFI_IP && safi == SAFI_UNICAST)
3124 {
3125 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3126 {
3127 /*
3128 * From draft-ietf-idr-bgp4-22, Section 6.3:
3129 * If a BGP router receives an UPDATE message with a
3130 * semantically incorrect NLRI field, in which a prefix is
3131 * semantically incorrect (eg. an unexpected multicast IP
3132 * address), it should ignore the prefix.
3133 */
3134 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3135 inet_ntoa (p.u.prefix4));
3136
3137 return -1;
3138 }
3139 }
3140
3141 #ifdef HAVE_IPV6
3142 /* Check address. */
3143 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3144 {
3145 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3146 {
3147 char buf[BUFSIZ];
3148
3149 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3150 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3151
3152 continue;
3153 }
3154 }
3155 #endif /* HAVE_IPV6 */
3156
3157 /* Normal process. */
3158 if (attr)
3159 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3160 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3161 else
3162 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3163 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3164
3165 /* Address family configuration mismatch or maximum-prefix count
3166 overflow. */
3167 if (ret < 0)
3168 return -1;
3169 }
3170
3171 /* Packet length consistency check. */
3172 if (pnt != lim)
3173 return -1;
3174
3175 return 0;
3176 }
3177
3178 /* NLRI encode syntax check routine. */
3179 int
3180 bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
3181 bgp_size_t length, int *numpfx)
3182 {
3183 u_char *end;
3184 u_char prefixlen;
3185 int psize;
3186 int addpath_encoded;
3187
3188 *numpfx = 0;
3189 end = pnt + length;
3190 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3191
3192 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3193 syntactic validity. If the field is syntactically incorrect,
3194 then the Error Subcode is set to Invalid Network Field. */
3195
3196 while (pnt < end)
3197 {
3198
3199 /* If the NLRI is encoded using addpath then the first 4 bytes are
3200 * the addpath ID. */
3201 if (addpath_encoded)
3202 {
3203 if (pnt + BGP_ADDPATH_ID_LEN > end)
3204 {
3205 zlog_err ("%s [Error] Update packet error"
3206 " (prefix data addpath overflow)",
3207 peer->host);
3208 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3209 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3210 return -1;
3211 }
3212 pnt += BGP_ADDPATH_ID_LEN;
3213 }
3214
3215 prefixlen = *pnt++;
3216
3217 /* Prefix length check. */
3218 if ((afi == AFI_IP && prefixlen > 32)
3219 || (afi == AFI_IP6 && prefixlen > 128))
3220 {
3221 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
3222 peer->host, prefixlen);
3223 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3224 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3225 return -1;
3226 }
3227
3228 /* Packet size overflow check. */
3229 psize = PSIZE (prefixlen);
3230
3231 if (pnt + psize > end)
3232 {
3233 zlog_err ("%s [Error] Update packet error"
3234 " (prefix data overflow prefix size is %d)",
3235 peer->host, psize);
3236 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3237 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3238 return -1;
3239 }
3240
3241 pnt += psize;
3242 (*numpfx)++;
3243 }
3244
3245 /* Packet length consistency check. */
3246 if (pnt != end)
3247 {
3248 zlog_err ("%s [Error] Update packet error"
3249 " (prefix length mismatch with total length)",
3250 peer->host);
3251 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3252 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3253 return -1;
3254 }
3255 return 0;
3256 }
3257
3258 static struct bgp_static *
3259 bgp_static_new (void)
3260 {
3261 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3262 }
3263
3264 static void
3265 bgp_static_free (struct bgp_static *bgp_static)
3266 {
3267 if (bgp_static->rmap.name)
3268 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3269 XFREE (MTYPE_BGP_STATIC, bgp_static);
3270 }
3271
3272 static void
3273 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3274 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3275 {
3276 struct bgp_node *rn;
3277 struct bgp_info *ri;
3278 struct bgp_info *new;
3279 struct bgp_info info;
3280 struct attr attr;
3281 struct attr *attr_new;
3282 int ret;
3283
3284 assert (bgp_static);
3285 if (!bgp_static)
3286 return;
3287
3288 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3289
3290 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3291
3292 attr.nexthop = bgp_static->igpnexthop;
3293 attr.med = bgp_static->igpmetric;
3294 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3295
3296 if (bgp_static->atomic)
3297 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3298
3299 /* Apply route-map. */
3300 if (bgp_static->rmap.name)
3301 {
3302 struct attr attr_tmp = attr;
3303 info.peer = bgp->peer_self;
3304 info.attr = &attr_tmp;
3305
3306 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3307
3308 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3309
3310 bgp->peer_self->rmap_type = 0;
3311
3312 if (ret == RMAP_DENYMATCH)
3313 {
3314 /* Free uninterned attribute. */
3315 bgp_attr_flush (&attr_tmp);
3316
3317 /* Unintern original. */
3318 aspath_unintern (&attr.aspath);
3319 bgp_attr_extra_free (&attr);
3320 bgp_static_withdraw (bgp, p, afi, safi);
3321 return;
3322 }
3323 attr_new = bgp_attr_intern (&attr_tmp);
3324 }
3325 else
3326 attr_new = bgp_attr_intern (&attr);
3327
3328 for (ri = rn->info; ri; ri = ri->next)
3329 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3330 && ri->sub_type == BGP_ROUTE_STATIC)
3331 break;
3332
3333 if (ri)
3334 {
3335 if (attrhash_cmp (ri->attr, attr_new) &&
3336 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3337 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
3338 {
3339 bgp_unlock_node (rn);
3340 bgp_attr_unintern (&attr_new);
3341 aspath_unintern (&attr.aspath);
3342 bgp_attr_extra_free (&attr);
3343 return;
3344 }
3345 else
3346 {
3347 /* The attribute is changed. */
3348 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3349
3350 /* Rewrite BGP route information. */
3351 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3352 bgp_info_restore(rn, ri);
3353 else
3354 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3355 bgp_attr_unintern (&ri->attr);
3356 ri->attr = attr_new;
3357 ri->uptime = bgp_clock ();
3358
3359 /* Nexthop reachability check. */
3360 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3361 {
3362 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
3363 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3364 else
3365 {
3366 if (BGP_DEBUG(nht, NHT))
3367 {
3368 char buf1[INET6_ADDRSTRLEN];
3369 inet_ntop(p->family, &p->u.prefix, buf1,
3370 INET6_ADDRSTRLEN);
3371 zlog_debug("%s(%s): Route not in table, not advertising",
3372 __FUNCTION__, buf1);
3373 }
3374 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3375 }
3376 }
3377 else
3378 {
3379 /* Delete the NHT structure if any, if we're toggling between
3380 * enabling/disabling import check. We deregister the route
3381 * from NHT to avoid overloading NHT and the process interaction
3382 */
3383 bgp_unlink_nexthop(ri);
3384 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3385 }
3386 /* Process change. */
3387 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3388 bgp_process (bgp, rn, afi, safi);
3389 bgp_unlock_node (rn);
3390 aspath_unintern (&attr.aspath);
3391 bgp_attr_extra_free (&attr);
3392 return;
3393 }
3394 }
3395
3396 /* Make new BGP info. */
3397 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3398 rn);
3399 /* Nexthop reachability check. */
3400 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3401 {
3402 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
3403 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3404 else
3405 {
3406 if (BGP_DEBUG(nht, NHT))
3407 {
3408 char buf1[INET6_ADDRSTRLEN];
3409 inet_ntop(p->family, &p->u.prefix, buf1,
3410 INET6_ADDRSTRLEN);
3411 zlog_debug("%s(%s): Route not in table, not advertising",
3412 __FUNCTION__, buf1);
3413 }
3414 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3415 }
3416 }
3417 else
3418 {
3419 /* Delete the NHT structure if any, if we're toggling between
3420 * enabling/disabling import check. We deregister the route
3421 * from NHT to avoid overloading NHT and the process interaction
3422 */
3423 bgp_unlink_nexthop(new);
3424
3425 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3426 }
3427
3428 /* Aggregate address increment. */
3429 bgp_aggregate_increment (bgp, p, new, afi, safi);
3430
3431 /* Register new BGP information. */
3432 bgp_info_add (rn, new);
3433
3434 /* route_node_get lock */
3435 bgp_unlock_node (rn);
3436
3437 /* Process change. */
3438 bgp_process (bgp, rn, afi, safi);
3439
3440 /* Unintern original. */
3441 aspath_unintern (&attr.aspath);
3442 bgp_attr_extra_free (&attr);
3443 }
3444
3445 void
3446 bgp_static_update (struct bgp *bgp, struct prefix *p,
3447 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3448 {
3449 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3450 }
3451
3452 static void
3453 bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3454 safi_t safi, struct prefix_rd *prd, u_char *tag)
3455 {
3456 struct bgp_node *rn;
3457 struct bgp_info *new;
3458
3459 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3460
3461 /* Make new BGP info. */
3462 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
3463 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3464
3465 SET_FLAG (new->flags, BGP_INFO_VALID);
3466 new->extra = bgp_info_extra_new();
3467 memcpy (new->extra->tag, tag, 3);
3468
3469 /* Aggregate address increment. */
3470 bgp_aggregate_increment (bgp, p, new, afi, safi);
3471
3472 /* Register new BGP information. */
3473 bgp_info_add (rn, new);
3474
3475 /* route_node_get lock */
3476 bgp_unlock_node (rn);
3477
3478 /* Process change. */
3479 bgp_process (bgp, rn, afi, safi);
3480 }
3481
3482 void
3483 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3484 safi_t safi)
3485 {
3486 struct bgp_node *rn;
3487 struct bgp_info *ri;
3488
3489 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3490
3491 /* Check selected route and self inserted route. */
3492 for (ri = rn->info; ri; ri = ri->next)
3493 if (ri->peer == bgp->peer_self
3494 && ri->type == ZEBRA_ROUTE_BGP
3495 && ri->sub_type == BGP_ROUTE_STATIC)
3496 break;
3497
3498 /* Withdraw static BGP route from routing table. */
3499 if (ri)
3500 {
3501 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3502 bgp_unlink_nexthop(ri);
3503 bgp_info_delete (rn, ri);
3504 bgp_process (bgp, rn, afi, safi);
3505 }
3506
3507 /* Unlock bgp_node_lookup. */
3508 bgp_unlock_node (rn);
3509 }
3510
3511 static void
3512 bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3513 safi_t safi, struct prefix_rd *prd, u_char *tag)
3514 {
3515 struct bgp_node *rn;
3516 struct bgp_info *ri;
3517
3518 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3519
3520 /* Check selected route and self inserted route. */
3521 for (ri = rn->info; ri; ri = ri->next)
3522 if (ri->peer == bgp->peer_self
3523 && ri->type == ZEBRA_ROUTE_BGP
3524 && ri->sub_type == BGP_ROUTE_STATIC)
3525 break;
3526
3527 /* Withdraw static BGP route from routing table. */
3528 if (ri)
3529 {
3530 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3531 bgp_info_delete (rn, ri);
3532 bgp_process (bgp, rn, afi, safi);
3533 }
3534
3535 /* Unlock bgp_node_lookup. */
3536 bgp_unlock_node (rn);
3537 }
3538
3539 /* Configure static BGP network. When user don't run zebra, static
3540 route should be installed as valid. */
3541 static int
3542 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3543 afi_t afi, safi_t safi, const char *rmap, int backdoor)
3544 {
3545 int ret;
3546 struct prefix p;
3547 struct bgp_static *bgp_static;
3548 struct bgp_node *rn;
3549 u_char need_update = 0;
3550
3551 /* Convert IP prefix string to struct prefix. */
3552 ret = str2prefix (ip_str, &p);
3553 if (! ret)
3554 {
3555 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3556 return CMD_WARNING;
3557 }
3558 #ifdef HAVE_IPV6
3559 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3560 {
3561 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3562 VTY_NEWLINE);
3563 return CMD_WARNING;
3564 }
3565 #endif /* HAVE_IPV6 */
3566
3567 apply_mask (&p);
3568
3569 /* Set BGP static route configuration. */
3570 rn = bgp_node_get (bgp->route[afi][safi], &p);
3571
3572 if (rn->info)
3573 {
3574 /* Configuration change. */
3575 bgp_static = rn->info;
3576
3577 /* Check previous routes are installed into BGP. */
3578 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3579 need_update = 1;
3580
3581 bgp_static->backdoor = backdoor;
3582
3583 if (rmap)
3584 {
3585 if (bgp_static->rmap.name)
3586 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3587 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
3588 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3589 }
3590 else
3591 {
3592 if (bgp_static->rmap.name)
3593 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3594 bgp_static->rmap.name = NULL;
3595 bgp_static->rmap.map = NULL;
3596 bgp_static->valid = 0;
3597 }
3598 bgp_unlock_node (rn);
3599 }
3600 else
3601 {
3602 /* New configuration. */
3603 bgp_static = bgp_static_new ();
3604 bgp_static->backdoor = backdoor;
3605 bgp_static->valid = 0;
3606 bgp_static->igpmetric = 0;
3607 bgp_static->igpnexthop.s_addr = 0;
3608
3609 if (rmap)
3610 {
3611 if (bgp_static->rmap.name)
3612 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3613 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
3614 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3615 }
3616 rn->info = bgp_static;
3617 }
3618
3619 bgp_static->valid = 1;
3620 if (need_update)
3621 bgp_static_withdraw (bgp, &p, afi, safi);
3622
3623 if (! bgp_static->backdoor)
3624 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3625
3626 return CMD_SUCCESS;
3627 }
3628
3629 /* Configure static BGP network. */
3630 static int
3631 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
3632 afi_t afi, safi_t safi)
3633 {
3634 int ret;
3635 struct prefix p;
3636 struct bgp_static *bgp_static;
3637 struct bgp_node *rn;
3638
3639 /* Convert IP prefix string to struct prefix. */
3640 ret = str2prefix (ip_str, &p);
3641 if (! ret)
3642 {
3643 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3644 return CMD_WARNING;
3645 }
3646 #ifdef HAVE_IPV6
3647 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3648 {
3649 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3650 VTY_NEWLINE);
3651 return CMD_WARNING;
3652 }
3653 #endif /* HAVE_IPV6 */
3654
3655 apply_mask (&p);
3656
3657 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3658 if (! rn)
3659 {
3660 vty_out (vty, "%% Can't find specified static route configuration.%s",
3661 VTY_NEWLINE);
3662 return CMD_WARNING;
3663 }
3664
3665 bgp_static = rn->info;
3666
3667 /* Update BGP RIB. */
3668 if (! bgp_static->backdoor)
3669 bgp_static_withdraw (bgp, &p, afi, safi);
3670
3671 /* Clear configuration. */
3672 bgp_static_free (bgp_static);
3673 rn->info = NULL;
3674 bgp_unlock_node (rn);
3675 bgp_unlock_node (rn);
3676
3677 return CMD_SUCCESS;
3678 }
3679
3680 void
3681 bgp_static_add (struct bgp *bgp)
3682 {
3683 afi_t afi;
3684 safi_t safi;
3685 struct bgp_node *rn;
3686 struct bgp_node *rm;
3687 struct bgp_table *table;
3688 struct bgp_static *bgp_static;
3689
3690 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3691 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3692 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3693 if (rn->info != NULL)
3694 {
3695 if (safi == SAFI_MPLS_VPN)
3696 {
3697 table = rn->info;
3698
3699 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3700 {
3701 bgp_static = rn->info;
3702 bgp_static_update_vpnv4 (bgp, &rm->p,
3703 AFI_IP, SAFI_MPLS_VPN,
3704 (struct prefix_rd *)&rn->p,
3705 bgp_static->tag);
3706 }
3707 }
3708 else
3709 {
3710 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
3711 }
3712 }
3713 }
3714
3715 /* Called from bgp_delete(). Delete all static routes from the BGP
3716 instance. */
3717 void
3718 bgp_static_delete (struct bgp *bgp)
3719 {
3720 afi_t afi;
3721 safi_t safi;
3722 struct bgp_node *rn;
3723 struct bgp_node *rm;
3724 struct bgp_table *table;
3725 struct bgp_static *bgp_static;
3726
3727 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3728 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3729 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3730 if (rn->info != NULL)
3731 {
3732 if (safi == SAFI_MPLS_VPN)
3733 {
3734 table = rn->info;
3735
3736 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3737 {
3738 bgp_static = rn->info;
3739 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3740 AFI_IP, SAFI_MPLS_VPN,
3741 (struct prefix_rd *)&rn->p,
3742 bgp_static->tag);
3743 bgp_static_free (bgp_static);
3744 rn->info = NULL;
3745 bgp_unlock_node (rn);
3746 }
3747 }
3748 else
3749 {
3750 bgp_static = rn->info;
3751 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3752 bgp_static_free (bgp_static);
3753 rn->info = NULL;
3754 bgp_unlock_node (rn);
3755 }
3756 }
3757 }
3758
3759 void
3760 bgp_static_redo_import_check (struct bgp *bgp)
3761 {
3762 afi_t afi;
3763 safi_t safi;
3764 struct bgp_node *rn;
3765 struct bgp_static *bgp_static;
3766
3767 /* Use this flag to force reprocessing of the route */
3768 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3769 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3770 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3771 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3772 if (rn->info != NULL)
3773 {
3774 bgp_static = rn->info;
3775 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
3776 }
3777 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
3778 }
3779
3780 static void
3781 bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
3782 {
3783 struct bgp_table *table;
3784 struct bgp_node *rn;
3785 struct bgp_info *ri;
3786
3787 table = bgp->rib[afi][safi];
3788 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3789 {
3790 for (ri = rn->info; ri; ri = ri->next)
3791 {
3792 if (ri->peer == bgp->peer_self &&
3793 ((ri->type == ZEBRA_ROUTE_BGP &&
3794 ri->sub_type == BGP_ROUTE_STATIC) ||
3795 (ri->type != ZEBRA_ROUTE_BGP &&
3796 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
3797 {
3798 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
3799 bgp_unlink_nexthop(ri);
3800 bgp_info_delete (rn, ri);
3801 bgp_process (bgp, rn, afi, safi);
3802 }
3803 }
3804 }
3805 }
3806
3807 /*
3808 * Purge all networks and redistributed routes from routing table.
3809 * Invoked upon the instance going down.
3810 */
3811 void
3812 bgp_purge_static_redist_routes (struct bgp *bgp)
3813 {
3814 afi_t afi;
3815 safi_t safi;
3816
3817 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3818 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3819 bgp_purge_af_static_redist_routes (bgp, afi, safi);
3820 }
3821
3822 int
3823 bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3824 const char *tag_str)
3825 {
3826 int ret;
3827 struct prefix p;
3828 struct prefix_rd prd;
3829 struct bgp *bgp;
3830 struct bgp_node *prn;
3831 struct bgp_node *rn;
3832 struct bgp_table *table;
3833 struct bgp_static *bgp_static;
3834 u_char tag[3];
3835
3836 bgp = vty->index;
3837
3838 ret = str2prefix (ip_str, &p);
3839 if (! ret)
3840 {
3841 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3842 return CMD_WARNING;
3843 }
3844 apply_mask (&p);
3845
3846 ret = str2prefix_rd (rd_str, &prd);
3847 if (! ret)
3848 {
3849 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3850 return CMD_WARNING;
3851 }
3852
3853 ret = str2tag (tag_str, tag);
3854 if (! ret)
3855 {
3856 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3857 return CMD_WARNING;
3858 }
3859
3860 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3861 (struct prefix *)&prd);
3862 if (prn->info == NULL)
3863 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3864 else
3865 bgp_unlock_node (prn);
3866 table = prn->info;
3867
3868 rn = bgp_node_get (table, &p);
3869
3870 if (rn->info)
3871 {
3872 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3873 bgp_unlock_node (rn);
3874 }
3875 else
3876 {
3877 /* New configuration. */
3878 bgp_static = bgp_static_new ();
3879 bgp_static->valid = 1;
3880 memcpy (bgp_static->tag, tag, 3);
3881 rn->info = bgp_static;
3882
3883 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3884 }
3885
3886 return CMD_SUCCESS;
3887 }
3888
3889 /* Configure static BGP network. */
3890 int
3891 bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3892 const char *rd_str, const char *tag_str)
3893 {
3894 int ret;
3895 struct bgp *bgp;
3896 struct prefix p;
3897 struct prefix_rd prd;
3898 struct bgp_node *prn;
3899 struct bgp_node *rn;
3900 struct bgp_table *table;
3901 struct bgp_static *bgp_static;
3902 u_char tag[3];
3903
3904 bgp = vty->index;
3905
3906 /* Convert IP prefix string to struct prefix. */
3907 ret = str2prefix (ip_str, &p);
3908 if (! ret)
3909 {
3910 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3911 return CMD_WARNING;
3912 }
3913 apply_mask (&p);
3914
3915 ret = str2prefix_rd (rd_str, &prd);
3916 if (! ret)
3917 {
3918 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3919 return CMD_WARNING;
3920 }
3921
3922 ret = str2tag (tag_str, tag);
3923 if (! ret)
3924 {
3925 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3926 return CMD_WARNING;
3927 }
3928
3929 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3930 (struct prefix *)&prd);
3931 if (prn->info == NULL)
3932 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3933 else
3934 bgp_unlock_node (prn);
3935 table = prn->info;
3936
3937 rn = bgp_node_lookup (table, &p);
3938
3939 if (rn)
3940 {
3941 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3942
3943 bgp_static = rn->info;
3944 bgp_static_free (bgp_static);
3945 rn->info = NULL;
3946 bgp_unlock_node (rn);
3947 bgp_unlock_node (rn);
3948 }
3949 else
3950 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3951
3952 return CMD_SUCCESS;
3953 }
3954
3955 static int
3956 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
3957 const char *rmap_name)
3958 {
3959 struct bgp_rmap *rmap;
3960
3961 rmap = &bgp->table_map[afi][safi];
3962 if (rmap_name)
3963 {
3964 if (rmap->name)
3965 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
3966 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
3967 rmap->map = route_map_lookup_by_name (rmap_name);
3968 }
3969 else
3970 {
3971 if (rmap->name)
3972 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
3973 rmap->name = NULL;
3974 rmap->map = NULL;
3975 }
3976
3977 bgp_zebra_announce_table(bgp, afi, safi);
3978
3979 return CMD_SUCCESS;
3980 }
3981
3982 static int
3983 bgp_table_map_unset (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 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
3991 rmap->name = NULL;
3992 rmap->map = NULL;
3993
3994 bgp_zebra_announce_table(bgp, afi, safi);
3995
3996 return CMD_SUCCESS;
3997 }
3998
3999 int
4000 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4001 safi_t safi, int *write)
4002 {
4003 if (bgp->table_map[afi][safi].name)
4004 {
4005 bgp_config_write_family_header (vty, afi, safi, write);
4006 vty_out (vty, " table-map %s%s",
4007 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4008 }
4009
4010 return 0;
4011 }
4012
4013
4014 DEFUN (bgp_table_map,
4015 bgp_table_map_cmd,
4016 "table-map WORD",
4017 "BGP table to RIB route download filter\n"
4018 "Name of the route map\n")
4019 {
4020 return bgp_table_map_set (vty, vty->index,
4021 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4022 }
4023 DEFUN (no_bgp_table_map,
4024 no_bgp_table_map_cmd,
4025 "no table-map WORD",
4026 "BGP table to RIB route download filter\n"
4027 "Name of the route map\n")
4028 {
4029 return bgp_table_map_unset (vty, vty->index,
4030 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4031 }
4032
4033 DEFUN (bgp_network,
4034 bgp_network_cmd,
4035 "network A.B.C.D/M",
4036 "Specify a network to announce via BGP\n"
4037 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4038 {
4039 return bgp_static_set (vty, vty->index, argv[0],
4040 AFI_IP, bgp_node_safi (vty), NULL, 0);
4041 }
4042
4043 DEFUN (bgp_network_route_map,
4044 bgp_network_route_map_cmd,
4045 "network A.B.C.D/M route-map WORD",
4046 "Specify a network to announce via BGP\n"
4047 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4048 "Route-map to modify the attributes\n"
4049 "Name of the route map\n")
4050 {
4051 return bgp_static_set (vty, vty->index, argv[0],
4052 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4053 }
4054
4055 DEFUN (bgp_network_backdoor,
4056 bgp_network_backdoor_cmd,
4057 "network A.B.C.D/M backdoor",
4058 "Specify a network to announce via BGP\n"
4059 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4060 "Specify a BGP backdoor route\n")
4061 {
4062 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4063 NULL, 1);
4064 }
4065
4066 DEFUN (bgp_network_mask,
4067 bgp_network_mask_cmd,
4068 "network A.B.C.D mask A.B.C.D",
4069 "Specify a network to announce via BGP\n"
4070 "Network number\n"
4071 "Network mask\n"
4072 "Network mask\n")
4073 {
4074 int ret;
4075 char prefix_str[BUFSIZ];
4076
4077 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4078 if (! ret)
4079 {
4080 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4081 return CMD_WARNING;
4082 }
4083
4084 return bgp_static_set (vty, vty->index, prefix_str,
4085 AFI_IP, bgp_node_safi (vty), NULL, 0);
4086 }
4087
4088 DEFUN (bgp_network_mask_route_map,
4089 bgp_network_mask_route_map_cmd,
4090 "network A.B.C.D mask A.B.C.D route-map WORD",
4091 "Specify a network to announce via BGP\n"
4092 "Network number\n"
4093 "Network mask\n"
4094 "Network mask\n"
4095 "Route-map to modify the attributes\n"
4096 "Name of the route map\n")
4097 {
4098 int ret;
4099 char prefix_str[BUFSIZ];
4100
4101 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4102 if (! ret)
4103 {
4104 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4105 return CMD_WARNING;
4106 }
4107
4108 return bgp_static_set (vty, vty->index, prefix_str,
4109 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4110 }
4111
4112 DEFUN (bgp_network_mask_backdoor,
4113 bgp_network_mask_backdoor_cmd,
4114 "network A.B.C.D mask A.B.C.D backdoor",
4115 "Specify a network to announce via BGP\n"
4116 "Network number\n"
4117 "Network mask\n"
4118 "Network mask\n"
4119 "Specify a BGP backdoor route\n")
4120 {
4121 int ret;
4122 char prefix_str[BUFSIZ];
4123
4124 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4125 if (! ret)
4126 {
4127 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4128 return CMD_WARNING;
4129 }
4130
4131 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4132 NULL, 1);
4133 }
4134
4135 DEFUN (bgp_network_mask_natural,
4136 bgp_network_mask_natural_cmd,
4137 "network A.B.C.D",
4138 "Specify a network to announce via BGP\n"
4139 "Network number\n")
4140 {
4141 int ret;
4142 char prefix_str[BUFSIZ];
4143
4144 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4145 if (! ret)
4146 {
4147 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4148 return CMD_WARNING;
4149 }
4150
4151 return bgp_static_set (vty, vty->index, prefix_str,
4152 AFI_IP, bgp_node_safi (vty), NULL, 0);
4153 }
4154
4155 DEFUN (bgp_network_mask_natural_route_map,
4156 bgp_network_mask_natural_route_map_cmd,
4157 "network A.B.C.D route-map WORD",
4158 "Specify a network to announce via BGP\n"
4159 "Network number\n"
4160 "Route-map to modify the attributes\n"
4161 "Name of the route map\n")
4162 {
4163 int ret;
4164 char prefix_str[BUFSIZ];
4165
4166 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4167 if (! ret)
4168 {
4169 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4170 return CMD_WARNING;
4171 }
4172
4173 return bgp_static_set (vty, vty->index, prefix_str,
4174 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4175 }
4176
4177 DEFUN (bgp_network_mask_natural_backdoor,
4178 bgp_network_mask_natural_backdoor_cmd,
4179 "network A.B.C.D backdoor",
4180 "Specify a network to announce via BGP\n"
4181 "Network number\n"
4182 "Specify a BGP backdoor route\n")
4183 {
4184 int ret;
4185 char prefix_str[BUFSIZ];
4186
4187 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4188 if (! ret)
4189 {
4190 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4191 return CMD_WARNING;
4192 }
4193
4194 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4195 NULL, 1);
4196 }
4197
4198 DEFUN (no_bgp_network,
4199 no_bgp_network_cmd,
4200 "no network A.B.C.D/M",
4201 NO_STR
4202 "Specify a network to announce via BGP\n"
4203 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4204 {
4205 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4206 bgp_node_safi (vty));
4207 }
4208
4209 ALIAS (no_bgp_network,
4210 no_bgp_network_route_map_cmd,
4211 "no network A.B.C.D/M route-map WORD",
4212 NO_STR
4213 "Specify a network to announce via BGP\n"
4214 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4215 "Route-map to modify the attributes\n"
4216 "Name of the route map\n")
4217
4218 ALIAS (no_bgp_network,
4219 no_bgp_network_backdoor_cmd,
4220 "no network A.B.C.D/M backdoor",
4221 NO_STR
4222 "Specify a network to announce via BGP\n"
4223 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4224 "Specify a BGP backdoor route\n")
4225
4226 DEFUN (no_bgp_network_mask,
4227 no_bgp_network_mask_cmd,
4228 "no network A.B.C.D mask A.B.C.D",
4229 NO_STR
4230 "Specify a network to announce via BGP\n"
4231 "Network number\n"
4232 "Network mask\n"
4233 "Network mask\n")
4234 {
4235 int ret;
4236 char prefix_str[BUFSIZ];
4237
4238 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4239 if (! ret)
4240 {
4241 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4242 return CMD_WARNING;
4243 }
4244
4245 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4246 bgp_node_safi (vty));
4247 }
4248
4249 ALIAS (no_bgp_network_mask,
4250 no_bgp_network_mask_route_map_cmd,
4251 "no network A.B.C.D mask A.B.C.D route-map WORD",
4252 NO_STR
4253 "Specify a network to announce via BGP\n"
4254 "Network number\n"
4255 "Network mask\n"
4256 "Network mask\n"
4257 "Route-map to modify the attributes\n"
4258 "Name of the route map\n")
4259
4260 ALIAS (no_bgp_network_mask,
4261 no_bgp_network_mask_backdoor_cmd,
4262 "no network A.B.C.D mask A.B.C.D backdoor",
4263 NO_STR
4264 "Specify a network to announce via BGP\n"
4265 "Network number\n"
4266 "Network mask\n"
4267 "Network mask\n"
4268 "Specify a BGP backdoor route\n")
4269
4270 DEFUN (no_bgp_network_mask_natural,
4271 no_bgp_network_mask_natural_cmd,
4272 "no network A.B.C.D",
4273 NO_STR
4274 "Specify a network to announce via BGP\n"
4275 "Network number\n")
4276 {
4277 int ret;
4278 char prefix_str[BUFSIZ];
4279
4280 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4281 if (! ret)
4282 {
4283 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4284 return CMD_WARNING;
4285 }
4286
4287 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4288 bgp_node_safi (vty));
4289 }
4290
4291 ALIAS (no_bgp_network_mask_natural,
4292 no_bgp_network_mask_natural_route_map_cmd,
4293 "no network A.B.C.D route-map WORD",
4294 NO_STR
4295 "Specify a network to announce via BGP\n"
4296 "Network number\n"
4297 "Route-map to modify the attributes\n"
4298 "Name of the route map\n")
4299
4300 ALIAS (no_bgp_network_mask_natural,
4301 no_bgp_network_mask_natural_backdoor_cmd,
4302 "no network A.B.C.D backdoor",
4303 NO_STR
4304 "Specify a network to announce via BGP\n"
4305 "Network number\n"
4306 "Specify a BGP backdoor route\n")
4307
4308 #ifdef HAVE_IPV6
4309 DEFUN (ipv6_bgp_network,
4310 ipv6_bgp_network_cmd,
4311 "network X:X::X:X/M",
4312 "Specify a network to announce via BGP\n"
4313 "IPv6 prefix <network>/<length>\n")
4314 {
4315 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4316 NULL, 0);
4317 }
4318
4319 DEFUN (ipv6_bgp_network_route_map,
4320 ipv6_bgp_network_route_map_cmd,
4321 "network X:X::X:X/M route-map WORD",
4322 "Specify a network to announce via BGP\n"
4323 "IPv6 prefix <network>/<length>\n"
4324 "Route-map to modify the attributes\n"
4325 "Name of the route map\n")
4326 {
4327 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4328 bgp_node_safi (vty), argv[1], 0);
4329 }
4330
4331 DEFUN (no_ipv6_bgp_network,
4332 no_ipv6_bgp_network_cmd,
4333 "no network X:X::X:X/M",
4334 NO_STR
4335 "Specify a network to announce via BGP\n"
4336 "IPv6 prefix <network>/<length>\n")
4337 {
4338 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4339 }
4340
4341 ALIAS (no_ipv6_bgp_network,
4342 no_ipv6_bgp_network_route_map_cmd,
4343 "no network X:X::X:X/M route-map WORD",
4344 NO_STR
4345 "Specify a network to announce via BGP\n"
4346 "IPv6 prefix <network>/<length>\n"
4347 "Route-map to modify the attributes\n"
4348 "Name of the route map\n")
4349
4350 ALIAS (ipv6_bgp_network,
4351 old_ipv6_bgp_network_cmd,
4352 "ipv6 bgp network X:X::X:X/M",
4353 IPV6_STR
4354 BGP_STR
4355 "Specify a network to announce via BGP\n"
4356 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4357
4358 ALIAS (no_ipv6_bgp_network,
4359 old_no_ipv6_bgp_network_cmd,
4360 "no ipv6 bgp network X:X::X:X/M",
4361 NO_STR
4362 IPV6_STR
4363 BGP_STR
4364 "Specify a network to announce via BGP\n"
4365 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4366 #endif /* HAVE_IPV6 */
4367
4368 /* Aggreagete address:
4369
4370 advertise-map Set condition to advertise attribute
4371 as-set Generate AS set path information
4372 attribute-map Set attributes of aggregate
4373 route-map Set parameters of aggregate
4374 summary-only Filter more specific routes from updates
4375 suppress-map Conditionally filter more specific routes from updates
4376 <cr>
4377 */
4378 struct bgp_aggregate
4379 {
4380 /* Summary-only flag. */
4381 u_char summary_only;
4382
4383 /* AS set generation. */
4384 u_char as_set;
4385
4386 /* Route-map for aggregated route. */
4387 struct route_map *map;
4388
4389 /* Suppress-count. */
4390 unsigned long count;
4391
4392 /* SAFI configuration. */
4393 safi_t safi;
4394 };
4395
4396 static struct bgp_aggregate *
4397 bgp_aggregate_new (void)
4398 {
4399 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4400 }
4401
4402 static void
4403 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4404 {
4405 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4406 }
4407
4408 /* Update an aggregate as routes are added/removed from the BGP table */
4409 static void
4410 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4411 afi_t afi, safi_t safi, struct bgp_info *del,
4412 struct bgp_aggregate *aggregate)
4413 {
4414 struct bgp_table *table;
4415 struct bgp_node *top;
4416 struct bgp_node *rn;
4417 u_char origin;
4418 struct aspath *aspath = NULL;
4419 struct aspath *asmerge = NULL;
4420 struct community *community = NULL;
4421 struct community *commerge = NULL;
4422 #if defined(AGGREGATE_NEXTHOP_CHECK)
4423 struct in_addr nexthop;
4424 u_int32_t med = 0;
4425 #endif
4426 struct bgp_info *ri;
4427 struct bgp_info *new;
4428 int first = 1;
4429 unsigned long match = 0;
4430 u_char atomic_aggregate = 0;
4431
4432 /* Record adding route's nexthop and med. */
4433 if (rinew)
4434 {
4435 #if defined(AGGREGATE_NEXTHOP_CHECK)
4436 nexthop = rinew->attr->nexthop;
4437 med = rinew->attr->med;
4438 #endif
4439 }
4440
4441 /* ORIGIN attribute: If at least one route among routes that are
4442 aggregated has ORIGIN with the value INCOMPLETE, then the
4443 aggregated route must have the ORIGIN attribute with the value
4444 INCOMPLETE. Otherwise, if at least one route among routes that
4445 are aggregated has ORIGIN with the value EGP, then the aggregated
4446 route must have the origin attribute with the value EGP. In all
4447 other case the value of the ORIGIN attribute of the aggregated
4448 route is INTERNAL. */
4449 origin = BGP_ORIGIN_IGP;
4450
4451 table = bgp->rib[afi][safi];
4452
4453 top = bgp_node_get (table, p);
4454 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4455 if (rn->p.prefixlen > p->prefixlen)
4456 {
4457 match = 0;
4458
4459 for (ri = rn->info; ri; ri = ri->next)
4460 {
4461 if (BGP_INFO_HOLDDOWN (ri))
4462 continue;
4463
4464 if (del && ri == del)
4465 continue;
4466
4467 if (! rinew && first)
4468 {
4469 #if defined(AGGREGATE_NEXTHOP_CHECK)
4470 nexthop = ri->attr->nexthop;
4471 med = ri->attr->med;
4472 #endif
4473 first = 0;
4474 }
4475
4476 #ifdef AGGREGATE_NEXTHOP_CHECK
4477 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4478 || ri->attr->med != med)
4479 {
4480 if (aspath)
4481 aspath_free (aspath);
4482 if (community)
4483 community_free (community);
4484 bgp_unlock_node (rn);
4485 bgp_unlock_node (top);
4486 return;
4487 }
4488 #endif /* AGGREGATE_NEXTHOP_CHECK */
4489
4490 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4491 atomic_aggregate = 1;
4492
4493 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4494 {
4495 if (aggregate->summary_only)
4496 {
4497 (bgp_info_extra_get (ri))->suppress++;
4498 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4499 match++;
4500 }
4501
4502 aggregate->count++;
4503
4504 if (origin < ri->attr->origin)
4505 origin = ri->attr->origin;
4506
4507 if (aggregate->as_set)
4508 {
4509 if (aspath)
4510 {
4511 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4512 aspath_free (aspath);
4513 aspath = asmerge;
4514 }
4515 else
4516 aspath = aspath_dup (ri->attr->aspath);
4517
4518 if (ri->attr->community)
4519 {
4520 if (community)
4521 {
4522 commerge = community_merge (community,
4523 ri->attr->community);
4524 community = community_uniq_sort (commerge);
4525 community_free (commerge);
4526 }
4527 else
4528 community = community_dup (ri->attr->community);
4529 }
4530 }
4531 }
4532 }
4533 if (match)
4534 bgp_process (bgp, rn, afi, safi);
4535 }
4536 bgp_unlock_node (top);
4537
4538 if (rinew)
4539 {
4540 aggregate->count++;
4541
4542 if (aggregate->summary_only)
4543 (bgp_info_extra_get (rinew))->suppress++;
4544
4545 if (origin < rinew->attr->origin)
4546 origin = rinew->attr->origin;
4547
4548 if (aggregate->as_set)
4549 {
4550 if (aspath)
4551 {
4552 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4553 aspath_free (aspath);
4554 aspath = asmerge;
4555 }
4556 else
4557 aspath = aspath_dup (rinew->attr->aspath);
4558
4559 if (rinew->attr->community)
4560 {
4561 if (community)
4562 {
4563 commerge = community_merge (community,
4564 rinew->attr->community);
4565 community = community_uniq_sort (commerge);
4566 community_free (commerge);
4567 }
4568 else
4569 community = community_dup (rinew->attr->community);
4570 }
4571 }
4572 }
4573
4574 if (aggregate->count > 0)
4575 {
4576 rn = bgp_node_get (table, p);
4577 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
4578 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4579 aggregate->as_set,
4580 atomic_aggregate), rn);
4581 SET_FLAG (new->flags, BGP_INFO_VALID);
4582
4583 bgp_info_add (rn, new);
4584 bgp_unlock_node (rn);
4585 bgp_process (bgp, rn, afi, safi);
4586 }
4587 else
4588 {
4589 if (aspath)
4590 aspath_free (aspath);
4591 if (community)
4592 community_free (community);
4593 }
4594 }
4595
4596 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4597 struct bgp_aggregate *);
4598
4599 void
4600 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4601 struct bgp_info *ri, afi_t afi, safi_t safi)
4602 {
4603 struct bgp_node *child;
4604 struct bgp_node *rn;
4605 struct bgp_aggregate *aggregate;
4606 struct bgp_table *table;
4607
4608 /* MPLS-VPN aggregation is not yet supported. */
4609 if (safi == SAFI_MPLS_VPN)
4610 return;
4611
4612 table = bgp->aggregate[afi][safi];
4613
4614 /* No aggregates configured. */
4615 if (bgp_table_top_nolock (table) == NULL)
4616 return;
4617
4618 if (p->prefixlen == 0)
4619 return;
4620
4621 if (BGP_INFO_HOLDDOWN (ri))
4622 return;
4623
4624 child = bgp_node_get (table, p);
4625
4626 /* Aggregate address configuration check. */
4627 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
4628 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4629 {
4630 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4631 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
4632 }
4633 bgp_unlock_node (child);
4634 }
4635
4636 void
4637 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4638 struct bgp_info *del, afi_t afi, safi_t safi)
4639 {
4640 struct bgp_node *child;
4641 struct bgp_node *rn;
4642 struct bgp_aggregate *aggregate;
4643 struct bgp_table *table;
4644
4645 /* MPLS-VPN aggregation is not yet supported. */
4646 if (safi == SAFI_MPLS_VPN)
4647 return;
4648
4649 table = bgp->aggregate[afi][safi];
4650
4651 /* No aggregates configured. */
4652 if (bgp_table_top_nolock (table) == NULL)
4653 return;
4654
4655 if (p->prefixlen == 0)
4656 return;
4657
4658 child = bgp_node_get (table, p);
4659
4660 /* Aggregate address configuration check. */
4661 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
4662 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4663 {
4664 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4665 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
4666 }
4667 bgp_unlock_node (child);
4668 }
4669
4670 /* Called via bgp_aggregate_set when the user configures aggregate-address */
4671 static void
4672 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4673 struct bgp_aggregate *aggregate)
4674 {
4675 struct bgp_table *table;
4676 struct bgp_node *top;
4677 struct bgp_node *rn;
4678 struct bgp_info *new;
4679 struct bgp_info *ri;
4680 unsigned long match;
4681 u_char origin = BGP_ORIGIN_IGP;
4682 struct aspath *aspath = NULL;
4683 struct aspath *asmerge = NULL;
4684 struct community *community = NULL;
4685 struct community *commerge = NULL;
4686 u_char atomic_aggregate = 0;
4687
4688 table = bgp->rib[afi][safi];
4689
4690 /* Sanity check. */
4691 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4692 return;
4693 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4694 return;
4695
4696 /* If routes exists below this node, generate aggregate routes. */
4697 top = bgp_node_get (table, p);
4698 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4699 if (rn->p.prefixlen > p->prefixlen)
4700 {
4701 match = 0;
4702
4703 for (ri = rn->info; ri; ri = ri->next)
4704 {
4705 if (BGP_INFO_HOLDDOWN (ri))
4706 continue;
4707
4708 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4709 atomic_aggregate = 1;
4710
4711 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4712 {
4713 /* summary-only aggregate route suppress aggregated
4714 route announcement. */
4715 if (aggregate->summary_only)
4716 {
4717 (bgp_info_extra_get (ri))->suppress++;
4718 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4719 match++;
4720 }
4721
4722 /* If at least one route among routes that are aggregated has
4723 * ORIGIN with the value INCOMPLETE, then the aggregated route
4724 * MUST have the ORIGIN attribute with the value INCOMPLETE.
4725 * Otherwise, if at least one route among routes that are
4726 * aggregated has ORIGIN with the value EGP, then the aggregated
4727 * route MUST have the ORIGIN attribute with the value EGP.
4728 */
4729 if (origin < ri->attr->origin)
4730 origin = ri->attr->origin;
4731
4732 /* as-set aggregate route generate origin, as path,
4733 community aggregation. */
4734 if (aggregate->as_set)
4735 {
4736 if (aspath)
4737 {
4738 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4739 aspath_free (aspath);
4740 aspath = asmerge;
4741 }
4742 else
4743 aspath = aspath_dup (ri->attr->aspath);
4744
4745 if (ri->attr->community)
4746 {
4747 if (community)
4748 {
4749 commerge = community_merge (community,
4750 ri->attr->community);
4751 community = community_uniq_sort (commerge);
4752 community_free (commerge);
4753 }
4754 else
4755 community = community_dup (ri->attr->community);
4756 }
4757 }
4758 aggregate->count++;
4759 }
4760 }
4761
4762 /* If this node is suppressed, process the change. */
4763 if (match)
4764 bgp_process (bgp, rn, afi, safi);
4765 }
4766 bgp_unlock_node (top);
4767
4768 /* Add aggregate route to BGP table. */
4769 if (aggregate->count)
4770 {
4771 rn = bgp_node_get (table, p);
4772 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
4773 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4774 aggregate->as_set,
4775 atomic_aggregate), rn);
4776 SET_FLAG (new->flags, BGP_INFO_VALID);
4777
4778 bgp_info_add (rn, new);
4779 bgp_unlock_node (rn);
4780
4781 /* Process change. */
4782 bgp_process (bgp, rn, afi, safi);
4783 }
4784 else
4785 {
4786 if (aspath)
4787 aspath_free (aspath);
4788 if (community)
4789 community_free (community);
4790 }
4791 }
4792
4793 void
4794 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4795 safi_t safi, struct bgp_aggregate *aggregate)
4796 {
4797 struct bgp_table *table;
4798 struct bgp_node *top;
4799 struct bgp_node *rn;
4800 struct bgp_info *ri;
4801 unsigned long match;
4802
4803 table = bgp->rib[afi][safi];
4804
4805 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4806 return;
4807 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4808 return;
4809
4810 /* If routes exists below this node, generate aggregate routes. */
4811 top = bgp_node_get (table, p);
4812 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4813 if (rn->p.prefixlen > p->prefixlen)
4814 {
4815 match = 0;
4816
4817 for (ri = rn->info; ri; ri = ri->next)
4818 {
4819 if (BGP_INFO_HOLDDOWN (ri))
4820 continue;
4821
4822 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4823 {
4824 if (aggregate->summary_only && ri->extra)
4825 {
4826 ri->extra->suppress--;
4827
4828 if (ri->extra->suppress == 0)
4829 {
4830 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4831 match++;
4832 }
4833 }
4834 aggregate->count--;
4835 }
4836 }
4837
4838 /* If this node was suppressed, process the change. */
4839 if (match)
4840 bgp_process (bgp, rn, afi, safi);
4841 }
4842 bgp_unlock_node (top);
4843
4844 /* Delete aggregate route from BGP table. */
4845 rn = bgp_node_get (table, p);
4846
4847 for (ri = rn->info; ri; ri = ri->next)
4848 if (ri->peer == bgp->peer_self
4849 && ri->type == ZEBRA_ROUTE_BGP
4850 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4851 break;
4852
4853 /* Withdraw static BGP route from routing table. */
4854 if (ri)
4855 {
4856 bgp_info_delete (rn, ri);
4857 bgp_process (bgp, rn, afi, safi);
4858 }
4859
4860 /* Unlock bgp_node_lookup. */
4861 bgp_unlock_node (rn);
4862 }
4863
4864 /* Aggregate route attribute. */
4865 #define AGGREGATE_SUMMARY_ONLY 1
4866 #define AGGREGATE_AS_SET 1
4867
4868 static int
4869 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4870 afi_t afi, safi_t safi)
4871 {
4872 int ret;
4873 struct prefix p;
4874 struct bgp_node *rn;
4875 struct bgp *bgp;
4876 struct bgp_aggregate *aggregate;
4877
4878 /* Convert string to prefix structure. */
4879 ret = str2prefix (prefix_str, &p);
4880 if (!ret)
4881 {
4882 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4883 return CMD_WARNING;
4884 }
4885 apply_mask (&p);
4886
4887 /* Get BGP structure. */
4888 bgp = vty->index;
4889
4890 /* Old configuration check. */
4891 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4892 if (! rn)
4893 {
4894 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4895 VTY_NEWLINE);
4896 return CMD_WARNING;
4897 }
4898
4899 aggregate = rn->info;
4900 if (aggregate->safi & SAFI_UNICAST)
4901 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4902 if (aggregate->safi & SAFI_MULTICAST)
4903 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4904
4905 /* Unlock aggregate address configuration. */
4906 rn->info = NULL;
4907 bgp_aggregate_free (aggregate);
4908 bgp_unlock_node (rn);
4909 bgp_unlock_node (rn);
4910
4911 return CMD_SUCCESS;
4912 }
4913
4914 static int
4915 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4916 afi_t afi, safi_t safi,
4917 u_char summary_only, u_char as_set)
4918 {
4919 int ret;
4920 struct prefix p;
4921 struct bgp_node *rn;
4922 struct bgp *bgp;
4923 struct bgp_aggregate *aggregate;
4924
4925 /* Convert string to prefix structure. */
4926 ret = str2prefix (prefix_str, &p);
4927 if (!ret)
4928 {
4929 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4930 return CMD_WARNING;
4931 }
4932 apply_mask (&p);
4933
4934 /* Get BGP structure. */
4935 bgp = vty->index;
4936
4937 /* Old configuration check. */
4938 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4939
4940 if (rn->info)
4941 {
4942 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4943 /* try to remove the old entry */
4944 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4945 if (ret)
4946 {
4947 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4948 bgp_unlock_node (rn);
4949 return CMD_WARNING;
4950 }
4951 }
4952
4953 /* Make aggregate address structure. */
4954 aggregate = bgp_aggregate_new ();
4955 aggregate->summary_only = summary_only;
4956 aggregate->as_set = as_set;
4957 aggregate->safi = safi;
4958 rn->info = aggregate;
4959
4960 /* Aggregate address insert into BGP routing table. */
4961 if (safi & SAFI_UNICAST)
4962 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4963 if (safi & SAFI_MULTICAST)
4964 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4965
4966 return CMD_SUCCESS;
4967 }
4968
4969 DEFUN (aggregate_address,
4970 aggregate_address_cmd,
4971 "aggregate-address A.B.C.D/M",
4972 "Configure BGP aggregate entries\n"
4973 "Aggregate prefix\n")
4974 {
4975 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4976 }
4977
4978 DEFUN (aggregate_address_mask,
4979 aggregate_address_mask_cmd,
4980 "aggregate-address A.B.C.D A.B.C.D",
4981 "Configure BGP aggregate entries\n"
4982 "Aggregate address\n"
4983 "Aggregate mask\n")
4984 {
4985 int ret;
4986 char prefix_str[BUFSIZ];
4987
4988 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4989
4990 if (! ret)
4991 {
4992 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4993 return CMD_WARNING;
4994 }
4995
4996 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4997 0, 0);
4998 }
4999
5000 DEFUN (aggregate_address_summary_only,
5001 aggregate_address_summary_only_cmd,
5002 "aggregate-address A.B.C.D/M summary-only",
5003 "Configure BGP aggregate entries\n"
5004 "Aggregate prefix\n"
5005 "Filter more specific routes from updates\n")
5006 {
5007 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5008 AGGREGATE_SUMMARY_ONLY, 0);
5009 }
5010
5011 DEFUN (aggregate_address_mask_summary_only,
5012 aggregate_address_mask_summary_only_cmd,
5013 "aggregate-address A.B.C.D A.B.C.D summary-only",
5014 "Configure BGP aggregate entries\n"
5015 "Aggregate address\n"
5016 "Aggregate mask\n"
5017 "Filter more specific routes from updates\n")
5018 {
5019 int ret;
5020 char prefix_str[BUFSIZ];
5021
5022 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5023
5024 if (! ret)
5025 {
5026 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5027 return CMD_WARNING;
5028 }
5029
5030 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5031 AGGREGATE_SUMMARY_ONLY, 0);
5032 }
5033
5034 DEFUN (aggregate_address_as_set,
5035 aggregate_address_as_set_cmd,
5036 "aggregate-address A.B.C.D/M as-set",
5037 "Configure BGP aggregate entries\n"
5038 "Aggregate prefix\n"
5039 "Generate AS set path information\n")
5040 {
5041 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5042 0, AGGREGATE_AS_SET);
5043 }
5044
5045 DEFUN (aggregate_address_mask_as_set,
5046 aggregate_address_mask_as_set_cmd,
5047 "aggregate-address A.B.C.D A.B.C.D as-set",
5048 "Configure BGP aggregate entries\n"
5049 "Aggregate address\n"
5050 "Aggregate mask\n"
5051 "Generate AS set path information\n")
5052 {
5053 int ret;
5054 char prefix_str[BUFSIZ];
5055
5056 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5057
5058 if (! ret)
5059 {
5060 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5061 return CMD_WARNING;
5062 }
5063
5064 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5065 0, AGGREGATE_AS_SET);
5066 }
5067
5068
5069 DEFUN (aggregate_address_as_set_summary,
5070 aggregate_address_as_set_summary_cmd,
5071 "aggregate-address A.B.C.D/M as-set summary-only",
5072 "Configure BGP aggregate entries\n"
5073 "Aggregate prefix\n"
5074 "Generate AS set path information\n"
5075 "Filter more specific routes from updates\n")
5076 {
5077 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5078 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5079 }
5080
5081 ALIAS (aggregate_address_as_set_summary,
5082 aggregate_address_summary_as_set_cmd,
5083 "aggregate-address A.B.C.D/M summary-only as-set",
5084 "Configure BGP aggregate entries\n"
5085 "Aggregate prefix\n"
5086 "Filter more specific routes from updates\n"
5087 "Generate AS set path information\n")
5088
5089 DEFUN (aggregate_address_mask_as_set_summary,
5090 aggregate_address_mask_as_set_summary_cmd,
5091 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5092 "Configure BGP aggregate entries\n"
5093 "Aggregate address\n"
5094 "Aggregate mask\n"
5095 "Generate AS set path information\n"
5096 "Filter more specific routes from updates\n")
5097 {
5098 int ret;
5099 char prefix_str[BUFSIZ];
5100
5101 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5102
5103 if (! ret)
5104 {
5105 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5106 return CMD_WARNING;
5107 }
5108
5109 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5110 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5111 }
5112
5113 ALIAS (aggregate_address_mask_as_set_summary,
5114 aggregate_address_mask_summary_as_set_cmd,
5115 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5116 "Configure BGP aggregate entries\n"
5117 "Aggregate address\n"
5118 "Aggregate mask\n"
5119 "Filter more specific routes from updates\n"
5120 "Generate AS set path information\n")
5121
5122 DEFUN (no_aggregate_address,
5123 no_aggregate_address_cmd,
5124 "no aggregate-address A.B.C.D/M",
5125 NO_STR
5126 "Configure BGP aggregate entries\n"
5127 "Aggregate prefix\n")
5128 {
5129 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5130 }
5131
5132 ALIAS (no_aggregate_address,
5133 no_aggregate_address_summary_only_cmd,
5134 "no aggregate-address A.B.C.D/M summary-only",
5135 NO_STR
5136 "Configure BGP aggregate entries\n"
5137 "Aggregate prefix\n"
5138 "Filter more specific routes from updates\n")
5139
5140 ALIAS (no_aggregate_address,
5141 no_aggregate_address_as_set_cmd,
5142 "no aggregate-address A.B.C.D/M as-set",
5143 NO_STR
5144 "Configure BGP aggregate entries\n"
5145 "Aggregate prefix\n"
5146 "Generate AS set path information\n")
5147
5148 ALIAS (no_aggregate_address,
5149 no_aggregate_address_as_set_summary_cmd,
5150 "no aggregate-address A.B.C.D/M as-set summary-only",
5151 NO_STR
5152 "Configure BGP aggregate entries\n"
5153 "Aggregate prefix\n"
5154 "Generate AS set path information\n"
5155 "Filter more specific routes from updates\n")
5156
5157 ALIAS (no_aggregate_address,
5158 no_aggregate_address_summary_as_set_cmd,
5159 "no aggregate-address A.B.C.D/M summary-only as-set",
5160 NO_STR
5161 "Configure BGP aggregate entries\n"
5162 "Aggregate prefix\n"
5163 "Filter more specific routes from updates\n"
5164 "Generate AS set path information\n")
5165
5166 DEFUN (no_aggregate_address_mask,
5167 no_aggregate_address_mask_cmd,
5168 "no aggregate-address A.B.C.D A.B.C.D",
5169 NO_STR
5170 "Configure BGP aggregate entries\n"
5171 "Aggregate address\n"
5172 "Aggregate mask\n")
5173 {
5174 int ret;
5175 char prefix_str[BUFSIZ];
5176
5177 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5178
5179 if (! ret)
5180 {
5181 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5182 return CMD_WARNING;
5183 }
5184
5185 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5186 }
5187
5188 ALIAS (no_aggregate_address_mask,
5189 no_aggregate_address_mask_summary_only_cmd,
5190 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5191 NO_STR
5192 "Configure BGP aggregate entries\n"
5193 "Aggregate address\n"
5194 "Aggregate mask\n"
5195 "Filter more specific routes from updates\n")
5196
5197 ALIAS (no_aggregate_address_mask,
5198 no_aggregate_address_mask_as_set_cmd,
5199 "no aggregate-address A.B.C.D A.B.C.D as-set",
5200 NO_STR
5201 "Configure BGP aggregate entries\n"
5202 "Aggregate address\n"
5203 "Aggregate mask\n"
5204 "Generate AS set path information\n")
5205
5206 ALIAS (no_aggregate_address_mask,
5207 no_aggregate_address_mask_as_set_summary_cmd,
5208 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5209 NO_STR
5210 "Configure BGP aggregate entries\n"
5211 "Aggregate address\n"
5212 "Aggregate mask\n"
5213 "Generate AS set path information\n"
5214 "Filter more specific routes from updates\n")
5215
5216 ALIAS (no_aggregate_address_mask,
5217 no_aggregate_address_mask_summary_as_set_cmd,
5218 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5219 NO_STR
5220 "Configure BGP aggregate entries\n"
5221 "Aggregate address\n"
5222 "Aggregate mask\n"
5223 "Filter more specific routes from updates\n"
5224 "Generate AS set path information\n")
5225
5226 #ifdef HAVE_IPV6
5227 DEFUN (ipv6_aggregate_address,
5228 ipv6_aggregate_address_cmd,
5229 "aggregate-address X:X::X:X/M",
5230 "Configure BGP aggregate entries\n"
5231 "Aggregate prefix\n")
5232 {
5233 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5234 }
5235
5236 DEFUN (ipv6_aggregate_address_summary_only,
5237 ipv6_aggregate_address_summary_only_cmd,
5238 "aggregate-address X:X::X:X/M summary-only",
5239 "Configure BGP aggregate entries\n"
5240 "Aggregate prefix\n"
5241 "Filter more specific routes from updates\n")
5242 {
5243 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5244 AGGREGATE_SUMMARY_ONLY, 0);
5245 }
5246
5247 DEFUN (no_ipv6_aggregate_address,
5248 no_ipv6_aggregate_address_cmd,
5249 "no aggregate-address X:X::X:X/M",
5250 NO_STR
5251 "Configure BGP aggregate entries\n"
5252 "Aggregate prefix\n")
5253 {
5254 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5255 }
5256
5257 DEFUN (no_ipv6_aggregate_address_summary_only,
5258 no_ipv6_aggregate_address_summary_only_cmd,
5259 "no aggregate-address X:X::X:X/M summary-only",
5260 NO_STR
5261 "Configure BGP aggregate entries\n"
5262 "Aggregate prefix\n"
5263 "Filter more specific routes from updates\n")
5264 {
5265 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5266 }
5267
5268 ALIAS (ipv6_aggregate_address,
5269 old_ipv6_aggregate_address_cmd,
5270 "ipv6 bgp aggregate-address X:X::X:X/M",
5271 IPV6_STR
5272 BGP_STR
5273 "Configure BGP aggregate entries\n"
5274 "Aggregate prefix\n")
5275
5276 ALIAS (ipv6_aggregate_address_summary_only,
5277 old_ipv6_aggregate_address_summary_only_cmd,
5278 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5279 IPV6_STR
5280 BGP_STR
5281 "Configure BGP aggregate entries\n"
5282 "Aggregate prefix\n"
5283 "Filter more specific routes from updates\n")
5284
5285 ALIAS (no_ipv6_aggregate_address,
5286 old_no_ipv6_aggregate_address_cmd,
5287 "no ipv6 bgp aggregate-address X:X::X:X/M",
5288 NO_STR
5289 IPV6_STR
5290 BGP_STR
5291 "Configure BGP aggregate entries\n"
5292 "Aggregate prefix\n")
5293
5294 ALIAS (no_ipv6_aggregate_address_summary_only,
5295 old_no_ipv6_aggregate_address_summary_only_cmd,
5296 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5297 NO_STR
5298 IPV6_STR
5299 BGP_STR
5300 "Configure BGP aggregate entries\n"
5301 "Aggregate prefix\n"
5302 "Filter more specific routes from updates\n")
5303 #endif /* HAVE_IPV6 */
5304
5305 /* Redistribute route treatment. */
5306 void
5307 bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
5308 const struct in6_addr *nexthop6, unsigned int ifindex,
5309 u_int32_t metric, u_char type, u_short instance, u_short tag)
5310 {
5311 struct bgp_info *new;
5312 struct bgp_info *bi;
5313 struct bgp_info info;
5314 struct bgp_node *bn;
5315 struct attr attr;
5316 struct attr *new_attr;
5317 afi_t afi;
5318 int ret;
5319 struct bgp_redist *red;
5320
5321 /* Make default attribute. */
5322 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5323 if (nexthop)
5324 attr.nexthop = *nexthop;
5325 attr.nh_ifindex = ifindex;
5326
5327 #ifdef HAVE_IPV6
5328 if (nexthop6)
5329 {
5330 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5331 extra->mp_nexthop_global = *nexthop6;
5332 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
5333 }
5334 #endif
5335
5336 attr.med = metric;
5337 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5338 attr.extra->tag = tag;
5339
5340 afi = family2afi (p->family);
5341
5342 red = bgp_redist_lookup(bgp, afi, type, instance);
5343 if (red)
5344 {
5345 struct attr attr_new;
5346 struct attr_extra extra_new;
5347
5348 /* Copy attribute for modification. */
5349 attr_new.extra = &extra_new;
5350 bgp_attr_dup (&attr_new, &attr);
5351
5352 if (red->redist_metric_flag)
5353 attr_new.med = red->redist_metric;
5354
5355 /* Apply route-map. */
5356 if (red->rmap.name)
5357 {
5358 info.peer = bgp->peer_self;
5359 info.attr = &attr_new;
5360
5361 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5362
5363 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5364
5365 bgp->peer_self->rmap_type = 0;
5366
5367 if (ret == RMAP_DENYMATCH)
5368 {
5369 /* Free uninterned attribute. */
5370 bgp_attr_flush (&attr_new);
5371
5372 /* Unintern original. */
5373 aspath_unintern (&attr.aspath);
5374 bgp_attr_extra_free (&attr);
5375 bgp_redistribute_delete (bgp, p, type, instance);
5376 return;
5377 }
5378 }
5379
5380 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5381 afi, SAFI_UNICAST, p, NULL);
5382
5383 new_attr = bgp_attr_intern (&attr_new);
5384
5385 for (bi = bn->info; bi; bi = bi->next)
5386 if (bi->peer == bgp->peer_self
5387 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5388 break;
5389
5390 if (bi)
5391 {
5392 /* Ensure the (source route) type is updated. */
5393 bi->type = type;
5394 if (attrhash_cmp (bi->attr, new_attr) &&
5395 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5396 {
5397 bgp_attr_unintern (&new_attr);
5398 aspath_unintern (&attr.aspath);
5399 bgp_attr_extra_free (&attr);
5400 bgp_unlock_node (bn);
5401 return;
5402 }
5403 else
5404 {
5405 /* The attribute is changed. */
5406 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5407
5408 /* Rewrite BGP route information. */
5409 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5410 bgp_info_restore(bn, bi);
5411 else
5412 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5413 bgp_attr_unintern (&bi->attr);
5414 bi->attr = new_attr;
5415 bi->uptime = bgp_clock ();
5416
5417 /* Process change. */
5418 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5419 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5420 bgp_unlock_node (bn);
5421 aspath_unintern (&attr.aspath);
5422 bgp_attr_extra_free (&attr);
5423 return;
5424 }
5425 }
5426
5427 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5428 new_attr, bn);
5429 SET_FLAG (new->flags, BGP_INFO_VALID);
5430
5431 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5432 bgp_info_add (bn, new);
5433 bgp_unlock_node (bn);
5434 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5435 }
5436
5437 /* Unintern original. */
5438 aspath_unintern (&attr.aspath);
5439 bgp_attr_extra_free (&attr);
5440 }
5441
5442 void
5443 bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
5444 {
5445 afi_t afi;
5446 struct bgp_node *rn;
5447 struct bgp_info *ri;
5448 struct bgp_redist *red;
5449
5450 afi = family2afi (p->family);
5451
5452 red = bgp_redist_lookup(bgp, afi, type, instance);
5453 if (red)
5454 {
5455 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5456
5457 for (ri = rn->info; ri; ri = ri->next)
5458 if (ri->peer == bgp->peer_self
5459 && ri->type == type)
5460 break;
5461
5462 if (ri)
5463 {
5464 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5465 bgp_info_delete (rn, ri);
5466 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5467 }
5468 bgp_unlock_node (rn);
5469 }
5470 }
5471
5472 /* Withdraw specified route type's route. */
5473 void
5474 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
5475 {
5476 struct bgp_node *rn;
5477 struct bgp_info *ri;
5478 struct bgp_table *table;
5479
5480 table = bgp->rib[afi][SAFI_UNICAST];
5481
5482 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5483 {
5484 for (ri = rn->info; ri; ri = ri->next)
5485 if (ri->peer == bgp->peer_self
5486 && ri->type == type
5487 && ri->instance == instance)
5488 break;
5489
5490 if (ri)
5491 {
5492 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5493 bgp_info_delete (rn, ri);
5494 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5495 }
5496 }
5497 }
5498
5499 /* Static function to display route. */
5500 static void
5501 route_vty_out_route (struct prefix *p, struct vty *vty)
5502 {
5503 int len;
5504 u_int32_t destination;
5505 char buf[BUFSIZ];
5506
5507 if (p->family == AF_INET)
5508 {
5509 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5510 destination = ntohl (p->u.prefix4.s_addr);
5511
5512 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5513 || (IN_CLASSB (destination) && p->prefixlen == 16)
5514 || (IN_CLASSA (destination) && p->prefixlen == 8)
5515 || p->u.prefix4.s_addr == 0)
5516 {
5517 /* When mask is natural, mask is not displayed. */
5518 }
5519 else
5520 len += vty_out (vty, "/%d", p->prefixlen);
5521 }
5522 else
5523 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5524 p->prefixlen);
5525
5526 len = 17 - len;
5527 if (len < 1)
5528 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5529 else
5530 vty_out (vty, "%*s", len, " ");
5531 }
5532
5533 enum bgp_display_type
5534 {
5535 normal_list,
5536 };
5537
5538 /* Print the short form route status for a bgp_info */
5539 static void
5540 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
5541 json_object *json_path)
5542 {
5543 if (json_path)
5544 {
5545
5546 /* Route status display. */
5547 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5548 json_object_boolean_true_add(json_path, "removed");
5549
5550 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5551 json_object_boolean_true_add(json_path, "stale");
5552
5553 if (binfo->extra && binfo->extra->suppress)
5554 json_object_boolean_true_add(json_path, "suppressed");
5555
5556 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5557 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5558 json_object_boolean_true_add(json_path, "valid");
5559
5560 /* Selected */
5561 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5562 json_object_boolean_true_add(json_path, "history");
5563
5564 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5565 json_object_boolean_true_add(json_path, "damped");
5566
5567 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5568 json_object_boolean_true_add(json_path, "bestpath");
5569
5570 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5571 json_object_boolean_true_add(json_path, "multipath");
5572
5573 /* Internal route. */
5574 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5575 json_object_string_add(json_path, "pathFrom", "internal");
5576 else
5577 json_object_string_add(json_path, "pathFrom", "external");
5578
5579 return;
5580 }
5581
5582 /* Route status display. */
5583 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5584 vty_out (vty, "R");
5585 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5586 vty_out (vty, "S");
5587 else if (binfo->extra && binfo->extra->suppress)
5588 vty_out (vty, "s");
5589 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5590 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5591 vty_out (vty, "*");
5592 else
5593 vty_out (vty, " ");
5594
5595 /* Selected */
5596 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5597 vty_out (vty, "h");
5598 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5599 vty_out (vty, "d");
5600 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5601 vty_out (vty, ">");
5602 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5603 vty_out (vty, "=");
5604 else
5605 vty_out (vty, " ");
5606
5607 /* Internal route. */
5608 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5609 vty_out (vty, "i");
5610 else
5611 vty_out (vty, " ");
5612 }
5613
5614 /* called from terminal list command */
5615 void
5616 route_vty_out (struct vty *vty, struct prefix *p,
5617 struct bgp_info *binfo, int display, safi_t safi,
5618 json_object *json_paths)
5619 {
5620 struct attr *attr;
5621 json_object *json_path = NULL;
5622 json_object *json_nexthops = NULL;
5623 json_object *json_nexthop_global = NULL;
5624 json_object *json_nexthop_ll = NULL;
5625
5626 if (json_paths)
5627 json_path = json_object_new_object();
5628
5629 /* short status lead text */
5630 route_vty_short_status_out (vty, binfo, json_path);
5631
5632 if (!json_paths)
5633 {
5634 /* print prefix and mask */
5635 if (! display)
5636 route_vty_out_route (p, vty);
5637 else
5638 vty_out (vty, "%*s", 17, " ");
5639 }
5640
5641 /* Print attribute */
5642 attr = binfo->attr;
5643 if (attr)
5644 {
5645
5646 /* IPv4 Next Hop */
5647 if (p->family == AF_INET
5648 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5649 {
5650 if (json_paths)
5651 {
5652 json_nexthop_global = json_object_new_object();
5653
5654 if (safi == SAFI_MPLS_VPN)
5655 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
5656 else
5657 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
5658
5659 json_object_string_add(json_nexthop_global, "afi", "ipv4");
5660 json_object_boolean_true_add(json_nexthop_global, "used");
5661 }
5662 else
5663 {
5664 if (safi == SAFI_MPLS_VPN)
5665 vty_out (vty, "%-16s",
5666 inet_ntoa (attr->extra->mp_nexthop_global_in));
5667 else
5668 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5669 }
5670 }
5671
5672 #ifdef HAVE_IPV6
5673 /* IPv6 Next Hop */
5674 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5675 {
5676 int len;
5677 char buf[BUFSIZ];
5678
5679 if (json_paths)
5680 {
5681 json_nexthop_global = json_object_new_object();
5682 json_object_string_add(json_nexthop_global, "ip",
5683 inet_ntop (AF_INET6,
5684 &attr->extra->mp_nexthop_global,
5685 buf, BUFSIZ));
5686 json_object_string_add(json_nexthop_global, "afi", "ipv6");
5687 json_object_string_add(json_nexthop_global, "scope", "global");
5688
5689 /* We display both LL & GL if both have been received */
5690 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5691 {
5692 json_nexthop_ll = json_object_new_object();
5693 json_object_string_add(json_nexthop_ll, "ip",
5694 inet_ntop (AF_INET6,
5695 &attr->extra->mp_nexthop_local,
5696 buf, BUFSIZ));
5697 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
5698 json_object_string_add(json_nexthop_ll, "scope", "link-local");
5699
5700 if (IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
5701 &attr->extra->mp_nexthop_local) != 0)
5702 json_object_boolean_true_add(json_nexthop_ll, "used");
5703 else
5704 json_object_boolean_true_add(json_nexthop_global, "used");
5705 }
5706 else
5707 json_object_boolean_true_add(json_nexthop_global, "used");
5708 }
5709 else
5710 {
5711 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
5712 {
5713 if (binfo->peer->conf_if)
5714 {
5715 len = vty_out (vty, "%s",
5716 binfo->peer->conf_if);
5717 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
5718
5719 if (len < 1)
5720 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
5721 else
5722 vty_out (vty, "%*s", len, " ");
5723 }
5724 else
5725 {
5726 len = vty_out (vty, "%s",
5727 inet_ntop (AF_INET6,
5728 &attr->extra->mp_nexthop_local,
5729 buf, BUFSIZ));
5730 len = 16 - len;
5731
5732 if (len < 1)
5733 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5734 else
5735 vty_out (vty, "%*s", len, " ");
5736 }
5737 }
5738 else
5739 {
5740 len = vty_out (vty, "%s",
5741 inet_ntop (AF_INET6,
5742 &attr->extra->mp_nexthop_global,
5743 buf, BUFSIZ));
5744 len = 16 - len;
5745
5746 if (len < 1)
5747 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5748 else
5749 vty_out (vty, "%*s", len, " ");
5750 }
5751 }
5752 }
5753 #endif /* HAVE_IPV6 */
5754
5755 /* MED/Metric */
5756 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5757 if (json_paths)
5758 json_object_int_add(json_path, "med", attr->med);
5759 else
5760 vty_out (vty, "%10u", attr->med);
5761 else
5762 if (!json_paths)
5763 vty_out (vty, " ");
5764
5765 /* Local Pref */
5766 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5767 if (json_paths)
5768 json_object_int_add(json_path, "localpref", attr->local_pref);
5769 else
5770 vty_out (vty, "%7u", attr->local_pref);
5771 else
5772 if (!json_paths)
5773 vty_out (vty, " ");
5774
5775 if (json_paths)
5776 {
5777 if (attr->extra)
5778 json_object_int_add(json_path, "weight", attr->extra->weight);
5779 else
5780 json_object_int_add(json_path, "weight", 0);
5781 }
5782 else
5783 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
5784
5785 /* Print aspath */
5786 if (attr->aspath)
5787 {
5788 if (json_paths)
5789 json_object_string_add(json_path, "aspath", attr->aspath->str);
5790 else
5791 aspath_print_vty (vty, "%s", attr->aspath, " ");
5792 }
5793
5794 /* Print origin */
5795 if (json_paths)
5796 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
5797 else
5798 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5799 }
5800 else
5801 {
5802 if (json_paths)
5803 json_object_string_add(json_path, "alert", "No attributes");
5804 else
5805 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
5806 }
5807
5808 if (json_paths)
5809 {
5810 if (json_nexthop_global || json_nexthop_ll)
5811 {
5812 json_nexthops = json_object_new_array();
5813
5814 if (json_nexthop_global)
5815 json_object_array_add(json_nexthops, json_nexthop_global);
5816
5817 if (json_nexthop_ll)
5818 json_object_array_add(json_nexthops, json_nexthop_ll);
5819
5820 json_object_object_add(json_path, "nexthops", json_nexthops);
5821 }
5822
5823 json_object_array_add(json_paths, json_path);
5824 }
5825 else
5826 vty_out (vty, "%s", VTY_NEWLINE);
5827 }
5828
5829 /* called from terminal list command */
5830 void
5831 route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
5832 u_char use_json, json_object *json_ar)
5833 {
5834 json_object *json_status = NULL;
5835 json_object *json_net = NULL;
5836 char buff[BUFSIZ];
5837 /* Route status display. */
5838 if (use_json)
5839 {
5840 json_status = json_object_new_object();
5841 json_net = json_object_new_object();
5842 }
5843 else
5844 {
5845 vty_out (vty, "*");
5846 vty_out (vty, ">");
5847 vty_out (vty, " ");
5848 }
5849
5850 /* print prefix and mask */
5851 if (use_json)
5852 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
5853 else
5854 route_vty_out_route (p, vty);
5855
5856 /* Print attribute */
5857 if (attr)
5858 {
5859 if (use_json)
5860 {
5861 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5862 {
5863 if (safi == SAFI_MPLS_VPN)
5864 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
5865 else
5866 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
5867 }
5868 #ifdef HAVE_IPV6
5869 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5870 {
5871 char buf[BUFSIZ];
5872
5873 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5874 buf, BUFSIZ));
5875 }
5876 #endif /* HAVE_IPV6 */
5877
5878 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5879 json_object_int_add(json_net, "metric", attr->med);
5880
5881 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5882 json_object_int_add(json_net, "localPref", attr->local_pref);
5883
5884 if (attr->extra)
5885 json_object_int_add(json_net, "weight", attr->extra->weight);
5886 else
5887 json_object_int_add(json_net, "weight", 0);
5888
5889 /* Print aspath */
5890 if (attr->aspath)
5891 json_object_string_add(json_net, "asPath", attr->aspath->str);
5892
5893 /* Print origin */
5894 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
5895 }
5896 else
5897 {
5898 if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5899 {
5900 if (safi == SAFI_MPLS_VPN)
5901 vty_out (vty, "%-16s",
5902 inet_ntoa (attr->extra->mp_nexthop_global_in));
5903 else
5904 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5905 }
5906 #ifdef HAVE_IPV6
5907 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
5908 {
5909 int len;
5910 char buf[BUFSIZ];
5911
5912 assert (attr->extra);
5913
5914 len = vty_out (vty, "%s",
5915 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5916 buf, BUFSIZ));
5917 len = 16 - len;
5918 if (len < 1)
5919 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5920 else
5921 vty_out (vty, "%*s", len, " ");
5922 }
5923 #endif /* HAVE_IPV6 */
5924 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5925 vty_out (vty, "%10u", attr->med);
5926 else
5927 vty_out (vty, " ");
5928
5929 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5930 vty_out (vty, "%7u", attr->local_pref);
5931 else
5932 vty_out (vty, " ");
5933
5934 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
5935
5936 /* Print aspath */
5937 if (attr->aspath)
5938 aspath_print_vty (vty, "%s", attr->aspath, " ");
5939
5940 /* Print origin */
5941 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5942 }
5943 }
5944 if (use_json)
5945 {
5946 json_object_boolean_true_add(json_status, "*");
5947 json_object_boolean_true_add(json_status, ">");
5948 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
5949 char buf_cut[BUFSIZ];
5950 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
5951 }
5952 else
5953 vty_out (vty, "%s", VTY_NEWLINE);
5954 }
5955
5956 void
5957 route_vty_out_tag (struct vty *vty, struct prefix *p,
5958 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
5959 {
5960 json_object *json_out = NULL;
5961 struct attr *attr;
5962 u_int32_t label = 0;
5963
5964 if (!binfo->extra)
5965 return;
5966
5967 if (json)
5968 json_out = json_object_new_object();
5969
5970 /* short status lead text */
5971 route_vty_short_status_out (vty, binfo, json_out);
5972
5973 /* print prefix and mask */
5974 if (json == NULL)
5975 {
5976 if (! display)
5977 route_vty_out_route (p, vty);
5978 else
5979 vty_out (vty, "%*s", 17, " ");
5980 }
5981
5982 /* Print attribute */
5983 attr = binfo->attr;
5984 if (attr)
5985 {
5986 if (p->family == AF_INET
5987 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
5988 {
5989 if (safi == SAFI_MPLS_VPN)
5990 {
5991 if (json)
5992 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
5993 else
5994 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
5995 }
5996 else
5997 {
5998 if (json)
5999 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6000 else
6001 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6002 }
6003 }
6004 #ifdef HAVE_IPV6
6005 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6006 {
6007 assert (attr->extra);
6008 char buf_a[BUFSIZ];
6009 char buf_b[BUFSIZ];
6010 char buf_c[BUFSIZ];
6011 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
6012 {
6013 if (json)
6014 json_object_string_add(json_out, "mpNexthopGlobalIn",
6015 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6016 else
6017 vty_out (vty, "%s",
6018 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6019 buf_a, BUFSIZ));
6020 }
6021 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6022 {
6023 if (json)
6024 {
6025 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6026 buf_a, BUFSIZ);
6027 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6028 buf_b, BUFSIZ);
6029 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6030 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6031 }
6032 else
6033 vty_out (vty, "%s(%s)",
6034 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6035 buf_a, BUFSIZ),
6036 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6037 buf_b, BUFSIZ));
6038 }
6039
6040 }
6041 #endif /* HAVE_IPV6 */
6042 }
6043
6044 label = decode_label (binfo->extra->tag);
6045
6046 if (json)
6047 {
6048 if (label)
6049 json_object_int_add(json_out, "notag", label);
6050 json_object_array_add(json, json_out);
6051 }
6052 else
6053 {
6054 vty_out (vty, "notag/%d", label);
6055 vty_out (vty, "%s", VTY_NEWLINE);
6056 }
6057 }
6058
6059 /* dampening route */
6060 static void
6061 damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6062 int display, safi_t safi, u_char use_json, json_object *json)
6063 {
6064 struct attr *attr;
6065 int len;
6066 char timebuf[BGP_UPTIME_LEN];
6067
6068 /* short status lead text */
6069 route_vty_short_status_out (vty, binfo, json);
6070
6071 /* print prefix and mask */
6072 if (!use_json)
6073 {
6074 if (! display)
6075 route_vty_out_route (p, vty);
6076 else
6077 vty_out (vty, "%*s", 17, " ");
6078 }
6079
6080 len = vty_out (vty, "%s", binfo->peer->host);
6081 len = 17 - len;
6082 if (len < 1)
6083 {
6084 if (!use_json)
6085 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6086 }
6087 else
6088 {
6089 if (use_json)
6090 json_object_int_add(json, "peerHost", len);
6091 else
6092 vty_out (vty, "%*s", len, " ");
6093 }
6094
6095 if (use_json)
6096 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6097 else
6098 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6099
6100 /* Print attribute */
6101 attr = binfo->attr;
6102 if (attr)
6103 {
6104 /* Print aspath */
6105 if (attr->aspath)
6106 {
6107 if (use_json)
6108 json_object_string_add(json, "asPath", attr->aspath->str);
6109 else
6110 aspath_print_vty (vty, "%s", attr->aspath, " ");
6111 }
6112
6113 /* Print origin */
6114 if (use_json)
6115 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6116 else
6117 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6118 }
6119 if (!use_json)
6120 vty_out (vty, "%s", VTY_NEWLINE);
6121 }
6122
6123 /* flap route */
6124 static void
6125 flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6126 int display, safi_t safi, u_char use_json, json_object *json)
6127 {
6128 struct attr *attr;
6129 struct bgp_damp_info *bdi;
6130 char timebuf[BGP_UPTIME_LEN];
6131 int len;
6132
6133 if (!binfo->extra)
6134 return;
6135
6136 bdi = binfo->extra->damp_info;
6137
6138 /* short status lead text */
6139 route_vty_short_status_out (vty, binfo, json);
6140
6141 /* print prefix and mask */
6142 if (!use_json)
6143 {
6144 if (! display)
6145 route_vty_out_route (p, vty);
6146 else
6147 vty_out (vty, "%*s", 17, " ");
6148 }
6149
6150 len = vty_out (vty, "%s", binfo->peer->host);
6151 len = 16 - len;
6152 if (len < 1)
6153 {
6154 if (!use_json)
6155 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6156 }
6157 else
6158 {
6159 if (use_json)
6160 json_object_int_add(json, "peerHost", len);
6161 else
6162 vty_out (vty, "%*s", len, " ");
6163 }
6164
6165 len = vty_out (vty, "%d", bdi->flap);
6166 len = 5 - len;
6167 if (len < 1)
6168 {
6169 if (!use_json)
6170 vty_out (vty, " ");
6171 }
6172 else
6173 {
6174 if (use_json)
6175 json_object_int_add(json, "bdiFlap", len);
6176 else
6177 vty_out (vty, "%*s", len, " ");
6178 }
6179
6180 if (use_json)
6181 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6182 else
6183 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6184 timebuf, BGP_UPTIME_LEN, 0, NULL));
6185
6186 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6187 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6188 {
6189 if (use_json)
6190 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6191 else
6192 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6193 }
6194 else
6195 {
6196 if (!use_json)
6197 vty_out (vty, "%*s ", 8, " ");
6198 }
6199
6200 /* Print attribute */
6201 attr = binfo->attr;
6202 if (attr)
6203 {
6204 /* Print aspath */
6205 if (attr->aspath)
6206 {
6207 if (use_json)
6208 json_object_string_add(json, "asPath", attr->aspath->str);
6209 else
6210 aspath_print_vty (vty, "%s", attr->aspath, " ");
6211 }
6212
6213 /* Print origin */
6214 if (use_json)
6215 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6216 else
6217 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6218 }
6219 if (!use_json)
6220 vty_out (vty, "%s", VTY_NEWLINE);
6221 }
6222
6223 static void
6224 route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6225 const char *header, json_object *json_adv_to)
6226 {
6227 char buf1[INET6_ADDRSTRLEN];
6228 json_object *json_peer = NULL;
6229
6230 if (json_adv_to)
6231 {
6232 /* 'advertised-to' is a dictionary of peers we have advertised this
6233 * prefix too. The key is the peer's IP or swpX, the value is the
6234 * hostname if we know it and "" if not.
6235 */
6236 json_peer = json_object_new_object();
6237
6238 if (peer->hostname)
6239 json_object_string_add(json_peer, "hostname", peer->hostname);
6240
6241 if (peer->conf_if)
6242 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6243 else
6244 json_object_object_add(json_adv_to,
6245 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6246 json_peer);
6247 }
6248 else
6249 {
6250 if (*first)
6251 {
6252 vty_out (vty, "%s", header);
6253 *first = 0;
6254 }
6255
6256 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6257 {
6258 if (peer->conf_if)
6259 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6260 else
6261 vty_out (vty, " %s(%s)", peer->hostname,
6262 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6263 }
6264 else
6265 {
6266 if (peer->conf_if)
6267 vty_out (vty, " %s", peer->conf_if);
6268 else
6269 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6270 }
6271 }
6272 }
6273
6274 static void
6275 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6276 struct bgp_info *binfo, afi_t afi, safi_t safi,
6277 json_object *json_paths)
6278 {
6279 char buf[INET6_ADDRSTRLEN];
6280 char buf1[BUFSIZ];
6281 struct attr *attr;
6282 int sockunion_vty_out (struct vty *, union sockunion *);
6283 #ifdef HAVE_CLOCK_MONOTONIC
6284 time_t tbuf;
6285 #endif
6286 json_object *json_bestpath = NULL;
6287 json_object *json_cluster_list = NULL;
6288 json_object *json_cluster_list_list = NULL;
6289 json_object *json_ext_community = NULL;
6290 json_object *json_last_update = NULL;
6291 json_object *json_nexthop_global = NULL;
6292 json_object *json_nexthop_ll = NULL;
6293 json_object *json_nexthops = NULL;
6294 json_object *json_path = NULL;
6295 json_object *json_peer = NULL;
6296 json_object *json_string = NULL;
6297 json_object *json_adv_to = NULL;
6298 int first = 0;
6299 struct listnode *node, *nnode;
6300 struct peer *peer;
6301 int addpath_capable;
6302 int has_adj;
6303 int first_as;
6304
6305 if (json_paths)
6306 {
6307 json_path = json_object_new_object();
6308 json_peer = json_object_new_object();
6309 json_nexthop_global = json_object_new_object();
6310 }
6311
6312 attr = binfo->attr;
6313
6314 if (attr)
6315 {
6316 /* Line1 display AS-path, Aggregator */
6317 if (attr->aspath)
6318 {
6319 if (json_paths)
6320 {
6321 json_object_lock(attr->aspath->json);
6322 json_object_object_add(json_path, "aspath", attr->aspath->json);
6323 }
6324 else
6325 {
6326 if (attr->aspath->segments)
6327 aspath_print_vty (vty, " %s", attr->aspath, "");
6328 else
6329 vty_out (vty, " Local");
6330 }
6331 }
6332
6333 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6334 {
6335 if (json_paths)
6336 json_object_boolean_true_add(json_path, "removed");
6337 else
6338 vty_out (vty, ", (removed)");
6339 }
6340
6341 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6342 {
6343 if (json_paths)
6344 json_object_boolean_true_add(json_path, "stale");
6345 else
6346 vty_out (vty, ", (stale)");
6347 }
6348
6349 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6350 {
6351 if (json_paths)
6352 {
6353 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6354 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
6355 }
6356 else
6357 {
6358 vty_out (vty, ", (aggregated by %u %s)",
6359 attr->extra->aggregator_as,
6360 inet_ntoa (attr->extra->aggregator_addr));
6361 }
6362 }
6363
6364 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6365 {
6366 if (json_paths)
6367 json_object_boolean_true_add(json_path, "rxedFromRrClient");
6368 else
6369 vty_out (vty, ", (Received from a RR-client)");
6370 }
6371
6372 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6373 {
6374 if (json_paths)
6375 json_object_boolean_true_add(json_path, "rxedFromRsClient");
6376 else
6377 vty_out (vty, ", (Received from a RS-client)");
6378 }
6379
6380 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6381 {
6382 if (json_paths)
6383 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
6384 else
6385 vty_out (vty, ", (history entry)");
6386 }
6387 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6388 {
6389 if (json_paths)
6390 json_object_boolean_true_add(json_path, "dampeningSuppressed");
6391 else
6392 vty_out (vty, ", (suppressed due to dampening)");
6393 }
6394
6395 if (!json_paths)
6396 vty_out (vty, "%s", VTY_NEWLINE);
6397
6398 /* Line2 display Next-hop, Neighbor, Router-id */
6399 /* Display the nexthop */
6400 if (p->family == AF_INET
6401 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6402 {
6403 if (safi == SAFI_MPLS_VPN)
6404 {
6405 if (json_paths)
6406 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6407 else
6408 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6409 }
6410 else
6411 {
6412 if (json_paths)
6413 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6414 else
6415 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6416 }
6417
6418 if (json_paths)
6419 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6420 }
6421 #ifdef HAVE_IPV6
6422 else
6423 {
6424 assert (attr->extra);
6425 if (json_paths)
6426 {
6427 json_object_string_add(json_nexthop_global, "ip",
6428 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6429 buf, INET6_ADDRSTRLEN));
6430 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6431 json_object_string_add(json_nexthop_global, "scope", "global");
6432 }
6433 else
6434 {
6435 vty_out (vty, " %s",
6436 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6437 buf, INET6_ADDRSTRLEN));
6438 }
6439 }
6440 #endif /* HAVE_IPV6 */
6441
6442
6443 /* Display the IGP cost or 'inaccessible' */
6444 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6445 {
6446 if (json_paths)
6447 json_object_boolean_false_add(json_nexthop_global, "accessible");
6448 else
6449 vty_out (vty, " (inaccessible)");
6450 }
6451 else
6452 {
6453 if (binfo->extra && binfo->extra->igpmetric)
6454 {
6455 if (json_paths)
6456 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
6457 else
6458 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
6459 }
6460
6461 /* IGP cost is 0, display this only for json */
6462 else
6463 {
6464 if (json_paths)
6465 json_object_int_add(json_nexthop_global, "metric", 0);
6466 }
6467
6468 if (json_paths)
6469 json_object_boolean_true_add(json_nexthop_global, "accessible");
6470 }
6471
6472 /* Display peer "from" output */
6473 /* This path was originated locally */
6474 if (binfo->peer == bgp->peer_self)
6475 {
6476
6477 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6478 {
6479 if (json_paths)
6480 json_object_string_add(json_peer, "peerId", "0.0.0.0");
6481 else
6482 vty_out (vty, " from 0.0.0.0 ");
6483 }
6484 else
6485 {
6486 if (json_paths)
6487 json_object_string_add(json_peer, "peerId", "::");
6488 else
6489 vty_out (vty, " from :: ");
6490 }
6491
6492 if (json_paths)
6493 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
6494 else
6495 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6496 }
6497
6498 /* We RXed this path from one of our peers */
6499 else
6500 {
6501
6502 if (json_paths)
6503 {
6504 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6505 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6506
6507 if (binfo->peer->hostname)
6508 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
6509
6510 if (binfo->peer->domainname)
6511 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
6512
6513 if (binfo->peer->conf_if)
6514 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
6515 }
6516 else
6517 {
6518 if (binfo->peer->conf_if)
6519 {
6520 if (binfo->peer->hostname &&
6521 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6522 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6523 binfo->peer->conf_if);
6524 else
6525 vty_out (vty, " from %s", binfo->peer->conf_if);
6526 }
6527 else
6528 {
6529 if (binfo->peer->hostname &&
6530 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6531 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
6532 binfo->peer->host);
6533 else
6534 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6535 }
6536
6537 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6538 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6539 else
6540 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6541 }
6542 }
6543
6544 if (!json_paths)
6545 vty_out (vty, "%s", VTY_NEWLINE);
6546
6547 #ifdef HAVE_IPV6
6548 /* display the link-local nexthop */
6549 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6550 {
6551 if (json_paths)
6552 {
6553 json_nexthop_ll = json_object_new_object();
6554 json_object_string_add(json_nexthop_ll, "ip",
6555 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6556 buf, INET6_ADDRSTRLEN));
6557 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6558 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6559
6560 json_object_boolean_true_add(json_nexthop_ll, "accessible");
6561 json_object_boolean_true_add(json_nexthop_ll, "used");
6562 }
6563 else
6564 {
6565 vty_out (vty, " (%s) (used)%s",
6566 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6567 buf, INET6_ADDRSTRLEN),
6568 VTY_NEWLINE);
6569 }
6570 }
6571 /* If we do not have a link-local nexthop then we must flag the global as "used" */
6572 else
6573 {
6574 if (json_paths)
6575 json_object_boolean_true_add(json_nexthop_global, "used");
6576 }
6577 #endif /* HAVE_IPV6 */
6578
6579 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
6580 if (json_paths)
6581 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6582 else
6583 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6584
6585 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6586 {
6587 if (json_paths)
6588 json_object_int_add(json_path, "med", attr->med);
6589 else
6590 vty_out (vty, ", metric %u", attr->med);
6591 }
6592
6593 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6594 {
6595 if (json_paths)
6596 json_object_int_add(json_path, "localpref", attr->local_pref);
6597 else
6598 vty_out (vty, ", localpref %u", attr->local_pref);
6599 }
6600 else
6601 {
6602 if (json_paths)
6603 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
6604 else
6605 vty_out (vty, ", localpref %u", bgp->default_local_pref);
6606 }
6607
6608 if (attr->extra && attr->extra->weight != 0)
6609 {
6610 if (json_paths)
6611 json_object_int_add(json_path, "weight", attr->extra->weight);
6612 else
6613 vty_out (vty, ", weight %u", attr->extra->weight);
6614 }
6615
6616 if (attr->extra && attr->extra->tag != 0)
6617 {
6618 if (json_paths)
6619 json_object_int_add(json_path, "tag", attr->extra->tag);
6620 else
6621 vty_out (vty, ", tag %d", attr->extra->tag);
6622 }
6623
6624 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6625 {
6626 if (json_paths)
6627 json_object_boolean_false_add(json_path, "valid");
6628 else
6629 vty_out (vty, ", invalid");
6630 }
6631 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6632 {
6633 if (json_paths)
6634 json_object_boolean_true_add(json_path, "valid");
6635 else
6636 vty_out (vty, ", valid");
6637 }
6638
6639 if (binfo->peer != bgp->peer_self)
6640 {
6641 if (binfo->peer->as == binfo->peer->local_as)
6642 {
6643 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
6644 {
6645 if (json_paths)
6646 json_object_string_add(json_peer, "type", "confed-internal");
6647 else
6648 vty_out (vty, ", confed-internal");
6649 }
6650 else
6651 {
6652 if (json_paths)
6653 json_object_string_add(json_peer, "type", "internal");
6654 else
6655 vty_out (vty, ", internal");
6656 }
6657 }
6658 else
6659 {
6660 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
6661 {
6662 if (json_paths)
6663 json_object_string_add(json_peer, "type", "confed-external");
6664 else
6665 vty_out (vty, ", confed-external");
6666 }
6667 else
6668 {
6669 if (json_paths)
6670 json_object_string_add(json_peer, "type", "external");
6671 else
6672 vty_out (vty, ", external");
6673 }
6674 }
6675 }
6676 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6677 {
6678 if (json_paths)
6679 {
6680 json_object_boolean_true_add(json_path, "aggregated");
6681 json_object_boolean_true_add(json_path, "local");
6682 }
6683 else
6684 {
6685 vty_out (vty, ", aggregated, local");
6686 }
6687 }
6688 else if (binfo->type != ZEBRA_ROUTE_BGP)
6689 {
6690 if (json_paths)
6691 json_object_boolean_true_add(json_path, "sourced");
6692 else
6693 vty_out (vty, ", sourced");
6694 }
6695 else
6696 {
6697 if (json_paths)
6698 {
6699 json_object_boolean_true_add(json_path, "sourced");
6700 json_object_boolean_true_add(json_path, "local");
6701 }
6702 else
6703 {
6704 vty_out (vty, ", sourced, local");
6705 }
6706 }
6707
6708 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6709 {
6710 if (json_paths)
6711 json_object_boolean_true_add(json_path, "atomicAggregate");
6712 else
6713 vty_out (vty, ", atomic-aggregate");
6714 }
6715
6716 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6717 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6718 bgp_info_mpath_count (binfo)))
6719 {
6720 if (json_paths)
6721 json_object_boolean_true_add(json_path, "multipath");
6722 else
6723 vty_out (vty, ", multipath");
6724 }
6725
6726 // Mark the bestpath(s)
6727 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
6728 {
6729 first_as = aspath_get_firstas(attr->aspath);
6730
6731 if (json_paths)
6732 {
6733 if (!json_bestpath)
6734 json_bestpath = json_object_new_object();
6735 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
6736 }
6737 else
6738 {
6739 if (first_as)
6740 vty_out (vty, ", bestpath-from-AS %d", first_as);
6741 else
6742 vty_out (vty, ", bestpath-from-AS Local");
6743 }
6744 }
6745
6746 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6747 {
6748 if (json_paths)
6749 {
6750 if (!json_bestpath)
6751 json_bestpath = json_object_new_object();
6752 json_object_boolean_true_add(json_bestpath, "overall");
6753 }
6754 else
6755 vty_out (vty, ", best");
6756 }
6757
6758 if (json_bestpath)
6759 json_object_object_add(json_path, "bestpath", json_bestpath);
6760
6761 if (!json_paths)
6762 vty_out (vty, "%s", VTY_NEWLINE);
6763
6764 /* Line 4 display Community */
6765 if (attr->community)
6766 {
6767 if (json_paths)
6768 {
6769 json_object_lock(attr->community->json);
6770 json_object_object_add(json_path, "community", attr->community->json);
6771 }
6772 else
6773 {
6774 vty_out (vty, " Community: %s%s", attr->community->str,
6775 VTY_NEWLINE);
6776 }
6777 }
6778
6779 /* Line 5 display Extended-community */
6780 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
6781 {
6782 if (json_paths)
6783 {
6784 json_ext_community = json_object_new_object();
6785 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
6786 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
6787 }
6788 else
6789 {
6790 vty_out (vty, " Extended Community: %s%s",
6791 attr->extra->ecommunity->str, VTY_NEWLINE);
6792 }
6793 }
6794
6795 /* Line 6 display Originator, Cluster-id */
6796 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6797 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6798 {
6799 assert (attr->extra);
6800 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6801 {
6802 if (json_paths)
6803 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
6804 else
6805 vty_out (vty, " Originator: %s",
6806 inet_ntoa (attr->extra->originator_id));
6807 }
6808
6809 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6810 {
6811 int i;
6812
6813 if (json_paths)
6814 {
6815 json_cluster_list = json_object_new_object();
6816 json_cluster_list_list = json_object_new_array();
6817
6818 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6819 {
6820 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
6821 json_object_array_add(json_cluster_list_list, json_string);
6822 }
6823
6824 /* struct cluster_list does not have "str" variable like
6825 * aspath and community do. Add this someday if someone
6826 * asks for it.
6827 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
6828 */
6829 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
6830 json_object_object_add(json_path, "clusterList", json_cluster_list);
6831 }
6832 else
6833 {
6834 vty_out (vty, ", Cluster list: ");
6835
6836 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6837 {
6838 vty_out (vty, "%s ",
6839 inet_ntoa (attr->extra->cluster->list[i]));
6840 }
6841 }
6842 }
6843
6844 if (!json_paths)
6845 vty_out (vty, "%s", VTY_NEWLINE);
6846 }
6847
6848 if (binfo->extra && binfo->extra->damp_info)
6849 bgp_damp_info_vty (vty, binfo, json_path);
6850
6851 /* Line 7 display Addpath IDs */
6852 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
6853 {
6854 if (json_paths)
6855 {
6856 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
6857 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
6858 }
6859 else
6860 {
6861 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
6862 binfo->addpath_rx_id, binfo->addpath_tx_id,
6863 VTY_NEWLINE);
6864 }
6865 }
6866
6867 /* If we used addpath to TX a non-bestpath we need to display
6868 * "Advertised to" on a path-by-path basis */
6869 if (bgp->addpath_tx_used[afi][safi])
6870 {
6871 first = 1;
6872
6873 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6874 {
6875 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
6876 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
6877
6878 if ((addpath_capable && has_adj) ||
6879 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
6880 {
6881 if (json_path && !json_adv_to)
6882 json_adv_to = json_object_new_object();
6883
6884 route_vty_out_advertised_to(vty, peer, &first,
6885 " Advertised to:",
6886 json_adv_to);
6887 }
6888 }
6889
6890 if (json_path)
6891 {
6892 if (json_adv_to)
6893 {
6894 json_object_object_add(json_path, "advertisedTo", json_adv_to);
6895 }
6896 }
6897 else
6898 {
6899 if (!first)
6900 {
6901 vty_out (vty, "%s", VTY_NEWLINE);
6902 }
6903 }
6904 }
6905
6906 /* Line 8 display Uptime */
6907 #ifdef HAVE_CLOCK_MONOTONIC
6908 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
6909 if (json_paths)
6910 {
6911 json_last_update = json_object_new_object();
6912 json_object_int_add(json_last_update, "epoch", tbuf);
6913 json_object_string_add(json_last_update, "string", ctime(&tbuf));
6914 json_object_object_add(json_path, "lastUpdate", json_last_update);
6915 }
6916 else
6917 vty_out (vty, " Last update: %s", ctime(&tbuf));
6918 #else
6919 if (json_paths)
6920 {
6921 json_last_update = json_object_new_object();
6922 json_object_int_add(json_last_update, "epoch", tbuf);
6923 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
6924 json_object_object_add(json_path, "lastUpdate", json_last_update);
6925 }
6926 else
6927 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6928 #endif /* HAVE_CLOCK_MONOTONIC */
6929 }
6930
6931 /* We've constructed the json object for this path, add it to the json
6932 * array of paths
6933 */
6934 if (json_paths)
6935 {
6936 if (json_nexthop_global || json_nexthop_ll)
6937 {
6938 json_nexthops = json_object_new_array();
6939
6940 if (json_nexthop_global)
6941 json_object_array_add(json_nexthops, json_nexthop_global);
6942
6943 if (json_nexthop_ll)
6944 json_object_array_add(json_nexthops, json_nexthop_ll);
6945
6946 json_object_object_add(json_path, "nexthops", json_nexthops);
6947 }
6948
6949 json_object_object_add(json_path, "peer", json_peer);
6950 json_object_array_add(json_paths, json_path);
6951 }
6952 else
6953 vty_out (vty, "%s", VTY_NEWLINE);
6954 }
6955
6956 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
6957 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6958 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6959
6960 enum bgp_show_type
6961 {
6962 bgp_show_type_normal,
6963 bgp_show_type_regexp,
6964 bgp_show_type_prefix_list,
6965 bgp_show_type_filter_list,
6966 bgp_show_type_route_map,
6967 bgp_show_type_neighbor,
6968 bgp_show_type_cidr_only,
6969 bgp_show_type_prefix_longer,
6970 bgp_show_type_community_all,
6971 bgp_show_type_community,
6972 bgp_show_type_community_exact,
6973 bgp_show_type_community_list,
6974 bgp_show_type_community_list_exact,
6975 bgp_show_type_flap_statistics,
6976 bgp_show_type_flap_address,
6977 bgp_show_type_flap_prefix,
6978 bgp_show_type_flap_cidr_only,
6979 bgp_show_type_flap_regexp,
6980 bgp_show_type_flap_filter_list,
6981 bgp_show_type_flap_prefix_list,
6982 bgp_show_type_flap_prefix_longer,
6983 bgp_show_type_flap_route_map,
6984 bgp_show_type_flap_neighbor,
6985 bgp_show_type_dampend_paths,
6986 bgp_show_type_damp_neighbor
6987 };
6988
6989 static int
6990 bgp_show_prefix_list (struct vty *vty, const char *name,
6991 const char *prefix_list_str, afi_t afi,
6992 safi_t safi, enum bgp_show_type type);
6993 static int
6994 bgp_show_filter_list (struct vty *vty, const char *name,
6995 const char *filter, afi_t afi,
6996 safi_t safi, enum bgp_show_type type);
6997 static int
6998 bgp_show_route_map (struct vty *vty, const char *name,
6999 const char *rmap_str, afi_t afi,
7000 safi_t safi, enum bgp_show_type type);
7001 static int
7002 bgp_show_community_list (struct vty *vty, const char *name,
7003 const char *com, int exact,
7004 afi_t afi, safi_t safi);
7005 static int
7006 bgp_show_prefix_longer (struct vty *vty, const char *name,
7007 const char *prefix, afi_t afi,
7008 safi_t safi, enum bgp_show_type type);
7009
7010 static int
7011 bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
7012 enum bgp_show_type type, void *output_arg, u_char use_json)
7013 {
7014 struct bgp_info *ri;
7015 struct bgp_node *rn;
7016 int header = 1;
7017 int display;
7018 unsigned long output_count;
7019 struct prefix *p;
7020 char buf[BUFSIZ];
7021 char buf2[BUFSIZ];
7022 json_object *json = NULL;
7023 json_object *json_paths = NULL;
7024 json_object *json_routes = NULL;
7025
7026 if (use_json)
7027 {
7028 json = json_object_new_object();
7029 json_object_int_add(json, "tableVersion", table->version);
7030 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
7031 json_routes = json_object_new_object();
7032 }
7033
7034 /* This is first entry point, so reset total line. */
7035 output_count = 0;
7036
7037 /* Start processing of routes. */
7038 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7039 if (rn->info != NULL)
7040 {
7041 display = 0;
7042
7043 if (use_json)
7044 json_paths = json_object_new_array();
7045 else
7046 json_paths = NULL;
7047
7048 for (ri = rn->info; ri; ri = ri->next)
7049 {
7050 if (type == bgp_show_type_flap_statistics
7051 || type == bgp_show_type_flap_address
7052 || type == bgp_show_type_flap_prefix
7053 || type == bgp_show_type_flap_cidr_only
7054 || type == bgp_show_type_flap_regexp
7055 || type == bgp_show_type_flap_filter_list
7056 || type == bgp_show_type_flap_prefix_list
7057 || type == bgp_show_type_flap_prefix_longer
7058 || type == bgp_show_type_flap_route_map
7059 || type == bgp_show_type_flap_neighbor
7060 || type == bgp_show_type_dampend_paths
7061 || type == bgp_show_type_damp_neighbor)
7062 {
7063 if (!(ri->extra && ri->extra->damp_info))
7064 continue;
7065 }
7066 if (type == bgp_show_type_regexp
7067 || type == bgp_show_type_flap_regexp)
7068 {
7069 regex_t *regex = output_arg;
7070
7071 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7072 continue;
7073 }
7074 if (type == bgp_show_type_prefix_list
7075 || type == bgp_show_type_flap_prefix_list)
7076 {
7077 struct prefix_list *plist = output_arg;
7078
7079 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7080 continue;
7081 }
7082 if (type == bgp_show_type_filter_list
7083 || type == bgp_show_type_flap_filter_list)
7084 {
7085 struct as_list *as_list = output_arg;
7086
7087 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7088 continue;
7089 }
7090 if (type == bgp_show_type_route_map
7091 || type == bgp_show_type_flap_route_map)
7092 {
7093 struct route_map *rmap = output_arg;
7094 struct bgp_info binfo;
7095 struct attr dummy_attr;
7096 struct attr_extra dummy_extra;
7097 int ret;
7098
7099 dummy_attr.extra = &dummy_extra;
7100 bgp_attr_dup (&dummy_attr, ri->attr);
7101
7102 binfo.peer = ri->peer;
7103 binfo.attr = &dummy_attr;
7104
7105 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7106 if (ret == RMAP_DENYMATCH)
7107 continue;
7108 }
7109 if (type == bgp_show_type_neighbor
7110 || type == bgp_show_type_flap_neighbor
7111 || type == bgp_show_type_damp_neighbor)
7112 {
7113 union sockunion *su = output_arg;
7114
7115 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7116 continue;
7117 }
7118 if (type == bgp_show_type_cidr_only
7119 || type == bgp_show_type_flap_cidr_only)
7120 {
7121 u_int32_t destination;
7122
7123 destination = ntohl (rn->p.u.prefix4.s_addr);
7124 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7125 continue;
7126 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7127 continue;
7128 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7129 continue;
7130 }
7131 if (type == bgp_show_type_prefix_longer
7132 || type == bgp_show_type_flap_prefix_longer)
7133 {
7134 struct prefix *p = output_arg;
7135
7136 if (! prefix_match (p, &rn->p))
7137 continue;
7138 }
7139 if (type == bgp_show_type_community_all)
7140 {
7141 if (! ri->attr->community)
7142 continue;
7143 }
7144 if (type == bgp_show_type_community)
7145 {
7146 struct community *com = output_arg;
7147
7148 if (! ri->attr->community ||
7149 ! community_match (ri->attr->community, com))
7150 continue;
7151 }
7152 if (type == bgp_show_type_community_exact)
7153 {
7154 struct community *com = output_arg;
7155
7156 if (! ri->attr->community ||
7157 ! community_cmp (ri->attr->community, com))
7158 continue;
7159 }
7160 if (type == bgp_show_type_community_list)
7161 {
7162 struct community_list *list = output_arg;
7163
7164 if (! community_list_match (ri->attr->community, list))
7165 continue;
7166 }
7167 if (type == bgp_show_type_community_list_exact)
7168 {
7169 struct community_list *list = output_arg;
7170
7171 if (! community_list_exact_match (ri->attr->community, list))
7172 continue;
7173 }
7174 if (type == bgp_show_type_flap_address
7175 || type == bgp_show_type_flap_prefix)
7176 {
7177 struct prefix *p = output_arg;
7178
7179 if (! prefix_match (&rn->p, p))
7180 continue;
7181
7182 if (type == bgp_show_type_flap_prefix)
7183 if (p->prefixlen != rn->p.prefixlen)
7184 continue;
7185 }
7186 if (type == bgp_show_type_dampend_paths
7187 || type == bgp_show_type_damp_neighbor)
7188 {
7189 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7190 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7191 continue;
7192 }
7193
7194 if (!use_json && header)
7195 {
7196 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
7197 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7198 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7199 if (type == bgp_show_type_dampend_paths
7200 || type == bgp_show_type_damp_neighbor)
7201 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7202 else if (type == bgp_show_type_flap_statistics
7203 || type == bgp_show_type_flap_address
7204 || type == bgp_show_type_flap_prefix
7205 || type == bgp_show_type_flap_cidr_only
7206 || type == bgp_show_type_flap_regexp
7207 || type == bgp_show_type_flap_filter_list
7208 || type == bgp_show_type_flap_prefix_list
7209 || type == bgp_show_type_flap_prefix_longer
7210 || type == bgp_show_type_flap_route_map
7211 || type == bgp_show_type_flap_neighbor)
7212 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7213 else
7214 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7215 header = 0;
7216 }
7217
7218 if (type == bgp_show_type_dampend_paths
7219 || type == bgp_show_type_damp_neighbor)
7220 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7221 else if (type == bgp_show_type_flap_statistics
7222 || type == bgp_show_type_flap_address
7223 || type == bgp_show_type_flap_prefix
7224 || type == bgp_show_type_flap_cidr_only
7225 || type == bgp_show_type_flap_regexp
7226 || type == bgp_show_type_flap_filter_list
7227 || type == bgp_show_type_flap_prefix_list
7228 || type == bgp_show_type_flap_prefix_longer
7229 || type == bgp_show_type_flap_route_map
7230 || type == bgp_show_type_flap_neighbor)
7231 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7232 else
7233 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7234 display++;
7235 }
7236
7237 if (display)
7238 {
7239 output_count++;
7240 if (use_json)
7241 {
7242 p = &rn->p;
7243 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7244 json_object_object_add(json_routes, buf2, json_paths);
7245 }
7246 }
7247 }
7248
7249 if (use_json)
7250 {
7251 json_object_object_add(json, "routes", json_routes);
7252 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7253 json_object_free(json);
7254 }
7255 else
7256 {
7257 /* No route is displayed */
7258 if (output_count == 0)
7259 {
7260 if (type == bgp_show_type_normal)
7261 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
7262 }
7263 else
7264 vty_out (vty, "%sTotal number of prefixes %ld%s",
7265 VTY_NEWLINE, output_count, VTY_NEWLINE);
7266 }
7267
7268 return CMD_SUCCESS;
7269 }
7270
7271 static int
7272 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
7273 enum bgp_show_type type, void *output_arg, u_char use_json)
7274 {
7275 struct bgp_table *table;
7276
7277 if (bgp == NULL)
7278 {
7279 bgp = bgp_get_default ();
7280 }
7281
7282 if (bgp == NULL)
7283 {
7284 if (!use_json)
7285 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7286 return CMD_WARNING;
7287 }
7288
7289 table = bgp->rib[afi][safi];
7290
7291 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, use_json);
7292 }
7293
7294 /* Header of detailed BGP route information */
7295 static void
7296 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7297 struct bgp_node *rn,
7298 struct prefix_rd *prd, afi_t afi, safi_t safi,
7299 json_object *json)
7300 {
7301 struct bgp_info *ri;
7302 struct prefix *p;
7303 struct peer *peer;
7304 struct listnode *node, *nnode;
7305 char buf1[INET6_ADDRSTRLEN];
7306 char buf2[INET6_ADDRSTRLEN];
7307 int count = 0;
7308 int best = 0;
7309 int suppress = 0;
7310 int no_export = 0;
7311 int no_advertise = 0;
7312 int local_as = 0;
7313 int first = 1;
7314 json_object *json_adv_to = NULL;
7315
7316 p = &rn->p;
7317
7318 if (json)
7319 {
7320 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7321 json_object_int_add(json, "prefixlen", p->prefixlen);
7322 }
7323 else
7324 {
7325 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7326 (safi == SAFI_MPLS_VPN ?
7327 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7328 safi == SAFI_MPLS_VPN ? ":" : "",
7329 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7330 p->prefixlen, VTY_NEWLINE);
7331 }
7332
7333 for (ri = rn->info; ri; ri = ri->next)
7334 {
7335 count++;
7336 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7337 {
7338 best = count;
7339 if (ri->extra && ri->extra->suppress)
7340 suppress = 1;
7341 if (ri->attr->community != NULL)
7342 {
7343 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7344 no_advertise = 1;
7345 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7346 no_export = 1;
7347 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7348 local_as = 1;
7349 }
7350 }
7351 }
7352
7353 if (!json)
7354 {
7355 vty_out (vty, "Paths: (%d available", count);
7356 if (best)
7357 {
7358 vty_out (vty, ", best #%d", best);
7359 if (safi == SAFI_UNICAST)
7360 vty_out (vty, ", table Default-IP-Routing-Table");
7361 }
7362 else
7363 vty_out (vty, ", no best path");
7364
7365 if (no_advertise)
7366 vty_out (vty, ", not advertised to any peer");
7367 else if (no_export)
7368 vty_out (vty, ", not advertised to EBGP peer");
7369 else if (local_as)
7370 vty_out (vty, ", not advertised outside local AS");
7371
7372 if (suppress)
7373 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7374 vty_out (vty, ")%s", VTY_NEWLINE);
7375 }
7376
7377 /* If we are not using addpath then we can display Advertised to and that will
7378 * show what peers we advertised the bestpath to. If we are using addpath
7379 * though then we must display Advertised to on a path-by-path basis. */
7380 if (!bgp->addpath_tx_used[afi][safi])
7381 {
7382 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7383 {
7384 if (bgp_adj_out_lookup (peer, rn, 0))
7385 {
7386 if (json && !json_adv_to)
7387 json_adv_to = json_object_new_object();
7388
7389 route_vty_out_advertised_to(vty, peer, &first,
7390 " Advertised to non peer-group peers:\n ",
7391 json_adv_to);
7392 }
7393 }
7394
7395 if (json)
7396 {
7397 if (json_adv_to)
7398 {
7399 json_object_object_add(json, "advertisedTo", json_adv_to);
7400 }
7401 }
7402 else
7403 {
7404 if (first)
7405 vty_out (vty, " Not advertised to any peer");
7406 vty_out (vty, "%s", VTY_NEWLINE);
7407 }
7408 }
7409 }
7410
7411 /* Display specified route of BGP table. */
7412 static int
7413 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
7414 struct bgp_table *rib, const char *ip_str,
7415 afi_t afi, safi_t safi, struct prefix_rd *prd,
7416 int prefix_check, enum bgp_path_type pathtype,
7417 u_char use_json)
7418 {
7419 int ret;
7420 int header;
7421 int display = 0;
7422 struct prefix match;
7423 struct bgp_node *rn;
7424 struct bgp_node *rm;
7425 struct bgp_info *ri;
7426 struct bgp_table *table;
7427 json_object *json = NULL;
7428 json_object *json_paths = NULL;
7429
7430 /* Check IP address argument. */
7431 ret = str2prefix (ip_str, &match);
7432 if (! ret)
7433 {
7434 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
7435 return CMD_WARNING;
7436 }
7437
7438 match.family = afi2family (afi);
7439
7440 if (use_json)
7441 {
7442 json = json_object_new_object();
7443 json_paths = json_object_new_array();
7444 }
7445
7446 if (safi == SAFI_MPLS_VPN)
7447 {
7448 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
7449 {
7450 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
7451 continue;
7452
7453 if ((table = rn->info) != NULL)
7454 {
7455 header = 1;
7456
7457 if ((rm = bgp_node_match (table, &match)) != NULL)
7458 {
7459 if (prefix_check && rm->p.prefixlen != match.prefixlen)
7460 {
7461 bgp_unlock_node (rm);
7462 continue;
7463 }
7464
7465 for (ri = rm->info; ri; ri = ri->next)
7466 {
7467 if (header)
7468 {
7469 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
7470 AFI_IP, SAFI_MPLS_VPN, json);
7471
7472 header = 0;
7473 }
7474 display++;
7475
7476 if (pathtype == BGP_PATH_ALL ||
7477 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7478 (pathtype == BGP_PATH_MULTIPATH &&
7479 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7480 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN, json_paths);
7481 }
7482
7483 bgp_unlock_node (rm);
7484 }
7485 }
7486 }
7487 }
7488 else
7489 {
7490 header = 1;
7491
7492 if ((rn = bgp_node_match (rib, &match)) != NULL)
7493 {
7494 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
7495 {
7496 for (ri = rn->info; ri; ri = ri->next)
7497 {
7498 if (header)
7499 {
7500 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
7501 header = 0;
7502 }
7503 display++;
7504
7505 if (pathtype == BGP_PATH_ALL ||
7506 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
7507 (pathtype == BGP_PATH_MULTIPATH &&
7508 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
7509 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
7510 }
7511 }
7512
7513 bgp_unlock_node (rn);
7514 }
7515 }
7516
7517 if (use_json)
7518 {
7519 if (display)
7520 json_object_object_add(json, "paths", json_paths);
7521
7522 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7523 json_object_free(json);
7524 }
7525 else
7526 {
7527 if (!display)
7528 {
7529 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
7530 return CMD_WARNING;
7531 }
7532 }
7533
7534 return CMD_SUCCESS;
7535 }
7536
7537 /* Display specified route of Main RIB */
7538 static int
7539 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
7540 afi_t afi, safi_t safi, struct prefix_rd *prd,
7541 int prefix_check, enum bgp_path_type pathtype,
7542 u_char use_json)
7543 {
7544 struct bgp *bgp;
7545
7546 /* BGP structure lookup. */
7547 if (view_name)
7548 {
7549 bgp = bgp_lookup_by_name (view_name);
7550 if (bgp == NULL)
7551 {
7552 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
7553 return CMD_WARNING;
7554 }
7555 }
7556 else
7557 {
7558 bgp = bgp_get_default ();
7559 if (bgp == NULL)
7560 {
7561 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7562 return CMD_WARNING;
7563 }
7564 }
7565
7566 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
7567 afi, safi, prd, prefix_check, pathtype,
7568 use_json);
7569 }
7570
7571 /* BGP route print out function. */
7572 DEFUN (show_ip_bgp,
7573 show_ip_bgp_cmd,
7574 "show ip bgp {json}",
7575 SHOW_STR
7576 IP_STR
7577 BGP_STR
7578 "JavaScript Object Notation\n")
7579 {
7580 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
7581 }
7582
7583 DEFUN (show_ip_bgp_ipv4,
7584 show_ip_bgp_ipv4_cmd,
7585 "show ip bgp ipv4 (unicast|multicast) {json}",
7586 SHOW_STR
7587 IP_STR
7588 BGP_STR
7589 "Address family\n"
7590 "Address Family modifier\n"
7591 "Address Family modifier\n"
7592 "JavaScript Object Notation\n")
7593 {
7594 u_char uj = use_json(argc, argv);
7595
7596 if (strncmp (argv[0], "m", 1) == 0)
7597 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7598 NULL, uj);
7599
7600 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
7601 }
7602
7603 ALIAS (show_ip_bgp_ipv4,
7604 show_bgp_ipv4_safi_cmd,
7605 "show bgp ipv4 (unicast|multicast) {json}",
7606 SHOW_STR
7607 BGP_STR
7608 "Address family\n"
7609 "Address Family modifier\n"
7610 "Address Family modifier\n"
7611 "JavaScript Object Notation\n")
7612
7613 DEFUN (show_ip_bgp_route,
7614 show_ip_bgp_route_cmd,
7615 "show ip bgp A.B.C.D {json}",
7616 SHOW_STR
7617 IP_STR
7618 BGP_STR
7619 "Network in the BGP routing table to display\n"
7620 "JavaScript Object Notation\n")
7621 {
7622 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7623 }
7624
7625 DEFUN (show_ip_bgp_route_pathtype,
7626 show_ip_bgp_route_pathtype_cmd,
7627 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
7628 SHOW_STR
7629 IP_STR
7630 BGP_STR
7631 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7632 "Display only the bestpath\n"
7633 "Display only multipaths\n"
7634 "JavaScript Object Notation\n")
7635 {
7636 u_char uj = use_json(argc, argv);
7637
7638 if (strncmp (argv[1], "b", 1) == 0)
7639 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7640 else
7641 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7642 }
7643
7644 DEFUN (show_bgp_ipv4_safi_route_pathtype,
7645 show_bgp_ipv4_safi_route_pathtype_cmd,
7646 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
7647 SHOW_STR
7648 BGP_STR
7649 "Address family\n"
7650 "Address Family modifier\n"
7651 "Address Family modifier\n"
7652 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7653 "Display only the bestpath\n"
7654 "Display only multipaths\n"
7655 "JavaScript Object Notation\n")
7656 {
7657 u_char uj = use_json(argc, argv);
7658
7659 if (strncmp (argv[0], "m", 1) == 0)
7660 if (strncmp (argv[2], "b", 1) == 0)
7661 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7662 else
7663 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7664 else
7665 if (strncmp (argv[2], "b", 1) == 0)
7666 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7667 else
7668 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7669 }
7670
7671 DEFUN (show_ip_bgp_ipv4_route,
7672 show_ip_bgp_ipv4_route_cmd,
7673 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
7674 SHOW_STR
7675 IP_STR
7676 BGP_STR
7677 "Address family\n"
7678 "Address Family modifier\n"
7679 "Address Family modifier\n"
7680 "Network in the BGP routing table to display\n"
7681 "JavaScript Object Notation\n")
7682 {
7683 u_char uj = use_json(argc, argv);
7684
7685 if (strncmp (argv[0], "m", 1) == 0)
7686 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
7687
7688 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
7689 }
7690
7691 ALIAS (show_ip_bgp_ipv4_route,
7692 show_bgp_ipv4_safi_route_cmd,
7693 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
7694 SHOW_STR
7695 BGP_STR
7696 "Address family\n"
7697 "Address Family modifier\n"
7698 "Address Family modifier\n"
7699 "Network in the BGP routing table to display\n"
7700 "JavaScript Object Notation\n")
7701
7702 DEFUN (show_ip_bgp_vpnv4_all_route,
7703 show_ip_bgp_vpnv4_all_route_cmd,
7704 "show ip bgp vpnv4 all A.B.C.D {json}",
7705 SHOW_STR
7706 IP_STR
7707 BGP_STR
7708 "Display VPNv4 NLRI specific information\n"
7709 "Display information about all VPNv4 NLRIs\n"
7710 "Network in the BGP routing table to display\n"
7711 "JavaScript Object Notation\n")
7712 {
7713 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7714 }
7715
7716
7717 DEFUN (show_ip_bgp_vpnv4_rd_route,
7718 show_ip_bgp_vpnv4_rd_route_cmd,
7719 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
7720 SHOW_STR
7721 IP_STR
7722 BGP_STR
7723 "Display VPNv4 NLRI specific information\n"
7724 "Display information for a route distinguisher\n"
7725 "VPN Route Distinguisher\n"
7726 "Network in the BGP routing table to display\n"
7727 "JavaScript Object Notation\n")
7728 {
7729 int ret;
7730 struct prefix_rd prd;
7731 u_char uj= use_json(argc, argv);
7732
7733 ret = str2prefix_rd (argv[0], &prd);
7734 if (! ret)
7735 {
7736 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7737 return CMD_WARNING;
7738 }
7739 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj);
7740 }
7741
7742 DEFUN (show_ip_bgp_prefix,
7743 show_ip_bgp_prefix_cmd,
7744 "show ip bgp A.B.C.D/M {json}",
7745 SHOW_STR
7746 IP_STR
7747 BGP_STR
7748 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7749 "JavaScript Object Notation\n")
7750 {
7751 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
7752 }
7753
7754 DEFUN (show_ip_bgp_prefix_pathtype,
7755 show_ip_bgp_prefix_pathtype_cmd,
7756 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
7757 SHOW_STR
7758 IP_STR
7759 BGP_STR
7760 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7761 "Display only the bestpath\n"
7762 "Display only multipaths\n"
7763 "JavaScript Object Notation\n")
7764 {
7765 u_char uj = use_json(argc, argv);
7766 if (strncmp (argv[1], "b", 1) == 0)
7767 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
7768 else
7769 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
7770 }
7771
7772 DEFUN (show_ip_bgp_ipv4_prefix,
7773 show_ip_bgp_ipv4_prefix_cmd,
7774 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
7775 SHOW_STR
7776 IP_STR
7777 BGP_STR
7778 "Address family\n"
7779 "Address Family modifier\n"
7780 "Address Family modifier\n"
7781 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7782 "JavaScript Object Notation\n")
7783 {
7784 u_char uj = use_json(argc, argv);
7785
7786 if (strncmp (argv[0], "m", 1) == 0)
7787 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
7788
7789 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
7790 }
7791
7792 ALIAS (show_ip_bgp_ipv4_prefix,
7793 show_bgp_ipv4_safi_prefix_cmd,
7794 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
7795 SHOW_STR
7796 BGP_STR
7797 "Address family\n"
7798 "Address Family modifier\n"
7799 "Address Family modifier\n"
7800 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7801 "JavaScript Object Notation\n")
7802
7803 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7804 show_ip_bgp_ipv4_prefix_pathtype_cmd,
7805 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
7806 SHOW_STR
7807 IP_STR
7808 BGP_STR
7809 "Address family\n"
7810 "Address Family modifier\n"
7811 "Address Family modifier\n"
7812 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7813 "Display only the bestpath\n"
7814 "Display only multipaths\n"
7815 "JavaScript Object Notation\n")
7816 {
7817 u_char uj = use_json(argc, argv);
7818
7819 if (strncmp (argv[0], "m", 1) == 0)
7820 if (strncmp (argv[2], "b", 1) == 0)
7821 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
7822 else
7823 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
7824 else
7825 if (strncmp (argv[2], "b", 1) == 0)
7826 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
7827 else
7828 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
7829 }
7830
7831 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7832 show_bgp_ipv4_safi_prefix_pathtype_cmd,
7833 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
7834 SHOW_STR
7835 BGP_STR
7836 "Address family\n"
7837 "Address Family modifier\n"
7838 "Address Family modifier\n"
7839 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7840 "Display only the bestpath\n"
7841 "Display only multipaths\n"
7842 "JavaScript Object Notation\n")
7843
7844 DEFUN (show_ip_bgp_vpnv4_all_prefix,
7845 show_ip_bgp_vpnv4_all_prefix_cmd,
7846 "show ip bgp vpnv4 all A.B.C.D/M {json}",
7847 SHOW_STR
7848 IP_STR
7849 BGP_STR
7850 "Display VPNv4 NLRI specific information\n"
7851 "Display information about all VPNv4 NLRIs\n"
7852 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7853 "JavaScript Object Notation\n")
7854 {
7855 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
7856 }
7857
7858 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7859 show_ip_bgp_vpnv4_rd_prefix_cmd,
7860 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
7861 SHOW_STR
7862 IP_STR
7863 BGP_STR
7864 "Display VPNv4 NLRI specific information\n"
7865 "Display information for a route distinguisher\n"
7866 "VPN Route Distinguisher\n"
7867 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7868 "JavaScript Object Notation\n")
7869 {
7870 int ret;
7871 struct prefix_rd prd;
7872
7873 ret = str2prefix_rd (argv[0], &prd);
7874 if (! ret)
7875 {
7876 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7877 return CMD_WARNING;
7878 }
7879 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv));
7880 }
7881
7882 DEFUN (show_ip_bgp_view,
7883 show_ip_bgp_instance_cmd,
7884 "show ip bgp " BGP_INSTANCE_CMD " {json}",
7885 SHOW_STR
7886 IP_STR
7887 BGP_STR
7888 BGP_INSTANCE_HELP_STR
7889 "JavaScript Object Notation\n")
7890 {
7891 struct bgp *bgp;
7892
7893 /* BGP structure lookup. */
7894 bgp = bgp_lookup_by_name (argv[1]);
7895 if (bgp == NULL)
7896 {
7897 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
7898 return CMD_WARNING;
7899 }
7900
7901 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
7902 }
7903
7904 DEFUN (show_ip_bgp_instance_route,
7905 show_ip_bgp_instance_route_cmd,
7906 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
7907 SHOW_STR
7908 IP_STR
7909 BGP_STR
7910 BGP_INSTANCE_HELP_STR
7911 "Network in the BGP routing table to display\n"
7912 "JavaScript Object Notation\n")
7913 {
7914 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
7915 }
7916
7917 DEFUN (show_ip_bgp_instance_route_pathtype,
7918 show_ip_bgp_instance_route_pathtype_cmd,
7919 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
7920 SHOW_STR
7921 IP_STR
7922 BGP_STR
7923 BGP_INSTANCE_HELP_STR
7924 "Network in the BGP routing table to display\n"
7925 "Display only the bestpath\n"
7926 "Display only multipaths\n"
7927 "JavaScript Object Notation\n")
7928 {
7929 u_char uj = use_json(argc, argv);
7930
7931 if (strncmp (argv[3], "b", 1) == 0)
7932 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
7933 else
7934 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
7935 }
7936
7937 DEFUN (show_ip_bgp_instance_prefix,
7938 show_ip_bgp_instance_prefix_cmd,
7939 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
7940 SHOW_STR
7941 IP_STR
7942 BGP_STR
7943 BGP_INSTANCE_HELP_STR
7944 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7945 "JavaScript Object Notation\n")
7946 {
7947 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
7948 }
7949
7950 DEFUN (show_ip_bgp_instance_prefix_pathtype,
7951 show_ip_bgp_instance_prefix_pathtype_cmd,
7952 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
7953 SHOW_STR
7954 IP_STR
7955 BGP_STR
7956 BGP_INSTANCE_HELP_STR
7957 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7958 "Display only the bestpath\n"
7959 "Display only multipaths\n"
7960 "JavaScript Object Notation\n")
7961 {
7962 u_char uj = use_json(argc, argv);
7963 if (strncmp (argv[3], "b", 1) == 0)
7964 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
7965 else
7966 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
7967 }
7968
7969 #ifdef HAVE_IPV6
7970 DEFUN (show_bgp,
7971 show_bgp_cmd,
7972 "show bgp {json}",
7973 SHOW_STR
7974 BGP_STR
7975 "JavaScript Object Notation\n")
7976 {
7977 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7978 NULL, use_json(argc, argv));
7979 }
7980
7981 ALIAS (show_bgp,
7982 show_bgp_ipv6_cmd,
7983 "show bgp ipv6 {json}",
7984 SHOW_STR
7985 BGP_STR
7986 "Address family\n"
7987 "JavaScript Object Notation\n")
7988
7989 DEFUN (show_bgp_ipv6_safi,
7990 show_bgp_ipv6_safi_cmd,
7991 "show bgp ipv6 (unicast|multicast) {json}",
7992 SHOW_STR
7993 BGP_STR
7994 "Address family\n"
7995 "Address Family modifier\n"
7996 "Address Family modifier\n"
7997 "JavaScript Object Notation\n")
7998 {
7999 u_char uj = use_json(argc, argv);
8000 if (strncmp (argv[0], "m", 1) == 0)
8001 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8002 NULL, uj);
8003
8004 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
8005 }
8006
8007 static void
8008 bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8009 {
8010 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8011 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8012 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8013 }
8014
8015 /* old command */
8016 DEFUN (show_ipv6_bgp,
8017 show_ipv6_bgp_cmd,
8018 "show ipv6 bgp {json}",
8019 SHOW_STR
8020 IP_STR
8021 BGP_STR
8022 "JavaScript Object Notation\n")
8023 {
8024 bgp_show_ipv6_bgp_deprecate_warning(vty);
8025 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8026 NULL, use_json(argc, argv));
8027 }
8028
8029 DEFUN (show_bgp_route,
8030 show_bgp_route_cmd,
8031 "show bgp X:X::X:X {json}",
8032 SHOW_STR
8033 BGP_STR
8034 "Network in the BGP routing table to display\n"
8035 "JavaScript Object Notation\n")
8036 {
8037 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8038 }
8039
8040 ALIAS (show_bgp_route,
8041 show_bgp_ipv6_route_cmd,
8042 "show bgp ipv6 X:X::X:X {json}",
8043 SHOW_STR
8044 BGP_STR
8045 "Address family\n"
8046 "Network in the BGP routing table to display\n"
8047 "JavaScript Object Notation\n")
8048
8049 DEFUN (show_bgp_ipv6_safi_route,
8050 show_bgp_ipv6_safi_route_cmd,
8051 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
8052 SHOW_STR
8053 BGP_STR
8054 "Address family\n"
8055 "Address Family modifier\n"
8056 "Address Family modifier\n"
8057 "Network in the BGP routing table to display\n"
8058 "JavaScript Object Notation\n")
8059 {
8060 u_char uj = use_json(argc, argv);
8061 if (strncmp (argv[0], "m", 1) == 0)
8062 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
8063
8064 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
8065 }
8066
8067 DEFUN (show_bgp_route_pathtype,
8068 show_bgp_route_pathtype_cmd,
8069 "show bgp X:X::X:X (bestpath|multipath) {json}",
8070 SHOW_STR
8071 BGP_STR
8072 "Network in the BGP routing table to display\n"
8073 "Display only the bestpath\n"
8074 "Display only multipaths\n"
8075 "JavaScript Object Notation\n")
8076 {
8077 u_char uj = use_json(argc, argv);
8078 if (strncmp (argv[1], "b", 1) == 0)
8079 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8080 else
8081 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8082 }
8083
8084 ALIAS (show_bgp_route_pathtype,
8085 show_bgp_ipv6_route_pathtype_cmd,
8086 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
8087 SHOW_STR
8088 BGP_STR
8089 "Address family\n"
8090 "Network in the BGP routing table to display\n"
8091 "Display only the bestpath\n"
8092 "Display only multipaths\n"
8093 "JavaScript Object Notation\n")
8094
8095 DEFUN (show_bgp_ipv6_safi_route_pathtype,
8096 show_bgp_ipv6_safi_route_pathtype_cmd,
8097 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
8098 SHOW_STR
8099 BGP_STR
8100 "Address family\n"
8101 "Address Family modifier\n"
8102 "Address Family modifier\n"
8103 "Network in the BGP routing table to display\n"
8104 "Display only the bestpath\n"
8105 "Display only multipaths\n"
8106 "JavaScript Object Notation\n")
8107 {
8108 u_char uj = use_json(argc, argv);
8109 if (strncmp (argv[0], "m", 1) == 0)
8110 if (strncmp (argv[2], "b", 1) == 0)
8111 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8112 else
8113 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8114 else
8115 if (strncmp (argv[2], "b", 1) == 0)
8116 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8117 else
8118 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8119 }
8120
8121 /* old command */
8122 DEFUN (show_ipv6_bgp_route,
8123 show_ipv6_bgp_route_cmd,
8124 "show ipv6 bgp X:X::X:X {json}",
8125 SHOW_STR
8126 IP_STR
8127 BGP_STR
8128 "Network in the BGP routing table to display\n"
8129 "JavaScript Object Notation\n")
8130 {
8131 bgp_show_ipv6_bgp_deprecate_warning(vty);
8132 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8133 }
8134
8135 DEFUN (show_bgp_prefix,
8136 show_bgp_prefix_cmd,
8137 "show bgp X:X::X:X/M {json}",
8138 SHOW_STR
8139 BGP_STR
8140 "IPv6 prefix <network>/<length>\n"
8141 "JavaScript Object Notation\n")
8142 {
8143 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8144 }
8145
8146 ALIAS (show_bgp_prefix,
8147 show_bgp_ipv6_prefix_cmd,
8148 "show bgp ipv6 X:X::X:X/M {json}",
8149 SHOW_STR
8150 BGP_STR
8151 "Address family\n"
8152 "IPv6 prefix <network>/<length>\n"
8153 "JavaScript Object Notation\n")
8154
8155 DEFUN (show_bgp_ipv6_safi_prefix,
8156 show_bgp_ipv6_safi_prefix_cmd,
8157 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
8158 SHOW_STR
8159 BGP_STR
8160 "Address family\n"
8161 "Address Family modifier\n"
8162 "Address Family modifier\n"
8163 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8164 "JavaScript Object Notation\n")
8165 {
8166 u_char uj = use_json(argc, argv);
8167 if (strncmp (argv[0], "m", 1) == 0)
8168 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
8169
8170 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
8171 }
8172
8173 DEFUN (show_bgp_prefix_pathtype,
8174 show_bgp_prefix_pathtype_cmd,
8175 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
8176 SHOW_STR
8177 BGP_STR
8178 "IPv6 prefix <network>/<length>\n"
8179 "Display only the bestpath\n"
8180 "Display only multipaths\n"
8181 "JavaScript Object Notation\n")
8182 {
8183 u_char uj = use_json(argc, argv);
8184 if (strncmp (argv[1], "b", 1) == 0)
8185 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8186 else
8187 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8188 }
8189
8190 ALIAS (show_bgp_prefix_pathtype,
8191 show_bgp_ipv6_prefix_pathtype_cmd,
8192 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8193 SHOW_STR
8194 BGP_STR
8195 "Address family\n"
8196 "IPv6 prefix <network>/<length>\n"
8197 "Display only the bestpath\n"
8198 "Display only multipaths\n"
8199 "JavaScript Object Notation\n")
8200
8201 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8202 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8203 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
8204 SHOW_STR
8205 BGP_STR
8206 "Address family\n"
8207 "Address Family modifier\n"
8208 "Address Family modifier\n"
8209 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8210 "Display only the bestpath\n"
8211 "Display only multipaths\n"
8212 "JavaScript Object Notation\n")
8213 {
8214 u_char uj = use_json(argc, argv);
8215 if (strncmp (argv[0], "m", 1) == 0)
8216 if (strncmp (argv[2], "b", 1) == 0)
8217 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8218 else
8219 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8220 else
8221 if (strncmp (argv[2], "b", 1) == 0)
8222 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8223 else
8224 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8225 }
8226
8227 /* old command */
8228 DEFUN (show_ipv6_bgp_prefix,
8229 show_ipv6_bgp_prefix_cmd,
8230 "show ipv6 bgp X:X::X:X/M {json}",
8231 SHOW_STR
8232 IP_STR
8233 BGP_STR
8234 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8235 "JavaScript Object Notation\n")
8236 {
8237 bgp_show_ipv6_bgp_deprecate_warning(vty);
8238 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8239 }
8240
8241 DEFUN (show_bgp_view,
8242 show_bgp_instance_cmd,
8243 "show bgp " BGP_INSTANCE_CMD " {json}",
8244 SHOW_STR
8245 BGP_STR
8246 BGP_INSTANCE_HELP_STR
8247 "JavaScript Object Notation\n")
8248 {
8249 struct bgp *bgp;
8250
8251 /* BGP structure lookup. */
8252 bgp = bgp_lookup_by_name (argv[1]);
8253 if (bgp == NULL)
8254 {
8255 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8256 return CMD_WARNING;
8257 }
8258
8259 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8260 }
8261
8262 ALIAS (show_bgp_view,
8263 show_bgp_instance_ipv6_cmd,
8264 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
8265 SHOW_STR
8266 BGP_STR
8267 BGP_INSTANCE_HELP_STR
8268 "Address family\n"
8269 "JavaScript Object Notation\n")
8270
8271 DEFUN (show_bgp_instance_route,
8272 show_bgp_instance_route_cmd,
8273 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
8274 SHOW_STR
8275 BGP_STR
8276 BGP_INSTANCE_HELP_STR
8277 "Network in the BGP routing table to display\n"
8278 "JavaScript Object Notation\n")
8279 {
8280 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8281 }
8282
8283 ALIAS (show_bgp_instance_route,
8284 show_bgp_instance_ipv6_route_cmd,
8285 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
8286 SHOW_STR
8287 BGP_STR
8288 BGP_INSTANCE_HELP_STR
8289 "Address family\n"
8290 "Network in the BGP routing table to display\n"
8291 "JavaScript Object Notation\n")
8292
8293 DEFUN (show_bgp_instance_route_pathtype,
8294 show_bgp_instance_route_pathtype_cmd,
8295 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
8296 SHOW_STR
8297 BGP_STR
8298 BGP_INSTANCE_HELP_STR
8299 "Network in the BGP routing table to display\n"
8300 "Display only the bestpath\n"
8301 "Display only multipaths\n"
8302 "JavaScript Object Notation\n")
8303 {
8304 u_char uj = use_json(argc, argv);
8305 if (strncmp (argv[3], "b", 1) == 0)
8306 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8307 else
8308 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8309 }
8310
8311 ALIAS (show_bgp_instance_route_pathtype,
8312 show_bgp_instance_ipv6_route_pathtype_cmd,
8313 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
8314 SHOW_STR
8315 BGP_STR
8316 BGP_INSTANCE_HELP_STR
8317 "Address family\n"
8318 "Network in the BGP routing table to display\n"
8319 "Display only the bestpath\n"
8320 "Display only multipaths\n"
8321 "JavaScript Object Notation\n")
8322
8323 DEFUN (show_bgp_instance_prefix,
8324 show_bgp_instance_prefix_cmd,
8325 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
8326 SHOW_STR
8327 BGP_STR
8328 BGP_INSTANCE_HELP_STR
8329 "IPv6 prefix <network>/<length>\n"
8330 "JavaScript Object Notation\n")
8331 {
8332 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8333 }
8334
8335 ALIAS (show_bgp_instance_prefix,
8336 show_bgp_instance_ipv6_prefix_cmd,
8337 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
8338 SHOW_STR
8339 BGP_STR
8340 BGP_INSTANCE_HELP_STR
8341 "Address family\n"
8342 "IPv6 prefix <network>/<length>\n"
8343 "JavaScript Object Notation\n")
8344
8345 DEFUN (show_bgp_instance_prefix_pathtype,
8346 show_bgp_instance_prefix_pathtype_cmd,
8347 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
8348 SHOW_STR
8349 BGP_STR
8350 BGP_INSTANCE_HELP_STR
8351 "IPv6 prefix <network>/<length>\n"
8352 "Display only the bestpath\n"
8353 "Display only multipaths\n"
8354 "JavaScript Object Notation\n")
8355 {
8356 u_char uj = use_json(argc, argv);
8357 if (strncmp (argv[3], "b", 1) == 0)
8358 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8359 else
8360 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8361 }
8362
8363 ALIAS (show_bgp_instance_prefix_pathtype,
8364 show_bgp_instance_ipv6_prefix_pathtype_cmd,
8365 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8366 SHOW_STR
8367 BGP_STR
8368 BGP_INSTANCE_HELP_STR
8369 "Address family\n"
8370 "IPv6 prefix <network>/<length>\n"
8371 "Display only the bestpath\n"
8372 "Display only multipaths\n"
8373 "JavaScript Object Notation\n")
8374
8375 DEFUN (show_bgp_instance_prefix_list,
8376 show_bgp_instance_prefix_list_cmd,
8377 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
8378 SHOW_STR
8379 BGP_STR
8380 BGP_INSTANCE_HELP_STR
8381 "Display routes conforming to the prefix-list\n"
8382 "IPv6 prefix-list name\n")
8383 {
8384 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8385 bgp_show_type_prefix_list);
8386 }
8387
8388 ALIAS (show_bgp_instance_prefix_list,
8389 show_bgp_instance_ipv6_prefix_list_cmd,
8390 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
8391 SHOW_STR
8392 BGP_STR
8393 BGP_INSTANCE_HELP_STR
8394 "Address family\n"
8395 "Display routes conforming to the prefix-list\n"
8396 "IPv6 prefix-list name\n")
8397
8398 DEFUN (show_bgp_instance_filter_list,
8399 show_bgp_instance_filter_list_cmd,
8400 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
8401 SHOW_STR
8402 BGP_STR
8403 BGP_INSTANCE_HELP_STR
8404 "Display routes conforming to the filter-list\n"
8405 "Regular expression access list name\n")
8406 {
8407 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8408 bgp_show_type_filter_list);
8409 }
8410
8411 ALIAS (show_bgp_instance_filter_list,
8412 show_bgp_instance_ipv6_filter_list_cmd,
8413 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
8414 SHOW_STR
8415 BGP_STR
8416 BGP_INSTANCE_HELP_STR
8417 "Address family\n"
8418 "Display routes conforming to the filter-list\n"
8419 "Regular expression access list name\n")
8420
8421 DEFUN (show_bgp_instance_route_map,
8422 show_bgp_instance_route_map_cmd,
8423 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
8424 SHOW_STR
8425 BGP_STR
8426 BGP_INSTANCE_HELP_STR
8427 "Display routes matching the route-map\n"
8428 "A route-map to match on\n")
8429 {
8430 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8431 bgp_show_type_route_map);
8432 }
8433
8434 ALIAS (show_bgp_instance_route_map,
8435 show_bgp_instance_ipv6_route_map_cmd,
8436 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
8437 SHOW_STR
8438 BGP_STR
8439 BGP_INSTANCE_HELP_STR
8440 "Address family\n"
8441 "Display routes matching the route-map\n"
8442 "A route-map to match on\n")
8443
8444 DEFUN (show_bgp_instance_community_list,
8445 show_bgp_instance_community_list_cmd,
8446 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
8447 SHOW_STR
8448 BGP_STR
8449 BGP_INSTANCE_HELP_STR
8450 "Display routes matching the community-list\n"
8451 "community-list number\n"
8452 "community-list name\n")
8453 {
8454 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
8455 }
8456
8457 ALIAS (show_bgp_instance_community_list,
8458 show_bgp_instance_ipv6_community_list_cmd,
8459 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
8460 SHOW_STR
8461 BGP_STR
8462 BGP_INSTANCE_HELP_STR
8463 "Address family\n"
8464 "Display routes matching the community-list\n"
8465 "community-list number\n"
8466 "community-list name\n")
8467
8468 DEFUN (show_bgp_instance_prefix_longer,
8469 show_bgp_instance_prefix_longer_cmd,
8470 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
8471 SHOW_STR
8472 BGP_STR
8473 BGP_INSTANCE_HELP_STR
8474 "IPv6 prefix <network>/<length>\n"
8475 "Display route and more specific routes\n")
8476 {
8477 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
8478 bgp_show_type_prefix_longer);
8479 }
8480
8481 ALIAS (show_bgp_instance_prefix_longer,
8482 show_bgp_instance_ipv6_prefix_longer_cmd,
8483 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
8484 SHOW_STR
8485 BGP_STR
8486 BGP_INSTANCE_HELP_STR
8487 "Address family\n"
8488 "IPv6 prefix <network>/<length>\n"
8489 "Display route and more specific routes\n")
8490
8491 /* old command */
8492 DEFUN (show_ipv6_mbgp,
8493 show_ipv6_mbgp_cmd,
8494 "show ipv6 mbgp {json}",
8495 SHOW_STR
8496 IP_STR
8497 MBGP_STR
8498 "JavaScript Object Notation\n")
8499 {
8500 bgp_show_ipv6_bgp_deprecate_warning(vty);
8501 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8502 NULL, use_json(argc, argv));
8503 }
8504
8505 /* old command */
8506 DEFUN (show_ipv6_mbgp_route,
8507 show_ipv6_mbgp_route_cmd,
8508 "show ipv6 mbgp X:X::X:X {json}",
8509 SHOW_STR
8510 IP_STR
8511 MBGP_STR
8512 "Network in the MBGP routing table to display\n"
8513 "JavaScript Object Notation\n")
8514 {
8515 bgp_show_ipv6_bgp_deprecate_warning(vty);
8516 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8517 }
8518
8519 /* old command */
8520 DEFUN (show_ipv6_mbgp_prefix,
8521 show_ipv6_mbgp_prefix_cmd,
8522 "show ipv6 mbgp X:X::X:X/M {json}",
8523 SHOW_STR
8524 IP_STR
8525 MBGP_STR
8526 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8527 "JavaScript Object Notation\n")
8528 {
8529 bgp_show_ipv6_bgp_deprecate_warning(vty);
8530 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8531 }
8532 #endif
8533
8534
8535 static int
8536 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
8537 safi_t safi, enum bgp_show_type type)
8538 {
8539 int i;
8540 struct buffer *b;
8541 char *regstr;
8542 int first;
8543 regex_t *regex;
8544 int rc;
8545
8546 first = 0;
8547 b = buffer_new (1024);
8548 for (i = 0; i < argc; i++)
8549 {
8550 if (first)
8551 buffer_putc (b, ' ');
8552 else
8553 {
8554 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8555 continue;
8556 first = 1;
8557 }
8558
8559 buffer_putstr (b, argv[i]);
8560 }
8561 buffer_putc (b, '\0');
8562
8563 regstr = buffer_getstr (b);
8564 buffer_free (b);
8565
8566 regex = bgp_regcomp (regstr);
8567 XFREE(MTYPE_TMP, regstr);
8568 if (! regex)
8569 {
8570 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8571 VTY_NEWLINE);
8572 return CMD_WARNING;
8573 }
8574
8575 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
8576 bgp_regex_free (regex);
8577 return rc;
8578 }
8579
8580 DEFUN (show_ip_bgp_regexp,
8581 show_ip_bgp_regexp_cmd,
8582 "show ip bgp regexp .LINE",
8583 SHOW_STR
8584 IP_STR
8585 BGP_STR
8586 "Display routes matching the AS path regular expression\n"
8587 "A regular-expression to match the BGP AS paths\n")
8588 {
8589 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8590 bgp_show_type_regexp);
8591 }
8592
8593 DEFUN (show_ip_bgp_flap_regexp,
8594 show_ip_bgp_flap_regexp_cmd,
8595 "show ip bgp flap-statistics regexp .LINE",
8596 SHOW_STR
8597 IP_STR
8598 BGP_STR
8599 "Display flap statistics of routes\n"
8600 "Display routes matching the AS path regular expression\n"
8601 "A regular-expression to match the BGP AS paths\n")
8602 {
8603 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8604 bgp_show_type_flap_regexp);
8605 }
8606
8607 DEFUN (show_ip_bgp_ipv4_regexp,
8608 show_ip_bgp_ipv4_regexp_cmd,
8609 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8610 SHOW_STR
8611 IP_STR
8612 BGP_STR
8613 "Address family\n"
8614 "Address Family modifier\n"
8615 "Address Family modifier\n"
8616 "Display routes matching the AS path regular expression\n"
8617 "A regular-expression to match the BGP AS paths\n")
8618 {
8619 if (strncmp (argv[0], "m", 1) == 0)
8620 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8621 bgp_show_type_regexp);
8622
8623 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8624 bgp_show_type_regexp);
8625 }
8626
8627 #ifdef HAVE_IPV6
8628 DEFUN (show_bgp_regexp,
8629 show_bgp_regexp_cmd,
8630 "show bgp regexp .LINE",
8631 SHOW_STR
8632 BGP_STR
8633 "Display routes matching the AS path regular expression\n"
8634 "A regular-expression to match the BGP AS paths\n")
8635 {
8636 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8637 bgp_show_type_regexp);
8638 }
8639
8640 ALIAS (show_bgp_regexp,
8641 show_bgp_ipv6_regexp_cmd,
8642 "show bgp ipv6 regexp .LINE",
8643 SHOW_STR
8644 BGP_STR
8645 "Address family\n"
8646 "Display routes matching the AS path regular expression\n"
8647 "A regular-expression to match the BGP AS paths\n")
8648
8649 /* old command */
8650 DEFUN (show_ipv6_bgp_regexp,
8651 show_ipv6_bgp_regexp_cmd,
8652 "show ipv6 bgp regexp .LINE",
8653 SHOW_STR
8654 IP_STR
8655 BGP_STR
8656 "Display routes matching the AS path regular expression\n"
8657 "A regular-expression to match the BGP AS paths\n")
8658 {
8659 bgp_show_ipv6_bgp_deprecate_warning(vty);
8660 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8661 bgp_show_type_regexp);
8662 }
8663
8664 /* old command */
8665 DEFUN (show_ipv6_mbgp_regexp,
8666 show_ipv6_mbgp_regexp_cmd,
8667 "show ipv6 mbgp regexp .LINE",
8668 SHOW_STR
8669 IP_STR
8670 BGP_STR
8671 "Display routes matching the AS path regular expression\n"
8672 "A regular-expression to match the MBGP AS paths\n")
8673 {
8674 bgp_show_ipv6_bgp_deprecate_warning(vty);
8675 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8676 bgp_show_type_regexp);
8677 }
8678 #endif /* HAVE_IPV6 */
8679
8680 static int
8681 bgp_show_prefix_list (struct vty *vty, const char *name,
8682 const char *prefix_list_str, afi_t afi,
8683 safi_t safi, enum bgp_show_type type)
8684 {
8685 struct prefix_list *plist;
8686 struct bgp *bgp = NULL;
8687
8688 if (name && !(bgp = bgp_lookup_by_name(name)))
8689 {
8690 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
8691 return CMD_WARNING;
8692 }
8693
8694 plist = prefix_list_lookup (afi, prefix_list_str);
8695 if (plist == NULL)
8696 {
8697 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8698 prefix_list_str, VTY_NEWLINE);
8699 return CMD_WARNING;
8700 }
8701
8702 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
8703 }
8704
8705 DEFUN (show_ip_bgp_prefix_list,
8706 show_ip_bgp_prefix_list_cmd,
8707 "show ip bgp prefix-list WORD",
8708 SHOW_STR
8709 IP_STR
8710 BGP_STR
8711 "Display routes conforming to the prefix-list\n"
8712 "IP prefix-list name\n")
8713 {
8714 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
8715 bgp_show_type_prefix_list);
8716 }
8717
8718 DEFUN (show_ip_bgp_instance_prefix_list,
8719 show_ip_bgp_instance_prefix_list_cmd,
8720 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
8721 SHOW_STR
8722 IP_STR
8723 BGP_STR
8724 BGP_INSTANCE_HELP_STR
8725 "Display routes conforming to the prefix-list\n"
8726 "IP prefix-list name\n")
8727 {
8728 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
8729 bgp_show_type_prefix_list);
8730 }
8731
8732 DEFUN (show_ip_bgp_flap_prefix_list,
8733 show_ip_bgp_flap_prefix_list_cmd,
8734 "show ip bgp flap-statistics prefix-list WORD",
8735 SHOW_STR
8736 IP_STR
8737 BGP_STR
8738 "Display flap statistics of routes\n"
8739 "Display routes conforming to the prefix-list\n"
8740 "IP prefix-list name\n")
8741 {
8742 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
8743 bgp_show_type_flap_prefix_list);
8744 }
8745
8746 DEFUN (show_ip_bgp_ipv4_prefix_list,
8747 show_ip_bgp_ipv4_prefix_list_cmd,
8748 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8749 SHOW_STR
8750 IP_STR
8751 BGP_STR
8752 "Address family\n"
8753 "Address Family modifier\n"
8754 "Address Family modifier\n"
8755 "Display routes conforming to the prefix-list\n"
8756 "IP prefix-list name\n")
8757 {
8758 if (strncmp (argv[0], "m", 1) == 0)
8759 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
8760 bgp_show_type_prefix_list);
8761
8762 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
8763 bgp_show_type_prefix_list);
8764 }
8765
8766 #ifdef HAVE_IPV6
8767 DEFUN (show_bgp_prefix_list,
8768 show_bgp_prefix_list_cmd,
8769 "show bgp prefix-list WORD",
8770 SHOW_STR
8771 BGP_STR
8772 "Display routes conforming to the prefix-list\n"
8773 "IPv6 prefix-list name\n")
8774 {
8775 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
8776 bgp_show_type_prefix_list);
8777 }
8778
8779 ALIAS (show_bgp_prefix_list,
8780 show_bgp_ipv6_prefix_list_cmd,
8781 "show bgp ipv6 prefix-list WORD",
8782 SHOW_STR
8783 BGP_STR
8784 "Address family\n"
8785 "Display routes conforming to the prefix-list\n"
8786 "IPv6 prefix-list name\n")
8787
8788 /* old command */
8789 DEFUN (show_ipv6_bgp_prefix_list,
8790 show_ipv6_bgp_prefix_list_cmd,
8791 "show ipv6 bgp prefix-list WORD",
8792 SHOW_STR
8793 IPV6_STR
8794 BGP_STR
8795 "Display routes matching the prefix-list\n"
8796 "IPv6 prefix-list name\n")
8797 {
8798 bgp_show_ipv6_bgp_deprecate_warning(vty);
8799 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
8800 bgp_show_type_prefix_list);
8801 }
8802
8803 /* old command */
8804 DEFUN (show_ipv6_mbgp_prefix_list,
8805 show_ipv6_mbgp_prefix_list_cmd,
8806 "show ipv6 mbgp prefix-list WORD",
8807 SHOW_STR
8808 IPV6_STR
8809 MBGP_STR
8810 "Display routes matching the prefix-list\n"
8811 "IPv6 prefix-list name\n")
8812 {
8813 bgp_show_ipv6_bgp_deprecate_warning(vty);
8814 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
8815 bgp_show_type_prefix_list);
8816 }
8817 #endif /* HAVE_IPV6 */
8818
8819 static int
8820 bgp_show_filter_list (struct vty *vty, const char *name,
8821 const char *filter, afi_t afi,
8822 safi_t safi, enum bgp_show_type type)
8823 {
8824 struct as_list *as_list;
8825 struct bgp *bgp = NULL;
8826
8827 if (name && !(bgp = bgp_lookup_by_name(name)))
8828 {
8829 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
8830 return CMD_WARNING;
8831 }
8832
8833 as_list = as_list_lookup (filter);
8834 if (as_list == NULL)
8835 {
8836 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8837 return CMD_WARNING;
8838 }
8839
8840 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
8841 }
8842
8843 DEFUN (show_ip_bgp_filter_list,
8844 show_ip_bgp_filter_list_cmd,
8845 "show ip bgp filter-list WORD",
8846 SHOW_STR
8847 IP_STR
8848 BGP_STR
8849 "Display routes conforming to the filter-list\n"
8850 "Regular expression access list name\n")
8851 {
8852 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
8853 bgp_show_type_filter_list);
8854 }
8855
8856 DEFUN (show_ip_bgp_instance_filter_list,
8857 show_ip_bgp_instance_filter_list_cmd,
8858 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
8859 SHOW_STR
8860 IP_STR
8861 BGP_STR
8862 BGP_INSTANCE_HELP_STR
8863 "Display routes conforming to the filter-list\n"
8864 "Regular expression access list name\n")
8865 {
8866 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
8867 bgp_show_type_filter_list);
8868 }
8869
8870 DEFUN (show_ip_bgp_flap_filter_list,
8871 show_ip_bgp_flap_filter_list_cmd,
8872 "show ip bgp flap-statistics filter-list WORD",
8873 SHOW_STR
8874 IP_STR
8875 BGP_STR
8876 "Display flap statistics of routes\n"
8877 "Display routes conforming to the filter-list\n"
8878 "Regular expression access list name\n")
8879 {
8880 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
8881 bgp_show_type_flap_filter_list);
8882 }
8883
8884 DEFUN (show_ip_bgp_ipv4_filter_list,
8885 show_ip_bgp_ipv4_filter_list_cmd,
8886 "show ip bgp ipv4 (unicast|multicast) filter-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 filter-list\n"
8894 "Regular expression access list name\n")
8895 {
8896 if (strncmp (argv[0], "m", 1) == 0)
8897 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
8898 bgp_show_type_filter_list);
8899
8900 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
8901 bgp_show_type_filter_list);
8902 }
8903
8904 #ifdef HAVE_IPV6
8905 DEFUN (show_bgp_filter_list,
8906 show_bgp_filter_list_cmd,
8907 "show bgp filter-list WORD",
8908 SHOW_STR
8909 BGP_STR
8910 "Display routes conforming to the filter-list\n"
8911 "Regular expression access list name\n")
8912 {
8913 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
8914 bgp_show_type_filter_list);
8915 }
8916
8917 ALIAS (show_bgp_filter_list,
8918 show_bgp_ipv6_filter_list_cmd,
8919 "show bgp ipv6 filter-list WORD",
8920 SHOW_STR
8921 BGP_STR
8922 "Address family\n"
8923 "Display routes conforming to the filter-list\n"
8924 "Regular expression access list name\n")
8925
8926 /* old command */
8927 DEFUN (show_ipv6_bgp_filter_list,
8928 show_ipv6_bgp_filter_list_cmd,
8929 "show ipv6 bgp filter-list WORD",
8930 SHOW_STR
8931 IPV6_STR
8932 BGP_STR
8933 "Display routes conforming to the filter-list\n"
8934 "Regular expression access list name\n")
8935 {
8936 bgp_show_ipv6_bgp_deprecate_warning(vty);
8937 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
8938 bgp_show_type_filter_list);
8939 }
8940
8941 /* old command */
8942 DEFUN (show_ipv6_mbgp_filter_list,
8943 show_ipv6_mbgp_filter_list_cmd,
8944 "show ipv6 mbgp filter-list WORD",
8945 SHOW_STR
8946 IPV6_STR
8947 MBGP_STR
8948 "Display routes conforming to the filter-list\n"
8949 "Regular expression access list name\n")
8950 {
8951 bgp_show_ipv6_bgp_deprecate_warning(vty);
8952 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
8953 bgp_show_type_filter_list);
8954 }
8955 #endif /* HAVE_IPV6 */
8956
8957 static int
8958 bgp_show_route_map (struct vty *vty, const char *name,
8959 const char *rmap_str, afi_t afi,
8960 safi_t safi, enum bgp_show_type type)
8961 {
8962 struct route_map *rmap;
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 rmap = route_map_lookup_by_name (rmap_str);
8972 if (! rmap)
8973 {
8974 vty_out (vty, "%% %s is not a valid route-map name%s",
8975 rmap_str, VTY_NEWLINE);
8976 return CMD_WARNING;
8977 }
8978
8979 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
8980 }
8981
8982 DEFUN (show_ip_bgp_route_map,
8983 show_ip_bgp_route_map_cmd,
8984 "show ip bgp route-map WORD",
8985 SHOW_STR
8986 IP_STR
8987 BGP_STR
8988 "Display routes matching the route-map\n"
8989 "A route-map to match on\n")
8990 {
8991 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
8992 bgp_show_type_route_map);
8993 }
8994
8995 DEFUN (show_ip_bgp_instance_route_map,
8996 show_ip_bgp_instance_route_map_cmd,
8997 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
8998 SHOW_STR
8999 IP_STR
9000 BGP_STR
9001 BGP_INSTANCE_HELP_STR
9002 "Display routes matching the route-map\n"
9003 "A route-map to match on\n")
9004 {
9005 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9006 bgp_show_type_route_map);
9007 }
9008
9009 DEFUN (show_ip_bgp_flap_route_map,
9010 show_ip_bgp_flap_route_map_cmd,
9011 "show ip bgp flap-statistics route-map WORD",
9012 SHOW_STR
9013 IP_STR
9014 BGP_STR
9015 "Display flap statistics of routes\n"
9016 "Display routes matching the route-map\n"
9017 "A route-map to match on\n")
9018 {
9019 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9020 bgp_show_type_flap_route_map);
9021 }
9022
9023 DEFUN (show_ip_bgp_ipv4_route_map,
9024 show_ip_bgp_ipv4_route_map_cmd,
9025 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9026 SHOW_STR
9027 IP_STR
9028 BGP_STR
9029 "Address family\n"
9030 "Address Family modifier\n"
9031 "Address Family modifier\n"
9032 "Display routes matching the route-map\n"
9033 "A route-map to match on\n")
9034 {
9035 if (strncmp (argv[0], "m", 1) == 0)
9036 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9037 bgp_show_type_route_map);
9038
9039 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9040 bgp_show_type_route_map);
9041 }
9042
9043 DEFUN (show_bgp_route_map,
9044 show_bgp_route_map_cmd,
9045 "show bgp route-map WORD",
9046 SHOW_STR
9047 BGP_STR
9048 "Display routes matching the route-map\n"
9049 "A route-map to match on\n")
9050 {
9051 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9052 bgp_show_type_route_map);
9053 }
9054
9055 ALIAS (show_bgp_route_map,
9056 show_bgp_ipv6_route_map_cmd,
9057 "show bgp ipv6 route-map WORD",
9058 SHOW_STR
9059 BGP_STR
9060 "Address family\n"
9061 "Display routes matching the route-map\n"
9062 "A route-map to match on\n")
9063
9064 DEFUN (show_ip_bgp_cidr_only,
9065 show_ip_bgp_cidr_only_cmd,
9066 "show ip bgp cidr-only",
9067 SHOW_STR
9068 IP_STR
9069 BGP_STR
9070 "Display only routes with non-natural netmasks\n")
9071 {
9072 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9073 bgp_show_type_cidr_only, NULL, 0);
9074 }
9075
9076 DEFUN (show_ip_bgp_flap_cidr_only,
9077 show_ip_bgp_flap_cidr_only_cmd,
9078 "show ip bgp flap-statistics cidr-only",
9079 SHOW_STR
9080 IP_STR
9081 BGP_STR
9082 "Display flap statistics of routes\n"
9083 "Display only routes with non-natural netmasks\n")
9084 {
9085 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9086 bgp_show_type_flap_cidr_only, NULL, 0);
9087 }
9088
9089 DEFUN (show_ip_bgp_ipv4_cidr_only,
9090 show_ip_bgp_ipv4_cidr_only_cmd,
9091 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9092 SHOW_STR
9093 IP_STR
9094 BGP_STR
9095 "Address family\n"
9096 "Address Family modifier\n"
9097 "Address Family modifier\n"
9098 "Display only routes with non-natural netmasks\n")
9099 {
9100 if (strncmp (argv[0], "m", 1) == 0)
9101 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9102 bgp_show_type_cidr_only, NULL, 0);
9103
9104 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9105 bgp_show_type_cidr_only, NULL, 0);
9106 }
9107
9108 DEFUN (show_ip_bgp_community_all,
9109 show_ip_bgp_community_all_cmd,
9110 "show ip bgp community",
9111 SHOW_STR
9112 IP_STR
9113 BGP_STR
9114 "Display routes matching the communities\n")
9115 {
9116 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9117 bgp_show_type_community_all, NULL, 0);
9118 }
9119
9120 DEFUN (show_ip_bgp_ipv4_community_all,
9121 show_ip_bgp_ipv4_community_all_cmd,
9122 "show ip bgp ipv4 (unicast|multicast) community",
9123 SHOW_STR
9124 IP_STR
9125 BGP_STR
9126 "Address family\n"
9127 "Address Family modifier\n"
9128 "Address Family modifier\n"
9129 "Display routes matching the communities\n")
9130 {
9131 if (strncmp (argv[0], "m", 1) == 0)
9132 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9133 bgp_show_type_community_all, NULL, 0);
9134
9135 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9136 bgp_show_type_community_all, NULL, 0);
9137 }
9138
9139 #ifdef HAVE_IPV6
9140 DEFUN (show_bgp_community_all,
9141 show_bgp_community_all_cmd,
9142 "show bgp community",
9143 SHOW_STR
9144 BGP_STR
9145 "Display routes matching the communities\n")
9146 {
9147 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9148 bgp_show_type_community_all, NULL, 0);
9149 }
9150
9151 ALIAS (show_bgp_community_all,
9152 show_bgp_ipv6_community_all_cmd,
9153 "show bgp ipv6 community",
9154 SHOW_STR
9155 BGP_STR
9156 "Address family\n"
9157 "Display routes matching the communities\n")
9158
9159 /* old command */
9160 DEFUN (show_ipv6_bgp_community_all,
9161 show_ipv6_bgp_community_all_cmd,
9162 "show ipv6 bgp community",
9163 SHOW_STR
9164 IPV6_STR
9165 BGP_STR
9166 "Display routes matching the communities\n")
9167 {
9168 bgp_show_ipv6_bgp_deprecate_warning(vty);
9169 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9170 bgp_show_type_community_all, NULL, 0);
9171 }
9172
9173 /* old command */
9174 DEFUN (show_ipv6_mbgp_community_all,
9175 show_ipv6_mbgp_community_all_cmd,
9176 "show ipv6 mbgp community",
9177 SHOW_STR
9178 IPV6_STR
9179 MBGP_STR
9180 "Display routes matching the communities\n")
9181 {
9182 bgp_show_ipv6_bgp_deprecate_warning(vty);
9183 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9184 bgp_show_type_community_all, NULL, 0);
9185 }
9186 #endif /* HAVE_IPV6 */
9187
9188 static int
9189 bgp_show_community (struct vty *vty, const char *view_name, int argc,
9190 const char **argv, int exact, afi_t afi, safi_t safi)
9191 {
9192 struct community *com;
9193 struct buffer *b;
9194 struct bgp *bgp;
9195 int i;
9196 char *str;
9197 int first = 0;
9198
9199 /* BGP structure lookup */
9200 if (view_name)
9201 {
9202 bgp = bgp_lookup_by_name (view_name);
9203 if (bgp == NULL)
9204 {
9205 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
9206 return CMD_WARNING;
9207 }
9208 }
9209 else
9210 {
9211 bgp = bgp_get_default ();
9212 if (bgp == NULL)
9213 {
9214 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9215 return CMD_WARNING;
9216 }
9217 }
9218
9219 b = buffer_new (1024);
9220 for (i = 0; i < argc; i++)
9221 {
9222 if (first)
9223 buffer_putc (b, ' ');
9224 else
9225 {
9226 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9227 continue;
9228 first = 1;
9229 }
9230
9231 buffer_putstr (b, argv[i]);
9232 }
9233 buffer_putc (b, '\0');
9234
9235 str = buffer_getstr (b);
9236 buffer_free (b);
9237
9238 com = community_str2com (str);
9239 XFREE (MTYPE_TMP, str);
9240 if (! com)
9241 {
9242 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9243 return CMD_WARNING;
9244 }
9245
9246 return bgp_show (vty, bgp, afi, safi,
9247 (exact ? bgp_show_type_community_exact :
9248 bgp_show_type_community), com, 0);
9249 }
9250
9251 DEFUN (show_ip_bgp_community,
9252 show_ip_bgp_community_cmd,
9253 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9254 SHOW_STR
9255 IP_STR
9256 BGP_STR
9257 "Display routes matching the communities\n"
9258 "community number\n"
9259 "Do not send outside local AS (well-known community)\n"
9260 "Do not advertise to any peer (well-known community)\n"
9261 "Do not export to next AS (well-known community)\n")
9262 {
9263 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9264 }
9265
9266 ALIAS (show_ip_bgp_community,
9267 show_ip_bgp_community2_cmd,
9268 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9269 SHOW_STR
9270 IP_STR
9271 BGP_STR
9272 "Display routes matching the communities\n"
9273 "community number\n"
9274 "Do not send outside local AS (well-known community)\n"
9275 "Do not advertise to any peer (well-known community)\n"
9276 "Do not export to next AS (well-known community)\n"
9277 "community number\n"
9278 "Do not send outside local AS (well-known community)\n"
9279 "Do not advertise to any peer (well-known community)\n"
9280 "Do not export to next AS (well-known community)\n")
9281
9282 ALIAS (show_ip_bgp_community,
9283 show_ip_bgp_community3_cmd,
9284 "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)",
9285 SHOW_STR
9286 IP_STR
9287 BGP_STR
9288 "Display routes matching the communities\n"
9289 "community number\n"
9290 "Do not send outside local AS (well-known community)\n"
9291 "Do not advertise to any peer (well-known community)\n"
9292 "Do not export to next AS (well-known community)\n"
9293 "community number\n"
9294 "Do not send outside local AS (well-known community)\n"
9295 "Do not advertise to any peer (well-known community)\n"
9296 "Do not export to next AS (well-known community)\n"
9297 "community number\n"
9298 "Do not send outside local AS (well-known community)\n"
9299 "Do not advertise to any peer (well-known community)\n"
9300 "Do not export to next AS (well-known community)\n")
9301
9302 ALIAS (show_ip_bgp_community,
9303 show_ip_bgp_community4_cmd,
9304 "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)",
9305 SHOW_STR
9306 IP_STR
9307 BGP_STR
9308 "Display routes matching the communities\n"
9309 "community number\n"
9310 "Do not send outside local AS (well-known community)\n"
9311 "Do not advertise to any peer (well-known community)\n"
9312 "Do not export to next AS (well-known community)\n"
9313 "community number\n"
9314 "Do not send outside local AS (well-known community)\n"
9315 "Do not advertise to any peer (well-known community)\n"
9316 "Do not export to next AS (well-known community)\n"
9317 "community number\n"
9318 "Do not send outside local AS (well-known community)\n"
9319 "Do not advertise to any peer (well-known community)\n"
9320 "Do not export to next AS (well-known community)\n"
9321 "community number\n"
9322 "Do not send outside local AS (well-known community)\n"
9323 "Do not advertise to any peer (well-known community)\n"
9324 "Do not export to next AS (well-known community)\n")
9325
9326 DEFUN (show_ip_bgp_ipv4_community,
9327 show_ip_bgp_ipv4_community_cmd,
9328 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9329 SHOW_STR
9330 IP_STR
9331 BGP_STR
9332 "Address family\n"
9333 "Address Family modifier\n"
9334 "Address Family modifier\n"
9335 "Display routes matching the communities\n"
9336 "community number\n"
9337 "Do not send outside local AS (well-known community)\n"
9338 "Do not advertise to any peer (well-known community)\n"
9339 "Do not export to next AS (well-known community)\n")
9340 {
9341 if (strncmp (argv[0], "m", 1) == 0)
9342 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9343
9344 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9345 }
9346
9347 ALIAS (show_ip_bgp_ipv4_community,
9348 show_ip_bgp_ipv4_community2_cmd,
9349 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9350 SHOW_STR
9351 IP_STR
9352 BGP_STR
9353 "Address family\n"
9354 "Address Family modifier\n"
9355 "Address Family modifier\n"
9356 "Display routes matching the communities\n"
9357 "community number\n"
9358 "Do not send outside local AS (well-known community)\n"
9359 "Do not advertise to any peer (well-known community)\n"
9360 "Do not export to next AS (well-known community)\n"
9361 "community number\n"
9362 "Do not send outside local AS (well-known community)\n"
9363 "Do not advertise to any peer (well-known community)\n"
9364 "Do not export to next AS (well-known community)\n")
9365
9366 ALIAS (show_ip_bgp_ipv4_community,
9367 show_ip_bgp_ipv4_community3_cmd,
9368 "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)",
9369 SHOW_STR
9370 IP_STR
9371 BGP_STR
9372 "Address family\n"
9373 "Address Family modifier\n"
9374 "Address Family modifier\n"
9375 "Display routes matching the communities\n"
9376 "community number\n"
9377 "Do not send outside local AS (well-known community)\n"
9378 "Do not advertise to any peer (well-known community)\n"
9379 "Do not export to next AS (well-known community)\n"
9380 "community number\n"
9381 "Do not send outside local AS (well-known community)\n"
9382 "Do not advertise to any peer (well-known community)\n"
9383 "Do not export to next AS (well-known community)\n"
9384 "community number\n"
9385 "Do not send outside local AS (well-known community)\n"
9386 "Do not advertise to any peer (well-known community)\n"
9387 "Do not export to next AS (well-known community)\n")
9388
9389 ALIAS (show_ip_bgp_ipv4_community,
9390 show_ip_bgp_ipv4_community4_cmd,
9391 "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)",
9392 SHOW_STR
9393 IP_STR
9394 BGP_STR
9395 "Address family\n"
9396 "Address Family modifier\n"
9397 "Address Family modifier\n"
9398 "Display routes matching the communities\n"
9399 "community number\n"
9400 "Do not send outside local AS (well-known community)\n"
9401 "Do not advertise to any peer (well-known community)\n"
9402 "Do not export to next AS (well-known community)\n"
9403 "community number\n"
9404 "Do not send outside local AS (well-known community)\n"
9405 "Do not advertise to any peer (well-known community)\n"
9406 "Do not export to next AS (well-known community)\n"
9407 "community number\n"
9408 "Do not send outside local AS (well-known community)\n"
9409 "Do not advertise to any peer (well-known community)\n"
9410 "Do not export to next AS (well-known community)\n"
9411 "community number\n"
9412 "Do not send outside local AS (well-known community)\n"
9413 "Do not advertise to any peer (well-known community)\n"
9414 "Do not export to next AS (well-known community)\n")
9415
9416 DEFUN (show_bgp_instance_afi_safi_community_all,
9417 show_bgp_instance_afi_safi_community_all_cmd,
9418 #ifdef HAVE_IPV6
9419 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
9420 #else
9421 "show bgp " BGP_INSTANCE_CMD " ipv4 (unicast|multicast) community",
9422 #endif
9423 SHOW_STR
9424 BGP_STR
9425 BGP_INSTANCE_HELP_STR
9426 "Address family\n"
9427 #ifdef HAVE_IPV6
9428 "Address family\n"
9429 #endif
9430 "Address Family modifier\n"
9431 "Address Family modifier\n"
9432 "Display routes matching the communities\n")
9433 {
9434 int afi;
9435 int safi;
9436 struct bgp *bgp;
9437
9438 /* BGP structure lookup. */
9439 bgp = bgp_lookup_by_name (argv[1]);
9440 if (bgp == NULL)
9441 {
9442 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
9443 return CMD_WARNING;
9444 }
9445
9446 #ifdef HAVE_IPV6
9447 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9448 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9449 #else
9450 afi = AFI_IP;
9451 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9452 #endif
9453 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
9454 }
9455
9456 DEFUN (show_bgp_instance_afi_safi_community,
9457 show_bgp_instance_afi_safi_community_cmd,
9458 #ifdef HAVE_IPV6
9459 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9460 #else
9461 "show bgp " BGP_INSTANCE_CMD " ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9462 #endif
9463 SHOW_STR
9464 BGP_STR
9465 BGP_INSTANCE_HELP_STR
9466 "Address family\n"
9467 #ifdef HAVE_IPV6
9468 "Address family\n"
9469 #endif
9470 "Address family modifier\n"
9471 "Address family modifier\n"
9472 "Display routes matching the communities\n"
9473 "community number\n"
9474 "Do not send outside local AS (well-known community)\n"
9475 "Do not advertise to any peer (well-known community)\n"
9476 "Do not export to next AS (well-known community)\n")
9477 {
9478 int afi;
9479 int safi;
9480
9481 #ifdef HAVE_IPV6
9482 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
9483 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9484 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
9485 #else
9486 afi = AFI_IP;
9487 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9488 return bgp_show_community (vty, argv[1], argc-3, &argv[3], 0, afi, safi);
9489 #endif
9490 }
9491
9492 ALIAS (show_bgp_instance_afi_safi_community,
9493 show_bgp_instance_afi_safi_community2_cmd,
9494 #ifdef HAVE_IPV6
9495 "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)",
9496 #else
9497 "show bgp " BGP_INSTANCE_CMD " ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9498 #endif
9499 SHOW_STR
9500 BGP_STR
9501 BGP_INSTANCE_HELP_STR
9502 "Address family\n"
9503 #ifdef HAVE_IPV6
9504 "Address family\n"
9505 #endif
9506 "Address family modifier\n"
9507 "Address family modifier\n"
9508 "Display routes matching the communities\n"
9509 "community number\n"
9510 "Do not send outside local AS (well-known community)\n"
9511 "Do not advertise to any peer (well-known community)\n"
9512 "Do not export to next AS (well-known community)\n"
9513 "community number\n"
9514 "Do not send outside local AS (well-known community)\n"
9515 "Do not advertise to any peer (well-known community)\n"
9516 "Do not export to next AS (well-known community)\n")
9517
9518 ALIAS (show_bgp_instance_afi_safi_community,
9519 show_bgp_instance_afi_safi_community3_cmd,
9520 #ifdef HAVE_IPV6
9521 "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)",
9522 #else
9523 "show bgp " BGP_INSTANCE_CMD " 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)",
9524 #endif
9525 SHOW_STR
9526 BGP_STR
9527 BGP_INSTANCE_HELP_STR
9528 "Address family\n"
9529 #ifdef HAVE_IPV6
9530 "Address family\n"
9531 #endif
9532 "Address family modifier\n"
9533 "Address family modifier\n"
9534 "Display routes matching the communities\n"
9535 "community number\n"
9536 "Do not send outside local AS (well-known community)\n"
9537 "Do not advertise to any peer (well-known community)\n"
9538 "Do not export to next AS (well-known community)\n"
9539 "community number\n"
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 number\n"
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_bgp_instance_afi_safi_community,
9549 show_bgp_instance_afi_safi_community4_cmd,
9550 #ifdef HAVE_IPV6
9551 "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)",
9552 #else
9553 "show bgp " BGP_INSTANCE_CMD " 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)",
9554 #endif
9555 SHOW_STR
9556 BGP_STR
9557 BGP_INSTANCE_HELP_STR
9558 "Address family\n"
9559 #ifdef HAVE_IPV6
9560 "Address family\n"
9561 #endif
9562 "Address family modifier\n"
9563 "Address family modifier\n"
9564 "Display routes matching the communities\n"
9565 "community number\n"
9566 "Do not send outside local AS (well-known community)\n"
9567 "Do not advertise to any peer (well-known community)\n"
9568 "Do not export to next AS (well-known community)\n"
9569 "community number\n"
9570 "Do not send outside local AS (well-known community)\n"
9571 "Do not advertise to any peer (well-known community)\n"
9572 "Do not export to next AS (well-known community)\n"
9573 "community number\n"
9574 "Do not send outside local AS (well-known community)\n"
9575 "Do not advertise to any peer (well-known community)\n"
9576 "Do not export to next AS (well-known community)\n"
9577 "community number\n"
9578 "Do not send outside local AS (well-known community)\n"
9579 "Do not advertise to any peer (well-known community)\n"
9580 "Do not export to next AS (well-known community)\n")
9581
9582 DEFUN (show_ip_bgp_community_exact,
9583 show_ip_bgp_community_exact_cmd,
9584 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9585 SHOW_STR
9586 IP_STR
9587 BGP_STR
9588 "Display routes matching the communities\n"
9589 "community number\n"
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 "Exact match of the communities")
9594 {
9595 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9596 }
9597
9598 ALIAS (show_ip_bgp_community_exact,
9599 show_ip_bgp_community2_exact_cmd,
9600 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9601 SHOW_STR
9602 IP_STR
9603 BGP_STR
9604 "Display routes matching the communities\n"
9605 "community number\n"
9606 "Do not send outside local AS (well-known community)\n"
9607 "Do not advertise to any peer (well-known community)\n"
9608 "Do not export to next AS (well-known community)\n"
9609 "community number\n"
9610 "Do not send outside local AS (well-known community)\n"
9611 "Do not advertise to any peer (well-known community)\n"
9612 "Do not export to next AS (well-known community)\n"
9613 "Exact match of the communities")
9614
9615 ALIAS (show_ip_bgp_community_exact,
9616 show_ip_bgp_community3_exact_cmd,
9617 "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",
9618 SHOW_STR
9619 IP_STR
9620 BGP_STR
9621 "Display routes matching the communities\n"
9622 "community number\n"
9623 "Do not send outside local AS (well-known community)\n"
9624 "Do not advertise to any peer (well-known community)\n"
9625 "Do not export to next AS (well-known community)\n"
9626 "community number\n"
9627 "Do not send outside local AS (well-known community)\n"
9628 "Do not advertise to any peer (well-known community)\n"
9629 "Do not export to next AS (well-known community)\n"
9630 "community number\n"
9631 "Do not send outside local AS (well-known community)\n"
9632 "Do not advertise to any peer (well-known community)\n"
9633 "Do not export to next AS (well-known community)\n"
9634 "Exact match of the communities")
9635
9636 ALIAS (show_ip_bgp_community_exact,
9637 show_ip_bgp_community4_exact_cmd,
9638 "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",
9639 SHOW_STR
9640 IP_STR
9641 BGP_STR
9642 "Display routes matching the communities\n"
9643 "community number\n"
9644 "Do not send outside local AS (well-known community)\n"
9645 "Do not advertise to any peer (well-known community)\n"
9646 "Do not export to next AS (well-known community)\n"
9647 "community number\n"
9648 "Do not send outside local AS (well-known community)\n"
9649 "Do not advertise to any peer (well-known community)\n"
9650 "Do not export to next AS (well-known community)\n"
9651 "community number\n"
9652 "Do not send outside local AS (well-known community)\n"
9653 "Do not advertise to any peer (well-known community)\n"
9654 "Do not export to next AS (well-known community)\n"
9655 "community number\n"
9656 "Do not send outside local AS (well-known community)\n"
9657 "Do not advertise to any peer (well-known community)\n"
9658 "Do not export to next AS (well-known community)\n"
9659 "Exact match of the communities")
9660
9661 DEFUN (show_ip_bgp_ipv4_community_exact,
9662 show_ip_bgp_ipv4_community_exact_cmd,
9663 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9664 SHOW_STR
9665 IP_STR
9666 BGP_STR
9667 "Address family\n"
9668 "Address Family modifier\n"
9669 "Address Family modifier\n"
9670 "Display routes matching the communities\n"
9671 "community number\n"
9672 "Do not send outside local AS (well-known community)\n"
9673 "Do not advertise to any peer (well-known community)\n"
9674 "Do not export to next AS (well-known community)\n"
9675 "Exact match of the communities")
9676 {
9677 if (strncmp (argv[0], "m", 1) == 0)
9678 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9679
9680 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9681 }
9682
9683 ALIAS (show_ip_bgp_ipv4_community_exact,
9684 show_ip_bgp_ipv4_community2_exact_cmd,
9685 "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",
9686 SHOW_STR
9687 IP_STR
9688 BGP_STR
9689 "Address family\n"
9690 "Address Family modifier\n"
9691 "Address Family modifier\n"
9692 "Display routes matching the communities\n"
9693 "community number\n"
9694 "Do not send outside local AS (well-known community)\n"
9695 "Do not advertise to any peer (well-known community)\n"
9696 "Do not export to next AS (well-known community)\n"
9697 "community number\n"
9698 "Do not send outside local AS (well-known community)\n"
9699 "Do not advertise to any peer (well-known community)\n"
9700 "Do not export to next AS (well-known community)\n"
9701 "Exact match of the communities")
9702
9703 ALIAS (show_ip_bgp_ipv4_community_exact,
9704 show_ip_bgp_ipv4_community3_exact_cmd,
9705 "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",
9706 SHOW_STR
9707 IP_STR
9708 BGP_STR
9709 "Address family\n"
9710 "Address Family modifier\n"
9711 "Address Family modifier\n"
9712 "Display routes matching the communities\n"
9713 "community number\n"
9714 "Do not send outside local AS (well-known community)\n"
9715 "Do not advertise to any peer (well-known community)\n"
9716 "Do not export to next AS (well-known community)\n"
9717 "community number\n"
9718 "Do not send outside local AS (well-known community)\n"
9719 "Do not advertise to any peer (well-known community)\n"
9720 "Do not export to next AS (well-known community)\n"
9721 "community number\n"
9722 "Do not send outside local AS (well-known community)\n"
9723 "Do not advertise to any peer (well-known community)\n"
9724 "Do not export to next AS (well-known community)\n"
9725 "Exact match of the communities")
9726
9727 ALIAS (show_ip_bgp_ipv4_community_exact,
9728 show_ip_bgp_ipv4_community4_exact_cmd,
9729 "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",
9730 SHOW_STR
9731 IP_STR
9732 BGP_STR
9733 "Address family\n"
9734 "Address Family modifier\n"
9735 "Address Family modifier\n"
9736 "Display routes matching the communities\n"
9737 "community number\n"
9738 "Do not send outside local AS (well-known community)\n"
9739 "Do not advertise to any peer (well-known community)\n"
9740 "Do not export to next AS (well-known community)\n"
9741 "community number\n"
9742 "Do not send outside local AS (well-known community)\n"
9743 "Do not advertise to any peer (well-known community)\n"
9744 "Do not export to next AS (well-known community)\n"
9745 "community number\n"
9746 "Do not send outside local AS (well-known community)\n"
9747 "Do not advertise to any peer (well-known community)\n"
9748 "Do not export to next AS (well-known community)\n"
9749 "community number\n"
9750 "Do not send outside local AS (well-known community)\n"
9751 "Do not advertise to any peer (well-known community)\n"
9752 "Do not export to next AS (well-known community)\n"
9753 "Exact match of the communities")
9754
9755 #ifdef HAVE_IPV6
9756 DEFUN (show_bgp_community,
9757 show_bgp_community_cmd,
9758 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9759 SHOW_STR
9760 BGP_STR
9761 "Display routes matching the communities\n"
9762 "community number\n"
9763 "Do not send outside local AS (well-known community)\n"
9764 "Do not advertise to any peer (well-known community)\n"
9765 "Do not export to next AS (well-known community)\n")
9766 {
9767 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9768 }
9769
9770 ALIAS (show_bgp_community,
9771 show_bgp_ipv6_community_cmd,
9772 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9773 SHOW_STR
9774 BGP_STR
9775 "Address family\n"
9776 "Display routes matching the communities\n"
9777 "community number\n"
9778 "Do not send outside local AS (well-known community)\n"
9779 "Do not advertise to any peer (well-known community)\n"
9780 "Do not export to next AS (well-known community)\n")
9781
9782 ALIAS (show_bgp_community,
9783 show_bgp_community2_cmd,
9784 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9785 SHOW_STR
9786 BGP_STR
9787 "Display routes matching the communities\n"
9788 "community number\n"
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 number\n"
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
9797 ALIAS (show_bgp_community,
9798 show_bgp_ipv6_community2_cmd,
9799 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9800 SHOW_STR
9801 BGP_STR
9802 "Address family\n"
9803 "Display routes matching the communities\n"
9804 "community number\n"
9805 "Do not send outside local AS (well-known community)\n"
9806 "Do not advertise to any peer (well-known community)\n"
9807 "Do not export to next AS (well-known community)\n"
9808 "community number\n"
9809 "Do not send outside local AS (well-known community)\n"
9810 "Do not advertise to any peer (well-known community)\n"
9811 "Do not export to next AS (well-known community)\n")
9812
9813 ALIAS (show_bgp_community,
9814 show_bgp_community3_cmd,
9815 "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)",
9816 SHOW_STR
9817 BGP_STR
9818 "Display routes matching the communities\n"
9819 "community number\n"
9820 "Do not send outside local AS (well-known community)\n"
9821 "Do not advertise to any peer (well-known community)\n"
9822 "Do not export to next AS (well-known community)\n"
9823 "community number\n"
9824 "Do not send outside local AS (well-known community)\n"
9825 "Do not advertise to any peer (well-known community)\n"
9826 "Do not export to next AS (well-known community)\n"
9827 "community number\n"
9828 "Do not send outside local AS (well-known community)\n"
9829 "Do not advertise to any peer (well-known community)\n"
9830 "Do not export to next AS (well-known community)\n")
9831
9832 ALIAS (show_bgp_community,
9833 show_bgp_ipv6_community3_cmd,
9834 "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)",
9835 SHOW_STR
9836 BGP_STR
9837 "Address family\n"
9838 "Display routes matching the communities\n"
9839 "community number\n"
9840 "Do not send outside local AS (well-known community)\n"
9841 "Do not advertise to any peer (well-known community)\n"
9842 "Do not export to next AS (well-known community)\n"
9843 "community number\n"
9844 "Do not send outside local AS (well-known community)\n"
9845 "Do not advertise to any peer (well-known community)\n"
9846 "Do not export to next AS (well-known community)\n"
9847 "community number\n"
9848 "Do not send outside local AS (well-known community)\n"
9849 "Do not advertise to any peer (well-known community)\n"
9850 "Do not export to next AS (well-known community)\n")
9851
9852 ALIAS (show_bgp_community,
9853 show_bgp_community4_cmd,
9854 "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)",
9855 SHOW_STR
9856 BGP_STR
9857 "Display routes matching the communities\n"
9858 "community number\n"
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 number\n"
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 "community number\n"
9867 "Do not send outside local AS (well-known community)\n"
9868 "Do not advertise to any peer (well-known community)\n"
9869 "Do not export to next AS (well-known community)\n"
9870 "community number\n"
9871 "Do not send outside local AS (well-known community)\n"
9872 "Do not advertise to any peer (well-known community)\n"
9873 "Do not export to next AS (well-known community)\n")
9874
9875 ALIAS (show_bgp_community,
9876 show_bgp_ipv6_community4_cmd,
9877 "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)",
9878 SHOW_STR
9879 BGP_STR
9880 "Address family\n"
9881 "Display routes matching the communities\n"
9882 "community number\n"
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 number\n"
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 number\n"
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 "community number\n"
9895 "Do not send outside local AS (well-known community)\n"
9896 "Do not advertise to any peer (well-known community)\n"
9897 "Do not export to next AS (well-known community)\n")
9898
9899 /* old command */
9900 DEFUN (show_ipv6_bgp_community,
9901 show_ipv6_bgp_community_cmd,
9902 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9903 SHOW_STR
9904 IPV6_STR
9905 BGP_STR
9906 "Display routes matching the communities\n"
9907 "community number\n"
9908 "Do not send outside local AS (well-known community)\n"
9909 "Do not advertise to any peer (well-known community)\n"
9910 "Do not export to next AS (well-known community)\n")
9911 {
9912 bgp_show_ipv6_bgp_deprecate_warning(vty);
9913 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9914 }
9915
9916 /* old command */
9917 ALIAS (show_ipv6_bgp_community,
9918 show_ipv6_bgp_community2_cmd,
9919 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9920 SHOW_STR
9921 IPV6_STR
9922 BGP_STR
9923 "Display routes matching the communities\n"
9924 "community number\n"
9925 "Do not send outside local AS (well-known community)\n"
9926 "Do not advertise to any peer (well-known community)\n"
9927 "Do not export to next AS (well-known community)\n"
9928 "community number\n"
9929 "Do not send outside local AS (well-known community)\n"
9930 "Do not advertise to any peer (well-known community)\n"
9931 "Do not export to next AS (well-known community)\n")
9932
9933 /* old command */
9934 ALIAS (show_ipv6_bgp_community,
9935 show_ipv6_bgp_community3_cmd,
9936 "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)",
9937 SHOW_STR
9938 IPV6_STR
9939 BGP_STR
9940 "Display routes matching the communities\n"
9941 "community number\n"
9942 "Do not send outside local AS (well-known community)\n"
9943 "Do not advertise to any peer (well-known community)\n"
9944 "Do not export to next AS (well-known community)\n"
9945 "community number\n"
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 number\n"
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 /* old command */
9955 ALIAS (show_ipv6_bgp_community,
9956 show_ipv6_bgp_community4_cmd,
9957 "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)",
9958 SHOW_STR
9959 IPV6_STR
9960 BGP_STR
9961 "Display routes matching the communities\n"
9962 "community number\n"
9963 "Do not send outside local AS (well-known community)\n"
9964 "Do not advertise to any peer (well-known community)\n"
9965 "Do not export to next AS (well-known community)\n"
9966 "community number\n"
9967 "Do not send outside local AS (well-known community)\n"
9968 "Do not advertise to any peer (well-known community)\n"
9969 "Do not export to next AS (well-known community)\n"
9970 "community number\n"
9971 "Do not send outside local AS (well-known community)\n"
9972 "Do not advertise to any peer (well-known community)\n"
9973 "Do not export to next AS (well-known community)\n"
9974 "community number\n"
9975 "Do not send outside local AS (well-known community)\n"
9976 "Do not advertise to any peer (well-known community)\n"
9977 "Do not export to next AS (well-known community)\n")
9978
9979 DEFUN (show_bgp_community_exact,
9980 show_bgp_community_exact_cmd,
9981 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9982 SHOW_STR
9983 BGP_STR
9984 "Display routes matching the communities\n"
9985 "community number\n"
9986 "Do not send outside local AS (well-known community)\n"
9987 "Do not advertise to any peer (well-known community)\n"
9988 "Do not export to next AS (well-known community)\n"
9989 "Exact match of the communities")
9990 {
9991 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9992 }
9993
9994 ALIAS (show_bgp_community_exact,
9995 show_bgp_ipv6_community_exact_cmd,
9996 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9997 SHOW_STR
9998 BGP_STR
9999 "Address family\n"
10000 "Display routes matching the communities\n"
10001 "community number\n"
10002 "Do not send outside local AS (well-known community)\n"
10003 "Do not advertise to any peer (well-known community)\n"
10004 "Do not export to next AS (well-known community)\n"
10005 "Exact match of the communities")
10006
10007 ALIAS (show_bgp_community_exact,
10008 show_bgp_community2_exact_cmd,
10009 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10010 SHOW_STR
10011 BGP_STR
10012 "Display routes matching the communities\n"
10013 "community number\n"
10014 "Do not send outside local AS (well-known community)\n"
10015 "Do not advertise to any peer (well-known community)\n"
10016 "Do not export to next AS (well-known community)\n"
10017 "community number\n"
10018 "Do not send outside local AS (well-known community)\n"
10019 "Do not advertise to any peer (well-known community)\n"
10020 "Do not export to next AS (well-known community)\n"
10021 "Exact match of the communities")
10022
10023 ALIAS (show_bgp_community_exact,
10024 show_bgp_ipv6_community2_exact_cmd,
10025 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10026 SHOW_STR
10027 BGP_STR
10028 "Address family\n"
10029 "Display routes matching the communities\n"
10030 "community number\n"
10031 "Do not send outside local AS (well-known community)\n"
10032 "Do not advertise to any peer (well-known community)\n"
10033 "Do not export to next AS (well-known community)\n"
10034 "community number\n"
10035 "Do not send outside local AS (well-known community)\n"
10036 "Do not advertise to any peer (well-known community)\n"
10037 "Do not export to next AS (well-known community)\n"
10038 "Exact match of the communities")
10039
10040 ALIAS (show_bgp_community_exact,
10041 show_bgp_community3_exact_cmd,
10042 "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",
10043 SHOW_STR
10044 BGP_STR
10045 "Display routes matching the communities\n"
10046 "community number\n"
10047 "Do not send outside local AS (well-known community)\n"
10048 "Do not advertise to any peer (well-known community)\n"
10049 "Do not export to next AS (well-known community)\n"
10050 "community number\n"
10051 "Do not send outside local AS (well-known community)\n"
10052 "Do not advertise to any peer (well-known community)\n"
10053 "Do not export to next AS (well-known community)\n"
10054 "community number\n"
10055 "Do not send outside local AS (well-known community)\n"
10056 "Do not advertise to any peer (well-known community)\n"
10057 "Do not export to next AS (well-known community)\n"
10058 "Exact match of the communities")
10059
10060 ALIAS (show_bgp_community_exact,
10061 show_bgp_ipv6_community3_exact_cmd,
10062 "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",
10063 SHOW_STR
10064 BGP_STR
10065 "Address family\n"
10066 "Display routes matching the communities\n"
10067 "community number\n"
10068 "Do not send outside local AS (well-known community)\n"
10069 "Do not advertise to any peer (well-known community)\n"
10070 "Do not export to next AS (well-known community)\n"
10071 "community number\n"
10072 "Do not send outside local AS (well-known community)\n"
10073 "Do not advertise to any peer (well-known community)\n"
10074 "Do not export to next AS (well-known community)\n"
10075 "community number\n"
10076 "Do not send outside local AS (well-known community)\n"
10077 "Do not advertise to any peer (well-known community)\n"
10078 "Do not export to next AS (well-known community)\n"
10079 "Exact match of the communities")
10080
10081 ALIAS (show_bgp_community_exact,
10082 show_bgp_community4_exact_cmd,
10083 "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",
10084 SHOW_STR
10085 BGP_STR
10086 "Display routes matching the communities\n"
10087 "community number\n"
10088 "Do not send outside local AS (well-known community)\n"
10089 "Do not advertise to any peer (well-known community)\n"
10090 "Do not export to next AS (well-known community)\n"
10091 "community number\n"
10092 "Do not send outside local AS (well-known community)\n"
10093 "Do not advertise to any peer (well-known community)\n"
10094 "Do not export to next AS (well-known community)\n"
10095 "community number\n"
10096 "Do not send outside local AS (well-known community)\n"
10097 "Do not advertise to any peer (well-known community)\n"
10098 "Do not export to next AS (well-known community)\n"
10099 "community number\n"
10100 "Do not send outside local AS (well-known community)\n"
10101 "Do not advertise to any peer (well-known community)\n"
10102 "Do not export to next AS (well-known community)\n"
10103 "Exact match of the communities")
10104
10105 ALIAS (show_bgp_community_exact,
10106 show_bgp_ipv6_community4_exact_cmd,
10107 "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",
10108 SHOW_STR
10109 BGP_STR
10110 "Address family\n"
10111 "Display routes matching the communities\n"
10112 "community number\n"
10113 "Do not send outside local AS (well-known community)\n"
10114 "Do not advertise to any peer (well-known community)\n"
10115 "Do not export to next AS (well-known community)\n"
10116 "community number\n"
10117 "Do not send outside local AS (well-known community)\n"
10118 "Do not advertise to any peer (well-known community)\n"
10119 "Do not export to next AS (well-known community)\n"
10120 "community number\n"
10121 "Do not send outside local AS (well-known community)\n"
10122 "Do not advertise to any peer (well-known community)\n"
10123 "Do not export to next AS (well-known community)\n"
10124 "community number\n"
10125 "Do not send outside local AS (well-known community)\n"
10126 "Do not advertise to any peer (well-known community)\n"
10127 "Do not export to next AS (well-known community)\n"
10128 "Exact match of the communities")
10129
10130 /* old command */
10131 DEFUN (show_ipv6_bgp_community_exact,
10132 show_ipv6_bgp_community_exact_cmd,
10133 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10134 SHOW_STR
10135 IPV6_STR
10136 BGP_STR
10137 "Display routes matching the communities\n"
10138 "community number\n"
10139 "Do not send outside local AS (well-known community)\n"
10140 "Do not advertise to any peer (well-known community)\n"
10141 "Do not export to next AS (well-known community)\n"
10142 "Exact match of the communities")
10143 {
10144 bgp_show_ipv6_bgp_deprecate_warning(vty);
10145 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10146 }
10147
10148 /* old command */
10149 ALIAS (show_ipv6_bgp_community_exact,
10150 show_ipv6_bgp_community2_exact_cmd,
10151 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10152 SHOW_STR
10153 IPV6_STR
10154 BGP_STR
10155 "Display routes matching the communities\n"
10156 "community number\n"
10157 "Do not send outside local AS (well-known community)\n"
10158 "Do not advertise to any peer (well-known community)\n"
10159 "Do not export to next AS (well-known community)\n"
10160 "community number\n"
10161 "Do not send outside local AS (well-known community)\n"
10162 "Do not advertise to any peer (well-known community)\n"
10163 "Do not export to next AS (well-known community)\n"
10164 "Exact match of the communities")
10165
10166 /* old command */
10167 ALIAS (show_ipv6_bgp_community_exact,
10168 show_ipv6_bgp_community3_exact_cmd,
10169 "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",
10170 SHOW_STR
10171 IPV6_STR
10172 BGP_STR
10173 "Display routes matching the communities\n"
10174 "community number\n"
10175 "Do not send outside local AS (well-known community)\n"
10176 "Do not advertise to any peer (well-known community)\n"
10177 "Do not export to next AS (well-known community)\n"
10178 "community number\n"
10179 "Do not send outside local AS (well-known community)\n"
10180 "Do not advertise to any peer (well-known community)\n"
10181 "Do not export to next AS (well-known community)\n"
10182 "community number\n"
10183 "Do not send outside local AS (well-known community)\n"
10184 "Do not advertise to any peer (well-known community)\n"
10185 "Do not export to next AS (well-known community)\n"
10186 "Exact match of the communities")
10187
10188 /* old command */
10189 ALIAS (show_ipv6_bgp_community_exact,
10190 show_ipv6_bgp_community4_exact_cmd,
10191 "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",
10192 SHOW_STR
10193 IPV6_STR
10194 BGP_STR
10195 "Display routes matching the communities\n"
10196 "community number\n"
10197 "Do not send outside local AS (well-known community)\n"
10198 "Do not advertise to any peer (well-known community)\n"
10199 "Do not export to next AS (well-known community)\n"
10200 "community number\n"
10201 "Do not send outside local AS (well-known community)\n"
10202 "Do not advertise to any peer (well-known community)\n"
10203 "Do not export to next AS (well-known community)\n"
10204 "community number\n"
10205 "Do not send outside local AS (well-known community)\n"
10206 "Do not advertise to any peer (well-known community)\n"
10207 "Do not export to next AS (well-known community)\n"
10208 "community number\n"
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 "Exact match of the communities")
10213
10214 /* old command */
10215 DEFUN (show_ipv6_mbgp_community,
10216 show_ipv6_mbgp_community_cmd,
10217 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10218 SHOW_STR
10219 IPV6_STR
10220 MBGP_STR
10221 "Display routes matching the communities\n"
10222 "community number\n"
10223 "Do not send outside local AS (well-known community)\n"
10224 "Do not advertise to any peer (well-known community)\n"
10225 "Do not export to next AS (well-known community)\n")
10226 {
10227 bgp_show_ipv6_bgp_deprecate_warning(vty);
10228 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10229 }
10230
10231 /* old command */
10232 ALIAS (show_ipv6_mbgp_community,
10233 show_ipv6_mbgp_community2_cmd,
10234 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10235 SHOW_STR
10236 IPV6_STR
10237 MBGP_STR
10238 "Display routes matching the communities\n"
10239 "community number\n"
10240 "Do not send outside local AS (well-known community)\n"
10241 "Do not advertise to any peer (well-known community)\n"
10242 "Do not export to next AS (well-known community)\n"
10243 "community number\n"
10244 "Do not send outside local AS (well-known community)\n"
10245 "Do not advertise to any peer (well-known community)\n"
10246 "Do not export to next AS (well-known community)\n")
10247
10248 /* old command */
10249 ALIAS (show_ipv6_mbgp_community,
10250 show_ipv6_mbgp_community3_cmd,
10251 "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)",
10252 SHOW_STR
10253 IPV6_STR
10254 MBGP_STR
10255 "Display routes matching the communities\n"
10256 "community number\n"
10257 "Do not send outside local AS (well-known community)\n"
10258 "Do not advertise to any peer (well-known community)\n"
10259 "Do not export to next AS (well-known community)\n"
10260 "community number\n"
10261 "Do not send outside local AS (well-known community)\n"
10262 "Do not advertise to any peer (well-known community)\n"
10263 "Do not export to next AS (well-known community)\n"
10264 "community number\n"
10265 "Do not send outside local AS (well-known community)\n"
10266 "Do not advertise to any peer (well-known community)\n"
10267 "Do not export to next AS (well-known community)\n")
10268
10269 /* old command */
10270 ALIAS (show_ipv6_mbgp_community,
10271 show_ipv6_mbgp_community4_cmd,
10272 "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)",
10273 SHOW_STR
10274 IPV6_STR
10275 MBGP_STR
10276 "Display routes matching the communities\n"
10277 "community number\n"
10278 "Do not send outside local AS (well-known community)\n"
10279 "Do not advertise to any peer (well-known community)\n"
10280 "Do not export to next AS (well-known community)\n"
10281 "community number\n"
10282 "Do not send outside local AS (well-known community)\n"
10283 "Do not advertise to any peer (well-known community)\n"
10284 "Do not export to next AS (well-known community)\n"
10285 "community number\n"
10286 "Do not send outside local AS (well-known community)\n"
10287 "Do not advertise to any peer (well-known community)\n"
10288 "Do not export to next AS (well-known community)\n"
10289 "community number\n"
10290 "Do not send outside local AS (well-known community)\n"
10291 "Do not advertise to any peer (well-known community)\n"
10292 "Do not export to next AS (well-known community)\n")
10293
10294 /* old command */
10295 DEFUN (show_ipv6_mbgp_community_exact,
10296 show_ipv6_mbgp_community_exact_cmd,
10297 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10298 SHOW_STR
10299 IPV6_STR
10300 MBGP_STR
10301 "Display routes matching the communities\n"
10302 "community number\n"
10303 "Do not send outside local AS (well-known community)\n"
10304 "Do not advertise to any peer (well-known community)\n"
10305 "Do not export to next AS (well-known community)\n"
10306 "Exact match of the communities")
10307 {
10308 bgp_show_ipv6_bgp_deprecate_warning(vty);
10309 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10310 }
10311
10312 /* old command */
10313 ALIAS (show_ipv6_mbgp_community_exact,
10314 show_ipv6_mbgp_community2_exact_cmd,
10315 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10316 SHOW_STR
10317 IPV6_STR
10318 MBGP_STR
10319 "Display routes matching the communities\n"
10320 "community number\n"
10321 "Do not send outside local AS (well-known community)\n"
10322 "Do not advertise to any peer (well-known community)\n"
10323 "Do not export to next AS (well-known community)\n"
10324 "community number\n"
10325 "Do not send outside local AS (well-known community)\n"
10326 "Do not advertise to any peer (well-known community)\n"
10327 "Do not export to next AS (well-known community)\n"
10328 "Exact match of the communities")
10329
10330 /* old command */
10331 ALIAS (show_ipv6_mbgp_community_exact,
10332 show_ipv6_mbgp_community3_exact_cmd,
10333 "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",
10334 SHOW_STR
10335 IPV6_STR
10336 MBGP_STR
10337 "Display routes matching the communities\n"
10338 "community number\n"
10339 "Do not send outside local AS (well-known community)\n"
10340 "Do not advertise to any peer (well-known community)\n"
10341 "Do not export to next AS (well-known community)\n"
10342 "community number\n"
10343 "Do not send outside local AS (well-known community)\n"
10344 "Do not advertise to any peer (well-known community)\n"
10345 "Do not export to next AS (well-known community)\n"
10346 "community number\n"
10347 "Do not send outside local AS (well-known community)\n"
10348 "Do not advertise to any peer (well-known community)\n"
10349 "Do not export to next AS (well-known community)\n"
10350 "Exact match of the communities")
10351
10352 /* old command */
10353 ALIAS (show_ipv6_mbgp_community_exact,
10354 show_ipv6_mbgp_community4_exact_cmd,
10355 "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",
10356 SHOW_STR
10357 IPV6_STR
10358 MBGP_STR
10359 "Display routes matching the communities\n"
10360 "community number\n"
10361 "Do not send outside local AS (well-known community)\n"
10362 "Do not advertise to any peer (well-known community)\n"
10363 "Do not export to next AS (well-known community)\n"
10364 "community number\n"
10365 "Do not send outside local AS (well-known community)\n"
10366 "Do not advertise to any peer (well-known community)\n"
10367 "Do not export to next AS (well-known community)\n"
10368 "community number\n"
10369 "Do not send outside local AS (well-known community)\n"
10370 "Do not advertise to any peer (well-known community)\n"
10371 "Do not export to next AS (well-known community)\n"
10372 "community number\n"
10373 "Do not send outside local AS (well-known community)\n"
10374 "Do not advertise to any peer (well-known community)\n"
10375 "Do not export to next AS (well-known community)\n"
10376 "Exact match of the communities")
10377 #endif /* HAVE_IPV6 */
10378
10379 static int
10380 bgp_show_community_list (struct vty *vty, const char *name,
10381 const char *com, int exact,
10382 afi_t afi, safi_t safi)
10383 {
10384 struct community_list *list;
10385 struct bgp *bgp = NULL;
10386
10387 if (name && !(bgp = bgp_lookup_by_name(name)))
10388 {
10389 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
10390 return CMD_WARNING;
10391 }
10392
10393 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
10394 if (list == NULL)
10395 {
10396 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10397 VTY_NEWLINE);
10398 return CMD_WARNING;
10399 }
10400
10401 return bgp_show (vty, bgp, afi, safi,
10402 (exact ? bgp_show_type_community_list_exact :
10403 bgp_show_type_community_list), list, 0);
10404 }
10405
10406 DEFUN (show_ip_bgp_community_list,
10407 show_ip_bgp_community_list_cmd,
10408 "show ip bgp community-list (<1-500>|WORD)",
10409 SHOW_STR
10410 IP_STR
10411 BGP_STR
10412 "Display routes matching the community-list\n"
10413 "community-list number\n"
10414 "community-list name\n")
10415 {
10416 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
10417 }
10418
10419 DEFUN (show_ip_bgp_instance_community_list,
10420 show_ip_bgp_instance_community_list_cmd,
10421 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
10422 SHOW_STR
10423 IP_STR
10424 BGP_STR
10425 BGP_INSTANCE_HELP_STR
10426 "Display routes matching the community-list\n"
10427 "community-list number\n"
10428 "community-list name\n")
10429 {
10430 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
10431 }
10432
10433 DEFUN (show_ip_bgp_ipv4_community_list,
10434 show_ip_bgp_ipv4_community_list_cmd,
10435 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
10436 SHOW_STR
10437 IP_STR
10438 BGP_STR
10439 "Address family\n"
10440 "Address Family modifier\n"
10441 "Address Family modifier\n"
10442 "Display routes matching the community-list\n"
10443 "community-list number\n"
10444 "community-list name\n")
10445 {
10446 if (strncmp (argv[0], "m", 1) == 0)
10447 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10448
10449 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_UNICAST);
10450 }
10451
10452 DEFUN (show_ip_bgp_community_list_exact,
10453 show_ip_bgp_community_list_exact_cmd,
10454 "show ip bgp community-list (<1-500>|WORD) exact-match",
10455 SHOW_STR
10456 IP_STR
10457 BGP_STR
10458 "Display routes matching the community-list\n"
10459 "community-list number\n"
10460 "community-list name\n"
10461 "Exact match of the communities\n")
10462 {
10463 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
10464 }
10465
10466 DEFUN (show_ip_bgp_ipv4_community_list_exact,
10467 show_ip_bgp_ipv4_community_list_exact_cmd,
10468 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
10469 SHOW_STR
10470 IP_STR
10471 BGP_STR
10472 "Address family\n"
10473 "Address Family modifier\n"
10474 "Address Family modifier\n"
10475 "Display routes matching the community-list\n"
10476 "community-list number\n"
10477 "community-list name\n"
10478 "Exact match of the communities\n")
10479 {
10480 if (strncmp (argv[0], "m", 1) == 0)
10481 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10482
10483 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_UNICAST);
10484 }
10485
10486 #ifdef HAVE_IPV6
10487 DEFUN (show_bgp_community_list,
10488 show_bgp_community_list_cmd,
10489 "show bgp community-list (<1-500>|WORD)",
10490 SHOW_STR
10491 BGP_STR
10492 "Display routes matching the community-list\n"
10493 "community-list number\n"
10494 "community-list name\n")
10495 {
10496 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10497 }
10498
10499 ALIAS (show_bgp_community_list,
10500 show_bgp_ipv6_community_list_cmd,
10501 "show bgp ipv6 community-list (<1-500>|WORD)",
10502 SHOW_STR
10503 BGP_STR
10504 "Address family\n"
10505 "Display routes matching the community-list\n"
10506 "community-list number\n"
10507 "community-list name\n")
10508
10509 /* old command */
10510 DEFUN (show_ipv6_bgp_community_list,
10511 show_ipv6_bgp_community_list_cmd,
10512 "show ipv6 bgp community-list WORD",
10513 SHOW_STR
10514 IPV6_STR
10515 BGP_STR
10516 "Display routes matching the community-list\n"
10517 "community-list name\n")
10518 {
10519 bgp_show_ipv6_bgp_deprecate_warning(vty);
10520 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10521 }
10522
10523 /* old command */
10524 DEFUN (show_ipv6_mbgp_community_list,
10525 show_ipv6_mbgp_community_list_cmd,
10526 "show ipv6 mbgp community-list WORD",
10527 SHOW_STR
10528 IPV6_STR
10529 MBGP_STR
10530 "Display routes matching the community-list\n"
10531 "community-list name\n")
10532 {
10533 bgp_show_ipv6_bgp_deprecate_warning(vty);
10534 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10535 }
10536
10537 DEFUN (show_bgp_community_list_exact,
10538 show_bgp_community_list_exact_cmd,
10539 "show bgp community-list (<1-500>|WORD) exact-match",
10540 SHOW_STR
10541 BGP_STR
10542 "Display routes matching the community-list\n"
10543 "community-list number\n"
10544 "community-list name\n"
10545 "Exact match of the communities\n")
10546 {
10547 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10548 }
10549
10550 ALIAS (show_bgp_community_list_exact,
10551 show_bgp_ipv6_community_list_exact_cmd,
10552 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
10553 SHOW_STR
10554 BGP_STR
10555 "Address family\n"
10556 "Display routes matching the community-list\n"
10557 "community-list number\n"
10558 "community-list name\n"
10559 "Exact match of the communities\n")
10560
10561 /* old command */
10562 DEFUN (show_ipv6_bgp_community_list_exact,
10563 show_ipv6_bgp_community_list_exact_cmd,
10564 "show ipv6 bgp community-list WORD exact-match",
10565 SHOW_STR
10566 IPV6_STR
10567 BGP_STR
10568 "Display routes matching the community-list\n"
10569 "community-list name\n"
10570 "Exact match of the communities\n")
10571 {
10572 bgp_show_ipv6_bgp_deprecate_warning(vty);
10573 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10574 }
10575
10576 /* old command */
10577 DEFUN (show_ipv6_mbgp_community_list_exact,
10578 show_ipv6_mbgp_community_list_exact_cmd,
10579 "show ipv6 mbgp community-list WORD exact-match",
10580 SHOW_STR
10581 IPV6_STR
10582 MBGP_STR
10583 "Display routes matching the community-list\n"
10584 "community-list name\n"
10585 "Exact match of the communities\n")
10586 {
10587 bgp_show_ipv6_bgp_deprecate_warning(vty);
10588 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
10589 }
10590 #endif /* HAVE_IPV6 */
10591
10592 static int
10593 bgp_show_prefix_longer (struct vty *vty, const char *name,
10594 const char *prefix, afi_t afi,
10595 safi_t safi, enum bgp_show_type type)
10596 {
10597 int ret;
10598 struct prefix *p;
10599 struct bgp *bgp = NULL;
10600
10601 if (name && !(bgp = bgp_lookup_by_name(name)))
10602 {
10603 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
10604 return CMD_WARNING;
10605 }
10606
10607 p = prefix_new();
10608
10609 ret = str2prefix (prefix, p);
10610 if (! ret)
10611 {
10612 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
10613 return CMD_WARNING;
10614 }
10615
10616 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
10617 prefix_free(p);
10618 return ret;
10619 }
10620
10621 DEFUN (show_ip_bgp_prefix_longer,
10622 show_ip_bgp_prefix_longer_cmd,
10623 "show ip bgp A.B.C.D/M longer-prefixes",
10624 SHOW_STR
10625 IP_STR
10626 BGP_STR
10627 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10628 "Display route and more specific routes\n")
10629 {
10630 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10631 bgp_show_type_prefix_longer);
10632 }
10633
10634 DEFUN (show_ip_bgp_instance_prefix_longer,
10635 show_ip_bgp_instance_prefix_longer_cmd,
10636 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
10637 SHOW_STR
10638 IP_STR
10639 BGP_STR
10640 BGP_INSTANCE_HELP_STR
10641 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10642 "Display route and more specific routes\n")
10643 {
10644 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
10645 bgp_show_type_prefix_longer);
10646 }
10647
10648 DEFUN (show_ip_bgp_flap_prefix_longer,
10649 show_ip_bgp_flap_prefix_longer_cmd,
10650 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
10651 SHOW_STR
10652 IP_STR
10653 BGP_STR
10654 "Display flap statistics of routes\n"
10655 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10656 "Display route and more specific routes\n")
10657 {
10658 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10659 bgp_show_type_flap_prefix_longer);
10660 }
10661
10662 DEFUN (show_ip_bgp_ipv4_prefix_longer,
10663 show_ip_bgp_ipv4_prefix_longer_cmd,
10664 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
10665 SHOW_STR
10666 IP_STR
10667 BGP_STR
10668 "Address family\n"
10669 "Address Family modifier\n"
10670 "Address Family modifier\n"
10671 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
10672 "Display route and more specific routes\n")
10673 {
10674 if (strncmp (argv[0], "m", 1) == 0)
10675 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
10676 bgp_show_type_prefix_longer);
10677
10678 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
10679 bgp_show_type_prefix_longer);
10680 }
10681
10682 DEFUN (show_ip_bgp_flap_address,
10683 show_ip_bgp_flap_address_cmd,
10684 "show ip bgp flap-statistics A.B.C.D",
10685 SHOW_STR
10686 IP_STR
10687 BGP_STR
10688 "Display flap statistics of routes\n"
10689 "Network in the BGP routing table to display\n")
10690 {
10691 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10692 bgp_show_type_flap_address);
10693 }
10694
10695 DEFUN (show_ip_bgp_flap_prefix,
10696 show_ip_bgp_flap_prefix_cmd,
10697 "show ip bgp flap-statistics A.B.C.D/M",
10698 SHOW_STR
10699 IP_STR
10700 BGP_STR
10701 "Display flap statistics of routes\n"
10702 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10703 {
10704 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
10705 bgp_show_type_flap_prefix);
10706 }
10707 #ifdef HAVE_IPV6
10708 DEFUN (show_bgp_prefix_longer,
10709 show_bgp_prefix_longer_cmd,
10710 "show bgp X:X::X:X/M longer-prefixes",
10711 SHOW_STR
10712 BGP_STR
10713 "IPv6 prefix <network>/<length>\n"
10714 "Display route and more specific routes\n")
10715 {
10716 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
10717 bgp_show_type_prefix_longer);
10718 }
10719
10720 ALIAS (show_bgp_prefix_longer,
10721 show_bgp_ipv6_prefix_longer_cmd,
10722 "show bgp ipv6 X:X::X:X/M longer-prefixes",
10723 SHOW_STR
10724 BGP_STR
10725 "Address family\n"
10726 "IPv6 prefix <network>/<length>\n"
10727 "Display route and more specific routes\n")
10728
10729 /* old command */
10730 DEFUN (show_ipv6_bgp_prefix_longer,
10731 show_ipv6_bgp_prefix_longer_cmd,
10732 "show ipv6 bgp X:X::X:X/M longer-prefixes",
10733 SHOW_STR
10734 IPV6_STR
10735 BGP_STR
10736 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
10737 "Display route and more specific routes\n")
10738 {
10739 bgp_show_ipv6_bgp_deprecate_warning(vty);
10740 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
10741 bgp_show_type_prefix_longer);
10742 }
10743
10744 /* old command */
10745 DEFUN (show_ipv6_mbgp_prefix_longer,
10746 show_ipv6_mbgp_prefix_longer_cmd,
10747 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
10748 SHOW_STR
10749 IPV6_STR
10750 MBGP_STR
10751 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
10752 "Display route and more specific routes\n")
10753 {
10754 bgp_show_ipv6_bgp_deprecate_warning(vty);
10755 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
10756 bgp_show_type_prefix_longer);
10757 }
10758 #endif /* HAVE_IPV6 */
10759
10760 static struct peer *
10761 peer_lookup_in_view (struct vty *vty, const char *view_name,
10762 const char *ip_str, u_char use_json)
10763 {
10764 int ret;
10765 struct bgp *bgp;
10766 struct peer *peer;
10767 union sockunion su;
10768
10769 /* BGP structure lookup. */
10770 if (view_name)
10771 {
10772 bgp = bgp_lookup_by_name (view_name);
10773 if (! bgp)
10774 {
10775 if (use_json)
10776 {
10777 json_object *json_no = NULL;
10778 json_no = json_object_new_object();
10779 json_object_string_add(json_no, "warning", "Can't find BGP view");
10780 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10781 json_object_free(json_no);
10782 }
10783 else
10784 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
10785 return NULL;
10786 }
10787 }
10788 else
10789 {
10790 bgp = bgp_get_default ();
10791 if (! bgp)
10792 {
10793 if (use_json)
10794 {
10795 json_object *json_no = NULL;
10796 json_no = json_object_new_object();
10797 json_object_string_add(json_no, "warning", "No BGP process configured");
10798 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10799 json_object_free(json_no);
10800 }
10801 else
10802 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10803 return NULL;
10804 }
10805 }
10806
10807 /* Get peer sockunion. */
10808 ret = str2sockunion (ip_str, &su);
10809 if (ret < 0)
10810 {
10811 peer = peer_lookup_by_conf_if (bgp, ip_str);
10812 if (!peer)
10813 {
10814 peer = peer_lookup_by_hostname(bgp, ip_str);
10815
10816 if (!peer)
10817 {
10818 if (use_json)
10819 {
10820 json_object *json_no = NULL;
10821 json_no = json_object_new_object();
10822 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
10823 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10824 json_object_free(json_no);
10825 }
10826 else
10827 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
10828 return NULL;
10829 }
10830 }
10831 return peer;
10832 }
10833
10834 /* Peer structure lookup. */
10835 peer = peer_lookup (bgp, &su);
10836 if (! peer)
10837 {
10838 if (use_json)
10839 {
10840 json_object *json_no = NULL;
10841 json_no = json_object_new_object();
10842 json_object_string_add(json_no, "warning","No such neighbor");
10843 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
10844 json_object_free(json_no);
10845 }
10846 else
10847 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
10848 return NULL;
10849 }
10850
10851 return peer;
10852 }
10853
10854 enum bgp_stats
10855 {
10856 BGP_STATS_MAXBITLEN = 0,
10857 BGP_STATS_RIB,
10858 BGP_STATS_PREFIXES,
10859 BGP_STATS_TOTPLEN,
10860 BGP_STATS_UNAGGREGATEABLE,
10861 BGP_STATS_MAX_AGGREGATEABLE,
10862 BGP_STATS_AGGREGATES,
10863 BGP_STATS_SPACE,
10864 BGP_STATS_ASPATH_COUNT,
10865 BGP_STATS_ASPATH_MAXHOPS,
10866 BGP_STATS_ASPATH_TOTHOPS,
10867 BGP_STATS_ASPATH_MAXSIZE,
10868 BGP_STATS_ASPATH_TOTSIZE,
10869 BGP_STATS_ASN_HIGHEST,
10870 BGP_STATS_MAX,
10871 };
10872
10873 static const char *table_stats_strs[] =
10874 {
10875 [BGP_STATS_PREFIXES] = "Total Prefixes",
10876 [BGP_STATS_TOTPLEN] = "Average prefix length",
10877 [BGP_STATS_RIB] = "Total Advertisements",
10878 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
10879 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
10880 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
10881 [BGP_STATS_SPACE] = "Address space advertised",
10882 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
10883 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
10884 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
10885 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
10886 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
10887 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
10888 [BGP_STATS_MAX] = NULL,
10889 };
10890
10891 struct bgp_table_stats
10892 {
10893 struct bgp_table *table;
10894 unsigned long long counts[BGP_STATS_MAX];
10895 };
10896
10897 #if 0
10898 #define TALLY_SIGFIG 100000
10899 static unsigned long
10900 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
10901 {
10902 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
10903 unsigned long res = (newtot * TALLY_SIGFIG) / count;
10904 unsigned long ret = newtot / count;
10905
10906 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
10907 return ret + 1;
10908 else
10909 return ret;
10910 }
10911 #endif
10912
10913 static int
10914 bgp_table_stats_walker (struct thread *t)
10915 {
10916 struct bgp_node *rn;
10917 struct bgp_node *top;
10918 struct bgp_table_stats *ts = THREAD_ARG (t);
10919 unsigned int space = 0;
10920
10921 if (!(top = bgp_table_top (ts->table)))
10922 return 0;
10923
10924 switch (top->p.family)
10925 {
10926 case AF_INET:
10927 space = IPV4_MAX_BITLEN;
10928 break;
10929 case AF_INET6:
10930 space = IPV6_MAX_BITLEN;
10931 break;
10932 }
10933
10934 ts->counts[BGP_STATS_MAXBITLEN] = space;
10935
10936 for (rn = top; rn; rn = bgp_route_next (rn))
10937 {
10938 struct bgp_info *ri;
10939 struct bgp_node *prn = bgp_node_parent_nolock (rn);
10940 unsigned int rinum = 0;
10941
10942 if (rn == top)
10943 continue;
10944
10945 if (!rn->info)
10946 continue;
10947
10948 ts->counts[BGP_STATS_PREFIXES]++;
10949 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
10950
10951 #if 0
10952 ts->counts[BGP_STATS_AVGPLEN]
10953 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
10954 ts->counts[BGP_STATS_AVGPLEN],
10955 rn->p.prefixlen);
10956 #endif
10957
10958 /* check if the prefix is included by any other announcements */
10959 while (prn && !prn->info)
10960 prn = bgp_node_parent_nolock (prn);
10961
10962 if (prn == NULL || prn == top)
10963 {
10964 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
10965 /* announced address space */
10966 if (space)
10967 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
10968 }
10969 else if (prn->info)
10970 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
10971
10972 for (ri = rn->info; ri; ri = ri->next)
10973 {
10974 rinum++;
10975 ts->counts[BGP_STATS_RIB]++;
10976
10977 if (ri->attr &&
10978 (CHECK_FLAG (ri->attr->flag,
10979 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
10980 ts->counts[BGP_STATS_AGGREGATES]++;
10981
10982 /* as-path stats */
10983 if (ri->attr && ri->attr->aspath)
10984 {
10985 unsigned int hops = aspath_count_hops (ri->attr->aspath);
10986 unsigned int size = aspath_size (ri->attr->aspath);
10987 as_t highest = aspath_highest (ri->attr->aspath);
10988
10989 ts->counts[BGP_STATS_ASPATH_COUNT]++;
10990
10991 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
10992 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
10993
10994 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
10995 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
10996
10997 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
10998 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
10999 #if 0
11000 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11001 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11002 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11003 hops);
11004 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11005 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11006 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11007 size);
11008 #endif
11009 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11010 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11011 }
11012 }
11013 }
11014 return 0;
11015 }
11016
11017 static int
11018 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11019 {
11020 struct bgp_table_stats ts;
11021 unsigned int i;
11022
11023 if (!bgp->rib[afi][safi])
11024 {
11025 vty_out (vty, "%% No RIB exist's for the AFI(%d)/SAFI(%d)%s",
11026 afi, safi, VTY_NEWLINE);
11027 return CMD_WARNING;
11028 }
11029
11030 memset (&ts, 0, sizeof (ts));
11031 ts.table = bgp->rib[afi][safi];
11032 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11033
11034 vty_out (vty, "BGP %s RIB statistics%s%s",
11035 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11036
11037 for (i = 0; i < BGP_STATS_MAX; i++)
11038 {
11039 if (!table_stats_strs[i])
11040 continue;
11041
11042 switch (i)
11043 {
11044 #if 0
11045 case BGP_STATS_ASPATH_AVGHOPS:
11046 case BGP_STATS_ASPATH_AVGSIZE:
11047 case BGP_STATS_AVGPLEN:
11048 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11049 vty_out (vty, "%12.2f",
11050 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11051 break;
11052 #endif
11053 case BGP_STATS_ASPATH_TOTHOPS:
11054 case BGP_STATS_ASPATH_TOTSIZE:
11055 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11056 vty_out (vty, "%12.2f",
11057 ts.counts[i] ?
11058 (float)ts.counts[i] /
11059 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11060 : 0);
11061 break;
11062 case BGP_STATS_TOTPLEN:
11063 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11064 vty_out (vty, "%12.2f",
11065 ts.counts[i] ?
11066 (float)ts.counts[i] /
11067 (float)ts.counts[BGP_STATS_PREFIXES]
11068 : 0);
11069 break;
11070 case BGP_STATS_SPACE:
11071 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11072 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11073 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11074 break;
11075 vty_out (vty, "%30s: ", "%% announced ");
11076 vty_out (vty, "%12.2f%s",
11077 100 * (float)ts.counts[BGP_STATS_SPACE] /
11078 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
11079 VTY_NEWLINE);
11080 vty_out (vty, "%30s: ", "/8 equivalent ");
11081 vty_out (vty, "%12.2f%s",
11082 (float)ts.counts[BGP_STATS_SPACE] /
11083 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11084 VTY_NEWLINE);
11085 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11086 break;
11087 vty_out (vty, "%30s: ", "/24 equivalent ");
11088 vty_out (vty, "%12.2f",
11089 (float)ts.counts[BGP_STATS_SPACE] /
11090 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11091 break;
11092 default:
11093 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11094 vty_out (vty, "%12llu", ts.counts[i]);
11095 }
11096
11097 vty_out (vty, "%s", VTY_NEWLINE);
11098 }
11099 return CMD_SUCCESS;
11100 }
11101
11102 static int
11103 bgp_table_stats_vty (struct vty *vty, const char *name,
11104 const char *afi_str, const char *safi_str)
11105 {
11106 struct bgp *bgp;
11107 afi_t afi;
11108 safi_t safi;
11109
11110 if (name)
11111 bgp = bgp_lookup_by_name (name);
11112 else
11113 bgp = bgp_get_default ();
11114
11115 if (!bgp)
11116 {
11117 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
11118 return CMD_WARNING;
11119 }
11120 if (strncmp (afi_str, "ipv", 3) == 0)
11121 {
11122 if (strncmp (afi_str, "ipv4", 4) == 0)
11123 afi = AFI_IP;
11124 else if (strncmp (afi_str, "ipv6", 4) == 0)
11125 afi = AFI_IP6;
11126 else
11127 {
11128 vty_out (vty, "%% Invalid address family %s%s",
11129 afi_str, VTY_NEWLINE);
11130 return CMD_WARNING;
11131 }
11132 if (strncmp (safi_str, "m", 1) == 0)
11133 safi = SAFI_MULTICAST;
11134 else if (strncmp (safi_str, "u", 1) == 0)
11135 safi = SAFI_UNICAST;
11136 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
11137 safi = SAFI_MPLS_VPN;
11138 else
11139 {
11140 vty_out (vty, "%% Invalid subsequent address family %s%s",
11141 safi_str, VTY_NEWLINE);
11142 return CMD_WARNING;
11143 }
11144 }
11145 else
11146 {
11147 vty_out (vty, "%% Invalid address family %s%s",
11148 afi_str, VTY_NEWLINE);
11149 return CMD_WARNING;
11150 }
11151
11152 return bgp_table_stats (vty, bgp, afi, safi);
11153 }
11154
11155 DEFUN (show_bgp_statistics,
11156 show_bgp_statistics_cmd,
11157 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
11158 SHOW_STR
11159 BGP_STR
11160 "Address family\n"
11161 "Address family\n"
11162 "Address Family modifier\n"
11163 "Address Family modifier\n"
11164 "BGP RIB advertisement statistics\n")
11165 {
11166 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11167 }
11168
11169 ALIAS (show_bgp_statistics,
11170 show_bgp_statistics_vpnv4_cmd,
11171 "show bgp (ipv4) (vpnv4) statistics",
11172 SHOW_STR
11173 BGP_STR
11174 "Address family\n"
11175 "Address Family modifier\n"
11176 "BGP RIB advertisement statistics\n")
11177
11178 DEFUN (show_bgp_statistics_view,
11179 show_bgp_statistics_view_cmd,
11180 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) statistics",
11181 SHOW_STR
11182 BGP_STR
11183 BGP_INSTANCE_HELP_STR
11184 "Address family\n"
11185 "Address family\n"
11186 "Address Family modifier\n"
11187 "Address Family modifier\n"
11188 "BGP RIB advertisement statistics\n")
11189 {
11190 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
11191 }
11192
11193 ALIAS (show_bgp_statistics_view,
11194 show_bgp_statistics_view_vpnv4_cmd,
11195 "show bgp " BGP_INSTANCE_CMD " (ipv4) (vpnv4) statistics",
11196 SHOW_STR
11197 BGP_STR
11198 BGP_INSTANCE_HELP_STR
11199 "Address family\n"
11200 "Address Family modifier\n"
11201 "BGP RIB advertisement statistics\n")
11202
11203 enum bgp_pcounts
11204 {
11205 PCOUNT_ADJ_IN = 0,
11206 PCOUNT_DAMPED,
11207 PCOUNT_REMOVED,
11208 PCOUNT_HISTORY,
11209 PCOUNT_STALE,
11210 PCOUNT_VALID,
11211 PCOUNT_ALL,
11212 PCOUNT_COUNTED,
11213 PCOUNT_PFCNT, /* the figure we display to users */
11214 PCOUNT_MAX,
11215 };
11216
11217 static const char *pcount_strs[] =
11218 {
11219 [PCOUNT_ADJ_IN] = "Adj-in",
11220 [PCOUNT_DAMPED] = "Damped",
11221 [PCOUNT_REMOVED] = "Removed",
11222 [PCOUNT_HISTORY] = "History",
11223 [PCOUNT_STALE] = "Stale",
11224 [PCOUNT_VALID] = "Valid",
11225 [PCOUNT_ALL] = "All RIB",
11226 [PCOUNT_COUNTED] = "PfxCt counted",
11227 [PCOUNT_PFCNT] = "Useable",
11228 [PCOUNT_MAX] = NULL,
11229 };
11230
11231 struct peer_pcounts
11232 {
11233 unsigned int count[PCOUNT_MAX];
11234 const struct peer *peer;
11235 const struct bgp_table *table;
11236 };
11237
11238 static int
11239 bgp_peer_count_walker (struct thread *t)
11240 {
11241 struct bgp_node *rn;
11242 struct peer_pcounts *pc = THREAD_ARG (t);
11243 const struct peer *peer = pc->peer;
11244
11245 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
11246 {
11247 struct bgp_adj_in *ain;
11248 struct bgp_info *ri;
11249
11250 for (ain = rn->adj_in; ain; ain = ain->next)
11251 if (ain->peer == peer)
11252 pc->count[PCOUNT_ADJ_IN]++;
11253
11254 for (ri = rn->info; ri; ri = ri->next)
11255 {
11256 char buf[SU_ADDRSTRLEN];
11257
11258 if (ri->peer != peer)
11259 continue;
11260
11261 pc->count[PCOUNT_ALL]++;
11262
11263 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
11264 pc->count[PCOUNT_DAMPED]++;
11265 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
11266 pc->count[PCOUNT_HISTORY]++;
11267 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
11268 pc->count[PCOUNT_REMOVED]++;
11269 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
11270 pc->count[PCOUNT_STALE]++;
11271 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
11272 pc->count[PCOUNT_VALID]++;
11273 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11274 pc->count[PCOUNT_PFCNT]++;
11275
11276 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11277 {
11278 pc->count[PCOUNT_COUNTED]++;
11279 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11280 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
11281 peer->host,
11282 inet_ntop(rn->p.family, &rn->p.u.prefix,
11283 buf, SU_ADDRSTRLEN),
11284 rn->p.prefixlen,
11285 ri->flags);
11286 }
11287 else
11288 {
11289 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11290 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
11291 peer->host,
11292 inet_ntop(rn->p.family, &rn->p.u.prefix,
11293 buf, SU_ADDRSTRLEN),
11294 rn->p.prefixlen,
11295 ri->flags);
11296 }
11297 }
11298 }
11299 return 0;
11300 }
11301
11302 static int
11303 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
11304 {
11305 struct peer_pcounts pcounts = { .peer = peer };
11306 unsigned int i;
11307 json_object *json = NULL;
11308 json_object *json_loop = NULL;
11309
11310 if (use_json)
11311 {
11312 json = json_object_new_object();
11313 json_loop = json_object_new_object();
11314 }
11315
11316 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11317 || !peer->bgp->rib[afi][safi])
11318 {
11319 if (use_json)
11320 {
11321 json_object_string_add(json, "warning", "No such neighbor or address family");
11322 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11323 json_object_free(json);
11324 }
11325 else
11326 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11327
11328 return CMD_WARNING;
11329 }
11330
11331 memset (&pcounts, 0, sizeof(pcounts));
11332 pcounts.peer = peer;
11333 pcounts.table = peer->bgp->rib[afi][safi];
11334
11335 /* in-place call via thread subsystem so as to record execution time
11336 * * stats for the thread-walk (i.e. ensure this can't be blamed on
11337 * * on just vty_read()).
11338 * */
11339 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
11340
11341 if (use_json)
11342 {
11343 json_object_string_add(json, "prefixCountsFor", peer->host);
11344 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
11345 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
11346
11347 for (i = 0; i < PCOUNT_MAX; i++)
11348 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
11349
11350 json_object_object_add(json, "ribTableWalkCounters", json_loop);
11351
11352 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11353 {
11354 json_object_string_add(json, "pfxctDriftFor", peer->host);
11355 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
11356 }
11357 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11358 json_object_free(json);
11359 }
11360 else
11361 {
11362
11363 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
11364 {
11365 vty_out (vty, "Prefix counts for %s/%s, %s%s",
11366 peer->hostname, peer->host, afi_safi_print (afi, safi),
11367 VTY_NEWLINE);
11368 }
11369 else
11370 {
11371 vty_out (vty, "Prefix counts for %s, %s%s",
11372 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
11373 }
11374
11375 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
11376 vty_out (vty, "%sCounts from RIB table walk:%s%s",
11377 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
11378
11379 for (i = 0; i < PCOUNT_MAX; i++)
11380 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
11381
11382 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
11383 {
11384 vty_out (vty, "%s [pcount] PfxCt drift!%s",
11385 peer->host, VTY_NEWLINE);
11386 vty_out (vty, "Please report this bug, with the above command output%s",
11387 VTY_NEWLINE);
11388 }
11389 }
11390
11391 return CMD_SUCCESS;
11392 }
11393
11394 DEFUN (show_ip_bgp_neighbor_prefix_counts,
11395 show_ip_bgp_neighbor_prefix_counts_cmd,
11396 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11397 SHOW_STR
11398 IP_STR
11399 BGP_STR
11400 "Detailed information on TCP and BGP neighbor connections\n"
11401 "Neighbor to display information about\n"
11402 "Neighbor to display information about\n"
11403 "Neighbor on bgp configured interface\n"
11404 "Display detailed prefix count information\n"
11405 "JavaScript Object Notation\n")
11406 {
11407 struct peer *peer;
11408 u_char uj = use_json(argc, argv);
11409
11410 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11411 if (! peer)
11412 return CMD_WARNING;
11413
11414 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11415 }
11416
11417 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
11418 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
11419 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11420 SHOW_STR
11421 IP_STR
11422 BGP_STR
11423 BGP_INSTANCE_HELP_STR
11424 "Detailed information on TCP and BGP neighbor connections\n"
11425 "Neighbor to display information about\n"
11426 "Neighbor to display information about\n"
11427 "Neighbor on bgp configured interface\n"
11428 "Display detailed prefix count information\n"
11429 "JavaScript Object Notation\n")
11430 {
11431 struct peer *peer;
11432 u_char uj = use_json(argc, argv);
11433
11434 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11435 if (! peer)
11436 return CMD_WARNING;
11437
11438 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11439 }
11440
11441 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
11442 show_bgp_ipv6_neighbor_prefix_counts_cmd,
11443 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11444 SHOW_STR
11445 BGP_STR
11446 "Address family\n"
11447 "Detailed information on TCP and BGP neighbor connections\n"
11448 "Neighbor to display information about\n"
11449 "Neighbor to display information about\n"
11450 "Neighbor on bgp configured interface\n"
11451 "Display detailed prefix count information\n"
11452 "JavaScript Object Notation\n")
11453 {
11454 struct peer *peer;
11455 u_char uj = use_json(argc, argv);
11456
11457 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11458 if (! peer)
11459 return CMD_WARNING;
11460
11461 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
11462 }
11463
11464 DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
11465 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
11466 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11467 SHOW_STR
11468 BGP_STR
11469 BGP_INSTANCE_HELP_STR
11470 "Address family\n"
11471 "Detailed information on TCP and BGP neighbor connections\n"
11472 "Neighbor to display information about\n"
11473 "Neighbor to display information about\n"
11474 "Neighbor on bgp configured interface\n"
11475 "Display detailed prefix count information\n"
11476 "JavaScript Object Notation\n")
11477 {
11478 struct peer *peer;
11479 u_char uj = use_json(argc, argv);
11480
11481 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11482 if (! peer)
11483 return CMD_WARNING;
11484
11485 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
11486 }
11487
11488 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
11489 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
11490 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11491 SHOW_STR
11492 IP_STR
11493 BGP_STR
11494 "Address family\n"
11495 "Address Family modifier\n"
11496 "Address Family modifier\n"
11497 "Detailed information on TCP and BGP neighbor connections\n"
11498 "Neighbor to display information about\n"
11499 "Neighbor to display information about\n"
11500 "Neighbor on bgp configured interface\n"
11501 "Display detailed prefix count information\n"
11502 "JavaScript Object Notation\n")
11503 {
11504 struct peer *peer;
11505 u_char uj = use_json(argc, argv);
11506
11507 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
11508 if (! peer)
11509 return CMD_WARNING;
11510
11511 if (strncmp (argv[0], "m", 1) == 0)
11512 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj);
11513
11514 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
11515 }
11516
11517 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
11518 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
11519 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
11520 SHOW_STR
11521 IP_STR
11522 BGP_STR
11523 "Address family\n"
11524 "Address Family modifier\n"
11525 "Address Family modifier\n"
11526 "Detailed information on TCP and BGP neighbor connections\n"
11527 "Neighbor to display information about\n"
11528 "Neighbor to display information about\n"
11529 "Neighbor on bgp configured interface\n"
11530 "Display detailed prefix count information\n"
11531 "JavaScript Object Notation\n")
11532 {
11533 struct peer *peer;
11534 u_char uj = use_json(argc, argv);
11535
11536 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11537 if (! peer)
11538 return CMD_WARNING;
11539
11540 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
11541 }
11542
11543 static void
11544 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
11545 int in, const char *rmap_name, u_char use_json, json_object *json)
11546 {
11547 struct bgp_table *table;
11548 struct bgp_adj_in *ain;
11549 struct bgp_adj_out *adj;
11550 unsigned long output_count;
11551 unsigned long filtered_count;
11552 struct bgp_node *rn;
11553 int header1 = 1;
11554 struct bgp *bgp;
11555 int header2 = 1;
11556 struct attr attr;
11557 struct attr_extra extra;
11558 int ret;
11559 struct update_subgroup *subgrp;
11560 json_object *json_scode = NULL;
11561 json_object *json_ocode = NULL;
11562 json_object *json_ar = NULL;
11563 struct peer_af *paf;
11564
11565 if (use_json)
11566 {
11567 json_scode = json_object_new_object();
11568 json_ocode = json_object_new_object();
11569 json_ar = json_object_new_object();
11570
11571 json_object_string_add(json_scode, "suppressed", "s");
11572 json_object_string_add(json_scode, "damped", "d");
11573 json_object_string_add(json_scode, "history", "h");
11574 json_object_string_add(json_scode, "valid", "*");
11575 json_object_string_add(json_scode, "best", ">");
11576 json_object_string_add(json_scode, "multipath", "=");
11577 json_object_string_add(json_scode, "internal", "i");
11578 json_object_string_add(json_scode, "ribFailure", "r");
11579 json_object_string_add(json_scode, "stale", "S");
11580 json_object_string_add(json_scode, "removed", "R");
11581
11582 json_object_string_add(json_ocode, "igp", "i");
11583 json_object_string_add(json_ocode, "egp", "e");
11584 json_object_string_add(json_ocode, "incomplete", "?");
11585 }
11586
11587 bgp = peer->bgp;
11588
11589 if (! bgp)
11590 {
11591 if (use_json)
11592 {
11593 json_object_string_add(json, "alert", "no BGP");
11594 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11595 json_object_free(json);
11596 }
11597 else
11598 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
11599 return;
11600 }
11601
11602 table = bgp->rib[afi][safi];
11603
11604 output_count = filtered_count = 0;
11605 subgrp = peer_subgroup(peer, afi, safi);
11606
11607 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
11608 {
11609 if (use_json)
11610 {
11611 json_object_int_add(json, "bgpTableVersion", table->version);
11612 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11613 json_object_object_add(json, "bgpStatusCodes", json_scode);
11614 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11615 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
11616 }
11617 else
11618 {
11619 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
11620 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11621 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11622
11623 vty_out (vty, "Originating default network 0.0.0.0%s%s",
11624 VTY_NEWLINE, VTY_NEWLINE);
11625 }
11626 header1 = 0;
11627 }
11628
11629 attr.extra = &extra;
11630 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11631 {
11632 if (in)
11633 {
11634 for (ain = rn->adj_in; ain; ain = ain->next)
11635 {
11636 if (ain->peer == peer)
11637 {
11638 if (header1)
11639 {
11640 if (use_json)
11641 {
11642 json_object_int_add(json, "bgpTableVersion", 0);
11643 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11644 json_object_object_add(json, "bgpStatusCodes", json_scode);
11645 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11646 }
11647 else
11648 {
11649 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
11650 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11651 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11652 }
11653 header1 = 0;
11654 }
11655 if (header2)
11656 {
11657 if (!use_json)
11658 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
11659 header2 = 0;
11660 }
11661 if (ain->attr)
11662 {
11663 bgp_attr_dup(&attr, ain->attr);
11664 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
11665 {
11666 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
11667 output_count++;
11668 }
11669 else
11670 filtered_count++;
11671 }
11672 }
11673 }
11674 }
11675 else
11676 {
11677 for (adj = rn->adj_out; adj; adj = adj->next)
11678 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
11679 if (paf->peer == peer)
11680 {
11681 if (header1)
11682 {
11683 if (use_json)
11684 {
11685 json_object_int_add(json, "bgpTableVersion", table->version);
11686 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
11687 json_object_object_add(json, "bgpStatusCodes", json_scode);
11688 json_object_object_add(json, "bgpOriginCodes", json_ocode);
11689 }
11690 else
11691 {
11692 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
11693 inet_ntoa (bgp->router_id), VTY_NEWLINE);
11694 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11695 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
11696 }
11697 header1 = 0;
11698 }
11699
11700 if (header2)
11701 {
11702 if (!use_json)
11703 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
11704 header2 = 0;
11705 }
11706
11707 if (adj->attr)
11708 {
11709 bgp_attr_dup(&attr, adj->attr);
11710 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
11711 if (ret != RMAP_DENY)
11712 {
11713 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
11714 output_count++;
11715 }
11716 else
11717 filtered_count++;
11718 }
11719 }
11720 }
11721 }
11722 if (use_json)
11723 json_object_object_add(json, "advertisedRoutes", json_ar);
11724
11725 if (output_count != 0)
11726 {
11727 if (use_json)
11728 json_object_int_add(json, "totalPrefixCounter", output_count);
11729 else
11730 vty_out (vty, "%sTotal number of prefixes %ld%s",
11731 VTY_NEWLINE, output_count, VTY_NEWLINE);
11732 }
11733 if (use_json)
11734 {
11735 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11736 json_object_free(json);
11737 }
11738
11739 }
11740
11741 static int
11742 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
11743 int in, const char *rmap_name, u_char use_json)
11744 {
11745 json_object *json = NULL;
11746
11747 if (use_json)
11748 json = json_object_new_object();
11749
11750 if (!peer || !peer->afc[afi][safi])
11751 {
11752 if (use_json)
11753 {
11754 json_object_string_add(json, "warning", "No such neighbor or address family");
11755 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11756 json_object_free(json);
11757 }
11758 else
11759 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11760
11761 return CMD_WARNING;
11762 }
11763
11764 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11765 {
11766 if (use_json)
11767 {
11768 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
11769 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
11770 json_object_free(json);
11771 }
11772 else
11773 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
11774
11775 return CMD_WARNING;
11776 }
11777
11778 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
11779
11780 return CMD_SUCCESS;
11781 }
11782
11783 DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
11784 show_ip_bgp_instance_neighbor_advertised_route_cmd,
11785 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11786 SHOW_STR
11787 IP_STR
11788 BGP_STR
11789 BGP_INSTANCE_HELP_STR
11790 "Detailed information on TCP and BGP neighbor connections\n"
11791 "Neighbor to display information about\n"
11792 "Neighbor to display information about\n"
11793 "Display the routes advertised to a BGP neighbor\n"
11794 "JavaScript Object Notation\n")
11795 {
11796 struct peer *peer;
11797 u_char uj = use_json(argc, argv);
11798
11799 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
11800 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11801 else
11802 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
11803
11804 if (! peer)
11805 return CMD_WARNING;
11806
11807 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
11808 }
11809
11810 DEFUN (show_ip_bgp_neighbor_advertised_route,
11811 show_ip_bgp_neighbor_advertised_route_cmd,
11812 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11813 SHOW_STR
11814 IP_STR
11815 BGP_STR
11816 "Detailed information on TCP and BGP neighbor connections\n"
11817 "Neighbor to display information about\n"
11818 "Neighbor to display information about\n"
11819 "Neighbor on bgp configured interface\n"
11820 "Display the routes advertised to a BGP neighbor\n"
11821 "JavaScript Object Notation\n")
11822
11823 {
11824 struct peer *peer;
11825 const char *rmap_name = NULL;
11826 u_char uj = use_json(argc, argv);
11827
11828 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11829
11830 if (! peer)
11831 return CMD_WARNING;
11832
11833 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
11834 || (argc == 3))
11835 rmap_name = argv[1];
11836
11837 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
11838 }
11839
11840 ALIAS (show_ip_bgp_neighbor_advertised_route,
11841 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
11842 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
11843 SHOW_STR
11844 IP_STR
11845 BGP_STR
11846 "Detailed information on TCP and BGP neighbor connections\n"
11847 "Neighbor to display information about\n"
11848 "Neighbor to display information about\n"
11849 "Neighbor on bgp configured interface\n"
11850 "Display the routes advertised to a BGP neighbor\n"
11851 "JavaScript Object Notation\n")
11852
11853 ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
11854 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
11855 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
11856 SHOW_STR
11857 IP_STR
11858 BGP_STR
11859 BGP_INSTANCE_HELP_STR
11860 "Detailed information on TCP and BGP neighbor connections\n"
11861 "Neighbor to display information about\n"
11862 "Neighbor to display information about\n"
11863 "Neighbor on bgp configured interface\n"
11864 "Display the routes advertised to a BGP neighbor\n"
11865 "JavaScript Object Notation\n")
11866 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
11867 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
11868 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11869 SHOW_STR
11870 IP_STR
11871 BGP_STR
11872 "Address family\n"
11873 "Address Family modifier\n"
11874 "Address Family modifier\n"
11875 "Detailed information on TCP and BGP neighbor connections\n"
11876 "Neighbor to display information about\n"
11877 "Neighbor to display information about\n"
11878 "Neighbor on bgp configured interface\n"
11879 "Display the routes advertised to a BGP neighbor\n"
11880 "JavaScript Object Notation\n")
11881 {
11882 struct peer *peer;
11883 const char *rmap_name = NULL;
11884 u_char uj = use_json(argc, argv);
11885
11886 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
11887 if (! peer)
11888 return CMD_WARNING;
11889
11890 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
11891 rmap_name = argv[2];
11892
11893 if (strncmp (argv[0], "m", 1) == 0)
11894 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj);
11895 else
11896 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
11897 }
11898
11899 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
11900 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
11901 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
11902 SHOW_STR
11903 IP_STR
11904 BGP_STR
11905 "Address family\n"
11906 "Address Family modifier\n"
11907 "Address Family modifier\n"
11908 "Detailed information on TCP and BGP neighbor connections\n"
11909 "Neighbor to display information about\n"
11910 "Neighbor to display information about\n"
11911 "Neighbor on bgp configured interface\n"
11912 "Display the routes advertised to a BGP neighbor\n"
11913 "Route-map to control what is displayed\n"
11914 "JavaScript Object Notation\n")
11915
11916 #ifdef HAVE_IPV6
11917 DEFUN (show_bgp_instance_neighbor_advertised_route,
11918 show_bgp_instance_neighbor_advertised_route_cmd,
11919 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11920 SHOW_STR
11921 BGP_STR
11922 BGP_INSTANCE_HELP_STR
11923 "Detailed information on TCP and BGP neighbor connections\n"
11924 "Neighbor to display information about\n"
11925 "Neighbor to display information about\n"
11926 "Neighbor on bgp configured interface\n"
11927 "Display the routes advertised to a BGP neighbor\n"
11928 "JavaScript Object Notation\n")
11929 {
11930 struct peer *peer;
11931 u_char uj = use_json(argc, argv);
11932
11933 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
11934 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
11935 else
11936 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
11937
11938 if (! peer)
11939 return CMD_WARNING;
11940
11941 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
11942 }
11943
11944 ALIAS (show_bgp_instance_neighbor_advertised_route,
11945 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
11946 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11947 SHOW_STR
11948 BGP_STR
11949 BGP_INSTANCE_HELP_STR
11950 "Address family\n"
11951 "Detailed information on TCP and BGP neighbor connections\n"
11952 "Neighbor to display information about\n"
11953 "Neighbor to display information about\n"
11954 "Neighbor on bgp configured interface\n"
11955 "Display the routes advertised to a BGP neighbor\n"
11956 "JavaScript Object Notation\n")
11957
11958 DEFUN (show_bgp_neighbor_advertised_route,
11959 show_bgp_neighbor_advertised_route_cmd,
11960 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11961 SHOW_STR
11962 BGP_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 "Neighbor on bgp configured interface\n"
11967 "Display the routes advertised to a BGP neighbor\n"
11968 "JavaScript Object Notation\n")
11969
11970 {
11971 struct peer *peer;
11972 const char *rmap_name = NULL;
11973 u_char uj = use_json(argc, argv);
11974
11975 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
11976
11977 if (!peer)
11978 return CMD_WARNING;
11979
11980 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
11981 rmap_name = argv[1];
11982
11983 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
11984 }
11985
11986 ALIAS (show_bgp_neighbor_advertised_route,
11987 show_bgp_ipv6_neighbor_advertised_route_cmd,
11988 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
11989 SHOW_STR
11990 BGP_STR
11991 "Address family\n"
11992 "Detailed information on TCP and BGP neighbor connections\n"
11993 "Neighbor to display information about\n"
11994 "Neighbor to display information about\n"
11995 "Neighbor on bgp configured interface\n"
11996 "Display the routes advertised to a BGP neighbor\n"
11997 "JavaScript Object Notation\n")
11998
11999 /* old command */
12000 ALIAS (show_bgp_neighbor_advertised_route,
12001 ipv6_bgp_neighbor_advertised_route_cmd,
12002 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12003 SHOW_STR
12004 IPV6_STR
12005 BGP_STR
12006 "Detailed information on TCP and BGP neighbor connections\n"
12007 "Neighbor to display information about\n"
12008 "Neighbor to display information about\n"
12009 "Neighbor on bgp configured interface\n"
12010 "Display the routes advertised to a BGP neighbor\n"
12011 "JavaScript Object Notation\n")
12012
12013 /* old command */
12014 DEFUN (ipv6_mbgp_neighbor_advertised_route,
12015 ipv6_mbgp_neighbor_advertised_route_cmd,
12016 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12017 SHOW_STR
12018 IPV6_STR
12019 MBGP_STR
12020 "Detailed information on TCP and BGP neighbor connections\n"
12021 "Neighbor to display information about\n"
12022 "Neighbor to display information about\n"
12023 "Neighbor on bgp configured interface\n"
12024 "Neighbor on bgp configured interface\n"
12025 "Display the routes advertised to a BGP neighbor\n"
12026 "JavaScript Object Notation\n")
12027 {
12028 struct peer *peer;
12029 u_char uj = use_json(argc, argv);
12030
12031 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12032 if (! peer)
12033 return CMD_WARNING;
12034
12035 bgp_show_ipv6_bgp_deprecate_warning(vty);
12036 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
12037 }
12038 #endif /* HAVE_IPV6 */
12039
12040 DEFUN (show_bgp_instance_neighbor_received_routes,
12041 show_bgp_instance_neighbor_received_routes_cmd,
12042 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12043 SHOW_STR
12044 BGP_STR
12045 BGP_INSTANCE_HELP_STR
12046 "Detailed information on TCP and BGP neighbor connections\n"
12047 "Neighbor to display information about\n"
12048 "Neighbor to display information about\n"
12049 "Neighbor on bgp configured interface\n"
12050 "Display the received routes from neighbor\n"
12051 "JavaScript Object Notation\n")
12052 {
12053 struct peer *peer;
12054 u_char uj = use_json(argc, argv);
12055
12056 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12057 if (! peer)
12058 return CMD_WARNING;
12059
12060 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
12061 }
12062
12063 DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12064 show_ip_bgp_instance_neighbor_received_routes_cmd,
12065 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12066 SHOW_STR
12067 IP_STR
12068 BGP_STR
12069 BGP_INSTANCE_HELP_STR
12070 "Detailed information on TCP and BGP neighbor connections\n"
12071 "Neighbor to display information about\n"
12072 "Neighbor to display information about\n"
12073 "Neighbor on bgp configured interface\n"
12074 "Display the received routes from neighbor\n"
12075 "JavaScript Object Notation\n")
12076 {
12077 struct peer *peer;
12078 u_char uj = use_json(argc, argv);
12079
12080 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12081 if (! peer)
12082 return CMD_WARNING;
12083
12084 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
12085 }
12086
12087 ALIAS (show_bgp_instance_neighbor_received_routes,
12088 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12089 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12090 SHOW_STR
12091 BGP_STR
12092 BGP_INSTANCE_HELP_STR
12093 "Address family\n"
12094 "Detailed information on TCP and BGP neighbor connections\n"
12095 "Neighbor to display information about\n"
12096 "Neighbor to display information about\n"
12097 "Neighbor on bgp configured interface\n"
12098 "Display the received routes from neighbor\n"
12099 "JavaScript Object Notation\n")
12100
12101 DEFUN (show_ip_bgp_neighbor_received_routes,
12102 show_ip_bgp_neighbor_received_routes_cmd,
12103 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12104 SHOW_STR
12105 IP_STR
12106 BGP_STR
12107 "Detailed information on TCP and BGP neighbor connections\n"
12108 "Neighbor to display information about\n"
12109 "Neighbor to display information about\n"
12110 "Neighbor on bgp configured interface\n"
12111 "Display the received routes from neighbor\n"
12112 "JavaScript Object Notation\n")
12113
12114 {
12115 struct peer *peer;
12116 const char *rmap_name = NULL;
12117 u_char uj = use_json(argc, argv);
12118
12119 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12120
12121 if (! peer)
12122 return CMD_WARNING;
12123
12124 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12125 rmap_name = argv[1];
12126
12127 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12128 }
12129
12130 ALIAS (show_ip_bgp_neighbor_received_routes,
12131 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12132 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12133 SHOW_STR
12134 IP_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 received routes from neighbor\n"
12141 "JavaScript Object Notation\n")
12142
12143 ALIAS (show_ip_bgp_instance_neighbor_received_routes,
12144 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
12145 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12146 SHOW_STR
12147 IP_STR
12148 BGP_STR
12149 BGP_INSTANCE_HELP_STR
12150 "Detailed information on TCP and BGP neighbor connections\n"
12151 "Neighbor to display information about\n"
12152 "Neighbor to display information about\n"
12153 "Neighbor on bgp configured interface\n"
12154 "Display the received routes from neighbor\n"
12155 "JavaScript Object Notation\n")
12156
12157 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12158 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12159 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12160 SHOW_STR
12161 IP_STR
12162 BGP_STR
12163 "Address family\n"
12164 "Address Family modifier\n"
12165 "Address Family modifier\n"
12166 "Detailed information on TCP and BGP neighbor connections\n"
12167 "Neighbor to display information about\n"
12168 "Neighbor to display information about\n"
12169 "Neighbor on bgp configured interface\n"
12170 "Display the received routes from neighbor\n"
12171 "JavaScript Object Notation\n")
12172 {
12173 struct peer *peer;
12174 const char *rmap_name = NULL;
12175 u_char uj = use_json(argc, argv);
12176
12177 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12178 if (! peer)
12179 return CMD_WARNING;
12180
12181 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12182 rmap_name = argv[2];
12183
12184 if (strncmp (argv[0], "m", 1) == 0)
12185 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj);
12186 else
12187 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12188 }
12189
12190 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12191 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
12192 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12193 SHOW_STR
12194 IP_STR
12195 BGP_STR
12196 "Address family\n"
12197 "Address Family modifier\n"
12198 "Address Family modifier\n"
12199 "Detailed information on TCP and BGP neighbor connections\n"
12200 "Neighbor to display information about\n"
12201 "Neighbor to display information about\n"
12202 "Neighbor on bgp configured interface\n"
12203 "Display the received routes from neighbor\n"
12204 "JavaScript Object Notation\n")
12205
12206 DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12207 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
12208 #ifdef HAVE_IPV6
12209 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
12210 #else
12211 "show bgp " BGP_INSTANCE_CMD " ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
12212 #endif
12213 SHOW_STR
12214 BGP_STR
12215 BGP_INSTANCE_HELP_STR
12216 "Address family\n"
12217 #ifdef HAVE_IPV6
12218 "Address family\n"
12219 #endif
12220 "Address family modifier\n"
12221 "Address family modifier\n"
12222 "Detailed information on TCP and BGP neighbor connections\n"
12223 "Neighbor to display information about\n"
12224 "Neighbor to display information about\n"
12225 "Neighbor on bgp configured interface\n"
12226 "Display the advertised routes to neighbor\n"
12227 "Display the received routes from neighbor\n"
12228 "JavaScript Object Notation\n")
12229 {
12230 int afi;
12231 int safi;
12232 int in;
12233 struct peer *peer;
12234 u_char uj = use_json(argc, argv);
12235
12236 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
12237
12238 if (! peer)
12239 return CMD_WARNING;
12240
12241 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12242 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12243 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
12244
12245 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
12246 }
12247
12248 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12249 show_ip_bgp_neighbor_received_prefix_filter_cmd,
12250 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12251 SHOW_STR
12252 IP_STR
12253 BGP_STR
12254 "Detailed information on TCP and BGP neighbor connections\n"
12255 "Neighbor to display information about\n"
12256 "Neighbor to display information about\n"
12257 "Neighbor on bgp configured interface\n"
12258 "Display information received from a BGP neighbor\n"
12259 "Display the prefixlist filter\n"
12260 "JavaScript Object Notation\n")
12261 {
12262 char name[BUFSIZ];
12263 union sockunion su;
12264 struct peer *peer;
12265 int count, ret;
12266 u_char uj = use_json(argc, argv);
12267
12268 ret = str2sockunion (argv[0], &su);
12269 if (ret < 0)
12270 {
12271 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12272 if (! peer)
12273 {
12274 if (uj)
12275 {
12276 json_object *json_no = NULL;
12277 json_object *json_sub = NULL;
12278 json_no = json_object_new_object();
12279 json_sub = json_object_new_object();
12280 json_object_string_add(json_no, "warning", "Malformed address or name");
12281 json_object_string_add(json_sub, "warningCause", argv[0]);
12282 json_object_object_add(json_no, "detail", json_sub);
12283 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12284 json_object_free(json_no);
12285 }
12286 else
12287 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12288 return CMD_WARNING;
12289 }
12290 }
12291 else
12292 {
12293 peer = peer_lookup (NULL, &su);
12294 if (! peer)
12295 {
12296 if (uj)
12297 {
12298 json_object *json_no = NULL;
12299 json_no = json_object_new_object();
12300 json_object_string_add(json_no, "warning", "Peer not found");
12301 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12302 json_object_free(json_no);
12303 }
12304 else
12305 vty_out (vty, "No peer%s", VTY_NEWLINE);
12306 return CMD_WARNING;
12307 }
12308 }
12309
12310 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12311 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12312 if (count)
12313 {
12314 if (!uj)
12315 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12316 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12317 }
12318 else
12319 {
12320 if (uj)
12321 {
12322 json_object *json_no = NULL;
12323 json_no = json_object_new_object();
12324 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12325 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12326 json_object_free(json_no);
12327 }
12328 else
12329 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12330 }
12331
12332 return CMD_SUCCESS;
12333 }
12334
12335 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12336 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
12337 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12338 SHOW_STR
12339 IP_STR
12340 BGP_STR
12341 "Address family\n"
12342 "Address Family modifier\n"
12343 "Address Family modifier\n"
12344 "Detailed information on TCP and BGP neighbor connections\n"
12345 "Neighbor to display information about\n"
12346 "Neighbor to display information about\n"
12347 "Neighbor on bgp configured interface\n"
12348 "Display information received from a BGP neighbor\n"
12349 "Display the prefixlist filter\n"
12350 "JavaScript Object Notation\n")
12351 {
12352 char name[BUFSIZ];
12353 union sockunion su;
12354 struct peer *peer;
12355 int count, ret;
12356 u_char uj = use_json(argc, argv);
12357
12358 ret = str2sockunion (argv[1], &su);
12359 if (ret < 0)
12360 {
12361 peer = peer_lookup_by_conf_if (NULL, argv[1]);
12362 if (! peer)
12363 {
12364 if (uj)
12365 {
12366 json_object *json_no = NULL;
12367 json_object *json_sub = NULL;
12368 json_no = json_object_new_object();
12369 json_sub = json_object_new_object();
12370 json_object_string_add(json_no, "warning", "Malformed address or name");
12371 json_object_string_add(json_sub, "warningCause", argv[1]);
12372 json_object_object_add(json_no, "detail", json_sub);
12373 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12374 json_object_free(json_no);
12375 }
12376 else
12377 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12378 return CMD_WARNING;
12379 }
12380 }
12381 else
12382 {
12383 peer = peer_lookup (NULL, &su);
12384 if (! peer)
12385 {
12386 if (uj)
12387 {
12388 json_object *json_no = NULL;
12389 json_no = json_object_new_object();
12390 json_object_string_add(json_no, "warning", "Peer not found");
12391 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12392 json_object_free(json_no);
12393 }
12394 else
12395 vty_out (vty, "No peer%s", VTY_NEWLINE);
12396 return CMD_WARNING;
12397 }
12398 }
12399
12400 if (strncmp (argv[0], "m", 1) == 0)
12401 {
12402 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
12403 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12404 if (count)
12405 {
12406 if (!uj)
12407 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
12408 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12409 }
12410 else
12411 {
12412 if (uj)
12413 {
12414 json_object *json_no = NULL;
12415 json_no = json_object_new_object();
12416 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12417 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12418 json_object_free(json_no);
12419 }
12420 else
12421 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12422 }
12423 }
12424 else
12425 {
12426 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12427 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12428 if (count)
12429 {
12430 if (!uj)
12431 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12432 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12433 }
12434 else
12435 {
12436 if (uj)
12437 {
12438 json_object *json_no = NULL;
12439 json_no = json_object_new_object();
12440 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12441 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12442 json_object_free(json_no);
12443 }
12444 else
12445 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12446 }
12447 }
12448
12449 return CMD_SUCCESS;
12450 }
12451 #ifdef HAVE_IPV6
12452 DEFUN (show_bgp_neighbor_received_routes,
12453 show_bgp_neighbor_received_routes_cmd,
12454 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12455 SHOW_STR
12456 BGP_STR
12457 "Detailed information on TCP and BGP neighbor connections\n"
12458 "Neighbor to display information about\n"
12459 "Neighbor to display information about\n"
12460 "Neighbor on bgp configured interface\n"
12461 "Display the received routes from neighbor\n"
12462 "JavaScript Object Notation\n")
12463 {
12464 struct peer *peer;
12465 const char *rmap_name = NULL;
12466 u_char uj = use_json(argc, argv);
12467
12468 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12469
12470 if (! peer)
12471 return CMD_WARNING;
12472
12473 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12474 rmap_name = argv[1];
12475
12476 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
12477 }
12478
12479 ALIAS (show_bgp_neighbor_received_routes,
12480 show_bgp_ipv6_neighbor_received_routes_cmd,
12481 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12482 SHOW_STR
12483 BGP_STR
12484 "Address family\n"
12485 "Detailed information on TCP and BGP neighbor connections\n"
12486 "Neighbor to display information about\n"
12487 "Neighbor to display information about\n"
12488 "Neighbor on bgp configured interface\n"
12489 "Display the received routes from neighbor\n"
12490 "JavaScript Object Notation\n")
12491
12492 DEFUN (show_bgp_neighbor_received_prefix_filter,
12493 show_bgp_neighbor_received_prefix_filter_cmd,
12494 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12495 SHOW_STR
12496 BGP_STR
12497 "Detailed information on TCP and BGP neighbor connections\n"
12498 "Neighbor to display information about\n"
12499 "Neighbor to display information about\n"
12500 "Neighbor on bgp configured interface\n"
12501 "Display information received from a BGP neighbor\n"
12502 "Display the prefixlist filter\n"
12503 "JavaScript Object Notation\n")
12504 {
12505 char name[BUFSIZ];
12506 union sockunion su;
12507 struct peer *peer;
12508 int count, ret;
12509 u_char uj = use_json(argc, argv);
12510
12511 ret = str2sockunion (argv[0], &su);
12512 if (ret < 0)
12513 {
12514 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12515 if (! peer)
12516 {
12517 if (uj)
12518 {
12519 json_object *json_no = NULL;
12520 json_object *json_sub = NULL;
12521 json_no = json_object_new_object();
12522 json_sub = json_object_new_object();
12523 json_object_string_add(json_no, "warning", "Malformed address or name");
12524 json_object_string_add(json_sub, "warningCause", argv[0]);
12525 json_object_object_add(json_no, "detail", json_sub);
12526 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12527 json_object_free(json_no);
12528 }
12529 else
12530 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12531 return CMD_WARNING;
12532 }
12533 }
12534 else
12535 {
12536 peer = peer_lookup (NULL, &su);
12537 if (! peer)
12538 {
12539 if (uj)
12540 {
12541 json_object *json_no = NULL;
12542 json_no = json_object_new_object();
12543 json_object_string_add(json_no, "warning", "No Peer");
12544 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12545 json_object_free(json_no);
12546 }
12547 else
12548 vty_out (vty, "No peer%s", VTY_NEWLINE);
12549 return CMD_WARNING;
12550 }
12551 }
12552
12553 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12554 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
12555 if (count)
12556 {
12557 if (!uj)
12558 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12559 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
12560 }
12561 else
12562 {
12563 if (uj)
12564 {
12565 json_object *json_no = NULL;
12566 json_no = json_object_new_object();
12567 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12568 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12569 json_object_free(json_no);
12570 }
12571 else
12572 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12573 }
12574
12575 return CMD_SUCCESS;
12576 }
12577
12578 ALIAS (show_bgp_neighbor_received_prefix_filter,
12579 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
12580 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12581 SHOW_STR
12582 BGP_STR
12583 "Address family\n"
12584 "Detailed information on TCP and BGP neighbor connections\n"
12585 "Neighbor to display information about\n"
12586 "Neighbor to display information about\n"
12587 "Neighbor on bgp configured interface\n"
12588 "Display information received from a BGP neighbor\n"
12589 "Display the prefixlist filter\n"
12590 "JavaScript Object Notation\n")
12591
12592 /* old command */
12593 ALIAS (show_bgp_neighbor_received_routes,
12594 ipv6_bgp_neighbor_received_routes_cmd,
12595 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12596 SHOW_STR
12597 IPV6_STR
12598 BGP_STR
12599 "Detailed information on TCP and BGP neighbor connections\n"
12600 "Neighbor to display information about\n"
12601 "Neighbor to display information about\n"
12602 "Neighbor on bgp configured interface\n"
12603 "Display the received routes from neighbor\n"
12604 "JavaScript Object Notation\n")
12605
12606 /* old command */
12607 DEFUN (ipv6_mbgp_neighbor_received_routes,
12608 ipv6_mbgp_neighbor_received_routes_cmd,
12609 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12610 SHOW_STR
12611 IPV6_STR
12612 MBGP_STR
12613 "Detailed information on TCP and BGP neighbor connections\n"
12614 "Neighbor to display information about\n"
12615 "Neighbor to display information about\n"
12616 "Neighbor on bgp configured interface\n"
12617 "Display the received routes from neighbor\n"
12618 "JavaScript Object Notation\n")
12619 {
12620 struct peer *peer;
12621 u_char uj = use_json(argc, argv);
12622
12623 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12624 if (! peer)
12625 return CMD_WARNING;
12626
12627 bgp_show_ipv6_bgp_deprecate_warning(vty);
12628 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
12629 }
12630
12631 DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
12632 show_bgp_instance_neighbor_received_prefix_filter_cmd,
12633 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12634 SHOW_STR
12635 BGP_STR
12636 BGP_INSTANCE_HELP_STR
12637 "Detailed information on TCP and BGP neighbor connections\n"
12638 "Neighbor to display information about\n"
12639 "Neighbor to display information about\n"
12640 "Neighbor on bgp configured interface\n"
12641 "Display information received from a BGP neighbor\n"
12642 "Display the prefixlist filter\n"
12643 "JavaScript Object Notation\n")
12644 {
12645 char name[BUFSIZ];
12646 union sockunion su;
12647 struct peer *peer;
12648 struct bgp *bgp;
12649 int count, ret;
12650 u_char uj = use_json(argc, argv);
12651
12652 /* BGP structure lookup. */
12653 bgp = bgp_lookup_by_name (argv[1]);
12654 if (bgp == NULL)
12655 {
12656 if (uj)
12657 {
12658 json_object *json_no = NULL;
12659 json_no = json_object_new_object();
12660 json_object_string_add(json_no, "warning", "Can't find BGP view");
12661 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12662 json_object_free(json_no);
12663 }
12664 else
12665 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
12666 return CMD_WARNING;
12667 }
12668
12669 ret = str2sockunion (argv[2], &su);
12670 if (ret < 0)
12671 {
12672 peer = peer_lookup_by_conf_if (bgp, argv[2]);
12673 if (! peer)
12674 {
12675 if (uj)
12676 {
12677 json_object *json_no = NULL;
12678 json_object *json_sub = NULL;
12679 json_no = json_object_new_object();
12680 json_sub = json_object_new_object();
12681 json_object_string_add(json_no, "warning", "Malformed address or name");
12682 json_object_string_add(json_sub, "warningCause", argv[2]);
12683 json_object_object_add(json_no, "detail", json_sub);
12684 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12685 json_object_free(json_no);
12686 }
12687 else
12688 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
12689 return CMD_WARNING;
12690 }
12691 }
12692 else
12693 {
12694 peer = peer_lookup (bgp, &su);
12695 if (! peer)
12696 {
12697 if (uj)
12698 {
12699 json_object *json_no = NULL;
12700 json_no = json_object_new_object();
12701 json_object_boolean_true_add(json_no, "noPeer");
12702 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12703 json_object_free(json_no);
12704 }
12705 else
12706 vty_out (vty, "No peer%s", VTY_NEWLINE);
12707 return CMD_WARNING;
12708 }
12709
12710 }
12711
12712 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12713 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
12714 if (count)
12715 {
12716 if (!uj)
12717 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12718 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
12719 }
12720
12721 return CMD_SUCCESS;
12722 }
12723 ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
12724 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
12725 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12726 SHOW_STR
12727 BGP_STR
12728 BGP_INSTANCE_HELP_STR
12729 "Address family\n"
12730 "Detailed information on TCP and BGP neighbor connections\n"
12731 "Neighbor to display information about\n"
12732 "Neighbor to display information about\n"
12733 "Neighbor on bgp configured interface\n"
12734 "Display information received from a BGP neighbor\n"
12735 "Display the prefixlist filter\n"
12736 "JavaScript Object NOtation\n")
12737 #endif /* HAVE_IPV6 */
12738
12739 static int
12740 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
12741 safi_t safi, enum bgp_show_type type, u_char use_json)
12742 {
12743 if (! peer || ! peer->afc[afi][safi])
12744 {
12745 if (use_json)
12746 {
12747 json_object *json_no = NULL;
12748 json_no = json_object_new_object();
12749 json_object_string_add(json_no, "warning", "No such neighbor or address family");
12750 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12751 json_object_free(json_no);
12752 }
12753 else
12754 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12755 return CMD_WARNING;
12756 }
12757
12758 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
12759 }
12760
12761 DEFUN (show_ip_bgp_neighbor_routes,
12762 show_ip_bgp_neighbor_routes_cmd,
12763 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12764 SHOW_STR
12765 IP_STR
12766 BGP_STR
12767 "Detailed information on TCP and BGP neighbor connections\n"
12768 "Neighbor to display information about\n"
12769 "Neighbor to display information about\n"
12770 "Neighbor on bgp configured interface\n"
12771 "Display routes learned from neighbor\n"
12772 "JavaScript Object Notation\n")
12773 {
12774 struct peer *peer;
12775 u_char uj = use_json(argc, argv);
12776
12777 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12778 if (! peer)
12779 return CMD_WARNING;
12780
12781 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12782 bgp_show_type_neighbor, uj);
12783 }
12784
12785 DEFUN (show_ip_bgp_instance_neighbor_routes,
12786 show_ip_bgp_instance_neighbor_routes_cmd,
12787 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12788 SHOW_STR
12789 IP_STR
12790 BGP_STR
12791 BGP_INSTANCE_HELP_STR
12792 "Detailed information on TCP and BGP neighbor connections\n"
12793 "Neighbor to display information about\n"
12794 "Neighbor to display information about\n"
12795 "Neighbor on bgp configured interface\n"
12796 "Display routes learned from neighbor\n"
12797 "JavaScript Object Notation\n")
12798 {
12799 struct peer *peer;
12800 u_char uj = use_json(argc, argv);
12801
12802 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12803 if (! peer)
12804 return CMD_WARNING;
12805
12806 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12807 bgp_show_type_neighbor, uj);
12808 }
12809
12810 DEFUN (show_ip_bgp_neighbor_flap,
12811 show_ip_bgp_neighbor_flap_cmd,
12812 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
12813 SHOW_STR
12814 IP_STR
12815 BGP_STR
12816 "Detailed information on TCP and BGP neighbor connections\n"
12817 "Neighbor to display information about\n"
12818 "Neighbor to display information about\n"
12819 "Neighbor on bgp configured interface\n"
12820 "Display flap statistics of the routes learned from neighbor\n"
12821 "JavaScript Object Notation\n")
12822 {
12823 struct peer *peer;
12824 u_char uj = use_json(argc, argv);
12825
12826 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12827 if (! peer)
12828 return CMD_WARNING;
12829
12830 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12831 bgp_show_type_flap_neighbor, uj);
12832 }
12833
12834 DEFUN (show_ip_bgp_neighbor_damp,
12835 show_ip_bgp_neighbor_damp_cmd,
12836 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
12837 SHOW_STR
12838 IP_STR
12839 BGP_STR
12840 "Detailed information on TCP and BGP neighbor connections\n"
12841 "Neighbor to display information about\n"
12842 "Neighbor to display information about\n"
12843 "Neighbor on bgp configured interface\n"
12844 "Display the dampened routes received from neighbor\n"
12845 "JavaScript Object Notation\n")
12846 {
12847 struct peer *peer;
12848 u_char uj = use_json(argc, argv);
12849
12850 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12851 if (! peer)
12852 return CMD_WARNING;
12853
12854 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12855 bgp_show_type_damp_neighbor, uj);
12856 }
12857
12858 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
12859 show_ip_bgp_ipv4_neighbor_routes_cmd,
12860 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12861 SHOW_STR
12862 IP_STR
12863 BGP_STR
12864 "Address family\n"
12865 "Address Family modifier\n"
12866 "Address Family modifier\n"
12867 "Detailed information on TCP and BGP neighbor connections\n"
12868 "Neighbor to display information about\n"
12869 "Neighbor to display information about\n"
12870 "Neighbor on bgp configured interface\n"
12871 "Display routes learned from neighbor\n"
12872 "JavaScript Object Notation\n")
12873 {
12874 struct peer *peer;
12875 u_char uj = use_json(argc, argv);
12876
12877 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12878 if (! peer)
12879 return CMD_WARNING;
12880
12881 if (strncmp (argv[0], "m", 1) == 0)
12882 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
12883 bgp_show_type_neighbor, uj);
12884
12885 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
12886 bgp_show_type_neighbor, uj);
12887 }
12888
12889 #ifdef HAVE_IPV6
12890 DEFUN (show_bgp_instance_neighbor_routes,
12891 show_bgp_instance_neighbor_routes_cmd,
12892 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12893 SHOW_STR
12894 BGP_STR
12895 BGP_INSTANCE_HELP_STR
12896 "Detailed information on TCP and BGP neighbor connections\n"
12897 "Neighbor to display information about\n"
12898 "Neighbor to display information about\n"
12899 "Neighbor on bgp configured interface\n"
12900 "Display routes learned from neighbor\n"
12901 "JavaScript Object Notation\n")
12902 {
12903 struct peer *peer;
12904 u_char uj = use_json(argc, argv);
12905
12906 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12907 if (! peer)
12908 return CMD_WARNING;
12909
12910 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12911 bgp_show_type_neighbor, uj);
12912 }
12913
12914 ALIAS (show_bgp_instance_neighbor_routes,
12915 show_bgp_instance_ipv6_neighbor_routes_cmd,
12916 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
12917 SHOW_STR
12918 BGP_STR
12919 BGP_INSTANCE_HELP_STR
12920 "Address family\n"
12921 "Detailed information on TCP and BGP neighbor connections\n"
12922 "Neighbor to display information about\n"
12923 "Neighbor to display information about\n"
12924 "Neighbor on bgp configured interface\n"
12925 "Display routes learned from neighbor\n"
12926 "JavaScript Object Notation\n")
12927
12928 DEFUN (show_bgp_instance_neighbor_damp,
12929 show_bgp_instance_neighbor_damp_cmd,
12930 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
12931 SHOW_STR
12932 BGP_STR
12933 BGP_INSTANCE_HELP_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 the dampened routes received from neighbor\n"
12939 "JavaScript Object Notation\n")
12940 {
12941 struct peer *peer;
12942 u_char uj = use_json(argc, argv);
12943
12944 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
12945 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12946 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12947 else
12948 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12949
12950 if (! peer)
12951 return CMD_WARNING;
12952
12953 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12954 bgp_show_type_damp_neighbor, uj);
12955 }
12956
12957 ALIAS (show_bgp_instance_neighbor_damp,
12958 show_bgp_instance_ipv6_neighbor_damp_cmd,
12959 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
12960 SHOW_STR
12961 BGP_STR
12962 BGP_INSTANCE_HELP_STR
12963 "Address family\n"
12964 "Detailed information on TCP and BGP neighbor connections\n"
12965 "Neighbor to display information about\n"
12966 "Neighbor to display information about\n"
12967 "Neighbor on bgp configured interface\n"
12968 "Display the dampened routes received from neighbor\n"
12969 "JavaScript Object Notation\n")
12970
12971 DEFUN (show_bgp_instance_neighbor_flap,
12972 show_bgp_instance_neighbor_flap_cmd,
12973 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
12974 SHOW_STR
12975 BGP_STR
12976 BGP_INSTANCE_HELP_STR
12977 "Detailed information on TCP and BGP neighbor connections\n"
12978 "Neighbor to display information about\n"
12979 "Neighbor to display information about\n"
12980 "Neighbor on bgp configured interface\n"
12981 "Display flap statistics of the routes learned from neighbor\n"
12982 "JavaScript Object Notation\n")
12983 {
12984 struct peer *peer;
12985 u_char uj = use_json(argc, argv);
12986
12987 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
12988 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12989 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12990 else
12991 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12992
12993 if (! peer)
12994 return CMD_WARNING;
12995
12996 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
12997 bgp_show_type_flap_neighbor, uj);
12998 }
12999
13000 ALIAS (show_bgp_instance_neighbor_flap,
13001 show_bgp_instance_ipv6_neighbor_flap_cmd,
13002 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13003 SHOW_STR
13004 BGP_STR
13005 BGP_INSTANCE_HELP_STR
13006 "Address family\n"
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 flap statistics of the routes learned from neighbor\n"
13012 "JavaScript Object Notation\n")
13013
13014 DEFUN (show_bgp_neighbor_routes,
13015 show_bgp_neighbor_routes_cmd,
13016 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13017 SHOW_STR
13018 BGP_STR
13019 "Detailed information on TCP and BGP neighbor connections\n"
13020 "Neighbor to display information about\n"
13021 "Neighbor to display information about\n"
13022 "Neighbor on bgp configured interface\n"
13023 "Display routes learned from neighbor\n"
13024 "JavaScript Object Notation\n")
13025 {
13026 struct peer *peer;
13027 u_char uj = use_json(argc, argv);
13028
13029 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13030 if (! peer)
13031 return CMD_WARNING;
13032
13033 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13034 bgp_show_type_neighbor, uj);
13035 }
13036
13037
13038 ALIAS (show_bgp_neighbor_routes,
13039 show_bgp_ipv6_neighbor_routes_cmd,
13040 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13041 SHOW_STR
13042 BGP_STR
13043 "Address family\n"
13044 "Detailed information on TCP and BGP neighbor connections\n"
13045 "Neighbor to display information about\n"
13046 "Neighbor to display information about\n"
13047 "Neighbor on bgp configured interface\n"
13048 "Display routes learned from neighbor\n"
13049 "JavaScript Object Notation\n")
13050
13051 /* old command */
13052 ALIAS (show_bgp_neighbor_routes,
13053 ipv6_bgp_neighbor_routes_cmd,
13054 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13055 SHOW_STR
13056 IPV6_STR
13057 BGP_STR
13058 "Detailed information on TCP and BGP neighbor connections\n"
13059 "Neighbor to display information about\n"
13060 "Neighbor to display information about\n"
13061 "Neighbor on bgp configured interface\n"
13062 "Display routes learned from neighbor\n"
13063 "JavaScript Object Notation\n")
13064
13065 /* old command */
13066 DEFUN (ipv6_mbgp_neighbor_routes,
13067 ipv6_mbgp_neighbor_routes_cmd,
13068 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13069 SHOW_STR
13070 IPV6_STR
13071 MBGP_STR
13072 "Detailed information on TCP and BGP neighbor connections\n"
13073 "Neighbor to display information about\n"
13074 "Neighbor to display information about\n"
13075 "Neighbor on bgp configured interface\n"
13076 "Display routes learned from neighbor\n"
13077 "JavaScript Object Notation\n")
13078 {
13079 struct peer *peer;
13080 u_char uj = use_json(argc, argv);
13081
13082 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13083 if (! peer)
13084 return CMD_WARNING;
13085
13086 bgp_show_ipv6_bgp_deprecate_warning(vty);
13087 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
13088 bgp_show_type_neighbor, uj);
13089 }
13090
13091 ALIAS (show_bgp_instance_neighbor_flap,
13092 show_bgp_neighbor_flap_cmd,
13093 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13094 SHOW_STR
13095 BGP_STR
13096 "Detailed information on TCP and BGP neighbor connections\n"
13097 "Neighbor to display information about\n"
13098 "Neighbor to display information about\n"
13099 "Neighbor on bgp configured interface\n"
13100 "Display flap statistics of the routes learned from neighbor\n"
13101 "JavaScript Object Notation\n")
13102
13103 ALIAS (show_bgp_instance_neighbor_flap,
13104 show_bgp_ipv6_neighbor_flap_cmd,
13105 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13106 SHOW_STR
13107 BGP_STR
13108 "Address family\n"
13109 "Detailed information on TCP and BGP neighbor connections\n"
13110 "Neighbor to display information about\n"
13111 "Neighbor to display information about\n"
13112 "Neighbor on bgp configured interface\n"
13113 "Display flap statistics of the routes learned from neighbor\n"
13114 "JavaScript Object Notation\n")
13115
13116 ALIAS (show_bgp_instance_neighbor_damp,
13117 show_bgp_neighbor_damp_cmd,
13118 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13119 SHOW_STR
13120 BGP_STR
13121 "Detailed information on TCP and BGP neighbor connections\n"
13122 "Neighbor to display information about\n"
13123 "Neighbor to display information about\n"
13124 "Neighbor on bgp configured interface\n"
13125 "Display the dampened routes received from neighbor\n"
13126 "JavaScript Object Notation\n")
13127
13128 ALIAS (show_bgp_instance_neighbor_damp,
13129 show_bgp_ipv6_neighbor_damp_cmd,
13130 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13131 SHOW_STR
13132 BGP_STR
13133 "Address family\n"
13134 "Detailed information on TCP and BGP neighbor connections\n"
13135 "Neighbor to display information about\n"
13136 "Neighbor to display information about\n"
13137 "Neighbor on bgp configured interface\n"
13138 "Display the dampened routes received from neighbor\n"
13139 "JavaScript Object Notation\n")
13140
13141 #endif /* HAVE_IPV6 */
13142
13143 struct bgp_table *bgp_distance_table;
13144
13145 struct bgp_distance
13146 {
13147 /* Distance value for the IP source prefix. */
13148 u_char distance;
13149
13150 /* Name of the access-list to be matched. */
13151 char *access_list;
13152 };
13153
13154 static struct bgp_distance *
13155 bgp_distance_new (void)
13156 {
13157 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
13158 }
13159
13160 static void
13161 bgp_distance_free (struct bgp_distance *bdistance)
13162 {
13163 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13164 }
13165
13166 static int
13167 bgp_distance_set (struct vty *vty, const char *distance_str,
13168 const char *ip_str, const char *access_list_str)
13169 {
13170 int ret;
13171 struct prefix_ipv4 p;
13172 u_char distance;
13173 struct bgp_node *rn;
13174 struct bgp_distance *bdistance;
13175
13176 ret = str2prefix_ipv4 (ip_str, &p);
13177 if (ret == 0)
13178 {
13179 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13180 return CMD_WARNING;
13181 }
13182
13183 distance = atoi (distance_str);
13184
13185 /* Get BGP distance node. */
13186 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
13187 if (rn->info)
13188 {
13189 bdistance = rn->info;
13190 bgp_unlock_node (rn);
13191 }
13192 else
13193 {
13194 bdistance = bgp_distance_new ();
13195 rn->info = bdistance;
13196 }
13197
13198 /* Set distance value. */
13199 bdistance->distance = distance;
13200
13201 /* Reset access-list configuration. */
13202 if (bdistance->access_list)
13203 {
13204 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13205 bdistance->access_list = NULL;
13206 }
13207 if (access_list_str)
13208 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
13209
13210 return CMD_SUCCESS;
13211 }
13212
13213 static int
13214 bgp_distance_unset (struct vty *vty, const char *distance_str,
13215 const char *ip_str, const char *access_list_str)
13216 {
13217 int ret;
13218 struct prefix_ipv4 p;
13219 struct bgp_node *rn;
13220 struct bgp_distance *bdistance;
13221
13222 ret = str2prefix_ipv4 (ip_str, &p);
13223 if (ret == 0)
13224 {
13225 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13226 return CMD_WARNING;
13227 }
13228
13229 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
13230 if (! rn)
13231 {
13232 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13233 return CMD_WARNING;
13234 }
13235
13236 bdistance = rn->info;
13237
13238 if (bdistance->access_list)
13239 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13240 bgp_distance_free (bdistance);
13241
13242 rn->info = NULL;
13243 bgp_unlock_node (rn);
13244 bgp_unlock_node (rn);
13245
13246 return CMD_SUCCESS;
13247 }
13248
13249 /* Apply BGP information to distance method. */
13250 u_char
13251 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
13252 {
13253 struct bgp_node *rn;
13254 struct prefix_ipv4 q;
13255 struct peer *peer;
13256 struct bgp_distance *bdistance;
13257 struct access_list *alist;
13258 struct bgp_static *bgp_static;
13259
13260 if (! bgp)
13261 return 0;
13262
13263 if (p->family != AF_INET)
13264 return 0;
13265
13266 peer = rinfo->peer;
13267
13268 if (peer->su.sa.sa_family != AF_INET)
13269 return 0;
13270
13271 memset (&q, 0, sizeof (struct prefix_ipv4));
13272 q.family = AF_INET;
13273 q.prefix = peer->su.sin.sin_addr;
13274 q.prefixlen = IPV4_MAX_BITLEN;
13275
13276 /* Check source address. */
13277 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
13278 if (rn)
13279 {
13280 bdistance = rn->info;
13281 bgp_unlock_node (rn);
13282
13283 if (bdistance->access_list)
13284 {
13285 alist = access_list_lookup (AFI_IP, bdistance->access_list);
13286 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13287 return bdistance->distance;
13288 }
13289 else
13290 return bdistance->distance;
13291 }
13292
13293 /* Backdoor check. */
13294 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
13295 if (rn)
13296 {
13297 bgp_static = rn->info;
13298 bgp_unlock_node (rn);
13299
13300 if (bgp_static->backdoor)
13301 {
13302 if (bgp->distance_local)
13303 return bgp->distance_local;
13304 else
13305 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13306 }
13307 }
13308
13309 if (peer->sort == BGP_PEER_EBGP)
13310 {
13311 if (bgp->distance_ebgp)
13312 return bgp->distance_ebgp;
13313 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13314 }
13315 else
13316 {
13317 if (bgp->distance_ibgp)
13318 return bgp->distance_ibgp;
13319 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13320 }
13321 }
13322
13323 DEFUN (bgp_distance,
13324 bgp_distance_cmd,
13325 "distance bgp <1-255> <1-255> <1-255>",
13326 "Define an administrative distance\n"
13327 "BGP distance\n"
13328 "Distance for routes external to the AS\n"
13329 "Distance for routes internal to the AS\n"
13330 "Distance for local routes\n")
13331 {
13332 struct bgp *bgp;
13333
13334 bgp = vty->index;
13335
13336 bgp->distance_ebgp = atoi (argv[0]);
13337 bgp->distance_ibgp = atoi (argv[1]);
13338 bgp->distance_local = atoi (argv[2]);
13339 return CMD_SUCCESS;
13340 }
13341
13342 DEFUN (no_bgp_distance,
13343 no_bgp_distance_cmd,
13344 "no distance bgp <1-255> <1-255> <1-255>",
13345 NO_STR
13346 "Define an administrative distance\n"
13347 "BGP distance\n"
13348 "Distance for routes external to the AS\n"
13349 "Distance for routes internal to the AS\n"
13350 "Distance for local routes\n")
13351 {
13352 struct bgp *bgp;
13353
13354 bgp = vty->index;
13355
13356 bgp->distance_ebgp= 0;
13357 bgp->distance_ibgp = 0;
13358 bgp->distance_local = 0;
13359 return CMD_SUCCESS;
13360 }
13361
13362 ALIAS (no_bgp_distance,
13363 no_bgp_distance2_cmd,
13364 "no distance bgp",
13365 NO_STR
13366 "Define an administrative distance\n"
13367 "BGP distance\n")
13368
13369 DEFUN (bgp_distance_source,
13370 bgp_distance_source_cmd,
13371 "distance <1-255> A.B.C.D/M",
13372 "Define an administrative distance\n"
13373 "Administrative distance\n"
13374 "IP source prefix\n")
13375 {
13376 bgp_distance_set (vty, argv[0], argv[1], NULL);
13377 return CMD_SUCCESS;
13378 }
13379
13380 DEFUN (no_bgp_distance_source,
13381 no_bgp_distance_source_cmd,
13382 "no distance <1-255> A.B.C.D/M",
13383 NO_STR
13384 "Define an administrative distance\n"
13385 "Administrative distance\n"
13386 "IP source prefix\n")
13387 {
13388 bgp_distance_unset (vty, argv[0], argv[1], NULL);
13389 return CMD_SUCCESS;
13390 }
13391
13392 DEFUN (bgp_distance_source_access_list,
13393 bgp_distance_source_access_list_cmd,
13394 "distance <1-255> A.B.C.D/M WORD",
13395 "Define an administrative distance\n"
13396 "Administrative distance\n"
13397 "IP source prefix\n"
13398 "Access list name\n")
13399 {
13400 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
13401 return CMD_SUCCESS;
13402 }
13403
13404 DEFUN (no_bgp_distance_source_access_list,
13405 no_bgp_distance_source_access_list_cmd,
13406 "no distance <1-255> A.B.C.D/M WORD",
13407 NO_STR
13408 "Define an administrative distance\n"
13409 "Administrative distance\n"
13410 "IP source prefix\n"
13411 "Access list name\n")
13412 {
13413 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
13414 return CMD_SUCCESS;
13415 }
13416
13417 DEFUN (bgp_damp_set,
13418 bgp_damp_set_cmd,
13419 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13420 "BGP Specific commands\n"
13421 "Enable route-flap dampening\n"
13422 "Half-life time for the penalty\n"
13423 "Value to start reusing a route\n"
13424 "Value to start suppressing a route\n"
13425 "Maximum duration to suppress a stable route\n")
13426 {
13427 struct bgp *bgp;
13428 int half = DEFAULT_HALF_LIFE * 60;
13429 int reuse = DEFAULT_REUSE;
13430 int suppress = DEFAULT_SUPPRESS;
13431 int max = 4 * half;
13432
13433 if (argc == 4)
13434 {
13435 half = atoi (argv[0]) * 60;
13436 reuse = atoi (argv[1]);
13437 suppress = atoi (argv[2]);
13438 max = atoi (argv[3]) * 60;
13439 }
13440 else if (argc == 1)
13441 {
13442 half = atoi (argv[0]) * 60;
13443 max = 4 * half;
13444 }
13445
13446 bgp = vty->index;
13447 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
13448 half, reuse, suppress, max);
13449 }
13450
13451 ALIAS (bgp_damp_set,
13452 bgp_damp_set2_cmd,
13453 "bgp dampening <1-45>",
13454 "BGP Specific commands\n"
13455 "Enable route-flap dampening\n"
13456 "Half-life time for the penalty\n")
13457
13458 ALIAS (bgp_damp_set,
13459 bgp_damp_set3_cmd,
13460 "bgp dampening",
13461 "BGP Specific commands\n"
13462 "Enable route-flap dampening\n")
13463
13464 DEFUN (bgp_damp_unset,
13465 bgp_damp_unset_cmd,
13466 "no bgp dampening",
13467 NO_STR
13468 "BGP Specific commands\n"
13469 "Enable route-flap dampening\n")
13470 {
13471 struct bgp *bgp;
13472
13473 bgp = vty->index;
13474 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
13475 }
13476
13477 ALIAS (bgp_damp_unset,
13478 bgp_damp_unset2_cmd,
13479 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
13480 NO_STR
13481 "BGP Specific commands\n"
13482 "Enable route-flap dampening\n"
13483 "Half-life time for the penalty\n"
13484 "Value to start reusing a route\n"
13485 "Value to start suppressing a route\n"
13486 "Maximum duration to suppress a stable route\n")
13487
13488 ALIAS (bgp_damp_unset,
13489 bgp_damp_unset3_cmd,
13490 "no bgp dampening <1-45>",
13491 NO_STR
13492 "BGP Specific commands\n"
13493 "Enable route-flap dampening\n"
13494 "Half-life time for the penalty\n")
13495
13496 DEFUN (show_ip_bgp_dampened_paths,
13497 show_ip_bgp_dampened_paths_cmd,
13498 "show ip bgp dampened-paths",
13499 SHOW_STR
13500 IP_STR
13501 BGP_STR
13502 "Display paths suppressed due to dampening\n")
13503 {
13504 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
13505 NULL, 0);
13506 }
13507
13508 DEFUN (show_ip_bgp_flap_statistics,
13509 show_ip_bgp_flap_statistics_cmd,
13510 "show ip bgp flap-statistics",
13511 SHOW_STR
13512 IP_STR
13513 BGP_STR
13514 "Display flap statistics of routes\n")
13515 {
13516 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
13517 bgp_show_type_flap_statistics, NULL, 0);
13518 }
13519
13520 /* Display specified route of BGP table. */
13521 static int
13522 bgp_clear_damp_route (struct vty *vty, const char *view_name,
13523 const char *ip_str, afi_t afi, safi_t safi,
13524 struct prefix_rd *prd, int prefix_check)
13525 {
13526 int ret;
13527 struct prefix match;
13528 struct bgp_node *rn;
13529 struct bgp_node *rm;
13530 struct bgp_info *ri;
13531 struct bgp_info *ri_temp;
13532 struct bgp *bgp;
13533 struct bgp_table *table;
13534
13535 /* BGP structure lookup. */
13536 if (view_name)
13537 {
13538 bgp = bgp_lookup_by_name (view_name);
13539 if (bgp == NULL)
13540 {
13541 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
13542 return CMD_WARNING;
13543 }
13544 }
13545 else
13546 {
13547 bgp = bgp_get_default ();
13548 if (bgp == NULL)
13549 {
13550 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
13551 return CMD_WARNING;
13552 }
13553 }
13554
13555 /* Check IP address argument. */
13556 ret = str2prefix (ip_str, &match);
13557 if (! ret)
13558 {
13559 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
13560 return CMD_WARNING;
13561 }
13562
13563 match.family = afi2family (afi);
13564
13565 if (safi == SAFI_MPLS_VPN)
13566 {
13567 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
13568 {
13569 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
13570 continue;
13571
13572 if ((table = rn->info) != NULL)
13573 if ((rm = bgp_node_match (table, &match)) != NULL)
13574 {
13575 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
13576 {
13577 ri = rm->info;
13578 while (ri)
13579 {
13580 if (ri->extra && ri->extra->damp_info)
13581 {
13582 ri_temp = ri->next;
13583 bgp_damp_info_free (ri->extra->damp_info, 1);
13584 ri = ri_temp;
13585 }
13586 else
13587 ri = ri->next;
13588 }
13589 }
13590
13591 bgp_unlock_node (rm);
13592 }
13593 }
13594 }
13595 else
13596 {
13597 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
13598 {
13599 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
13600 {
13601 ri = rn->info;
13602 while (ri)
13603 {
13604 if (ri->extra && ri->extra->damp_info)
13605 {
13606 ri_temp = ri->next;
13607 bgp_damp_info_free (ri->extra->damp_info, 1);
13608 ri = ri_temp;
13609 }
13610 else
13611 ri = ri->next;
13612 }
13613 }
13614
13615 bgp_unlock_node (rn);
13616 }
13617 }
13618
13619 return CMD_SUCCESS;
13620 }
13621
13622 DEFUN (clear_ip_bgp_dampening,
13623 clear_ip_bgp_dampening_cmd,
13624 "clear ip bgp dampening",
13625 CLEAR_STR
13626 IP_STR
13627 BGP_STR
13628 "Clear route flap dampening information\n")
13629 {
13630 bgp_damp_info_clean ();
13631 return CMD_SUCCESS;
13632 }
13633
13634 DEFUN (clear_ip_bgp_dampening_prefix,
13635 clear_ip_bgp_dampening_prefix_cmd,
13636 "clear ip bgp dampening A.B.C.D/M",
13637 CLEAR_STR
13638 IP_STR
13639 BGP_STR
13640 "Clear route flap dampening information\n"
13641 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13642 {
13643 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13644 SAFI_UNICAST, NULL, 1);
13645 }
13646
13647 DEFUN (clear_ip_bgp_dampening_address,
13648 clear_ip_bgp_dampening_address_cmd,
13649 "clear ip bgp dampening A.B.C.D",
13650 CLEAR_STR
13651 IP_STR
13652 BGP_STR
13653 "Clear route flap dampening information\n"
13654 "Network to clear damping information\n")
13655 {
13656 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
13657 SAFI_UNICAST, NULL, 0);
13658 }
13659
13660 DEFUN (clear_ip_bgp_dampening_address_mask,
13661 clear_ip_bgp_dampening_address_mask_cmd,
13662 "clear ip bgp dampening A.B.C.D A.B.C.D",
13663 CLEAR_STR
13664 IP_STR
13665 BGP_STR
13666 "Clear route flap dampening information\n"
13667 "Network to clear damping information\n"
13668 "Network mask\n")
13669 {
13670 int ret;
13671 char prefix_str[BUFSIZ];
13672
13673 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
13674 if (! ret)
13675 {
13676 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
13677 return CMD_WARNING;
13678 }
13679
13680 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
13681 SAFI_UNICAST, NULL, 0);
13682 }
13683
13684 static int
13685 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
13686 afi_t afi, safi_t safi, int *write)
13687 {
13688 struct bgp_node *prn;
13689 struct bgp_node *rn;
13690 struct bgp_table *table;
13691 struct prefix *p;
13692 struct prefix_rd *prd;
13693 struct bgp_static *bgp_static;
13694 u_int32_t label;
13695 char buf[SU_ADDRSTRLEN];
13696 char rdbuf[RD_ADDRSTRLEN];
13697
13698 /* Network configuration. */
13699 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
13700 if ((table = prn->info) != NULL)
13701 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
13702 if ((bgp_static = rn->info) != NULL)
13703 {
13704 p = &rn->p;
13705 prd = (struct prefix_rd *) &prn->p;
13706
13707 /* "address-family" display. */
13708 bgp_config_write_family_header (vty, afi, safi, write);
13709
13710 /* "network" configuration display. */
13711 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
13712 label = decode_label (bgp_static->tag);
13713
13714 vty_out (vty, " network %s/%d rd %s tag %d",
13715 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13716 p->prefixlen,
13717 rdbuf, label);
13718 vty_out (vty, "%s", VTY_NEWLINE);
13719 }
13720 return 0;
13721 }
13722
13723 /* Configuration of static route announcement and aggregate
13724 information. */
13725 int
13726 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
13727 afi_t afi, safi_t safi, int *write)
13728 {
13729 struct bgp_node *rn;
13730 struct prefix *p;
13731 struct bgp_static *bgp_static;
13732 struct bgp_aggregate *bgp_aggregate;
13733 char buf[SU_ADDRSTRLEN];
13734
13735 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
13736 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
13737
13738 /* Network configuration. */
13739 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
13740 if ((bgp_static = rn->info) != NULL)
13741 {
13742 p = &rn->p;
13743
13744 /* "address-family" display. */
13745 bgp_config_write_family_header (vty, afi, safi, write);
13746
13747 /* "network" configuration display. */
13748 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13749 {
13750 u_int32_t destination;
13751 struct in_addr netmask;
13752
13753 destination = ntohl (p->u.prefix4.s_addr);
13754 masklen2ip (p->prefixlen, &netmask);
13755 vty_out (vty, " network %s",
13756 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
13757
13758 if ((IN_CLASSC (destination) && p->prefixlen == 24)
13759 || (IN_CLASSB (destination) && p->prefixlen == 16)
13760 || (IN_CLASSA (destination) && p->prefixlen == 8)
13761 || p->u.prefix4.s_addr == 0)
13762 {
13763 /* Natural mask is not display. */
13764 }
13765 else
13766 vty_out (vty, " mask %s", inet_ntoa (netmask));
13767 }
13768 else
13769 {
13770 vty_out (vty, " network %s/%d",
13771 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13772 p->prefixlen);
13773 }
13774
13775 if (bgp_static->rmap.name)
13776 vty_out (vty, " route-map %s", bgp_static->rmap.name);
13777 else
13778 {
13779 if (bgp_static->backdoor)
13780 vty_out (vty, " backdoor");
13781 }
13782
13783 vty_out (vty, "%s", VTY_NEWLINE);
13784 }
13785
13786 /* Aggregate-address configuration. */
13787 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
13788 if ((bgp_aggregate = rn->info) != NULL)
13789 {
13790 p = &rn->p;
13791
13792 /* "address-family" display. */
13793 bgp_config_write_family_header (vty, afi, safi, write);
13794
13795 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
13796 {
13797 struct in_addr netmask;
13798
13799 masklen2ip (p->prefixlen, &netmask);
13800 vty_out (vty, " aggregate-address %s %s",
13801 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13802 inet_ntoa (netmask));
13803 }
13804 else
13805 {
13806 vty_out (vty, " aggregate-address %s/%d",
13807 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
13808 p->prefixlen);
13809 }
13810
13811 if (bgp_aggregate->as_set)
13812 vty_out (vty, " as-set");
13813
13814 if (bgp_aggregate->summary_only)
13815 vty_out (vty, " summary-only");
13816
13817 vty_out (vty, "%s", VTY_NEWLINE);
13818 }
13819
13820 return 0;
13821 }
13822
13823 int
13824 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
13825 {
13826 struct bgp_node *rn;
13827 struct bgp_distance *bdistance;
13828
13829 /* Distance configuration. */
13830 if (bgp->distance_ebgp
13831 && bgp->distance_ibgp
13832 && bgp->distance_local
13833 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
13834 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
13835 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
13836 vty_out (vty, " distance bgp %d %d %d%s",
13837 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
13838 VTY_NEWLINE);
13839
13840 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
13841 if ((bdistance = rn->info) != NULL)
13842 {
13843 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
13844 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
13845 bdistance->access_list ? bdistance->access_list : "",
13846 VTY_NEWLINE);
13847 }
13848
13849 return 0;
13850 }
13851
13852 /* Allocate routing table structure and install commands. */
13853 void
13854 bgp_route_init (void)
13855 {
13856 /* Init BGP distance table. */
13857 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
13858
13859 /* IPv4 BGP commands. */
13860 install_element (BGP_NODE, &bgp_table_map_cmd);
13861 install_element (BGP_NODE, &bgp_network_cmd);
13862 install_element (BGP_NODE, &bgp_network_mask_cmd);
13863 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
13864 install_element (BGP_NODE, &bgp_network_route_map_cmd);
13865 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
13866 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
13867 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
13868 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
13869 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
13870 install_element (BGP_NODE, &no_bgp_table_map_cmd);
13871 install_element (BGP_NODE, &no_bgp_network_cmd);
13872 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
13873 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
13874 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
13875 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
13876 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13877 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
13878 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
13879 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
13880
13881 install_element (BGP_NODE, &aggregate_address_cmd);
13882 install_element (BGP_NODE, &aggregate_address_mask_cmd);
13883 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
13884 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
13885 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
13886 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
13887 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
13888 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
13889 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
13890 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
13891 install_element (BGP_NODE, &no_aggregate_address_cmd);
13892 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
13893 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
13894 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
13895 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
13896 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
13897 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
13898 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
13899 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13900 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13901
13902 /* IPv4 unicast configuration. */
13903 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
13904 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
13905 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
13906 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
13907 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
13908 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
13909 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
13910 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
13911 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
13912 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
13913 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
13914 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
13915 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
13916 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13917
13918 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
13919 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
13920 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
13921 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
13922 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
13923 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
13924 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
13925 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
13926 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
13927 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
13928 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
13929 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
13930 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
13931 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
13932 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
13933 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
13934 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
13935 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
13936 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13937 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13938
13939 /* IPv4 multicast configuration. */
13940 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
13941 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
13942 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
13943 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
13944 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
13945 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
13946 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
13947 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
13948 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
13949 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
13950 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
13951 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
13952 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
13953 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
13954 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
13955 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
13956 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
13957 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
13958 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
13959 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
13960 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
13961 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
13962 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
13963 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
13964 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
13965 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
13966 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
13967 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
13968 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
13969 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
13970 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
13971 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
13972 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
13973 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
13974
13975 install_element (VIEW_NODE, &show_ip_bgp_cmd);
13976 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
13977 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
13978 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
13979 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
13980 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
13981 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
13982 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
13983 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
13984 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
13985 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
13986 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
13987 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13988 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
13989 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
13990 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
13991 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
13992 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
13993 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
13994 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
13995 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
13996 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13997 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13998
13999 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14000 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14001 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14002 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14003 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14004 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14005 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
14006 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14007 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14008 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
14009 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14010 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14011 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14012 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14013 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14014 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14015 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14016 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14017 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14018 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14019 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14020 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14021 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
14022 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14023 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14024 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14025 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14026 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14027 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14028 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14029 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14030 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14031 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14032 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14033 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14034 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14035 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14036 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
14037 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14038 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14039 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14040 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14041 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14042 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14043 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14044 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14045 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14046 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14047 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14048 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14049 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14050 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14051 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14052 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14053 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14054 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14055 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14056 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
14057 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14058 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14059 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14060 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14061 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14062 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14063 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14064 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14065 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14066 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14067 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14068 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14069 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14070 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14071 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14072 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
14073
14074 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
14075 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
14076 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14077 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
14078 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14079 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14080 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
14081 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
14082 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14083 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
14084 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
14085 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14086 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14087 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14088 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14089 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14090 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14091 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14092 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14093 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14094 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
14095 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
14096 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
14097 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
14098 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
14099 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
14100 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
14101 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
14102 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
14103 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14104 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_cmd);
14105 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14106 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14107 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14108 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
14109 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
14110 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
14111 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
14112 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14113 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14114 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14115 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14116
14117 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
14118 install_element (ENABLE_NODE, &show_ip_bgp_instance_cmd);
14119 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
14120 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
14121 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
14122 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_cmd);
14123 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
14124 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14125 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14126 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
14127 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
14128 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14129 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14130 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
14131 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_cmd);
14132 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14133 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14134 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14135 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14136 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14137 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14138 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14139 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14140
14141 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
14142 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14143 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
14144 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14145 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14146 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
14147 install_element (ENABLE_NODE, &show_ip_bgp_instance_filter_list_cmd);
14148 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14149 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
14150 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_map_cmd);
14151 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14152 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
14153 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14154 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
14155 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14156 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
14157 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
14158 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
14159 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
14160 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
14161 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
14162 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
14163 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
14164 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14165 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_cmd);
14166 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14167 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14168 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14169 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
14170 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
14171 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
14172 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
14173 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14174 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14175 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14176 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14177 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
14178 install_element (ENABLE_NODE, &show_ip_bgp_instance_community_list_cmd);
14179 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14180 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
14181 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14182 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
14183 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14184 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14185 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14186 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14187 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14188 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14189 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14190 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14191 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14192 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14193 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14194 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14195 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14196 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14197 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14198 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
14199 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14200 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14201 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14202 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14203 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
14204 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
14205 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
14206 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
14207 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14208 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
14209 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
14210 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14211 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14212 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
14213 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
14214 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
14215
14216 /* BGP dampening clear commands */
14217 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14218 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14219 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14220 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14221
14222 /* prefix count */
14223 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14224 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
14225 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14226 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
14227 #ifdef HAVE_IPV6
14228 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14229 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
14230
14231 /* New config IPv6 BGP commands. */
14232 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
14233 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14234 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
14235 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
14236 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14237 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14238
14239 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14240 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14241 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14242 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
14243
14244 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14245 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
14246
14247 /* Old config IPv6 BGP commands. */
14248 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14249 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14250
14251 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14252 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14253 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14254 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14255
14256 install_element (VIEW_NODE, &show_bgp_cmd);
14257 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
14258 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
14259 install_element (VIEW_NODE, &show_bgp_route_cmd);
14260 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
14261 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
14262 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14263 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14264 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14265 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14266 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
14267 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14268 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14269 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14270 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14271 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14272 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14273 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14274 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14275 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14276 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14277 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14278 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14279 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14280 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14281 install_element (VIEW_NODE, &show_bgp_community_cmd);
14282 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14283 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14284 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14285 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14286 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14287 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14288 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14289 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14290 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14291 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14292 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14293 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14294 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14295 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14296 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14297 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14298 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14299 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14300 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14301 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14302 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14303 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14304 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14305 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14306 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14307 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14308 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14309 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14310 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14311 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14312 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14313 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14314 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14315 install_element (VIEW_NODE, &show_bgp_instance_cmd);
14316 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
14317 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
14318 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
14319 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
14320 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14321 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
14322 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14323 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14324 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14325 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
14326 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14327 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
14328 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14329 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
14330 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14331 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
14332 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14333 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
14334 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14335 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14336 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14337 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14338 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14339 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
14340 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14341 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14342 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14343 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
14344 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14345 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
14346 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
14347
14348 /* Restricted:
14349 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
14350 */
14351 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
14352 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
14353 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
14354 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
14355 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14356 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14357 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
14358 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
14359 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14360 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
14361 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14362 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14363 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
14364 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
14365 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
14366 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
14367 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
14368 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
14369 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
14370 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
14371 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
14372 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
14373 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
14374 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
14375 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
14376 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
14377 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
14378 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
14379 install_element (RESTRICTED_NODE, &show_bgp_instance_route_cmd);
14380 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_cmd);
14381 install_element (RESTRICTED_NODE, &show_bgp_instance_route_pathtype_cmd);
14382 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14383 install_element (RESTRICTED_NODE, &show_bgp_instance_prefix_cmd);
14384 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14385 install_element (RESTRICTED_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14386 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14387
14388 install_element (ENABLE_NODE, &show_bgp_cmd);
14389 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
14390 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
14391 install_element (ENABLE_NODE, &show_bgp_route_cmd);
14392 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
14393 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
14394 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
14395 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14396 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14397 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
14398 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
14399 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14400 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14401 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
14402 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14403 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
14404 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
14405 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
14406 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
14407 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
14408 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
14409 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
14410 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
14411 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
14412 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
14413 install_element (ENABLE_NODE, &show_bgp_community_cmd);
14414 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
14415 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
14416 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
14417 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
14418 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
14419 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
14420 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
14421 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
14422 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
14423 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
14424 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
14425 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
14426 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
14427 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
14428 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
14429 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
14430 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
14431 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
14432 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14433 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
14434 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14435 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
14436 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14437 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
14438 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14439 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
14440 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14441 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14442 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14443 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
14444 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14445 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
14446 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14447 install_element (ENABLE_NODE, &show_bgp_instance_cmd);
14448 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_cmd);
14449 install_element (ENABLE_NODE, &show_bgp_instance_route_cmd);
14450 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_cmd);
14451 install_element (ENABLE_NODE, &show_bgp_instance_route_pathtype_cmd);
14452 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14453 install_element (ENABLE_NODE, &show_bgp_instance_prefix_cmd);
14454 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14455 install_element (ENABLE_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14456 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14457 install_element (ENABLE_NODE, &show_bgp_instance_prefix_list_cmd);
14458 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14459 install_element (ENABLE_NODE, &show_bgp_instance_filter_list_cmd);
14460 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14461 install_element (ENABLE_NODE, &show_bgp_instance_route_map_cmd);
14462 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14463 install_element (ENABLE_NODE, &show_bgp_instance_community_list_cmd);
14464 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14465 install_element (ENABLE_NODE, &show_bgp_instance_prefix_longer_cmd);
14466 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14467 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14468 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14469 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14470 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14471 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_routes_cmd);
14472 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14473 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14474 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14475 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_flap_cmd);
14476 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14477 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_damp_cmd);
14478 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
14479
14480 /* Statistics */
14481 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
14482 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
14483 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
14484 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
14485
14486 /* old command */
14487 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14488 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14489 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
14490 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
14491 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
14492 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
14493 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
14494 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
14495 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
14496 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
14497 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
14498 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
14499 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
14500 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
14501 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
14502 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
14503 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14504 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14505 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
14506 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
14507 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
14508 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
14509 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14510 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
14511 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
14512 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
14513 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
14514 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
14515 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
14516 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
14517 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14518 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14519 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14520 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
14521 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14522 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14523
14524 /* old command */
14525 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
14526 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
14527 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
14528 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
14529 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
14530 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
14531 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
14532 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
14533 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
14534 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
14535 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
14536 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
14537 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
14538 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
14539 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
14540 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
14541 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14542 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14543 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
14544 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
14545 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
14546 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
14547 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14548 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
14549 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
14550 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
14551 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
14552 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
14553 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
14554 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
14555 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14556 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14557 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14558 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
14559 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14560 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14561
14562 /* old command */
14563 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14564 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14565 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14566 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14567
14568 /* old command */
14569 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14570 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14571 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14572 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14573
14574 /* old command */
14575 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
14576 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
14577 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14578 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14579 #endif /* HAVE_IPV6 */
14580
14581 install_element (BGP_NODE, &bgp_distance_cmd);
14582 install_element (BGP_NODE, &no_bgp_distance_cmd);
14583 install_element (BGP_NODE, &no_bgp_distance2_cmd);
14584 install_element (BGP_NODE, &bgp_distance_source_cmd);
14585 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
14586 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
14587 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
14588
14589 install_element (BGP_NODE, &bgp_damp_set_cmd);
14590 install_element (BGP_NODE, &bgp_damp_set2_cmd);
14591 install_element (BGP_NODE, &bgp_damp_set3_cmd);
14592 install_element (BGP_NODE, &bgp_damp_unset_cmd);
14593 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
14594 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
14595 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
14596 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
14597 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
14598 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
14599 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
14600 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
14601 }
14602
14603 void
14604 bgp_route_finish (void)
14605 {
14606 bgp_table_unlock (bgp_distance_table);
14607 bgp_distance_table = NULL;
14608 }