]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
bgpd: add L3/L2VPN Virtual Network Control feature
[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 #if ENABLE_BGP_VNC
66 #include "rfapi_backend.h"
67 #include "vnc_import_bgp.h"
68 #include "vnc_export_bgp.h"
69 #endif
70
71 /* Extern from bgp_dump.c */
72 extern const char *bgp_origin_str[];
73 extern const char *bgp_origin_long_str[];
74
75 struct bgp_node *
76 bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
77 struct prefix_rd *prd)
78 {
79 struct bgp_node *rn;
80 struct bgp_node *prn = NULL;
81
82 assert (table);
83 if (!table)
84 return NULL;
85
86 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
87 {
88 prn = bgp_node_get (table, (struct prefix *) prd);
89
90 if (prn->info == NULL)
91 prn->info = bgp_table_init (afi, safi);
92 else
93 bgp_unlock_node (prn);
94 table = prn->info;
95 }
96
97 rn = bgp_node_get (table, p);
98
99 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
100 rn->prn = prn;
101
102 return rn;
103 }
104
105 /* Allocate bgp_info_extra */
106 static struct bgp_info_extra *
107 bgp_info_extra_new (void)
108 {
109 struct bgp_info_extra *new;
110 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
111 return new;
112 }
113
114 static void
115 bgp_info_extra_free (struct bgp_info_extra **extra)
116 {
117 if (extra && *extra)
118 {
119 if ((*extra)->damp_info)
120 bgp_damp_info_free ((*extra)->damp_info, 0);
121
122 (*extra)->damp_info = NULL;
123
124 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
125
126 *extra = NULL;
127 }
128 }
129
130 /* Get bgp_info extra information for the given bgp_info, lazy allocated
131 * if required.
132 */
133 struct bgp_info_extra *
134 bgp_info_extra_get (struct bgp_info *ri)
135 {
136 if (!ri->extra)
137 ri->extra = bgp_info_extra_new();
138 return ri->extra;
139 }
140
141 /* Allocate new bgp info structure. */
142 struct bgp_info *
143 bgp_info_new (void)
144 {
145 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
146 }
147
148 /* Free bgp route information. */
149 static void
150 bgp_info_free (struct bgp_info *binfo)
151 {
152 if (binfo->attr)
153 bgp_attr_unintern (&binfo->attr);
154
155 bgp_unlink_nexthop(binfo);
156 bgp_info_extra_free (&binfo->extra);
157 bgp_info_mpath_free (&binfo->mpath);
158
159 peer_unlock (binfo->peer); /* bgp_info peer reference */
160
161 XFREE (MTYPE_BGP_ROUTE, binfo);
162 }
163
164 struct bgp_info *
165 bgp_info_lock (struct bgp_info *binfo)
166 {
167 binfo->lock++;
168 return binfo;
169 }
170
171 struct bgp_info *
172 bgp_info_unlock (struct bgp_info *binfo)
173 {
174 assert (binfo && binfo->lock > 0);
175 binfo->lock--;
176
177 if (binfo->lock == 0)
178 {
179 #if 0
180 zlog_debug ("%s: unlocked and freeing", __func__);
181 zlog_backtrace (LOG_DEBUG);
182 #endif
183 bgp_info_free (binfo);
184 return NULL;
185 }
186
187 #if 0
188 if (binfo->lock == 1)
189 {
190 zlog_debug ("%s: unlocked to 1", __func__);
191 zlog_backtrace (LOG_DEBUG);
192 }
193 #endif
194
195 return binfo;
196 }
197
198 void
199 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
200 {
201 struct bgp_info *top;
202
203 top = rn->info;
204
205 ri->next = rn->info;
206 ri->prev = NULL;
207 if (top)
208 top->prev = ri;
209 rn->info = ri;
210
211 bgp_info_lock (ri);
212 bgp_lock_node (rn);
213 peer_lock (ri->peer); /* bgp_info peer reference */
214 }
215
216 /* Do the actual removal of info from RIB, for use by bgp_process
217 completion callback *only* */
218 static void
219 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
220 {
221 if (ri->next)
222 ri->next->prev = ri->prev;
223 if (ri->prev)
224 ri->prev->next = ri->next;
225 else
226 rn->info = ri->next;
227
228 bgp_info_mpath_dequeue (ri);
229 bgp_info_unlock (ri);
230 bgp_unlock_node (rn);
231 }
232
233 void
234 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
235 {
236 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
237 /* set of previous already took care of pcount */
238 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
239 }
240
241 /* undo the effects of a previous call to bgp_info_delete; typically
242 called when a route is deleted and then quickly re-added before the
243 deletion has been processed */
244 void
245 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
246 {
247 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
248 /* unset of previous already took care of pcount */
249 SET_FLAG (ri->flags, BGP_INFO_VALID);
250 }
251
252 /* Adjust pcount as required */
253 static void
254 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
255 {
256 struct bgp_table *table;
257
258 assert (rn && bgp_node_table (rn));
259 assert (ri && ri->peer && ri->peer->bgp);
260
261 table = bgp_node_table (rn);
262
263 if (ri->peer == ri->peer->bgp->peer_self)
264 return;
265
266 if (!BGP_INFO_COUNTABLE (ri)
267 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
268 {
269
270 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
271
272 /* slight hack, but more robust against errors. */
273 if (ri->peer->pcount[table->afi][table->safi])
274 ri->peer->pcount[table->afi][table->safi]--;
275 else
276 {
277 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
278 __func__, ri->peer->host);
279 zlog_backtrace (LOG_WARNING);
280 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
281 }
282 }
283 else if (BGP_INFO_COUNTABLE (ri)
284 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
285 {
286 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
287 ri->peer->pcount[table->afi][table->safi]++;
288 }
289 }
290
291
292 /* Set/unset bgp_info flags, adjusting any other state as needed.
293 * This is here primarily to keep prefix-count in check.
294 */
295 void
296 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
297 {
298 SET_FLAG (ri->flags, flag);
299
300 /* early bath if we know it's not a flag that changes countability state */
301 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
302 return;
303
304 bgp_pcount_adjust (rn, ri);
305 }
306
307 void
308 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
309 {
310 UNSET_FLAG (ri->flags, flag);
311
312 /* early bath if we know it's not a flag that changes countability state */
313 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
314 return;
315
316 bgp_pcount_adjust (rn, ri);
317 }
318
319 /* Get MED value. If MED value is missing and "bgp bestpath
320 missing-as-worst" is specified, treat it as the worst value. */
321 static u_int32_t
322 bgp_med_value (struct attr *attr, struct bgp *bgp)
323 {
324 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
325 return attr->med;
326 else
327 {
328 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
329 return BGP_MED_MAX;
330 else
331 return 0;
332 }
333 }
334
335 void
336 bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf)
337 {
338 if (ri->addpath_rx_id)
339 sprintf(buf, "path %s (addpath rxid %d)", ri->peer->host, ri->addpath_rx_id);
340 else
341 sprintf(buf, "path %s", ri->peer->host);
342 }
343
344 /* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
345 static int
346 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
347 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
348 const char *pfx_buf)
349 {
350 struct attr *newattr, *existattr;
351 struct attr_extra *newattre, *existattre;
352 bgp_peer_sort_t new_sort;
353 bgp_peer_sort_t exist_sort;
354 u_int32_t new_pref;
355 u_int32_t exist_pref;
356 u_int32_t new_med;
357 u_int32_t exist_med;
358 u_int32_t new_weight;
359 u_int32_t exist_weight;
360 uint32_t newm, existm;
361 struct in_addr new_id;
362 struct in_addr exist_id;
363 int new_cluster;
364 int exist_cluster;
365 int internal_as_route;
366 int confed_as_route;
367 int ret;
368 char new_buf[PATH_ADDPATH_STR_BUFFER];
369 char exist_buf[PATH_ADDPATH_STR_BUFFER];
370
371 *paths_eq = 0;
372
373 /* 0. Null check. */
374 if (new == NULL)
375 {
376 if (debug)
377 zlog_debug("%s: new is NULL", pfx_buf);
378 return 0;
379 }
380
381 if (debug)
382 bgp_info_path_with_addpath_rx_str (new, new_buf);
383
384 if (exist == NULL)
385 {
386 if (debug)
387 zlog_debug("%s: %s is the initial bestpath", pfx_buf, new_buf);
388 return 1;
389 }
390
391 if (debug)
392 {
393 bgp_info_path_with_addpath_rx_str (exist, exist_buf);
394 zlog_debug("%s: Comparing %s flags 0x%x with %s flags 0x%x",
395 pfx_buf, new_buf, new->flags, exist_buf, exist->flags);
396 }
397
398 newattr = new->attr;
399 existattr = exist->attr;
400 newattre = newattr->extra;
401 existattre = existattr->extra;
402
403 /* 1. Weight check. */
404 new_weight = exist_weight = 0;
405
406 if (newattre)
407 new_weight = newattre->weight;
408 if (existattre)
409 exist_weight = existattre->weight;
410
411 if (new_weight > exist_weight)
412 {
413 if (debug)
414 zlog_debug("%s: %s wins over %s due to weight %d > %d",
415 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
416 return 1;
417 }
418
419 if (new_weight < exist_weight)
420 {
421 if (debug)
422 zlog_debug("%s: %s loses to %s due to weight %d < %d",
423 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
424 return 0;
425 }
426
427 /* 2. Local preference check. */
428 new_pref = exist_pref = bgp->default_local_pref;
429
430 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
431 new_pref = newattr->local_pref;
432 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
433 exist_pref = existattr->local_pref;
434
435 if (new_pref > exist_pref)
436 {
437 if (debug)
438 zlog_debug("%s: %s wins over %s due to localpref %d > %d",
439 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
440 return 1;
441 }
442
443 if (new_pref < exist_pref)
444 {
445 if (debug)
446 zlog_debug("%s: %s loses to %s due to localpref %d < %d",
447 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
448 return 0;
449 }
450
451 /* 3. Local route check. We prefer:
452 * - BGP_ROUTE_STATIC
453 * - BGP_ROUTE_AGGREGATE
454 * - BGP_ROUTE_REDISTRIBUTE
455 */
456 if (! (new->sub_type == BGP_ROUTE_NORMAL))
457 {
458 if (debug)
459 zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type",
460 pfx_buf, new_buf, exist_buf);
461 return 1;
462 }
463
464 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
465 {
466 if (debug)
467 zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type",
468 pfx_buf, new_buf, exist_buf);
469 return 0;
470 }
471
472 /* 4. AS path length check. */
473 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
474 {
475 int exist_hops = aspath_count_hops (existattr->aspath);
476 int exist_confeds = aspath_count_confeds (existattr->aspath);
477
478 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
479 {
480 int aspath_hops;
481
482 aspath_hops = aspath_count_hops (newattr->aspath);
483 aspath_hops += aspath_count_confeds (newattr->aspath);
484
485 if ( aspath_hops < (exist_hops + exist_confeds))
486 {
487 if (debug)
488 zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
489 pfx_buf, new_buf, exist_buf,
490 aspath_hops, (exist_hops + exist_confeds));
491 return 1;
492 }
493
494 if ( aspath_hops > (exist_hops + exist_confeds))
495 {
496 if (debug)
497 zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
498 pfx_buf, new_buf, exist_buf,
499 aspath_hops, (exist_hops + exist_confeds));
500 return 0;
501 }
502 }
503 else
504 {
505 int newhops = aspath_count_hops (newattr->aspath);
506
507 if (newhops < exist_hops)
508 {
509 if (debug)
510 zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d",
511 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
512 return 1;
513 }
514
515 if (newhops > exist_hops)
516 {
517 if (debug)
518 zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d",
519 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
520 return 0;
521 }
522 }
523 }
524
525 /* 5. Origin check. */
526 if (newattr->origin < existattr->origin)
527 {
528 if (debug)
529 zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
530 pfx_buf, new_buf, exist_buf,
531 bgp_origin_long_str[newattr->origin],
532 bgp_origin_long_str[existattr->origin]);
533 return 1;
534 }
535
536 if (newattr->origin > existattr->origin)
537 {
538 if (debug)
539 zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
540 pfx_buf, new_buf, exist_buf,
541 bgp_origin_long_str[newattr->origin],
542 bgp_origin_long_str[existattr->origin]);
543 return 0;
544 }
545
546 /* 6. MED check. */
547 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
548 && aspath_count_hops (existattr->aspath) == 0);
549 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
550 && aspath_count_confeds (existattr->aspath) > 0
551 && aspath_count_hops (newattr->aspath) == 0
552 && aspath_count_hops (existattr->aspath) == 0);
553
554 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
555 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
556 && confed_as_route)
557 || aspath_cmp_left (newattr->aspath, existattr->aspath)
558 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
559 || internal_as_route)
560 {
561 new_med = bgp_med_value (new->attr, bgp);
562 exist_med = bgp_med_value (exist->attr, bgp);
563
564 if (new_med < exist_med)
565 {
566 if (debug)
567 zlog_debug("%s: %s wins over %s due to MED %d < %d",
568 pfx_buf, new_buf, exist_buf, new_med, exist_med);
569 return 1;
570 }
571
572 if (new_med > exist_med)
573 {
574 if (debug)
575 zlog_debug("%s: %s loses to %s due to MED %d > %d",
576 pfx_buf, new_buf, exist_buf, new_med, exist_med);
577 return 0;
578 }
579 }
580
581 /* 7. Peer type check. */
582 new_sort = new->peer->sort;
583 exist_sort = exist->peer->sort;
584
585 if (new_sort == BGP_PEER_EBGP
586 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
587 {
588 if (debug)
589 zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer",
590 pfx_buf, new_buf, exist_buf);
591 return 1;
592 }
593
594 if (exist_sort == BGP_PEER_EBGP
595 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
596 {
597 if (debug)
598 zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer",
599 pfx_buf, new_buf, exist_buf);
600 return 0;
601 }
602
603 /* 8. IGP metric check. */
604 newm = existm = 0;
605
606 if (new->extra)
607 newm = new->extra->igpmetric;
608 if (exist->extra)
609 existm = exist->extra->igpmetric;
610
611 if (newm < existm)
612 {
613 if (debug)
614 zlog_debug("%s: %s wins over %s due to IGP metric %d < %d",
615 pfx_buf, new_buf, exist_buf, newm, existm);
616 ret = 1;
617 }
618
619 if (newm > existm)
620 {
621 if (debug)
622 zlog_debug("%s: %s loses to %s due to IGP metric %d > %d",
623 pfx_buf, new_buf, exist_buf, newm, existm);
624 ret = 0;
625 }
626
627 /* 9. Same IGP metric. Compare the cluster list length as
628 representative of IGP hops metric. Rewrite the metric value
629 pair (newm, existm) with the cluster list length. Prefer the
630 path with smaller cluster list length. */
631 if (newm == existm)
632 {
633 if (peer_sort (new->peer) == BGP_PEER_IBGP
634 && peer_sort (exist->peer) == BGP_PEER_IBGP
635 && CHECK_FLAG (mpath_cfg->ibgp_flags,
636 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
637 {
638 newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
639 existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
640
641 if (newm < existm)
642 {
643 if (debug)
644 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
645 pfx_buf, new_buf, exist_buf, newm, existm);
646 ret = 1;
647 }
648
649 if (newm > existm)
650 {
651 if (debug)
652 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
653 pfx_buf, new_buf, exist_buf, newm, existm);
654 ret = 0;
655 }
656 }
657 }
658
659 /* 10. confed-external vs. confed-internal */
660 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
661 {
662 if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP)
663 {
664 if (debug)
665 zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer",
666 pfx_buf, new_buf, exist_buf);
667 return 1;
668 }
669
670 if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP)
671 {
672 if (debug)
673 zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer",
674 pfx_buf, new_buf, exist_buf);
675 return 0;
676 }
677 }
678
679 /* 11. Maximum path check. */
680 if (newm == existm)
681 {
682 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
683 {
684
685 /*
686 * For the two paths, all comparison steps till IGP metric
687 * have succeeded - including AS_PATH hop count. Since 'bgp
688 * bestpath as-path multipath-relax' knob is on, we don't need
689 * an exact match of AS_PATH. Thus, mark the paths are equal.
690 * That will trigger both these paths to get into the multipath
691 * array.
692 */
693 *paths_eq = 1;
694
695 if (debug)
696 zlog_debug("%s: %s and %s are equal via multipath-relax",
697 pfx_buf, new_buf, exist_buf);
698 }
699 else if (new->peer->sort == BGP_PEER_IBGP)
700 {
701 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
702 {
703 *paths_eq = 1;
704
705 if (debug)
706 zlog_debug("%s: %s and %s are equal via matching aspaths",
707 pfx_buf, new_buf, exist_buf);
708 }
709 }
710 else if (new->peer->as == exist->peer->as)
711 {
712 *paths_eq = 1;
713
714 if (debug)
715 zlog_debug("%s: %s and %s are equal via same remote-as",
716 pfx_buf, new_buf, exist_buf);
717 }
718 }
719 else
720 {
721 /*
722 * TODO: If unequal cost ibgp multipath is enabled we can
723 * mark the paths as equal here instead of returning
724 */
725 if (debug)
726 {
727 if (ret == 1)
728 zlog_debug("%s: %s wins over %s after IGP metric comparison",
729 pfx_buf, new_buf, exist_buf);
730 else
731 zlog_debug("%s: %s loses to %s after IGP metric comparison",
732 pfx_buf, new_buf, exist_buf);
733 }
734 return ret;
735 }
736
737 /* 12. If both paths are external, prefer the path that was received
738 first (the oldest one). This step minimizes route-flap, since a
739 newer path won't displace an older one, even if it was the
740 preferred route based on the additional decision criteria below. */
741 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
742 && new_sort == BGP_PEER_EBGP
743 && exist_sort == BGP_PEER_EBGP)
744 {
745 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
746 {
747 if (debug)
748 zlog_debug("%s: %s wins over %s due to oldest external",
749 pfx_buf, new_buf, exist_buf);
750 return 1;
751 }
752
753 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
754 {
755 if (debug)
756 zlog_debug("%s: %s loses to %s due to oldest external",
757 pfx_buf, new_buf, exist_buf);
758 return 0;
759 }
760 }
761
762 /* 13. Router-ID comparision. */
763 /* If one of the paths is "stale", the corresponding peer router-id will
764 * be 0 and would always win over the other path. If originator id is
765 * used for the comparision, it will decide which path is better.
766 */
767 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
768 new_id.s_addr = newattre->originator_id.s_addr;
769 else
770 new_id.s_addr = new->peer->remote_id.s_addr;
771 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
772 exist_id.s_addr = existattre->originator_id.s_addr;
773 else
774 exist_id.s_addr = exist->peer->remote_id.s_addr;
775
776 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
777 {
778 if (debug)
779 zlog_debug("%s: %s wins over %s due to Router-ID comparison",
780 pfx_buf, new_buf, exist_buf);
781 return 1;
782 }
783
784 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
785 {
786 if (debug)
787 zlog_debug("%s: %s loses to %s due to Router-ID comparison",
788 pfx_buf, new_buf, exist_buf);
789 return 0;
790 }
791
792 /* 14. Cluster length comparision. */
793 new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
794 exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
795
796 if (new_cluster < exist_cluster)
797 {
798 if (debug)
799 zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
800 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
801 return 1;
802 }
803
804 if (new_cluster > exist_cluster)
805 {
806 if (debug)
807 zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
808 pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster);
809 return 0;
810 }
811
812 /* 15. Neighbor address comparision. */
813 /* Do this only if neither path is "stale" as stale paths do not have
814 * valid peer information (as the connection may or may not be up).
815 */
816 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
817 {
818 if (debug)
819 zlog_debug("%s: %s wins over %s due to latter path being STALE",
820 pfx_buf, new_buf, exist_buf);
821 return 1;
822 }
823
824 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
825 {
826 if (debug)
827 zlog_debug("%s: %s loses to %s due to former path being STALE",
828 pfx_buf, new_buf, exist_buf);
829 return 0;
830 }
831
832 /* locally configured routes to advertise do not have su_remote */
833 if (new->peer->su_remote == NULL)
834 return 0;
835 if (exist->peer->su_remote == NULL)
836 return 1;
837
838 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
839
840 if (ret == 1)
841 {
842 if (debug)
843 zlog_debug("%s: %s loses to %s due to Neighor IP comparison",
844 pfx_buf, new_buf, exist_buf);
845 return 0;
846 }
847
848 if (ret == -1)
849 {
850 if (debug)
851 zlog_debug("%s: %s wins over %s due to Neighor IP comparison",
852 pfx_buf, new_buf, exist_buf);
853 return 1;
854 }
855
856 if (debug)
857 zlog_debug("%s: %s wins over %s due to nothing left to compare",
858 pfx_buf, new_buf, exist_buf);
859
860 return 1;
861 }
862
863 /* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
864 * is preferred, or 0 if they are the same (usually will only occur if
865 * multipath is enabled
866 * This version is compatible with */
867 int
868 bgp_info_cmp_compatible (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
869 afi_t afi, safi_t safi)
870 {
871 int paths_eq;
872 struct bgp_maxpaths_cfg mpath_cfg;
873 int ret;
874 ret = bgp_info_cmp (bgp, new, exist, &paths_eq, &mpath_cfg, 0, __func__);
875
876 if (paths_eq)
877 ret = 0;
878 else
879 {
880 if (ret == 1)
881 ret = -1;
882 else
883 ret = 1;
884 }
885 return ret;
886 }
887
888 static enum filter_type
889 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
890 afi_t afi, safi_t safi)
891 {
892 struct bgp_filter *filter;
893
894 filter = &peer->filter[afi][safi];
895
896 #define FILTER_EXIST_WARN(F,f,filter) \
897 if (BGP_DEBUG (update, UPDATE_IN) \
898 && !(F ## _IN (filter))) \
899 zlog_warn ("%s: Could not find configured input %s-list %s!", \
900 peer->host, #f, F ## _IN_NAME(filter));
901
902 if (DISTRIBUTE_IN_NAME (filter)) {
903 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
904
905 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
906 return FILTER_DENY;
907 }
908
909 if (PREFIX_LIST_IN_NAME (filter)) {
910 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
911
912 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
913 return FILTER_DENY;
914 }
915
916 if (FILTER_LIST_IN_NAME (filter)) {
917 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
918
919 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
920 return FILTER_DENY;
921 }
922
923 return FILTER_PERMIT;
924 #undef FILTER_EXIST_WARN
925 }
926
927 static enum filter_type
928 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
929 afi_t afi, safi_t safi)
930 {
931 struct bgp_filter *filter;
932
933 filter = &peer->filter[afi][safi];
934
935 #define FILTER_EXIST_WARN(F,f,filter) \
936 if (BGP_DEBUG (update, UPDATE_OUT) \
937 && !(F ## _OUT (filter))) \
938 zlog_warn ("%s: Could not find configured output %s-list %s!", \
939 peer->host, #f, F ## _OUT_NAME(filter));
940
941 if (DISTRIBUTE_OUT_NAME (filter)) {
942 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
943
944 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
945 return FILTER_DENY;
946 }
947
948 if (PREFIX_LIST_OUT_NAME (filter)) {
949 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
950
951 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
952 return FILTER_DENY;
953 }
954
955 if (FILTER_LIST_OUT_NAME (filter)) {
956 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
957
958 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
959 return FILTER_DENY;
960 }
961
962 return FILTER_PERMIT;
963 #undef FILTER_EXIST_WARN
964 }
965
966 /* If community attribute includes no_export then return 1. */
967 static int
968 bgp_community_filter (struct peer *peer, struct attr *attr)
969 {
970 if (attr->community)
971 {
972 /* NO_ADVERTISE check. */
973 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
974 return 1;
975
976 /* NO_EXPORT check. */
977 if (peer->sort == BGP_PEER_EBGP &&
978 community_include (attr->community, COMMUNITY_NO_EXPORT))
979 return 1;
980
981 /* NO_EXPORT_SUBCONFED check. */
982 if (peer->sort == BGP_PEER_EBGP
983 || peer->sort == BGP_PEER_CONFED)
984 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
985 return 1;
986 }
987 return 0;
988 }
989
990 /* Route reflection loop check. */
991 static int
992 bgp_cluster_filter (struct peer *peer, struct attr *attr)
993 {
994 struct in_addr cluster_id;
995
996 if (attr->extra && attr->extra->cluster)
997 {
998 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
999 cluster_id = peer->bgp->cluster_id;
1000 else
1001 cluster_id = peer->bgp->router_id;
1002
1003 if (cluster_loop_check (attr->extra->cluster, cluster_id))
1004 return 1;
1005 }
1006 return 0;
1007 }
1008
1009 static int
1010 bgp_input_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_IN_NAME(filter))
1034 {
1035 rmap = ROUTE_MAP_IN (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_IN);
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 {
1058 /* Free newly generated AS path and community by route-map. */
1059 bgp_attr_flush (attr);
1060 return RMAP_DENY;
1061 }
1062 }
1063 return RMAP_PERMIT;
1064 }
1065
1066 static int
1067 bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1068 afi_t afi, safi_t safi, const char *rmap_name)
1069 {
1070 struct bgp_filter *filter;
1071 struct bgp_info info;
1072 route_map_result_t ret;
1073 struct route_map *rmap = NULL;
1074
1075 filter = &peer->filter[afi][safi];
1076
1077 /* Apply default weight value. */
1078 if (peer->weight)
1079 (bgp_attr_extra_get (attr))->weight = peer->weight;
1080
1081 if (rmap_name)
1082 {
1083 rmap = route_map_lookup_by_name(rmap_name);
1084
1085 if (rmap == NULL)
1086 return RMAP_DENY;
1087 }
1088 else
1089 {
1090 if (ROUTE_MAP_OUT_NAME(filter))
1091 {
1092 rmap = ROUTE_MAP_OUT (filter);
1093
1094 if (rmap == NULL)
1095 return RMAP_DENY;
1096 }
1097 }
1098
1099 /* Route map apply. */
1100 if (rmap)
1101 {
1102 /* Duplicate current value to new strucutre for modification. */
1103 info.peer = peer;
1104 info.attr = attr;
1105
1106 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1107
1108 /* Apply BGP route map to the attribute. */
1109 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1110
1111 peer->rmap_type = 0;
1112
1113 if (ret == RMAP_DENYMATCH)
1114 /* caller has multiple error paths with bgp_attr_flush() */
1115 return RMAP_DENY;
1116 }
1117 return RMAP_PERMIT;
1118 }
1119
1120 /* If this is an EBGP peer with remove-private-AS */
1121 static void
1122 bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1123 struct peer *peer, struct attr *attr)
1124 {
1125 if (peer->sort == BGP_PEER_EBGP &&
1126 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1127 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1128 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1129 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
1130 {
1131 // Take action on the entire aspath
1132 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1133 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
1134 {
1135 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
1136 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1137
1138 // The entire aspath consists of private ASNs so create an empty aspath
1139 else if (aspath_private_as_check (attr->aspath))
1140 attr->aspath = aspath_empty_get ();
1141
1142 // There are some public and some private ASNs, remove the private ASNs
1143 else
1144 attr->aspath = aspath_remove_private_asns (attr->aspath);
1145 }
1146
1147 // 'all' was not specified so the entire aspath must be private ASNs
1148 // for us to do anything
1149 else if (aspath_private_as_check (attr->aspath))
1150 {
1151 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1152 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1153 else
1154 attr->aspath = aspath_empty_get ();
1155 }
1156 }
1157 }
1158
1159 /* If this is an EBGP peer with as-override */
1160 static void
1161 bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1162 struct peer *peer, struct attr *attr)
1163 {
1164 if (peer->sort == BGP_PEER_EBGP &&
1165 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1166 {
1167 if (aspath_single_asn_check (attr->aspath, peer->as))
1168 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1169 }
1170 }
1171
1172 static void
1173 subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1174 {
1175 if (family == AF_INET)
1176 attr->nexthop.s_addr = 0;
1177 #ifdef HAVE_IPV6
1178 if (family == AF_INET6)
1179 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1180 #endif
1181 }
1182
1183 int
1184 subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1185 struct prefix *p, struct attr *attr)
1186 {
1187 struct bgp_filter *filter;
1188 struct peer *from;
1189 struct peer *peer;
1190 struct peer *onlypeer;
1191 struct bgp *bgp;
1192 struct attr *riattr;
1193 struct peer_af *paf;
1194 char buf[SU_ADDRSTRLEN];
1195 int ret;
1196 int transparent;
1197 int reflect;
1198 afi_t afi;
1199 safi_t safi;
1200 int samepeer_safe = 0; /* for synthetic mplsvpns routes */
1201
1202 if (DISABLE_BGP_ANNOUNCE)
1203 return 0;
1204
1205 afi = SUBGRP_AFI(subgrp);
1206 safi = SUBGRP_SAFI(subgrp);
1207 peer = SUBGRP_PEER(subgrp);
1208 onlypeer = NULL;
1209 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1210 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1211
1212 from = ri->peer;
1213 filter = &peer->filter[afi][safi];
1214 bgp = SUBGRP_INST(subgrp);
1215 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1216
1217 #if ENABLE_BGP_VNC
1218 if (((afi == AFI_IP) || (afi == AFI_IP6)) && (safi == SAFI_MPLS_VPN) &&
1219 ((ri->type == ZEBRA_ROUTE_BGP_DIRECT) ||
1220 (ri->type == ZEBRA_ROUTE_BGP_DIRECT_EXT))) {
1221
1222 /*
1223 * direct and direct_ext type routes originate internally even
1224 * though they can have peer pointers that reference other systems
1225 */
1226 char buf[BUFSIZ];
1227 prefix2str(p, buf, BUFSIZ);
1228 zlog_debug("%s: pfx %s bgp_direct->vpn route peer safe", __func__, buf);
1229 samepeer_safe = 1;
1230 }
1231 #endif
1232
1233 /* With addpath we may be asked to TX all kinds of paths so make sure
1234 * ri is valid */
1235 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1236 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1237 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1238 {
1239 return 0;
1240 }
1241
1242 /* If this is not the bestpath then check to see if there is an enabled addpath
1243 * feature that requires us to advertise it */
1244 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1245 {
1246 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1247 {
1248 return 0;
1249 }
1250 }
1251
1252 /* Aggregate-address suppress check. */
1253 if (ri->extra && ri->extra->suppress)
1254 if (! UNSUPPRESS_MAP_NAME (filter))
1255 {
1256 return 0;
1257 }
1258
1259 /* Do not send back route to sender. */
1260 if (onlypeer && from == onlypeer)
1261 {
1262 return 0;
1263 }
1264
1265 /* Do not send the default route in the BGP table if the neighbor is
1266 * configured for default-originate */
1267 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1268 {
1269 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1270 return 0;
1271 #ifdef HAVE_IPV6
1272 else if (p->family == AF_INET6 && p->prefixlen == 0)
1273 return 0;
1274 #endif /* HAVE_IPV6 */
1275 }
1276
1277 /* Transparency check. */
1278 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1279 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1280 transparent = 1;
1281 else
1282 transparent = 0;
1283
1284 /* If community is not disabled check the no-export and local. */
1285 if (! transparent && bgp_community_filter (peer, riattr))
1286 {
1287 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1288 zlog_debug ("subgrpannouncecheck: community filter check fail");
1289 return 0;
1290 }
1291
1292 /* If the attribute has originator-id and it is same as remote
1293 peer's id. */
1294 if (onlypeer &&
1295 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1296 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1297 {
1298 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1299 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1300 "remote router-id",
1301 onlypeer->host,
1302 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1303 p->prefixlen);
1304 return 0;
1305 }
1306
1307 /* ORF prefix-list filter check */
1308 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1309 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1310 || CHECK_FLAG (peer->af_cap[afi][safi],
1311 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1312 if (peer->orf_plist[afi][safi])
1313 {
1314 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1315 {
1316 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1317 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1318 peer->host,
1319 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1320 p->prefixlen);
1321 return 0;
1322 }
1323 }
1324
1325 /* Output filter check. */
1326 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1327 {
1328 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1329 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1330 peer->host,
1331 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1332 p->prefixlen);
1333 return 0;
1334 }
1335
1336 #ifdef BGP_SEND_ASPATH_CHECK
1337 /* AS path loop check. */
1338 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1339 {
1340 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1341 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1342 "that is part of AS path.",
1343 onlypeer->host, onlypeer->as);
1344 return 0;
1345 }
1346 #endif /* BGP_SEND_ASPATH_CHECK */
1347
1348 /* If we're a CONFED we need to loop check the CONFED ID too */
1349 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1350 {
1351 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1352 {
1353 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1354 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1355 " is AS path.",
1356 peer->host,
1357 bgp->confed_id);
1358 return 0;
1359 }
1360 }
1361
1362 /* Route-Reflect check. */
1363 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1364 reflect = 1;
1365 else
1366 reflect = 0;
1367
1368 /* IBGP reflection check. */
1369 if (reflect && !samepeer_safe)
1370 {
1371 /* A route from a Client peer. */
1372 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1373 {
1374 /* Reflect to all the Non-Client peers and also to the
1375 Client peers other than the originator. Originator check
1376 is already done. So there is noting to do. */
1377 /* no bgp client-to-client reflection check. */
1378 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1379 if (CHECK_FLAG (peer->af_flags[afi][safi],
1380 PEER_FLAG_REFLECTOR_CLIENT))
1381 return 0;
1382 }
1383 else
1384 {
1385 /* A route from a Non-client peer. Reflect to all other
1386 clients. */
1387 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1388 PEER_FLAG_REFLECTOR_CLIENT))
1389 return 0;
1390 }
1391 }
1392
1393 /* For modify attribute, copy it to temporary structure. */
1394 bgp_attr_dup (attr, riattr);
1395
1396 /* If local-preference is not set. */
1397 if ((peer->sort == BGP_PEER_IBGP
1398 || peer->sort == BGP_PEER_CONFED)
1399 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1400 {
1401 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1402 attr->local_pref = bgp->default_local_pref;
1403 }
1404
1405 /* If originator-id is not set and the route is to be reflected,
1406 set the originator id */
1407 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1408 {
1409 attr->extra = bgp_attr_extra_get(attr);
1410 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1411 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1412 }
1413
1414 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1415 if (peer->sort == BGP_PEER_EBGP
1416 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1417 {
1418 if (from != bgp->peer_self && ! transparent
1419 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1420 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1421 }
1422
1423 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1424 * in announce check, only certain flags and length (or number of nexthops
1425 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1426 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1427 * Typically, the source nexthop in the attribute is preserved but in the
1428 * scenarios where we know it will always be overwritten, we reset the
1429 * nexthop to "0" in an attempt to achieve better Update packing. An
1430 * example of this is when a prefix from each of 2 IBGP peers needs to be
1431 * announced to an EBGP peer (and they have the same attributes barring
1432 * their nexthop).
1433 */
1434 if (reflect)
1435 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1436
1437 #ifdef HAVE_IPV6
1438 #define NEXTHOP_IS_V6 (\
1439 (safi != SAFI_ENCAP && \
1440 (p->family == AF_INET6 || peer_cap_enhe(peer))) || \
1441 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
1442
1443 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1444 * the peer (group) is configured to receive link-local nexthop unchanged
1445 * and it is available in the prefix OR we're not reflecting the route and
1446 * the peer (group) to whom we're going to announce is on a shared network
1447 * and this is either a self-originated route or the peer is EBGP.
1448 */
1449 if (NEXTHOP_IS_V6)
1450 {
1451 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
1452 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1453 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1454 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1455 (!reflect && peer->shared_network &&
1456 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
1457 {
1458 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
1459 }
1460
1461 /* Clear off link-local nexthop in source, whenever it is not needed to
1462 * ensure more prefixes share the same attribute for announcement.
1463 */
1464 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1465 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1466 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1467 }
1468 #endif /* HAVE_IPV6 */
1469
1470 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1471 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1472
1473 /* Route map & unsuppress-map apply. */
1474 if (ROUTE_MAP_OUT_NAME (filter)
1475 || (ri->extra && ri->extra->suppress) )
1476 {
1477 struct bgp_info info;
1478 struct attr dummy_attr;
1479 struct attr_extra dummy_extra;
1480
1481 dummy_attr.extra = &dummy_extra;
1482
1483 info.peer = peer;
1484 info.attr = attr;
1485 /* don't confuse inbound and outbound setting */
1486 RESET_FLAG(attr->rmap_change_flags);
1487
1488 /*
1489 * The route reflector is not allowed to modify the attributes
1490 * of the reflected IBGP routes unless explicitly allowed.
1491 */
1492 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1493 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1494 {
1495 bgp_attr_dup (&dummy_attr, attr);
1496 info.attr = &dummy_attr;
1497 }
1498
1499 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1500
1501 if (ri->extra && ri->extra->suppress)
1502 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1503 else
1504 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1505
1506 peer->rmap_type = 0;
1507
1508 if (ret == RMAP_DENYMATCH)
1509 {
1510 bgp_attr_flush (attr);
1511 return 0;
1512 }
1513 }
1514
1515 /* After route-map has been applied, we check to see if the nexthop to
1516 * be carried in the attribute (that is used for the announcement) can
1517 * be cleared off or not. We do this in all cases where we would be
1518 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1519 * the global nexthop here; the link-local nexthop would have been cleared
1520 * already, and if not, it is required by the update formation code.
1521 * Also see earlier comments in this function.
1522 */
1523 /*
1524 * If route-map has performed some operation on the nexthop or the peer
1525 * configuration says to pass it unchanged, we cannot reset the nexthop
1526 * here, so only attempt to do it if these aren't true. Note that the
1527 * route-map handler itself might have cleared the nexthop, if for example,
1528 * it is configured as 'peer-address'.
1529 */
1530 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1531 riattr->rmap_change_flags) &&
1532 !transparent &&
1533 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
1534 {
1535 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
1536 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1537 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
1538 {
1539 if (!reflect ||
1540 CHECK_FLAG (peer->af_flags[afi][safi],
1541 PEER_FLAG_FORCE_NEXTHOP_SELF))
1542 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1543 AF_INET6 : p->family), attr);
1544 }
1545 else if (peer->sort == BGP_PEER_EBGP)
1546 {
1547 /* Can also reset the nexthop if announcing to EBGP, but only if
1548 * no peer in the subgroup is on a shared subnet.
1549 * Note: 3rd party nexthop currently implemented for IPv4 only.
1550 */
1551 SUBGRP_FOREACH_PEER (subgrp, paf)
1552 {
1553 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1554 break;
1555 }
1556 if (!paf)
1557 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
1558 }
1559 /* If IPv6/MP and nexthop does not have any override and happens to
1560 * be a link-local address, reset it so that we don't pass along the
1561 * source's link-local IPv6 address to recipients who may not be on
1562 * the same interface.
1563 */
1564 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1565 {
1566 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1567 subgroup_announce_reset_nhop (AF_INET6, attr);
1568 }
1569 }
1570
1571 return 1;
1572 }
1573
1574 struct bgp_info_pair
1575 {
1576 struct bgp_info *old;
1577 struct bgp_info *new;
1578 };
1579
1580 static void
1581 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1582 struct bgp_maxpaths_cfg *mpath_cfg,
1583 struct bgp_info_pair *result)
1584 {
1585 struct bgp_info *new_select;
1586 struct bgp_info *old_select;
1587 struct bgp_info *ri;
1588 struct bgp_info *ri1;
1589 struct bgp_info *ri2;
1590 struct bgp_info *nextri = NULL;
1591 int paths_eq, do_mpath, debug;
1592 struct list mp_list;
1593 char pfx_buf[PREFIX2STR_BUFFER];
1594 char path_buf[PATH_ADDPATH_STR_BUFFER];
1595
1596 bgp_mp_list_init (&mp_list);
1597 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
1598
1599 debug = bgp_debug_bestpath(&rn->p);
1600
1601 if (debug)
1602 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1603
1604 /* bgp deterministic-med */
1605 new_select = NULL;
1606 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1607 {
1608
1609 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1610 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1611 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1612
1613 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1614 {
1615 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1616 continue;
1617 if (BGP_INFO_HOLDDOWN (ri1))
1618 continue;
1619 if (ri1->peer && ri1->peer != bgp->peer_self)
1620 if (ri1->peer->status != Established)
1621 continue;
1622
1623 new_select = ri1;
1624 if (ri1->next)
1625 {
1626 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1627 {
1628 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1629 continue;
1630 if (BGP_INFO_HOLDDOWN (ri2))
1631 continue;
1632 if (ri2->peer &&
1633 ri2->peer != bgp->peer_self &&
1634 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1635 if (ri2->peer->status != Established)
1636 continue;
1637
1638 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1639 || aspath_cmp_left_confed (ri1->attr->aspath,
1640 ri2->attr->aspath))
1641 {
1642 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1643 mpath_cfg, debug, pfx_buf))
1644 {
1645 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1646 new_select = ri2;
1647 }
1648
1649 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1650 }
1651 }
1652 }
1653 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1654 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1655
1656 if (debug)
1657 {
1658 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1659 zlog_debug("%s: %s is the bestpath from AS %d",
1660 pfx_buf, path_buf, aspath_get_firstas(new_select->attr->aspath));
1661 }
1662 }
1663 }
1664
1665 /* Check old selected route and new selected route. */
1666 old_select = NULL;
1667 new_select = NULL;
1668 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1669 {
1670 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1671 old_select = ri;
1672
1673 if (BGP_INFO_HOLDDOWN (ri))
1674 {
1675 /* reap REMOVED routes, if needs be
1676 * selected route must stay for a while longer though
1677 */
1678 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1679 && (ri != old_select))
1680 bgp_info_reap (rn, ri);
1681
1682 continue;
1683 }
1684
1685 if (ri->peer &&
1686 ri->peer != bgp->peer_self &&
1687 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1688 if (ri->peer->status != Established)
1689 continue;
1690
1691 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1692 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1693 {
1694 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1695 continue;
1696 }
1697
1698 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1699
1700 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
1701 {
1702 new_select = ri;
1703 }
1704 }
1705
1706 /* Now that we know which path is the bestpath see if any of the other paths
1707 * qualify as multipaths
1708 */
1709 if (debug)
1710 {
1711 if (new_select)
1712 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1713 else
1714 sprintf (path_buf, "NONE");
1715 zlog_debug("%s: After path selection, newbest is %s oldbest was %s",
1716 pfx_buf, path_buf,
1717 old_select ? old_select->peer->host : "NONE");
1718 }
1719
1720 if (do_mpath && new_select)
1721 {
1722 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1723 {
1724
1725 if (debug)
1726 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1727
1728 if (ri == new_select)
1729 {
1730 if (debug)
1731 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1732 pfx_buf, path_buf);
1733 bgp_mp_list_add (&mp_list, ri);
1734 continue;
1735 }
1736
1737 if (BGP_INFO_HOLDDOWN (ri))
1738 continue;
1739
1740 if (ri->peer &&
1741 ri->peer != bgp->peer_self &&
1742 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1743 if (ri->peer->status != Established)
1744 continue;
1745
1746 if (!bgp_info_nexthop_cmp (ri, new_select))
1747 {
1748 if (debug)
1749 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1750 pfx_buf, path_buf);
1751 continue;
1752 }
1753
1754 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
1755
1756 if (paths_eq)
1757 {
1758 if (debug)
1759 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1760 pfx_buf, path_buf);
1761 bgp_mp_list_add (&mp_list, ri);
1762 }
1763 }
1764 }
1765
1766 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1767 bgp_info_mpath_aggregate_update (new_select, old_select);
1768 bgp_mp_list_clear (&mp_list);
1769
1770 result->old = old_select;
1771 result->new = new_select;
1772
1773 return;
1774 }
1775
1776 /*
1777 * A new route/change in bestpath of an existing route. Evaluate the path
1778 * for advertisement to the subgroup.
1779 */
1780 int
1781 subgroup_process_announce_selected (struct update_subgroup *subgrp,
1782 struct bgp_info *selected,
1783 struct bgp_node *rn,
1784 u_int32_t addpath_tx_id)
1785 {
1786 struct prefix *p;
1787 struct peer *onlypeer;
1788 struct attr attr;
1789 struct attr_extra extra;
1790 afi_t afi;
1791 safi_t safi;
1792
1793 p = &rn->p;
1794 afi = SUBGRP_AFI(subgrp);
1795 safi = SUBGRP_SAFI(subgrp);
1796 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1797 (SUBGRP_PFIRST(subgrp))->peer : NULL);
1798
1799 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1800 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1801 PEER_STATUS_ORF_WAIT_REFRESH))
1802 return 0;
1803
1804 /* It's initialized in bgp_announce_check() */
1805 attr.extra = &extra;
1806
1807 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1808 if (selected)
1809 {
1810 if (subgroup_announce_check(selected, subgrp, p, &attr))
1811 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1812 else
1813 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1814 }
1815
1816 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1817 else
1818 {
1819 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
1820 }
1821
1822 return 0;
1823 }
1824
1825 /*
1826 * Clear IGP changed flag and attribute changed flag for a route (all paths).
1827 * This is called at the end of route processing.
1828 */
1829 static void
1830 bgp_zebra_clear_route_change_flags (struct bgp_node *rn)
1831 {
1832 struct bgp_info *ri;
1833
1834 for (ri = rn->info; ri; ri = ri->next)
1835 {
1836 if (BGP_INFO_HOLDDOWN (ri))
1837 continue;
1838 UNSET_FLAG (ri->flags, BGP_INFO_IGP_CHANGED);
1839 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1840 }
1841 }
1842
1843 /*
1844 * Has the route changed from the RIB's perspective? This is invoked only
1845 * if the route selection returns the same best route as earlier - to
1846 * determine if we need to update zebra or not.
1847 */
1848 static int
1849 bgp_zebra_has_route_changed (struct bgp_node *rn, struct bgp_info *selected)
1850 {
1851 struct bgp_info *mpinfo;
1852
1853 /* If this is multipath, check all selected paths for any nexthop change or
1854 * attribute change. Some attribute changes (e.g., community) aren't of
1855 * relevance to the RIB, but we'll update zebra to ensure we handle the
1856 * case of BGP nexthop change. This is the behavior when the best path has
1857 * an attribute change anyway.
1858 */
1859 if (CHECK_FLAG (selected->flags, BGP_INFO_IGP_CHANGED) ||
1860 CHECK_FLAG (selected->flags, BGP_INFO_MULTIPATH_CHG))
1861 return 1;
1862
1863 /* If this is multipath, check all selected paths for any nexthop change */
1864 for (mpinfo = bgp_info_mpath_first (selected); mpinfo;
1865 mpinfo = bgp_info_mpath_next (mpinfo))
1866 {
1867 if (CHECK_FLAG (mpinfo->flags, BGP_INFO_IGP_CHANGED)
1868 || CHECK_FLAG (mpinfo->flags, BGP_INFO_ATTR_CHANGED))
1869 return 1;
1870 }
1871
1872 /* Nothing has changed from the RIB's perspective. */
1873 return 0;
1874 }
1875
1876 struct bgp_process_queue
1877 {
1878 struct bgp *bgp;
1879 struct bgp_node *rn;
1880 afi_t afi;
1881 safi_t safi;
1882 };
1883
1884 static wq_item_status
1885 bgp_process_main (struct work_queue *wq, void *data)
1886 {
1887 struct bgp_process_queue *pq = data;
1888 struct bgp *bgp = pq->bgp;
1889 struct bgp_node *rn = pq->rn;
1890 afi_t afi = pq->afi;
1891 safi_t safi = pq->safi;
1892 struct prefix *p = &rn->p;
1893 struct bgp_info *new_select;
1894 struct bgp_info *old_select;
1895 struct bgp_info_pair old_and_new;
1896
1897 /* Is it end of initial update? (after startup) */
1898 if (!rn)
1899 {
1900 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1901 sizeof(bgp->update_delay_zebra_resume_time));
1902
1903 bgp->main_zebra_update_hold = 0;
1904 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1905 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1906 {
1907 bgp_zebra_announce_table(bgp, afi, safi);
1908 }
1909 bgp->main_peers_update_hold = 0;
1910
1911 bgp_start_routeadv(bgp);
1912 return WQ_SUCCESS;
1913 }
1914
1915 /* Best path selection. */
1916 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1917 old_select = old_and_new.old;
1918 new_select = old_and_new.new;
1919
1920 /* Nothing to do. */
1921 if (old_select && old_select == new_select &&
1922 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1923 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1924 !bgp->addpath_tx_used[afi][safi])
1925 {
1926 if (bgp_zebra_has_route_changed (rn, old_select))
1927 {
1928 #if ENABLE_BGP_VNC
1929 vnc_import_bgp_add_route(bgp, p, old_select);
1930 vnc_import_bgp_exterior_add_route(bgp, p, old_select);
1931 #endif
1932 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1933 }
1934 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1935 bgp_zebra_clear_route_change_flags (rn);
1936 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1937 return WQ_SUCCESS;
1938 }
1939
1940 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1941 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1942
1943 /* bestpath has changed; bump version */
1944 if (old_select || new_select)
1945 {
1946 bgp_bump_version(rn);
1947
1948 if (!bgp->t_rmap_def_originate_eval)
1949 {
1950 bgp_lock (bgp);
1951 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
1952 update_group_refresh_default_originate_route_map,
1953 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1954 }
1955 }
1956
1957 if (old_select)
1958 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1959 if (new_select)
1960 {
1961 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1962 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1963 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1964 }
1965
1966 #if ENABLE_BGP_VNC
1967 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
1968 if (old_select != new_select) {
1969 if (old_select) {
1970 vnc_import_bgp_exterior_del_route(bgp, p, old_select);
1971 vnc_import_bgp_del_route(bgp, p, old_select);
1972 }
1973 if (new_select) {
1974 vnc_import_bgp_exterior_add_route(bgp, p, new_select);
1975 vnc_import_bgp_add_route(bgp, p, new_select);
1976 }
1977 }
1978 }
1979 #endif
1980
1981 group_announce_route(bgp, afi, safi, rn, new_select);
1982
1983 /* FIB update. */
1984 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) &&
1985 (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) &&
1986 !bgp_option_check (BGP_OPT_NO_FIB))
1987 {
1988 if (new_select
1989 && new_select->type == ZEBRA_ROUTE_BGP
1990 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1991 new_select->sub_type == BGP_ROUTE_AGGREGATE))
1992 bgp_zebra_announce (p, new_select, bgp, afi, safi);
1993 else
1994 {
1995 /* Withdraw the route from the kernel. */
1996 if (old_select
1997 && old_select->type == ZEBRA_ROUTE_BGP
1998 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
1999 old_select->sub_type == BGP_ROUTE_AGGREGATE))
2000 bgp_zebra_withdraw (p, old_select, safi);
2001 }
2002 }
2003
2004 /* Clear any route change flags. */
2005 bgp_zebra_clear_route_change_flags (rn);
2006
2007 /* Reap old select bgp_info, if it has been removed */
2008 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2009 bgp_info_reap (rn, old_select);
2010
2011 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2012 return WQ_SUCCESS;
2013 }
2014
2015 static void
2016 bgp_processq_del (struct work_queue *wq, void *data)
2017 {
2018 struct bgp_process_queue *pq = data;
2019 struct bgp_table *table;
2020
2021 bgp_unlock (pq->bgp);
2022 if (pq->rn)
2023 {
2024 table = bgp_node_table (pq->rn);
2025 bgp_unlock_node (pq->rn);
2026 bgp_table_unlock (table);
2027 }
2028 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
2029 }
2030
2031 void
2032 bgp_process_queue_init (void)
2033 {
2034 if (!bm->process_main_queue)
2035 {
2036 bm->process_main_queue
2037 = work_queue_new (bm->master, "process_main_queue");
2038
2039 if ( !bm->process_main_queue)
2040 {
2041 zlog_err ("%s: Failed to allocate work queue", __func__);
2042 exit (1);
2043 }
2044 }
2045
2046 bm->process_main_queue->spec.workfunc = &bgp_process_main;
2047 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
2048 bm->process_main_queue->spec.max_retries = 0;
2049 bm->process_main_queue->spec.hold = 50;
2050 /* Use a higher yield value of 50ms for main queue processing */
2051 bm->process_main_queue->spec.yield = 50 * 1000L;
2052 }
2053
2054 void
2055 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
2056 {
2057 struct bgp_process_queue *pqnode;
2058
2059 /* already scheduled for processing? */
2060 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
2061 return;
2062
2063 if (bm->process_main_queue == NULL)
2064 bgp_process_queue_init ();
2065
2066 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2067 sizeof (struct bgp_process_queue));
2068 if (!pqnode)
2069 return;
2070
2071 /* all unlocked in bgp_processq_del */
2072 bgp_table_lock (bgp_node_table (rn));
2073 pqnode->rn = bgp_lock_node (rn);
2074 pqnode->bgp = bgp;
2075 bgp_lock (bgp);
2076 pqnode->afi = afi;
2077 pqnode->safi = safi;
2078 work_queue_add (bm->process_main_queue, pqnode);
2079 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2080 return;
2081 }
2082
2083 void
2084 bgp_add_eoiu_mark (struct bgp *bgp)
2085 {
2086 struct bgp_process_queue *pqnode;
2087
2088 if (bm->process_main_queue == NULL)
2089 bgp_process_queue_init ();
2090
2091 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2092 sizeof (struct bgp_process_queue));
2093 if (!pqnode)
2094 return;
2095
2096 pqnode->rn = NULL;
2097 pqnode->bgp = bgp;
2098 bgp_lock (bgp);
2099 work_queue_add (bm->process_main_queue, pqnode);
2100 }
2101
2102 static int
2103 bgp_maximum_prefix_restart_timer (struct thread *thread)
2104 {
2105 struct peer *peer;
2106
2107 peer = THREAD_ARG (thread);
2108 peer->t_pmax_restart = NULL;
2109
2110 if (bgp_debug_neighbor_events(peer))
2111 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2112 peer->host);
2113
2114 peer_clear (peer, NULL);
2115
2116 return 0;
2117 }
2118
2119 int
2120 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2121 safi_t safi, int always)
2122 {
2123 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2124 return 0;
2125
2126 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
2127 {
2128 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2129 && ! always)
2130 return 0;
2131
2132 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2133 "limit %ld", afi_safi_print (afi, safi), peer->host,
2134 peer->pcount[afi][safi], peer->pmax[afi][safi]);
2135 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2136
2137 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2138 return 0;
2139
2140 {
2141 u_int8_t ndata[7];
2142
2143 if (safi == SAFI_MPLS_VPN)
2144 safi = SAFI_MPLS_LABELED_VPN;
2145
2146 ndata[0] = (afi >> 8);
2147 ndata[1] = afi;
2148 ndata[2] = safi;
2149 ndata[3] = (peer->pmax[afi][safi] >> 24);
2150 ndata[4] = (peer->pmax[afi][safi] >> 16);
2151 ndata[5] = (peer->pmax[afi][safi] >> 8);
2152 ndata[6] = (peer->pmax[afi][safi]);
2153
2154 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2155 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2156 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2157 }
2158
2159 /* Dynamic peers will just close their connection. */
2160 if (peer_dynamic_neighbor (peer))
2161 return 1;
2162
2163 /* restart timer start */
2164 if (peer->pmax_restart[afi][safi])
2165 {
2166 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2167
2168 if (bgp_debug_neighbor_events(peer))
2169 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2170 peer->host, peer->v_pmax_restart);
2171
2172 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2173 peer->v_pmax_restart);
2174 }
2175
2176 return 1;
2177 }
2178 else
2179 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2180
2181 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2182 {
2183 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2184 && ! always)
2185 return 0;
2186
2187 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2188 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2189 peer->pmax[afi][safi]);
2190 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2191 }
2192 else
2193 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2194 return 0;
2195 }
2196
2197 /* Unconditionally remove the route from the RIB, without taking
2198 * damping into consideration (eg, because the session went down)
2199 */
2200 static void
2201 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2202 afi_t afi, safi_t safi)
2203 {
2204 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2205
2206 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2207 bgp_info_delete (rn, ri); /* keep historical info */
2208
2209 bgp_process (peer->bgp, rn, afi, safi);
2210 }
2211
2212 static void
2213 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2214 afi_t afi, safi_t safi, struct prefix_rd *prd)
2215 {
2216 int status = BGP_DAMP_NONE;
2217
2218 /* apply dampening, if result is suppressed, we'll be retaining
2219 * the bgp_info in the RIB for historical reference.
2220 */
2221 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2222 && peer->sort == BGP_PEER_EBGP)
2223 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2224 == BGP_DAMP_SUPPRESSED)
2225 {
2226 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2227 return;
2228 }
2229
2230 #if ENABLE_BGP_VNC
2231 if (safi == SAFI_MPLS_VPN) {
2232 struct bgp_node *prn = NULL;
2233 struct bgp_table *table = NULL;
2234
2235 prn = bgp_node_get(peer->bgp->rib[afi][safi], (struct prefix *) prd);
2236 if (prn->info) {
2237 table = (struct bgp_table *)(prn->info);
2238
2239 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2240 peer->bgp,
2241 prd,
2242 table,
2243 &rn->p,
2244 ri);
2245 }
2246 bgp_unlock_node(prn);
2247 }
2248 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2249 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2250
2251 vnc_import_bgp_del_route(peer->bgp, &rn->p, ri);
2252 vnc_import_bgp_exterior_del_route(peer->bgp, &rn->p, ri);
2253 }
2254 }
2255 #endif
2256 bgp_rib_remove (rn, ri, peer, afi, safi);
2257 }
2258
2259 static struct bgp_info *
2260 info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
2261 struct bgp_node *rn)
2262 {
2263 struct bgp_info *new;
2264
2265 /* Make new BGP info. */
2266 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2267 new->type = type;
2268 new->instance = instance;
2269 new->sub_type = sub_type;
2270 new->peer = peer;
2271 new->attr = attr;
2272 new->uptime = bgp_clock ();
2273 new->net = rn;
2274 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
2275 return new;
2276 }
2277
2278 static void
2279 bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
2280 {
2281 if (addpath_id)
2282 sprintf(buf, " with addpath ID %d", addpath_id);
2283 }
2284
2285
2286 /* Check if received nexthop is valid or not. */
2287 static int
2288 bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
2289 {
2290 struct attr_extra *attre = attr->extra;
2291 int ret = 0;
2292
2293 /* Only validated for unicast and multicast currently. */
2294 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2295 return 0;
2296
2297 /* If NEXT_HOP is present, validate it. */
2298 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2299 {
2300 if (attr->nexthop.s_addr == 0 ||
2301 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2302 bgp_nexthop_self (bgp, attr))
2303 ret = 1;
2304 }
2305
2306 /* If MP_NEXTHOP is present, validate it. */
2307 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2308 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2309 * it is not an IPv6 link-local address.
2310 */
2311 if (attre && attre->mp_nexthop_len)
2312 {
2313 switch (attre->mp_nexthop_len)
2314 {
2315 case BGP_ATTR_NHLEN_IPV4:
2316 case BGP_ATTR_NHLEN_VPNV4:
2317 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2318 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2319 break;
2320
2321 #ifdef HAVE_IPV6
2322 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2323 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2324 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2325 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2326 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2327 break;
2328 #endif /* HAVE_IPV6 */
2329
2330 default:
2331 ret = 1;
2332 break;
2333 }
2334 }
2335
2336 return ret;
2337 }
2338
2339 int
2340 bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2341 struct attr *attr, afi_t afi, safi_t safi, int type,
2342 int sub_type, struct prefix_rd *prd, u_char *tag,
2343 int soft_reconfig)
2344 {
2345 int ret;
2346 int aspath_loop_count = 0;
2347 struct bgp_node *rn;
2348 struct bgp *bgp;
2349 struct attr new_attr;
2350 struct attr_extra new_extra;
2351 struct attr *attr_new;
2352 struct bgp_info *ri;
2353 struct bgp_info *new;
2354 const char *reason;
2355 char buf[SU_ADDRSTRLEN];
2356 char buf2[30];
2357 int connected = 0;
2358 #if ENABLE_BGP_VNC
2359 int vnc_implicit_withdraw = 0;
2360 #endif
2361
2362 bgp = peer->bgp;
2363 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2364
2365 /* When peer's soft reconfiguration enabled. Record input packet in
2366 Adj-RIBs-In. */
2367 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2368 && peer != bgp->peer_self)
2369 bgp_adj_in_set (rn, peer, attr, addpath_id);
2370
2371 /* Check previously received route. */
2372 for (ri = rn->info; ri; ri = ri->next)
2373 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2374 ri->addpath_rx_id == addpath_id)
2375 break;
2376
2377 /* AS path local-as loop check. */
2378 if (peer->change_local_as)
2379 {
2380 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2381 aspath_loop_count = 1;
2382
2383 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2384 {
2385 reason = "as-path contains our own AS;";
2386 goto filtered;
2387 }
2388 }
2389
2390 /* AS path loop check. */
2391 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2392 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2393 && aspath_loop_check(attr->aspath, bgp->confed_id)
2394 > peer->allowas_in[afi][safi]))
2395 {
2396 reason = "as-path contains our own AS;";
2397 goto filtered;
2398 }
2399
2400 /* Route reflector originator ID check. */
2401 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2402 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2403 {
2404 reason = "originator is us;";
2405 goto filtered;
2406 }
2407
2408 /* Route reflector cluster ID check. */
2409 if (bgp_cluster_filter (peer, attr))
2410 {
2411 reason = "reflected from the same cluster;";
2412 goto filtered;
2413 }
2414
2415 /* Apply incoming filter. */
2416 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2417 {
2418 reason = "filter;";
2419 goto filtered;
2420 }
2421
2422 new_attr.extra = &new_extra;
2423 bgp_attr_dup (&new_attr, attr);
2424
2425 /* Apply incoming route-map.
2426 * NB: new_attr may now contain newly allocated values from route-map "set"
2427 * commands, so we need bgp_attr_flush in the error paths, until we intern
2428 * the attr (which takes over the memory references) */
2429 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2430 {
2431 reason = "route-map;";
2432 bgp_attr_flush (&new_attr);
2433 goto filtered;
2434 }
2435
2436 /* next hop check. */
2437 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
2438 {
2439 reason = "martian or self next-hop;";
2440 bgp_attr_flush (&new_attr);
2441 goto filtered;
2442 }
2443
2444 attr_new = bgp_attr_intern (&new_attr);
2445
2446 /* If the update is implicit withdraw. */
2447 if (ri)
2448 {
2449 ri->uptime = bgp_clock ();
2450
2451 /* Same attribute comes in. */
2452 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2453 && attrhash_cmp (ri->attr, attr_new))
2454 {
2455 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2456 && peer->sort == BGP_PEER_EBGP
2457 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2458 {
2459 if (bgp_debug_update(peer, p, NULL, 1))
2460 {
2461 bgp_info_addpath_rx_str(addpath_id, buf2);
2462 zlog_debug ("%s rcvd %s/%d%s",
2463 peer->host,
2464 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2465 p->prefixlen, buf2);
2466 }
2467
2468 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2469 {
2470 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2471 bgp_process (bgp, rn, afi, safi);
2472 }
2473 }
2474 else /* Duplicate - odd */
2475 {
2476 if (bgp_debug_update(peer, p, NULL, 1))
2477 {
2478 if (!peer->rcvd_attr_printed)
2479 {
2480 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2481 peer->rcvd_attr_printed = 1;
2482 }
2483
2484 bgp_info_addpath_rx_str(addpath_id, buf2);
2485 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
2486 peer->host,
2487 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2488 p->prefixlen, buf2);
2489 }
2490
2491 /* graceful restart STALE flag unset. */
2492 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2493 {
2494 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2495 bgp_process (bgp, rn, afi, safi);
2496 }
2497 }
2498
2499 bgp_unlock_node (rn);
2500 bgp_attr_unintern (&attr_new);
2501
2502 return 0;
2503 }
2504
2505 /* Withdraw/Announce before we fully processed the withdraw */
2506 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2507 {
2508 if (bgp_debug_update(peer, p, NULL, 1))
2509 {
2510 bgp_info_addpath_rx_str(addpath_id, buf2);
2511 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2512 peer->host,
2513 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2514 p->prefixlen, buf2);
2515 }
2516 bgp_info_restore (rn, ri);
2517 }
2518
2519 /* Received Logging. */
2520 if (bgp_debug_update(peer, p, NULL, 1))
2521 {
2522 bgp_info_addpath_rx_str(addpath_id, buf2);
2523 zlog_debug ("%s rcvd %s/%d%s",
2524 peer->host,
2525 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2526 p->prefixlen, buf2);
2527 }
2528
2529 /* graceful restart STALE flag unset. */
2530 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2531 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2532
2533 /* The attribute is changed. */
2534 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2535
2536 /* implicit withdraw, decrement aggregate and pcount here.
2537 * only if update is accepted, they'll increment below.
2538 */
2539 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2540
2541 /* Update bgp route dampening information. */
2542 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2543 && peer->sort == BGP_PEER_EBGP)
2544 {
2545 /* This is implicit withdraw so we should update dampening
2546 information. */
2547 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2548 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2549 }
2550 #if ENABLE_BGP_VNC
2551 if (safi == SAFI_MPLS_VPN) {
2552 struct bgp_node *prn = NULL;
2553 struct bgp_table *table = NULL;
2554
2555 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2556 if (prn->info) {
2557 table = (struct bgp_table *)(prn->info);
2558
2559 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2560 bgp,
2561 prd,
2562 table,
2563 p,
2564 ri);
2565 }
2566 bgp_unlock_node(prn);
2567 }
2568 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2569 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2570 /*
2571 * Implicit withdraw case.
2572 */
2573 ++vnc_implicit_withdraw;
2574 vnc_import_bgp_del_route(bgp, p, ri);
2575 vnc_import_bgp_exterior_del_route(bgp, p, ri);
2576 }
2577 }
2578 #endif
2579
2580 /* Update to new attribute. */
2581 bgp_attr_unintern (&ri->attr);
2582 ri->attr = attr_new;
2583
2584 /* Update MPLS tag. */
2585 if (safi == SAFI_MPLS_VPN)
2586 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2587
2588 #if ENABLE_BGP_VNC
2589 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
2590 {
2591 if (vnc_implicit_withdraw)
2592 {
2593 /*
2594 * Add back the route with its new attributes (e.g., nexthop).
2595 * The route is still selected, until the route selection
2596 * queued by bgp_process actually runs. We have to make this
2597 * update to the VNC side immediately to avoid racing against
2598 * configuration changes (e.g., route-map changes) which
2599 * trigger re-importation of the entire RIB.
2600 */
2601 vnc_import_bgp_add_route(bgp, p, ri);
2602 vnc_import_bgp_exterior_add_route(bgp, p, ri);
2603 }
2604 }
2605 #endif
2606
2607 /* Update bgp route dampening information. */
2608 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2609 && peer->sort == BGP_PEER_EBGP)
2610 {
2611 /* Now we do normal update dampening. */
2612 ret = bgp_damp_update (ri, rn, afi, safi);
2613 if (ret == BGP_DAMP_SUPPRESSED)
2614 {
2615 bgp_unlock_node (rn);
2616 return 0;
2617 }
2618 }
2619
2620 /* Nexthop reachability check. */
2621 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2622 {
2623 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2624 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2625 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2626 connected = 1;
2627 else
2628 connected = 0;
2629
2630 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
2631 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2632 else
2633 {
2634 if (BGP_DEBUG(nht, NHT))
2635 {
2636 char buf1[INET6_ADDRSTRLEN];
2637 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2638 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2639 }
2640 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2641 }
2642 }
2643 else
2644 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2645
2646 #if ENABLE_BGP_VNC
2647 if (safi == SAFI_MPLS_VPN)
2648 {
2649 struct bgp_node *prn = NULL;
2650 struct bgp_table *table = NULL;
2651
2652 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2653 if (prn->info)
2654 {
2655 table = (struct bgp_table *)(prn->info);
2656
2657 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2658 bgp,
2659 prd,
2660 table,
2661 p,
2662 ri);
2663 }
2664 bgp_unlock_node(prn);
2665 }
2666 #endif
2667
2668 /* Process change. */
2669 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2670
2671 bgp_process (bgp, rn, afi, safi);
2672 bgp_unlock_node (rn);
2673
2674 return 0;
2675 } // End of implicit withdraw
2676
2677 /* Received Logging. */
2678 if (bgp_debug_update(peer, p, NULL, 1))
2679 {
2680 if (!peer->rcvd_attr_printed)
2681 {
2682 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2683 peer->rcvd_attr_printed = 1;
2684 }
2685
2686 bgp_info_addpath_rx_str(addpath_id, buf2);
2687 zlog_debug ("%s rcvd %s/%d%s",
2688 peer->host,
2689 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2690 p->prefixlen, buf2);
2691 }
2692
2693 /* Make new BGP info. */
2694 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2695
2696 /* Update MPLS tag. */
2697 if (safi == SAFI_MPLS_VPN)
2698 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2699
2700 /* Nexthop reachability check. */
2701 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2702 {
2703 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2704 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2705 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2706 connected = 1;
2707 else
2708 connected = 0;
2709
2710 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
2711 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2712 else
2713 {
2714 if (BGP_DEBUG(nht, NHT))
2715 {
2716 char buf1[INET6_ADDRSTRLEN];
2717 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2718 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2719 }
2720 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2721 }
2722 }
2723 else
2724 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2725
2726 /* Addpath ID */
2727 new->addpath_rx_id = addpath_id;
2728
2729 /* Increment prefix */
2730 bgp_aggregate_increment (bgp, p, new, afi, safi);
2731
2732 /* Register new BGP information. */
2733 bgp_info_add (rn, new);
2734
2735 /* route_node_get lock */
2736 bgp_unlock_node (rn);
2737
2738 #if ENABLE_BGP_VNC
2739 if (safi == SAFI_MPLS_VPN)
2740 {
2741 struct bgp_node *prn = NULL;
2742 struct bgp_table *table = NULL;
2743
2744 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2745 if (prn->info)
2746 {
2747 table = (struct bgp_table *)(prn->info);
2748
2749 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2750 bgp,
2751 prd,
2752 table,
2753 p,
2754 new);
2755 }
2756 bgp_unlock_node(prn);
2757 }
2758 #endif
2759
2760 /* If maximum prefix count is configured and current prefix
2761 count exeed it. */
2762 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2763 return -1;
2764
2765 /* Process change. */
2766 bgp_process (bgp, rn, afi, safi);
2767
2768 return 0;
2769
2770 /* This BGP update is filtered. Log the reason then update BGP
2771 entry. */
2772 filtered:
2773 if (bgp_debug_update(peer, p, NULL, 1))
2774 {
2775 if (!peer->rcvd_attr_printed)
2776 {
2777 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2778 peer->rcvd_attr_printed = 1;
2779 }
2780
2781 bgp_info_addpath_rx_str(addpath_id, buf2);
2782 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
2783 peer->host,
2784 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2785 p->prefixlen, buf2, reason);
2786 }
2787
2788 if (ri)
2789 bgp_rib_remove (rn, ri, peer, afi, safi);
2790
2791 bgp_unlock_node (rn);
2792
2793 return 0;
2794 }
2795
2796 int
2797 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2798 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2799 struct prefix_rd *prd, u_char *tag)
2800 {
2801 struct bgp *bgp;
2802 char buf[SU_ADDRSTRLEN];
2803 char buf2[30];
2804 struct bgp_node *rn;
2805 struct bgp_info *ri;
2806
2807 bgp = peer->bgp;
2808
2809 /* Lookup node. */
2810 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2811
2812 /* If peer is soft reconfiguration enabled. Record input packet for
2813 * further calculation.
2814 *
2815 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2816 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2817 * the iteration over all RS clients.
2818 * Since we need to remove the entry from adj_in anyway, do that first and
2819 * if there was no entry, we don't need to do anything more.
2820 */
2821 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2822 && peer != bgp->peer_self)
2823 if (!bgp_adj_in_unset (rn, peer, addpath_id))
2824 {
2825 if (bgp_debug_update (peer, p, NULL, 1))
2826 zlog_debug ("%s withdrawing route %s/%d "
2827 "not in adj-in", peer->host,
2828 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2829 p->prefixlen);
2830 bgp_unlock_node (rn);
2831 return 0;
2832 }
2833
2834 /* Lookup withdrawn route. */
2835 for (ri = rn->info; ri; ri = ri->next)
2836 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2837 ri->addpath_rx_id == addpath_id)
2838 break;
2839
2840 /* Logging. */
2841 if (bgp_debug_update(peer, p, NULL, 1))
2842 {
2843 bgp_info_addpath_rx_str(addpath_id, buf2);
2844 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2845 peer->host,
2846 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2847 p->prefixlen, buf2);
2848 }
2849
2850 /* Withdraw specified route from routing table. */
2851 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2852 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
2853 else if (bgp_debug_update(peer, p, NULL, 1))
2854 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2855 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2856 p->prefixlen);
2857
2858 /* Unlock bgp_node_get() lock. */
2859 bgp_unlock_node (rn);
2860
2861 return 0;
2862 }
2863
2864 void
2865 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2866 {
2867 struct update_subgroup *subgrp;
2868 subgrp = peer_subgroup(peer, afi, safi);
2869 subgroup_default_originate(subgrp, withdraw);
2870 }
2871
2872
2873 /*
2874 * bgp_stop_announce_route_timer
2875 */
2876 void
2877 bgp_stop_announce_route_timer (struct peer_af *paf)
2878 {
2879 if (!paf->t_announce_route)
2880 return;
2881
2882 THREAD_TIMER_OFF (paf->t_announce_route);
2883 }
2884
2885 /*
2886 * bgp_announce_route_timer_expired
2887 *
2888 * Callback that is invoked when the route announcement timer for a
2889 * peer_af expires.
2890 */
2891 static int
2892 bgp_announce_route_timer_expired (struct thread *t)
2893 {
2894 struct peer_af *paf;
2895 struct peer *peer;
2896
2897 paf = THREAD_ARG (t);
2898 peer = paf->peer;
2899
2900 assert (paf->t_announce_route);
2901 paf->t_announce_route = NULL;
2902
2903 if (peer->status != Established)
2904 return 0;
2905
2906 if (!peer->afc_nego[paf->afi][paf->safi])
2907 return 0;
2908
2909 peer_af_announce_route (paf, 1);
2910 return 0;
2911 }
2912
2913 /*
2914 * bgp_announce_route
2915 *
2916 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2917 */
2918 void
2919 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2920 {
2921 struct peer_af *paf;
2922 struct update_subgroup *subgrp;
2923
2924 paf = peer_af_find (peer, afi, safi);
2925 if (!paf)
2926 return;
2927 subgrp = PAF_SUBGRP(paf);
2928
2929 /*
2930 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2931 * or a refresh has already been triggered.
2932 */
2933 if (!subgrp || paf->t_announce_route)
2934 return;
2935
2936 /*
2937 * Start a timer to stagger/delay the announce. This serves
2938 * two purposes - announcement can potentially be combined for
2939 * multiple peers and the announcement doesn't happen in the
2940 * vty context.
2941 */
2942 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
2943 bgp_announce_route_timer_expired, paf,
2944 (subgrp->peer_count == 1) ?
2945 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2946 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2947 }
2948
2949 /*
2950 * Announce routes from all AF tables to a peer.
2951 *
2952 * This should ONLY be called when there is a need to refresh the
2953 * routes to the peer based on a policy change for this peer alone
2954 * or a route refresh request received from the peer.
2955 * The operation will result in splitting the peer from its existing
2956 * subgroups and putting it in new subgroups.
2957 */
2958 void
2959 bgp_announce_route_all (struct peer *peer)
2960 {
2961 afi_t afi;
2962 safi_t safi;
2963
2964 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2965 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2966 bgp_announce_route (peer, afi, safi);
2967 }
2968
2969 static void
2970 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2971 struct bgp_table *table, struct prefix_rd *prd)
2972 {
2973 int ret;
2974 struct bgp_node *rn;
2975 struct bgp_adj_in *ain;
2976
2977 if (! table)
2978 table = peer->bgp->rib[afi][safi];
2979
2980 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2981 for (ain = rn->adj_in; ain; ain = ain->next)
2982 {
2983 if (ain->peer == peer)
2984 {
2985 struct bgp_info *ri = rn->info;
2986 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
2987
2988 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
2989 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2990 prd, tag, 1);
2991
2992 if (ret < 0)
2993 {
2994 bgp_unlock_node (rn);
2995 return;
2996 }
2997 }
2998 }
2999 }
3000
3001 void
3002 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3003 {
3004 struct bgp_node *rn;
3005 struct bgp_table *table;
3006
3007 if (peer->status != Established)
3008 return;
3009
3010 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
3011 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
3012 else
3013 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3014 rn = bgp_route_next (rn))
3015 if ((table = rn->info) != NULL)
3016 {
3017 struct prefix_rd prd;
3018 prd.family = AF_UNSPEC;
3019 prd.prefixlen = 64;
3020 memcpy(&prd.val, rn->p.u.val, 8);
3021
3022 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3023 }
3024 }
3025
3026
3027 struct bgp_clear_node_queue
3028 {
3029 struct bgp_node *rn;
3030 };
3031
3032 static wq_item_status
3033 bgp_clear_route_node (struct work_queue *wq, void *data)
3034 {
3035 struct bgp_clear_node_queue *cnq = data;
3036 struct bgp_node *rn = cnq->rn;
3037 struct peer *peer = wq->spec.data;
3038 struct bgp_info *ri;
3039 afi_t afi = bgp_node_table (rn)->afi;
3040 safi_t safi = bgp_node_table (rn)->safi;
3041
3042 assert (rn && peer);
3043
3044 /* It is possible that we have multiple paths for a prefix from a peer
3045 * if that peer is using AddPath.
3046 */
3047 for (ri = rn->info; ri; ri = ri->next)
3048 if (ri->peer == peer)
3049 {
3050 /* graceful restart STALE flag set. */
3051 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3052 && peer->nsf[afi][safi]
3053 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
3054 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3055 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
3056 else
3057 bgp_rib_remove (rn, ri, peer, afi, safi);
3058 }
3059 return WQ_SUCCESS;
3060 }
3061
3062 static void
3063 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
3064 {
3065 struct bgp_clear_node_queue *cnq = data;
3066 struct bgp_node *rn = cnq->rn;
3067 struct bgp_table *table = bgp_node_table (rn);
3068
3069 bgp_unlock_node (rn);
3070 bgp_table_unlock (table);
3071 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
3072 }
3073
3074 static void
3075 bgp_clear_node_complete (struct work_queue *wq)
3076 {
3077 struct peer *peer = wq->spec.data;
3078
3079 /* Tickle FSM to start moving again */
3080 BGP_EVENT_ADD (peer, Clearing_Completed);
3081
3082 peer_unlock (peer); /* bgp_clear_route */
3083 }
3084
3085 static void
3086 bgp_clear_node_queue_init (struct peer *peer)
3087 {
3088 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
3089
3090 snprintf (wname, sizeof(wname), "clear %s", peer->host);
3091 #undef CLEAR_QUEUE_NAME_LEN
3092
3093 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
3094 {
3095 zlog_err ("%s: Failed to allocate work queue", __func__);
3096 exit (1);
3097 }
3098 peer->clear_node_queue->spec.hold = 10;
3099 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3100 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3101 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3102 peer->clear_node_queue->spec.max_retries = 0;
3103
3104 /* we only 'lock' this peer reference when the queue is actually active */
3105 peer->clear_node_queue->spec.data = peer;
3106 }
3107
3108 static void
3109 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
3110 struct bgp_table *table)
3111 {
3112 struct bgp_node *rn;
3113
3114
3115 if (! table)
3116 table = peer->bgp->rib[afi][safi];
3117
3118 /* If still no table => afi/safi isn't configured at all or smth. */
3119 if (! table)
3120 return;
3121
3122 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3123 {
3124 struct bgp_info *ri;
3125 struct bgp_adj_in *ain;
3126 struct bgp_adj_in *ain_next;
3127
3128 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3129 * queued for every clearing peer, regardless of whether it is
3130 * relevant to the peer at hand.
3131 *
3132 * Overview: There are 3 different indices which need to be
3133 * scrubbed, potentially, when a peer is removed:
3134 *
3135 * 1 peer's routes visible via the RIB (ie accepted routes)
3136 * 2 peer's routes visible by the (optional) peer's adj-in index
3137 * 3 other routes visible by the peer's adj-out index
3138 *
3139 * 3 there is no hurry in scrubbing, once the struct peer is
3140 * removed from bgp->peer, we could just GC such deleted peer's
3141 * adj-outs at our leisure.
3142 *
3143 * 1 and 2 must be 'scrubbed' in some way, at least made
3144 * invisible via RIB index before peer session is allowed to be
3145 * brought back up. So one needs to know when such a 'search' is
3146 * complete.
3147 *
3148 * Ideally:
3149 *
3150 * - there'd be a single global queue or a single RIB walker
3151 * - rather than tracking which route_nodes still need to be
3152 * examined on a peer basis, we'd track which peers still
3153 * aren't cleared
3154 *
3155 * Given that our per-peer prefix-counts now should be reliable,
3156 * this may actually be achievable. It doesn't seem to be a huge
3157 * problem at this time,
3158 *
3159 * It is possible that we have multiple paths for a prefix from a peer
3160 * if that peer is using AddPath.
3161 */
3162 ain = rn->adj_in;
3163 while (ain)
3164 {
3165 ain_next = ain->next;
3166
3167 if (ain->peer == peer)
3168 {
3169 bgp_adj_in_remove (rn, ain);
3170 bgp_unlock_node (rn);
3171 }
3172
3173 ain = ain_next;
3174 }
3175
3176 for (ri = rn->info; ri; ri = ri->next)
3177 if (ri->peer == peer)
3178 {
3179 struct bgp_clear_node_queue *cnq;
3180
3181 /* both unlocked in bgp_clear_node_queue_del */
3182 bgp_table_lock (bgp_node_table (rn));
3183 bgp_lock_node (rn);
3184 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3185 sizeof (struct bgp_clear_node_queue));
3186 cnq->rn = rn;
3187 work_queue_add (peer->clear_node_queue, cnq);
3188 break;
3189 }
3190 }
3191 return;
3192 }
3193
3194 void
3195 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
3196 {
3197 struct bgp_node *rn;
3198 struct bgp_table *table;
3199
3200 if (peer->clear_node_queue == NULL)
3201 bgp_clear_node_queue_init (peer);
3202
3203 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3204 * Idle until it receives a Clearing_Completed event. This protects
3205 * against peers which flap faster than we can we clear, which could
3206 * lead to:
3207 *
3208 * a) race with routes from the new session being installed before
3209 * clear_route_node visits the node (to delete the route of that
3210 * peer)
3211 * b) resource exhaustion, clear_route_node likely leads to an entry
3212 * on the process_main queue. Fast-flapping could cause that queue
3213 * to grow and grow.
3214 */
3215
3216 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3217 * the unlock will happen upon work-queue completion; other wise, the
3218 * unlock happens at the end of this function.
3219 */
3220 if (!peer->clear_node_queue->thread)
3221 peer_lock (peer);
3222
3223 if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP)
3224 bgp_clear_route_table (peer, afi, safi, NULL);
3225 else
3226 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3227 rn = bgp_route_next (rn))
3228 if ((table = rn->info) != NULL)
3229 bgp_clear_route_table (peer, afi, safi, table);
3230
3231 /* unlock if no nodes got added to the clear-node-queue. */
3232 if (!peer->clear_node_queue->thread)
3233 peer_unlock (peer);
3234
3235 }
3236
3237 void
3238 bgp_clear_route_all (struct peer *peer)
3239 {
3240 afi_t afi;
3241 safi_t safi;
3242
3243 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3244 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3245 bgp_clear_route (peer, afi, safi);
3246
3247 #if ENABLE_BGP_VNC
3248 rfapiProcessPeerDown(peer);
3249 #endif
3250 }
3251
3252 void
3253 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3254 {
3255 struct bgp_table *table;
3256 struct bgp_node *rn;
3257 struct bgp_adj_in *ain;
3258 struct bgp_adj_in *ain_next;
3259
3260 table = peer->bgp->rib[afi][safi];
3261
3262 /* It is possible that we have multiple paths for a prefix from a peer
3263 * if that peer is using AddPath.
3264 */
3265 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3266 {
3267 ain = rn->adj_in;
3268
3269 while (ain)
3270 {
3271 ain_next = ain->next;
3272
3273 if (ain->peer == peer)
3274 {
3275 bgp_adj_in_remove (rn, ain);
3276 bgp_unlock_node (rn);
3277 }
3278
3279 ain = ain_next;
3280 }
3281 }
3282 }
3283
3284 void
3285 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3286 {
3287 struct bgp_node *rn;
3288 struct bgp_info *ri;
3289 struct bgp_table *table;
3290
3291 table = peer->bgp->rib[afi][safi];
3292
3293 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3294 {
3295 for (ri = rn->info; ri; ri = ri->next)
3296 if (ri->peer == peer)
3297 {
3298 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3299 bgp_rib_remove (rn, ri, peer, afi, safi);
3300 break;
3301 }
3302 }
3303 }
3304
3305 static void
3306 bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3307 {
3308 struct bgp_node *rn;
3309 struct bgp_info *ri;
3310 struct bgp_info *next;
3311
3312 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3313 for (ri = rn->info; ri; ri = next)
3314 {
3315 next = ri->next;
3316 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3317 && ri->type == ZEBRA_ROUTE_BGP
3318 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3319 ri->sub_type == BGP_ROUTE_AGGREGATE))
3320 {
3321 #if ENABLE_BGP_VNC
3322 if (table->owner && table->owner->bgp)
3323 vnc_import_bgp_del_route(table->owner->bgp, &rn->p, ri);
3324 #endif
3325 bgp_zebra_withdraw (&rn->p, ri, safi);
3326 }
3327 }
3328 }
3329
3330 /* Delete all kernel routes. */
3331 void
3332 bgp_cleanup_routes (void)
3333 {
3334 struct bgp *bgp;
3335 struct listnode *node, *nnode;
3336 afi_t afi;
3337
3338 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
3339 {
3340 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3341 {
3342 struct bgp_node *rn;
3343
3344 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
3345
3346 /*
3347 * VPN and ENCAP tables are two-level (RD is top level)
3348 */
3349 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3350 rn = bgp_route_next (rn))
3351 {
3352 if (rn->info)
3353 {
3354 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3355 bgp_table_finish ((struct bgp_table **)&(rn->info));
3356 rn->info = NULL;
3357 bgp_unlock_node(rn);
3358 }
3359 }
3360
3361 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3362 rn = bgp_route_next (rn))
3363 {
3364 if (rn->info)
3365 {
3366 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3367 bgp_table_finish ((struct bgp_table **)&(rn->info));
3368 rn->info = NULL;
3369 bgp_unlock_node(rn);
3370 }
3371 }
3372 }
3373 }
3374 }
3375
3376 void
3377 bgp_reset (void)
3378 {
3379 vty_reset ();
3380 bgp_zclient_reset ();
3381 access_list_reset ();
3382 prefix_list_reset ();
3383 }
3384
3385 static int
3386 bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3387 {
3388 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3389 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3390 }
3391
3392 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3393 value. */
3394 int
3395 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3396 {
3397 u_char *pnt;
3398 u_char *lim;
3399 struct prefix p;
3400 int psize;
3401 int ret;
3402 afi_t afi;
3403 safi_t safi;
3404 int addpath_encoded;
3405 u_int32_t addpath_id;
3406
3407 /* Check peer status. */
3408 if (peer->status != Established)
3409 return 0;
3410
3411 pnt = packet->nlri;
3412 lim = pnt + packet->length;
3413 afi = packet->afi;
3414 safi = packet->safi;
3415 addpath_id = 0;
3416 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3417
3418 for (; pnt < lim; pnt += psize)
3419 {
3420 /* Clear prefix structure. */
3421 memset (&p, 0, sizeof (struct prefix));
3422
3423 if (addpath_encoded)
3424 {
3425
3426 /* When packet overflow occurs return immediately. */
3427 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3428 return -1;
3429
3430 addpath_id = ntohl(*((uint32_t*) pnt));
3431 pnt += BGP_ADDPATH_ID_LEN;
3432 }
3433
3434 /* Fetch prefix length. */
3435 p.prefixlen = *pnt++;
3436 p.family = afi2family (afi);
3437
3438 /* Already checked in nlri_sanity_check(). We do double check
3439 here. */
3440 if ((afi == AFI_IP && p.prefixlen > 32)
3441 || (afi == AFI_IP6 && p.prefixlen > 128))
3442 return -1;
3443
3444 /* Packet size overflow check. */
3445 psize = PSIZE (p.prefixlen);
3446
3447 /* When packet overflow occur return immediately. */
3448 if (pnt + psize > lim)
3449 return -1;
3450
3451 /* Fetch prefix from NLRI packet. */
3452 memcpy (&p.u.prefix, pnt, psize);
3453
3454 /* Check address. */
3455 if (afi == AFI_IP && safi == SAFI_UNICAST)
3456 {
3457 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3458 {
3459 /*
3460 * From draft-ietf-idr-bgp4-22, Section 6.3:
3461 * If a BGP router receives an UPDATE message with a
3462 * semantically incorrect NLRI field, in which a prefix is
3463 * semantically incorrect (eg. an unexpected multicast IP
3464 * address), it should ignore the prefix.
3465 */
3466 zlog_err ("IPv4 unicast NLRI is multicast address %s",
3467 inet_ntoa (p.u.prefix4));
3468
3469 return -1;
3470 }
3471 }
3472
3473 #ifdef HAVE_IPV6
3474 /* Check address. */
3475 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3476 {
3477 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3478 {
3479 char buf[BUFSIZ];
3480
3481 zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI",
3482 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3483
3484 continue;
3485 }
3486 }
3487 #endif /* HAVE_IPV6 */
3488
3489 /* Normal process. */
3490 if (attr)
3491 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3492 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3493 else
3494 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3495 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3496
3497 /* Address family configuration mismatch or maximum-prefix count
3498 overflow. */
3499 if (ret < 0)
3500 return -1;
3501 }
3502
3503 /* Packet length consistency check. */
3504 if (pnt != lim)
3505 return -1;
3506
3507 return 0;
3508 }
3509
3510 /* NLRI encode syntax check routine. */
3511 int
3512 bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt,
3513 bgp_size_t length, int *numpfx)
3514 {
3515 u_char *end;
3516 u_char prefixlen;
3517 int psize;
3518 int addpath_encoded;
3519
3520 *numpfx = 0;
3521 end = pnt + length;
3522 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3523
3524 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3525 syntactic validity. If the field is syntactically incorrect,
3526 then the Error Subcode is set to Invalid Network Field. */
3527
3528 while (pnt < end)
3529 {
3530 int badlength;
3531
3532 /* If the NLRI is encoded using addpath then the first 4 bytes are
3533 * the addpath ID. */
3534 if (addpath_encoded)
3535 {
3536 if (pnt + BGP_ADDPATH_ID_LEN > end)
3537 {
3538 zlog_err ("%s [Error] Update packet error"
3539 " (prefix data addpath overflow)",
3540 peer->host);
3541 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3542 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3543 return -1;
3544 }
3545 pnt += BGP_ADDPATH_ID_LEN;
3546 }
3547
3548 prefixlen = *pnt++;
3549
3550 /* Prefix length check. */
3551 badlength = 0;
3552 if (safi == SAFI_ENCAP) {
3553 if (prefixlen > 128)
3554 badlength = 1;
3555 } else {
3556 if ((afi == AFI_IP && prefixlen > 32) ||
3557 (afi == AFI_IP6 && prefixlen > 128)) {
3558
3559 badlength = 1;
3560 }
3561 }
3562 if (badlength)
3563 {
3564 zlog_err ("%s [Error] Update packet error (wrong prefix length %d)",
3565 peer->host, prefixlen);
3566 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3567 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3568 return -1;
3569 }
3570
3571 /* Packet size overflow check. */
3572 psize = PSIZE (prefixlen);
3573
3574 if (pnt + psize > end)
3575 {
3576 zlog_err ("%s [Error] Update packet error"
3577 " (prefix data overflow prefix size is %d)",
3578 peer->host, psize);
3579 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3580 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3581 return -1;
3582 }
3583
3584 pnt += psize;
3585 (*numpfx)++;
3586 }
3587
3588 /* Packet length consistency check. */
3589 if (pnt != end)
3590 {
3591 zlog_err ("%s [Error] Update packet error"
3592 " (prefix length mismatch with total length)",
3593 peer->host);
3594 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3595 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3596 return -1;
3597 }
3598 return 0;
3599 }
3600
3601 static struct bgp_static *
3602 bgp_static_new (void)
3603 {
3604 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3605 }
3606
3607 static void
3608 bgp_static_free (struct bgp_static *bgp_static)
3609 {
3610 if (bgp_static->rmap.name)
3611 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3612 XFREE (MTYPE_BGP_STATIC, bgp_static);
3613 }
3614
3615 static void
3616 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3617 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3618 {
3619 struct bgp_node *rn;
3620 struct bgp_info *ri;
3621 struct bgp_info *new;
3622 struct bgp_info info;
3623 struct attr attr;
3624 struct attr *attr_new;
3625 int ret;
3626 #if ENABLE_BGP_VNC
3627 int vnc_implicit_withdraw = 0;
3628 #endif
3629
3630 assert (bgp_static);
3631 if (!bgp_static)
3632 return;
3633
3634 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3635
3636 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3637
3638 attr.nexthop = bgp_static->igpnexthop;
3639 attr.med = bgp_static->igpmetric;
3640 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3641
3642 if (bgp_static->atomic)
3643 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3644
3645 /* Apply route-map. */
3646 if (bgp_static->rmap.name)
3647 {
3648 struct attr attr_tmp = attr;
3649 info.peer = bgp->peer_self;
3650 info.attr = &attr_tmp;
3651
3652 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3653
3654 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3655
3656 bgp->peer_self->rmap_type = 0;
3657
3658 if (ret == RMAP_DENYMATCH)
3659 {
3660 /* Free uninterned attribute. */
3661 bgp_attr_flush (&attr_tmp);
3662
3663 /* Unintern original. */
3664 aspath_unintern (&attr.aspath);
3665 bgp_attr_extra_free (&attr);
3666 bgp_static_withdraw (bgp, p, afi, safi);
3667 return;
3668 }
3669 attr_new = bgp_attr_intern (&attr_tmp);
3670 }
3671 else
3672 attr_new = bgp_attr_intern (&attr);
3673
3674 for (ri = rn->info; ri; ri = ri->next)
3675 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3676 && ri->sub_type == BGP_ROUTE_STATIC)
3677 break;
3678
3679 if (ri)
3680 {
3681 if (attrhash_cmp (ri->attr, attr_new) &&
3682 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3683 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
3684 {
3685 bgp_unlock_node (rn);
3686 bgp_attr_unintern (&attr_new);
3687 aspath_unintern (&attr.aspath);
3688 bgp_attr_extra_free (&attr);
3689 return;
3690 }
3691 else
3692 {
3693 /* The attribute is changed. */
3694 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3695
3696 /* Rewrite BGP route information. */
3697 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3698 bgp_info_restore(rn, ri);
3699 else
3700 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3701 #if ENABLE_BGP_VNC
3702 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3703 {
3704 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
3705 {
3706 /*
3707 * Implicit withdraw case.
3708 * We have to do this before ri is changed
3709 */
3710 ++vnc_implicit_withdraw;
3711 vnc_import_bgp_del_route(bgp, p, ri);
3712 vnc_import_bgp_exterior_del_route(bgp, p, ri);
3713 }
3714 }
3715 #endif
3716 bgp_attr_unintern (&ri->attr);
3717 ri->attr = attr_new;
3718 ri->uptime = bgp_clock ();
3719 #if ENABLE_BGP_VNC
3720 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3721 {
3722 if (vnc_implicit_withdraw)
3723 {
3724 vnc_import_bgp_add_route(bgp, p, ri);
3725 vnc_import_bgp_exterior_add_route(bgp, p, ri);
3726 }
3727 }
3728 #endif
3729
3730 /* Nexthop reachability check. */
3731 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3732 {
3733 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
3734 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3735 else
3736 {
3737 if (BGP_DEBUG(nht, NHT))
3738 {
3739 char buf1[INET6_ADDRSTRLEN];
3740 inet_ntop(p->family, &p->u.prefix, buf1,
3741 INET6_ADDRSTRLEN);
3742 zlog_debug("%s(%s): Route not in table, not advertising",
3743 __FUNCTION__, buf1);
3744 }
3745 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3746 }
3747 }
3748 else
3749 {
3750 /* Delete the NHT structure if any, if we're toggling between
3751 * enabling/disabling import check. We deregister the route
3752 * from NHT to avoid overloading NHT and the process interaction
3753 */
3754 bgp_unlink_nexthop(ri);
3755 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3756 }
3757 /* Process change. */
3758 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3759 bgp_process (bgp, rn, afi, safi);
3760 bgp_unlock_node (rn);
3761 aspath_unintern (&attr.aspath);
3762 bgp_attr_extra_free (&attr);
3763 return;
3764 }
3765 }
3766
3767 /* Make new BGP info. */
3768 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3769 rn);
3770 /* Nexthop reachability check. */
3771 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3772 {
3773 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
3774 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3775 else
3776 {
3777 if (BGP_DEBUG(nht, NHT))
3778 {
3779 char buf1[INET6_ADDRSTRLEN];
3780 inet_ntop(p->family, &p->u.prefix, buf1,
3781 INET6_ADDRSTRLEN);
3782 zlog_debug("%s(%s): Route not in table, not advertising",
3783 __FUNCTION__, buf1);
3784 }
3785 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3786 }
3787 }
3788 else
3789 {
3790 /* Delete the NHT structure if any, if we're toggling between
3791 * enabling/disabling import check. We deregister the route
3792 * from NHT to avoid overloading NHT and the process interaction
3793 */
3794 bgp_unlink_nexthop(new);
3795
3796 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3797 }
3798
3799 /* Aggregate address increment. */
3800 bgp_aggregate_increment (bgp, p, new, afi, safi);
3801
3802 /* Register new BGP information. */
3803 bgp_info_add (rn, new);
3804
3805 /* route_node_get lock */
3806 bgp_unlock_node (rn);
3807
3808 /* Process change. */
3809 bgp_process (bgp, rn, afi, safi);
3810
3811 /* Unintern original. */
3812 aspath_unintern (&attr.aspath);
3813 bgp_attr_extra_free (&attr);
3814 }
3815
3816 void
3817 bgp_static_update (struct bgp *bgp, struct prefix *p,
3818 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3819 {
3820 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3821 }
3822
3823 void
3824 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3825 safi_t safi)
3826 {
3827 struct bgp_node *rn;
3828 struct bgp_info *ri;
3829
3830 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3831
3832 /* Check selected route and self inserted route. */
3833 for (ri = rn->info; ri; ri = ri->next)
3834 if (ri->peer == bgp->peer_self
3835 && ri->type == ZEBRA_ROUTE_BGP
3836 && ri->sub_type == BGP_ROUTE_STATIC)
3837 break;
3838
3839 /* Withdraw static BGP route from routing table. */
3840 if (ri)
3841 {
3842 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3843 bgp_unlink_nexthop(ri);
3844 bgp_info_delete (rn, ri);
3845 bgp_process (bgp, rn, afi, safi);
3846 }
3847
3848 /* Unlock bgp_node_lookup. */
3849 bgp_unlock_node (rn);
3850 }
3851
3852 /*
3853 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3854 */
3855 static void
3856 bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3857 safi_t safi, struct prefix_rd *prd, u_char *tag)
3858 {
3859 struct bgp_node *rn;
3860 struct bgp_info *ri;
3861
3862 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3863
3864 /* Check selected route and self inserted route. */
3865 for (ri = rn->info; ri; ri = ri->next)
3866 if (ri->peer == bgp->peer_self
3867 && ri->type == ZEBRA_ROUTE_BGP
3868 && ri->sub_type == BGP_ROUTE_STATIC)
3869 break;
3870
3871 /* Withdraw static BGP route from routing table. */
3872 if (ri)
3873 {
3874 #if ENABLE_BGP_VNC
3875 rfapiProcessWithdraw(
3876 ri->peer,
3877 NULL,
3878 p,
3879 prd,
3880 ri->attr,
3881 afi,
3882 safi,
3883 ri->type,
3884 1); /* Kill, since it is an administrative change */
3885 #endif
3886 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3887 bgp_info_delete (rn, ri);
3888 bgp_process (bgp, rn, afi, safi);
3889 }
3890
3891 /* Unlock bgp_node_lookup. */
3892 bgp_unlock_node (rn);
3893 }
3894
3895 static void
3896 bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3897 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3898 {
3899 struct bgp_node *rn;
3900 struct bgp_info *new;
3901 struct attr *attr_new;
3902 struct attr attr = { 0 };
3903 struct bgp_info *ri;
3904 #if ENABLE_BGP_VNC
3905 u_int32_t label = 0;
3906 #endif
3907
3908 assert (bgp_static);
3909
3910 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3911
3912 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3913
3914 attr.nexthop = bgp_static->igpnexthop;
3915 attr.med = bgp_static->igpmetric;
3916 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3917
3918 /* Apply route-map. */
3919 if (bgp_static->rmap.name)
3920 {
3921 struct attr attr_tmp = attr;
3922 struct bgp_info info;
3923 int ret;
3924
3925 info.peer = bgp->peer_self;
3926 info.attr = &attr_tmp;
3927
3928 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3929
3930 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3931
3932 bgp->peer_self->rmap_type = 0;
3933
3934 if (ret == RMAP_DENYMATCH)
3935 {
3936 /* Free uninterned attribute. */
3937 bgp_attr_flush (&attr_tmp);
3938
3939 /* Unintern original. */
3940 aspath_unintern (&attr.aspath);
3941 bgp_attr_extra_free (&attr);
3942 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3943 bgp_static->tag);
3944 return;
3945 }
3946
3947 attr_new = bgp_attr_intern (&attr_tmp);
3948 }
3949 else
3950 {
3951 attr_new = bgp_attr_intern (&attr);
3952 }
3953
3954 for (ri = rn->info; ri; ri = ri->next)
3955 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3956 && ri->sub_type == BGP_ROUTE_STATIC)
3957 break;
3958
3959 if (ri)
3960 {
3961 if (attrhash_cmp (ri->attr, attr_new) &&
3962 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3963 {
3964 bgp_unlock_node (rn);
3965 bgp_attr_unintern (&attr_new);
3966 aspath_unintern (&attr.aspath);
3967 bgp_attr_extra_free (&attr);
3968 return;
3969 }
3970 else
3971 {
3972 /* The attribute is changed. */
3973 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3974
3975 /* Rewrite BGP route information. */
3976 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3977 bgp_info_restore(rn, ri);
3978 else
3979 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3980 bgp_attr_unintern (&ri->attr);
3981 ri->attr = attr_new;
3982 ri->uptime = bgp_clock ();
3983 #if ENABLE_BGP_VNC
3984 if (ri->extra)
3985 label = decode_label (ri->extra->tag);
3986 #endif
3987
3988 /* Process change. */
3989 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3990 bgp_process (bgp, rn, afi, safi);
3991 #if ENABLE_BGP_VNC
3992 rfapiProcessUpdate(ri->peer, NULL, p, &bgp_static->prd,
3993 ri->attr, afi, safi,
3994 ri->type, ri->sub_type, &label);
3995 #endif
3996 bgp_unlock_node (rn);
3997 aspath_unintern (&attr.aspath);
3998 bgp_attr_extra_free (&attr);
3999 return;
4000 }
4001 }
4002
4003
4004 /* Make new BGP info. */
4005 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
4006 rn);
4007 SET_FLAG (new->flags, BGP_INFO_VALID);
4008 new->extra = bgp_info_extra_new();
4009 memcpy (new->extra->tag, bgp_static->tag, 3);
4010 #if ENABLE_BGP_VNC
4011 label = decode_label (bgp_static->tag);
4012 #endif
4013
4014 /* Aggregate address increment. */
4015 bgp_aggregate_increment (bgp, p, new, afi, safi);
4016
4017 /* Register new BGP information. */
4018 bgp_info_add (rn, new);
4019
4020 /* route_node_get lock */
4021 bgp_unlock_node (rn);
4022
4023 /* Process change. */
4024 bgp_process (bgp, rn, afi, safi);
4025
4026 #if ENABLE_BGP_VNC
4027 rfapiProcessUpdate(new->peer, NULL, p, &bgp_static->prd,
4028 new->attr, afi, safi,
4029 new->type, new->sub_type, &label);
4030 #endif
4031
4032 /* Unintern original. */
4033 aspath_unintern (&attr.aspath);
4034 bgp_attr_extra_free (&attr);
4035 }
4036
4037 /* Configure static BGP network. When user don't run zebra, static
4038 route should be installed as valid. */
4039 static int
4040 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
4041 afi_t afi, safi_t safi, const char *rmap, int backdoor)
4042 {
4043 int ret;
4044 struct prefix p;
4045 struct bgp_static *bgp_static;
4046 struct bgp_node *rn;
4047 u_char need_update = 0;
4048
4049 /* Convert IP prefix string to struct prefix. */
4050 ret = str2prefix (ip_str, &p);
4051 if (! ret)
4052 {
4053 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4054 return CMD_WARNING;
4055 }
4056 #ifdef HAVE_IPV6
4057 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4058 {
4059 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4060 VTY_NEWLINE);
4061 return CMD_WARNING;
4062 }
4063 #endif /* HAVE_IPV6 */
4064
4065 apply_mask (&p);
4066
4067 /* Set BGP static route configuration. */
4068 rn = bgp_node_get (bgp->route[afi][safi], &p);
4069
4070 if (rn->info)
4071 {
4072 /* Configuration change. */
4073 bgp_static = rn->info;
4074
4075 /* Check previous routes are installed into BGP. */
4076 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4077 need_update = 1;
4078
4079 bgp_static->backdoor = backdoor;
4080
4081 if (rmap)
4082 {
4083 if (bgp_static->rmap.name)
4084 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4085 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4086 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4087 }
4088 else
4089 {
4090 if (bgp_static->rmap.name)
4091 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4092 bgp_static->rmap.name = NULL;
4093 bgp_static->rmap.map = NULL;
4094 bgp_static->valid = 0;
4095 }
4096 bgp_unlock_node (rn);
4097 }
4098 else
4099 {
4100 /* New configuration. */
4101 bgp_static = bgp_static_new ();
4102 bgp_static->backdoor = backdoor;
4103 bgp_static->valid = 0;
4104 bgp_static->igpmetric = 0;
4105 bgp_static->igpnexthop.s_addr = 0;
4106
4107 if (rmap)
4108 {
4109 if (bgp_static->rmap.name)
4110 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4111 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4112 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4113 }
4114 rn->info = bgp_static;
4115 }
4116
4117 bgp_static->valid = 1;
4118 if (need_update)
4119 bgp_static_withdraw (bgp, &p, afi, safi);
4120
4121 if (! bgp_static->backdoor)
4122 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4123
4124 return CMD_SUCCESS;
4125 }
4126
4127 /* Configure static BGP network. */
4128 static int
4129 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4130 afi_t afi, safi_t safi)
4131 {
4132 int ret;
4133 struct prefix p;
4134 struct bgp_static *bgp_static;
4135 struct bgp_node *rn;
4136
4137 /* Convert IP prefix string to struct prefix. */
4138 ret = str2prefix (ip_str, &p);
4139 if (! ret)
4140 {
4141 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4142 return CMD_WARNING;
4143 }
4144 #ifdef HAVE_IPV6
4145 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4146 {
4147 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4148 VTY_NEWLINE);
4149 return CMD_WARNING;
4150 }
4151 #endif /* HAVE_IPV6 */
4152
4153 apply_mask (&p);
4154
4155 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4156 if (! rn)
4157 {
4158 vty_out (vty, "%% Can't find specified static route configuration.%s",
4159 VTY_NEWLINE);
4160 return CMD_WARNING;
4161 }
4162
4163 bgp_static = rn->info;
4164
4165 /* Update BGP RIB. */
4166 if (! bgp_static->backdoor)
4167 bgp_static_withdraw (bgp, &p, afi, safi);
4168
4169 /* Clear configuration. */
4170 bgp_static_free (bgp_static);
4171 rn->info = NULL;
4172 bgp_unlock_node (rn);
4173 bgp_unlock_node (rn);
4174
4175 return CMD_SUCCESS;
4176 }
4177
4178 void
4179 bgp_static_add (struct bgp *bgp)
4180 {
4181 afi_t afi;
4182 safi_t safi;
4183 struct bgp_node *rn;
4184 struct bgp_node *rm;
4185 struct bgp_table *table;
4186 struct bgp_static *bgp_static;
4187
4188 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4189 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4190 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4191 if (rn->info != NULL)
4192 {
4193 if (safi == SAFI_MPLS_VPN)
4194 {
4195 table = rn->info;
4196
4197 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4198 {
4199 bgp_static = rn->info;
4200 bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
4201 }
4202 }
4203 else
4204 {
4205 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
4206 }
4207 }
4208 }
4209
4210 /* Called from bgp_delete(). Delete all static routes from the BGP
4211 instance. */
4212 void
4213 bgp_static_delete (struct bgp *bgp)
4214 {
4215 afi_t afi;
4216 safi_t safi;
4217 struct bgp_node *rn;
4218 struct bgp_node *rm;
4219 struct bgp_table *table;
4220 struct bgp_static *bgp_static;
4221
4222 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4223 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4224 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4225 if (rn->info != NULL)
4226 {
4227 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
4228 {
4229 table = rn->info;
4230
4231 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4232 {
4233 bgp_static = rn->info;
4234 bgp_static_withdraw_safi (bgp, &rm->p,
4235 AFI_IP, safi,
4236 (struct prefix_rd *)&rn->p,
4237 bgp_static->tag);
4238 bgp_static_free (bgp_static);
4239 rn->info = NULL;
4240 bgp_unlock_node (rn);
4241 }
4242 }
4243 else
4244 {
4245 bgp_static = rn->info;
4246 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4247 bgp_static_free (bgp_static);
4248 rn->info = NULL;
4249 bgp_unlock_node (rn);
4250 }
4251 }
4252 }
4253
4254 void
4255 bgp_static_redo_import_check (struct bgp *bgp)
4256 {
4257 afi_t afi;
4258 safi_t safi;
4259 struct bgp_node *rn;
4260 struct bgp_static *bgp_static;
4261
4262 /* Use this flag to force reprocessing of the route */
4263 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4264 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4265 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4266 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4267 if (rn->info != NULL)
4268 {
4269 bgp_static = rn->info;
4270 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
4271 }
4272 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4273 }
4274
4275 static void
4276 bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
4277 {
4278 struct bgp_table *table;
4279 struct bgp_node *rn;
4280 struct bgp_info *ri;
4281
4282 table = bgp->rib[afi][safi];
4283 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4284 {
4285 for (ri = rn->info; ri; ri = ri->next)
4286 {
4287 if (ri->peer == bgp->peer_self &&
4288 ((ri->type == ZEBRA_ROUTE_BGP &&
4289 ri->sub_type == BGP_ROUTE_STATIC) ||
4290 (ri->type != ZEBRA_ROUTE_BGP &&
4291 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
4292 {
4293 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
4294 bgp_unlink_nexthop(ri);
4295 bgp_info_delete (rn, ri);
4296 bgp_process (bgp, rn, afi, safi);
4297 }
4298 }
4299 }
4300 }
4301
4302 /*
4303 * Purge all networks and redistributed routes from routing table.
4304 * Invoked upon the instance going down.
4305 */
4306 void
4307 bgp_purge_static_redist_routes (struct bgp *bgp)
4308 {
4309 afi_t afi;
4310 safi_t safi;
4311
4312 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4313 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4314 bgp_purge_af_static_redist_routes (bgp, afi, safi);
4315 }
4316
4317 /*
4318 * gpz 110624
4319 * Currently this is used to set static routes for VPN and ENCAP.
4320 * I think it can probably be factored with bgp_static_set.
4321 */
4322 int
4323 bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4324 const char *rd_str, const char *tag_str,
4325 const char *rmap_str)
4326 {
4327 int ret;
4328 struct prefix p;
4329 struct prefix_rd prd;
4330 struct bgp *bgp;
4331 struct bgp_node *prn;
4332 struct bgp_node *rn;
4333 struct bgp_table *table;
4334 struct bgp_static *bgp_static;
4335 u_char tag[3];
4336
4337 bgp = vty->index;
4338
4339 ret = str2prefix (ip_str, &p);
4340 if (! ret)
4341 {
4342 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4343 return CMD_WARNING;
4344 }
4345 apply_mask (&p);
4346
4347 ret = str2prefix_rd (rd_str, &prd);
4348 if (! ret)
4349 {
4350 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4351 return CMD_WARNING;
4352 }
4353
4354 ret = str2tag (tag_str, tag);
4355 if (! ret)
4356 {
4357 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4358 return CMD_WARNING;
4359 }
4360
4361 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4362 (struct prefix *)&prd);
4363 if (prn->info == NULL)
4364 prn->info = bgp_table_init (AFI_IP, safi);
4365 else
4366 bgp_unlock_node (prn);
4367 table = prn->info;
4368
4369 rn = bgp_node_get (table, &p);
4370
4371 if (rn->info)
4372 {
4373 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4374 bgp_unlock_node (rn);
4375 }
4376 else
4377 {
4378 /* New configuration. */
4379 bgp_static = bgp_static_new ();
4380 bgp_static->backdoor = 0;
4381 bgp_static->valid = 0;
4382 bgp_static->igpmetric = 0;
4383 bgp_static->igpnexthop.s_addr = 0;
4384 memcpy(bgp_static->tag, tag, 3);
4385 bgp_static->prd = prd;
4386
4387 if (rmap_str)
4388 {
4389 if (bgp_static->rmap.name)
4390 free (bgp_static->rmap.name);
4391 bgp_static->rmap.name = strdup (rmap_str);
4392 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4393 }
4394 rn->info = bgp_static;
4395
4396 bgp_static->valid = 1;
4397 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
4398 }
4399
4400 return CMD_SUCCESS;
4401 }
4402
4403 /* Configure static BGP network. */
4404 int
4405 bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4406 const char *rd_str, const char *tag_str)
4407 {
4408 int ret;
4409 struct bgp *bgp;
4410 struct prefix p;
4411 struct prefix_rd prd;
4412 struct bgp_node *prn;
4413 struct bgp_node *rn;
4414 struct bgp_table *table;
4415 struct bgp_static *bgp_static;
4416 u_char tag[3];
4417
4418 bgp = vty->index;
4419
4420 /* Convert IP prefix string to struct prefix. */
4421 ret = str2prefix (ip_str, &p);
4422 if (! ret)
4423 {
4424 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4425 return CMD_WARNING;
4426 }
4427 apply_mask (&p);
4428
4429 ret = str2prefix_rd (rd_str, &prd);
4430 if (! ret)
4431 {
4432 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4433 return CMD_WARNING;
4434 }
4435
4436 ret = str2tag (tag_str, tag);
4437 if (! ret)
4438 {
4439 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4440 return CMD_WARNING;
4441 }
4442
4443 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4444 (struct prefix *)&prd);
4445 if (prn->info == NULL)
4446 prn->info = bgp_table_init (AFI_IP, safi);
4447 else
4448 bgp_unlock_node (prn);
4449 table = prn->info;
4450
4451 rn = bgp_node_lookup (table, &p);
4452
4453 if (rn)
4454 {
4455 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
4456
4457 bgp_static = rn->info;
4458 bgp_static_free (bgp_static);
4459 rn->info = NULL;
4460 bgp_unlock_node (rn);
4461 bgp_unlock_node (rn);
4462 }
4463 else
4464 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4465
4466 return CMD_SUCCESS;
4467 }
4468
4469 static int
4470 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4471 const char *rmap_name)
4472 {
4473 struct bgp_rmap *rmap;
4474
4475 rmap = &bgp->table_map[afi][safi];
4476 if (rmap_name)
4477 {
4478 if (rmap->name)
4479 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4480 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
4481 rmap->map = route_map_lookup_by_name (rmap_name);
4482 }
4483 else
4484 {
4485 if (rmap->name)
4486 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4487 rmap->name = NULL;
4488 rmap->map = NULL;
4489 }
4490
4491 bgp_zebra_announce_table(bgp, afi, safi);
4492
4493 return CMD_SUCCESS;
4494 }
4495
4496 static int
4497 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4498 const char *rmap_name)
4499 {
4500 struct bgp_rmap *rmap;
4501
4502 rmap = &bgp->table_map[afi][safi];
4503 if (rmap->name)
4504 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4505 rmap->name = NULL;
4506 rmap->map = NULL;
4507
4508 bgp_zebra_announce_table(bgp, afi, safi);
4509
4510 return CMD_SUCCESS;
4511 }
4512
4513 int
4514 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4515 safi_t safi, int *write)
4516 {
4517 if (bgp->table_map[afi][safi].name)
4518 {
4519 bgp_config_write_family_header (vty, afi, safi, write);
4520 vty_out (vty, " table-map %s%s",
4521 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4522 }
4523
4524 return 0;
4525 }
4526
4527
4528 DEFUN (bgp_table_map,
4529 bgp_table_map_cmd,
4530 "table-map WORD",
4531 "BGP table to RIB route download filter\n"
4532 "Name of the route map\n")
4533 {
4534 return bgp_table_map_set (vty, vty->index,
4535 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4536 }
4537 DEFUN (no_bgp_table_map,
4538 no_bgp_table_map_cmd,
4539 "no table-map WORD",
4540 "BGP table to RIB route download filter\n"
4541 "Name of the route map\n")
4542 {
4543 return bgp_table_map_unset (vty, vty->index,
4544 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4545 }
4546
4547 DEFUN (bgp_network,
4548 bgp_network_cmd,
4549 "network A.B.C.D/M",
4550 "Specify a network to announce via BGP\n"
4551 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4552 {
4553 return bgp_static_set (vty, vty->index, argv[0],
4554 AFI_IP, bgp_node_safi (vty), NULL, 0);
4555 }
4556
4557 DEFUN (bgp_network_route_map,
4558 bgp_network_route_map_cmd,
4559 "network A.B.C.D/M route-map WORD",
4560 "Specify a network to announce via BGP\n"
4561 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4562 "Route-map to modify the attributes\n"
4563 "Name of the route map\n")
4564 {
4565 return bgp_static_set (vty, vty->index, argv[0],
4566 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4567 }
4568
4569 DEFUN (bgp_network_backdoor,
4570 bgp_network_backdoor_cmd,
4571 "network A.B.C.D/M backdoor",
4572 "Specify a network to announce via BGP\n"
4573 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4574 "Specify a BGP backdoor route\n")
4575 {
4576 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4577 NULL, 1);
4578 }
4579
4580 DEFUN (bgp_network_mask,
4581 bgp_network_mask_cmd,
4582 "network A.B.C.D mask A.B.C.D",
4583 "Specify a network to announce via BGP\n"
4584 "Network number\n"
4585 "Network mask\n"
4586 "Network mask\n")
4587 {
4588 int ret;
4589 char prefix_str[BUFSIZ];
4590
4591 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4592 if (! ret)
4593 {
4594 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4595 return CMD_WARNING;
4596 }
4597
4598 return bgp_static_set (vty, vty->index, prefix_str,
4599 AFI_IP, bgp_node_safi (vty), NULL, 0);
4600 }
4601
4602 DEFUN (bgp_network_mask_route_map,
4603 bgp_network_mask_route_map_cmd,
4604 "network A.B.C.D mask A.B.C.D route-map WORD",
4605 "Specify a network to announce via BGP\n"
4606 "Network number\n"
4607 "Network mask\n"
4608 "Network mask\n"
4609 "Route-map to modify the attributes\n"
4610 "Name of the route map\n")
4611 {
4612 int ret;
4613 char prefix_str[BUFSIZ];
4614
4615 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4616 if (! ret)
4617 {
4618 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4619 return CMD_WARNING;
4620 }
4621
4622 return bgp_static_set (vty, vty->index, prefix_str,
4623 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4624 }
4625
4626 DEFUN (bgp_network_mask_backdoor,
4627 bgp_network_mask_backdoor_cmd,
4628 "network A.B.C.D mask A.B.C.D backdoor",
4629 "Specify a network to announce via BGP\n"
4630 "Network number\n"
4631 "Network mask\n"
4632 "Network mask\n"
4633 "Specify a BGP backdoor route\n")
4634 {
4635 int ret;
4636 char prefix_str[BUFSIZ];
4637
4638 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4639 if (! ret)
4640 {
4641 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4642 return CMD_WARNING;
4643 }
4644
4645 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4646 NULL, 1);
4647 }
4648
4649 DEFUN (bgp_network_mask_natural,
4650 bgp_network_mask_natural_cmd,
4651 "network A.B.C.D",
4652 "Specify a network to announce via BGP\n"
4653 "Network number\n")
4654 {
4655 int ret;
4656 char prefix_str[BUFSIZ];
4657
4658 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4659 if (! ret)
4660 {
4661 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4662 return CMD_WARNING;
4663 }
4664
4665 return bgp_static_set (vty, vty->index, prefix_str,
4666 AFI_IP, bgp_node_safi (vty), NULL, 0);
4667 }
4668
4669 DEFUN (bgp_network_mask_natural_route_map,
4670 bgp_network_mask_natural_route_map_cmd,
4671 "network A.B.C.D route-map WORD",
4672 "Specify a network to announce via BGP\n"
4673 "Network number\n"
4674 "Route-map to modify the attributes\n"
4675 "Name of the route map\n")
4676 {
4677 int ret;
4678 char prefix_str[BUFSIZ];
4679
4680 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4681 if (! ret)
4682 {
4683 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4684 return CMD_WARNING;
4685 }
4686
4687 return bgp_static_set (vty, vty->index, prefix_str,
4688 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4689 }
4690
4691 DEFUN (bgp_network_mask_natural_backdoor,
4692 bgp_network_mask_natural_backdoor_cmd,
4693 "network A.B.C.D backdoor",
4694 "Specify a network to announce via BGP\n"
4695 "Network number\n"
4696 "Specify a BGP backdoor route\n")
4697 {
4698 int ret;
4699 char prefix_str[BUFSIZ];
4700
4701 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4702 if (! ret)
4703 {
4704 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4705 return CMD_WARNING;
4706 }
4707
4708 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4709 NULL, 1);
4710 }
4711
4712 DEFUN (no_bgp_network,
4713 no_bgp_network_cmd,
4714 "no network A.B.C.D/M",
4715 NO_STR
4716 "Specify a network to announce via BGP\n"
4717 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4718 {
4719 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4720 bgp_node_safi (vty));
4721 }
4722
4723 ALIAS (no_bgp_network,
4724 no_bgp_network_route_map_cmd,
4725 "no network A.B.C.D/M route-map WORD",
4726 NO_STR
4727 "Specify a network to announce via BGP\n"
4728 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4729 "Route-map to modify the attributes\n"
4730 "Name of the route map\n")
4731
4732 ALIAS (no_bgp_network,
4733 no_bgp_network_backdoor_cmd,
4734 "no network A.B.C.D/M backdoor",
4735 NO_STR
4736 "Specify a network to announce via BGP\n"
4737 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4738 "Specify a BGP backdoor route\n")
4739
4740 DEFUN (no_bgp_network_mask,
4741 no_bgp_network_mask_cmd,
4742 "no network A.B.C.D mask A.B.C.D",
4743 NO_STR
4744 "Specify a network to announce via BGP\n"
4745 "Network number\n"
4746 "Network mask\n"
4747 "Network mask\n")
4748 {
4749 int ret;
4750 char prefix_str[BUFSIZ];
4751
4752 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4753 if (! ret)
4754 {
4755 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4756 return CMD_WARNING;
4757 }
4758
4759 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4760 bgp_node_safi (vty));
4761 }
4762
4763 ALIAS (no_bgp_network_mask,
4764 no_bgp_network_mask_route_map_cmd,
4765 "no network A.B.C.D mask A.B.C.D route-map WORD",
4766 NO_STR
4767 "Specify a network to announce via BGP\n"
4768 "Network number\n"
4769 "Network mask\n"
4770 "Network mask\n"
4771 "Route-map to modify the attributes\n"
4772 "Name of the route map\n")
4773
4774 ALIAS (no_bgp_network_mask,
4775 no_bgp_network_mask_backdoor_cmd,
4776 "no network A.B.C.D mask A.B.C.D backdoor",
4777 NO_STR
4778 "Specify a network to announce via BGP\n"
4779 "Network number\n"
4780 "Network mask\n"
4781 "Network mask\n"
4782 "Specify a BGP backdoor route\n")
4783
4784 DEFUN (no_bgp_network_mask_natural,
4785 no_bgp_network_mask_natural_cmd,
4786 "no network A.B.C.D",
4787 NO_STR
4788 "Specify a network to announce via BGP\n"
4789 "Network number\n")
4790 {
4791 int ret;
4792 char prefix_str[BUFSIZ];
4793
4794 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4795 if (! ret)
4796 {
4797 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4798 return CMD_WARNING;
4799 }
4800
4801 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4802 bgp_node_safi (vty));
4803 }
4804
4805 ALIAS (no_bgp_network_mask_natural,
4806 no_bgp_network_mask_natural_route_map_cmd,
4807 "no network A.B.C.D route-map WORD",
4808 NO_STR
4809 "Specify a network to announce via BGP\n"
4810 "Network number\n"
4811 "Route-map to modify the attributes\n"
4812 "Name of the route map\n")
4813
4814 ALIAS (no_bgp_network_mask_natural,
4815 no_bgp_network_mask_natural_backdoor_cmd,
4816 "no network A.B.C.D backdoor",
4817 NO_STR
4818 "Specify a network to announce via BGP\n"
4819 "Network number\n"
4820 "Specify a BGP backdoor route\n")
4821
4822 #ifdef HAVE_IPV6
4823 DEFUN (ipv6_bgp_network,
4824 ipv6_bgp_network_cmd,
4825 "network X:X::X:X/M",
4826 "Specify a network to announce via BGP\n"
4827 "IPv6 prefix <network>/<length>\n")
4828 {
4829 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4830 NULL, 0);
4831 }
4832
4833 DEFUN (ipv6_bgp_network_route_map,
4834 ipv6_bgp_network_route_map_cmd,
4835 "network X:X::X:X/M route-map WORD",
4836 "Specify a network to announce via BGP\n"
4837 "IPv6 prefix <network>/<length>\n"
4838 "Route-map to modify the attributes\n"
4839 "Name of the route map\n")
4840 {
4841 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4842 bgp_node_safi (vty), argv[1], 0);
4843 }
4844
4845 DEFUN (no_ipv6_bgp_network,
4846 no_ipv6_bgp_network_cmd,
4847 "no network X:X::X:X/M",
4848 NO_STR
4849 "Specify a network to announce via BGP\n"
4850 "IPv6 prefix <network>/<length>\n")
4851 {
4852 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4853 }
4854
4855 ALIAS (no_ipv6_bgp_network,
4856 no_ipv6_bgp_network_route_map_cmd,
4857 "no network X:X::X:X/M route-map WORD",
4858 NO_STR
4859 "Specify a network to announce via BGP\n"
4860 "IPv6 prefix <network>/<length>\n"
4861 "Route-map to modify the attributes\n"
4862 "Name of the route map\n")
4863
4864 ALIAS (ipv6_bgp_network,
4865 old_ipv6_bgp_network_cmd,
4866 "ipv6 bgp network X:X::X:X/M",
4867 IPV6_STR
4868 BGP_STR
4869 "Specify a network to announce via BGP\n"
4870 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4871
4872 ALIAS (no_ipv6_bgp_network,
4873 old_no_ipv6_bgp_network_cmd,
4874 "no ipv6 bgp network X:X::X:X/M",
4875 NO_STR
4876 IPV6_STR
4877 BGP_STR
4878 "Specify a network to announce via BGP\n"
4879 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4880 #endif /* HAVE_IPV6 */
4881
4882 /* Aggreagete address:
4883
4884 advertise-map Set condition to advertise attribute
4885 as-set Generate AS set path information
4886 attribute-map Set attributes of aggregate
4887 route-map Set parameters of aggregate
4888 summary-only Filter more specific routes from updates
4889 suppress-map Conditionally filter more specific routes from updates
4890 <cr>
4891 */
4892 struct bgp_aggregate
4893 {
4894 /* Summary-only flag. */
4895 u_char summary_only;
4896
4897 /* AS set generation. */
4898 u_char as_set;
4899
4900 /* Route-map for aggregated route. */
4901 struct route_map *map;
4902
4903 /* Suppress-count. */
4904 unsigned long count;
4905
4906 /* SAFI configuration. */
4907 safi_t safi;
4908 };
4909
4910 static struct bgp_aggregate *
4911 bgp_aggregate_new (void)
4912 {
4913 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4914 }
4915
4916 static void
4917 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4918 {
4919 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4920 }
4921
4922 /* Update an aggregate as routes are added/removed from the BGP table */
4923 static void
4924 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4925 afi_t afi, safi_t safi, struct bgp_info *del,
4926 struct bgp_aggregate *aggregate)
4927 {
4928 struct bgp_table *table;
4929 struct bgp_node *top;
4930 struct bgp_node *rn;
4931 u_char origin;
4932 struct aspath *aspath = NULL;
4933 struct aspath *asmerge = NULL;
4934 struct community *community = NULL;
4935 struct community *commerge = NULL;
4936 #if defined(AGGREGATE_NEXTHOP_CHECK)
4937 struct in_addr nexthop;
4938 u_int32_t med = 0;
4939 #endif
4940 struct bgp_info *ri;
4941 struct bgp_info *new;
4942 int first = 1;
4943 unsigned long match = 0;
4944 u_char atomic_aggregate = 0;
4945
4946 /* Record adding route's nexthop and med. */
4947 if (rinew)
4948 {
4949 #if defined(AGGREGATE_NEXTHOP_CHECK)
4950 nexthop = rinew->attr->nexthop;
4951 med = rinew->attr->med;
4952 #endif
4953 }
4954
4955 /* ORIGIN attribute: If at least one route among routes that are
4956 aggregated has ORIGIN with the value INCOMPLETE, then the
4957 aggregated route must have the ORIGIN attribute with the value
4958 INCOMPLETE. Otherwise, if at least one route among routes that
4959 are aggregated has ORIGIN with the value EGP, then the aggregated
4960 route must have the origin attribute with the value EGP. In all
4961 other case the value of the ORIGIN attribute of the aggregated
4962 route is INTERNAL. */
4963 origin = BGP_ORIGIN_IGP;
4964
4965 table = bgp->rib[afi][safi];
4966
4967 top = bgp_node_get (table, p);
4968 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4969 if (rn->p.prefixlen > p->prefixlen)
4970 {
4971 match = 0;
4972
4973 for (ri = rn->info; ri; ri = ri->next)
4974 {
4975 if (BGP_INFO_HOLDDOWN (ri))
4976 continue;
4977
4978 if (del && ri == del)
4979 continue;
4980
4981 if (! rinew && first)
4982 {
4983 #if defined(AGGREGATE_NEXTHOP_CHECK)
4984 nexthop = ri->attr->nexthop;
4985 med = ri->attr->med;
4986 #endif
4987 first = 0;
4988 }
4989
4990 #ifdef AGGREGATE_NEXTHOP_CHECK
4991 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4992 || ri->attr->med != med)
4993 {
4994 if (aspath)
4995 aspath_free (aspath);
4996 if (community)
4997 community_free (community);
4998 bgp_unlock_node (rn);
4999 bgp_unlock_node (top);
5000 return;
5001 }
5002 #endif /* AGGREGATE_NEXTHOP_CHECK */
5003
5004 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5005 atomic_aggregate = 1;
5006
5007 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5008 {
5009 if (aggregate->summary_only)
5010 {
5011 (bgp_info_extra_get (ri))->suppress++;
5012 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5013 match++;
5014 }
5015
5016 aggregate->count++;
5017
5018 if (origin < ri->attr->origin)
5019 origin = ri->attr->origin;
5020
5021 if (aggregate->as_set)
5022 {
5023 if (aspath)
5024 {
5025 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5026 aspath_free (aspath);
5027 aspath = asmerge;
5028 }
5029 else
5030 aspath = aspath_dup (ri->attr->aspath);
5031
5032 if (ri->attr->community)
5033 {
5034 if (community)
5035 {
5036 commerge = community_merge (community,
5037 ri->attr->community);
5038 community = community_uniq_sort (commerge);
5039 community_free (commerge);
5040 }
5041 else
5042 community = community_dup (ri->attr->community);
5043 }
5044 }
5045 }
5046 }
5047 if (match)
5048 bgp_process (bgp, rn, afi, safi);
5049 }
5050 bgp_unlock_node (top);
5051
5052 if (rinew)
5053 {
5054 aggregate->count++;
5055
5056 if (aggregate->summary_only)
5057 (bgp_info_extra_get (rinew))->suppress++;
5058
5059 if (origin < rinew->attr->origin)
5060 origin = rinew->attr->origin;
5061
5062 if (aggregate->as_set)
5063 {
5064 if (aspath)
5065 {
5066 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5067 aspath_free (aspath);
5068 aspath = asmerge;
5069 }
5070 else
5071 aspath = aspath_dup (rinew->attr->aspath);
5072
5073 if (rinew->attr->community)
5074 {
5075 if (community)
5076 {
5077 commerge = community_merge (community,
5078 rinew->attr->community);
5079 community = community_uniq_sort (commerge);
5080 community_free (commerge);
5081 }
5082 else
5083 community = community_dup (rinew->attr->community);
5084 }
5085 }
5086 }
5087
5088 if (aggregate->count > 0)
5089 {
5090 rn = bgp_node_get (table, p);
5091 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5092 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5093 aggregate->as_set,
5094 atomic_aggregate), rn);
5095 SET_FLAG (new->flags, BGP_INFO_VALID);
5096
5097 bgp_info_add (rn, new);
5098 bgp_unlock_node (rn);
5099 bgp_process (bgp, rn, afi, safi);
5100 }
5101 else
5102 {
5103 if (aspath)
5104 aspath_free (aspath);
5105 if (community)
5106 community_free (community);
5107 }
5108 }
5109
5110 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5111 struct bgp_aggregate *);
5112
5113 void
5114 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5115 struct bgp_info *ri, afi_t afi, safi_t safi)
5116 {
5117 struct bgp_node *child;
5118 struct bgp_node *rn;
5119 struct bgp_aggregate *aggregate;
5120 struct bgp_table *table;
5121
5122 /* MPLS-VPN aggregation is not yet supported. */
5123 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5124 return;
5125
5126 table = bgp->aggregate[afi][safi];
5127
5128 /* No aggregates configured. */
5129 if (bgp_table_top_nolock (table) == NULL)
5130 return;
5131
5132 if (p->prefixlen == 0)
5133 return;
5134
5135 if (BGP_INFO_HOLDDOWN (ri))
5136 return;
5137
5138 child = bgp_node_get (table, p);
5139
5140 /* Aggregate address configuration check. */
5141 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5142 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5143 {
5144 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5145 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
5146 }
5147 bgp_unlock_node (child);
5148 }
5149
5150 void
5151 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5152 struct bgp_info *del, afi_t afi, safi_t safi)
5153 {
5154 struct bgp_node *child;
5155 struct bgp_node *rn;
5156 struct bgp_aggregate *aggregate;
5157 struct bgp_table *table;
5158
5159 /* MPLS-VPN aggregation is not yet supported. */
5160 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5161 return;
5162
5163 table = bgp->aggregate[afi][safi];
5164
5165 /* No aggregates configured. */
5166 if (bgp_table_top_nolock (table) == NULL)
5167 return;
5168
5169 if (p->prefixlen == 0)
5170 return;
5171
5172 child = bgp_node_get (table, p);
5173
5174 /* Aggregate address configuration check. */
5175 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5176 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5177 {
5178 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5179 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
5180 }
5181 bgp_unlock_node (child);
5182 }
5183
5184 /* Called via bgp_aggregate_set when the user configures aggregate-address */
5185 static void
5186 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5187 struct bgp_aggregate *aggregate)
5188 {
5189 struct bgp_table *table;
5190 struct bgp_node *top;
5191 struct bgp_node *rn;
5192 struct bgp_info *new;
5193 struct bgp_info *ri;
5194 unsigned long match;
5195 u_char origin = BGP_ORIGIN_IGP;
5196 struct aspath *aspath = NULL;
5197 struct aspath *asmerge = NULL;
5198 struct community *community = NULL;
5199 struct community *commerge = NULL;
5200 u_char atomic_aggregate = 0;
5201
5202 table = bgp->rib[afi][safi];
5203
5204 /* Sanity check. */
5205 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5206 return;
5207 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5208 return;
5209
5210 /* If routes exists below this node, generate aggregate routes. */
5211 top = bgp_node_get (table, p);
5212 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5213 if (rn->p.prefixlen > p->prefixlen)
5214 {
5215 match = 0;
5216
5217 for (ri = rn->info; ri; ri = ri->next)
5218 {
5219 if (BGP_INFO_HOLDDOWN (ri))
5220 continue;
5221
5222 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5223 atomic_aggregate = 1;
5224
5225 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5226 {
5227 /* summary-only aggregate route suppress aggregated
5228 route announcement. */
5229 if (aggregate->summary_only)
5230 {
5231 (bgp_info_extra_get (ri))->suppress++;
5232 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5233 match++;
5234 }
5235
5236 /* If at least one route among routes that are aggregated has
5237 * ORIGIN with the value INCOMPLETE, then the aggregated route
5238 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5239 * Otherwise, if at least one route among routes that are
5240 * aggregated has ORIGIN with the value EGP, then the aggregated
5241 * route MUST have the ORIGIN attribute with the value EGP.
5242 */
5243 if (origin < ri->attr->origin)
5244 origin = ri->attr->origin;
5245
5246 /* as-set aggregate route generate origin, as path,
5247 community aggregation. */
5248 if (aggregate->as_set)
5249 {
5250 if (aspath)
5251 {
5252 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5253 aspath_free (aspath);
5254 aspath = asmerge;
5255 }
5256 else
5257 aspath = aspath_dup (ri->attr->aspath);
5258
5259 if (ri->attr->community)
5260 {
5261 if (community)
5262 {
5263 commerge = community_merge (community,
5264 ri->attr->community);
5265 community = community_uniq_sort (commerge);
5266 community_free (commerge);
5267 }
5268 else
5269 community = community_dup (ri->attr->community);
5270 }
5271 }
5272 aggregate->count++;
5273 }
5274 }
5275
5276 /* If this node is suppressed, process the change. */
5277 if (match)
5278 bgp_process (bgp, rn, afi, safi);
5279 }
5280 bgp_unlock_node (top);
5281
5282 /* Add aggregate route to BGP table. */
5283 if (aggregate->count)
5284 {
5285 rn = bgp_node_get (table, p);
5286 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5287 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5288 aggregate->as_set,
5289 atomic_aggregate), rn);
5290 SET_FLAG (new->flags, BGP_INFO_VALID);
5291
5292 bgp_info_add (rn, new);
5293 bgp_unlock_node (rn);
5294
5295 /* Process change. */
5296 bgp_process (bgp, rn, afi, safi);
5297 }
5298 else
5299 {
5300 if (aspath)
5301 aspath_free (aspath);
5302 if (community)
5303 community_free (community);
5304 }
5305 }
5306
5307 void
5308 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5309 safi_t safi, struct bgp_aggregate *aggregate)
5310 {
5311 struct bgp_table *table;
5312 struct bgp_node *top;
5313 struct bgp_node *rn;
5314 struct bgp_info *ri;
5315 unsigned long match;
5316
5317 table = bgp->rib[afi][safi];
5318
5319 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5320 return;
5321 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5322 return;
5323
5324 /* If routes exists below this node, generate aggregate routes. */
5325 top = bgp_node_get (table, p);
5326 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5327 if (rn->p.prefixlen > p->prefixlen)
5328 {
5329 match = 0;
5330
5331 for (ri = rn->info; ri; ri = ri->next)
5332 {
5333 if (BGP_INFO_HOLDDOWN (ri))
5334 continue;
5335
5336 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5337 {
5338 if (aggregate->summary_only && ri->extra)
5339 {
5340 ri->extra->suppress--;
5341
5342 if (ri->extra->suppress == 0)
5343 {
5344 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5345 match++;
5346 }
5347 }
5348 aggregate->count--;
5349 }
5350 }
5351
5352 /* If this node was suppressed, process the change. */
5353 if (match)
5354 bgp_process (bgp, rn, afi, safi);
5355 }
5356 bgp_unlock_node (top);
5357
5358 /* Delete aggregate route from BGP table. */
5359 rn = bgp_node_get (table, p);
5360
5361 for (ri = rn->info; ri; ri = ri->next)
5362 if (ri->peer == bgp->peer_self
5363 && ri->type == ZEBRA_ROUTE_BGP
5364 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5365 break;
5366
5367 /* Withdraw static BGP route from routing table. */
5368 if (ri)
5369 {
5370 bgp_info_delete (rn, ri);
5371 bgp_process (bgp, rn, afi, safi);
5372 }
5373
5374 /* Unlock bgp_node_lookup. */
5375 bgp_unlock_node (rn);
5376 }
5377
5378 /* Aggregate route attribute. */
5379 #define AGGREGATE_SUMMARY_ONLY 1
5380 #define AGGREGATE_AS_SET 1
5381
5382 static int
5383 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5384 afi_t afi, safi_t safi)
5385 {
5386 int ret;
5387 struct prefix p;
5388 struct bgp_node *rn;
5389 struct bgp *bgp;
5390 struct bgp_aggregate *aggregate;
5391
5392 /* Convert string to prefix structure. */
5393 ret = str2prefix (prefix_str, &p);
5394 if (!ret)
5395 {
5396 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5397 return CMD_WARNING;
5398 }
5399 apply_mask (&p);
5400
5401 /* Get BGP structure. */
5402 bgp = vty->index;
5403
5404 /* Old configuration check. */
5405 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5406 if (! rn)
5407 {
5408 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5409 VTY_NEWLINE);
5410 return CMD_WARNING;
5411 }
5412
5413 aggregate = rn->info;
5414 if (aggregate->safi & SAFI_UNICAST)
5415 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5416 if (aggregate->safi & SAFI_MULTICAST)
5417 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5418
5419 /* Unlock aggregate address configuration. */
5420 rn->info = NULL;
5421 bgp_aggregate_free (aggregate);
5422 bgp_unlock_node (rn);
5423 bgp_unlock_node (rn);
5424
5425 return CMD_SUCCESS;
5426 }
5427
5428 static int
5429 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5430 afi_t afi, safi_t safi,
5431 u_char summary_only, u_char as_set)
5432 {
5433 int ret;
5434 struct prefix p;
5435 struct bgp_node *rn;
5436 struct bgp *bgp;
5437 struct bgp_aggregate *aggregate;
5438
5439 /* Convert string to prefix structure. */
5440 ret = str2prefix (prefix_str, &p);
5441 if (!ret)
5442 {
5443 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5444 return CMD_WARNING;
5445 }
5446 apply_mask (&p);
5447
5448 /* Get BGP structure. */
5449 bgp = vty->index;
5450
5451 /* Old configuration check. */
5452 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5453
5454 if (rn->info)
5455 {
5456 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5457 /* try to remove the old entry */
5458 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5459 if (ret)
5460 {
5461 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5462 bgp_unlock_node (rn);
5463 return CMD_WARNING;
5464 }
5465 }
5466
5467 /* Make aggregate address structure. */
5468 aggregate = bgp_aggregate_new ();
5469 aggregate->summary_only = summary_only;
5470 aggregate->as_set = as_set;
5471 aggregate->safi = safi;
5472 rn->info = aggregate;
5473
5474 /* Aggregate address insert into BGP routing table. */
5475 if (safi & SAFI_UNICAST)
5476 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5477 if (safi & SAFI_MULTICAST)
5478 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5479
5480 return CMD_SUCCESS;
5481 }
5482
5483 DEFUN (aggregate_address,
5484 aggregate_address_cmd,
5485 "aggregate-address A.B.C.D/M",
5486 "Configure BGP aggregate entries\n"
5487 "Aggregate prefix\n")
5488 {
5489 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5490 }
5491
5492 DEFUN (aggregate_address_mask,
5493 aggregate_address_mask_cmd,
5494 "aggregate-address A.B.C.D A.B.C.D",
5495 "Configure BGP aggregate entries\n"
5496 "Aggregate address\n"
5497 "Aggregate mask\n")
5498 {
5499 int ret;
5500 char prefix_str[BUFSIZ];
5501
5502 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5503
5504 if (! ret)
5505 {
5506 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5507 return CMD_WARNING;
5508 }
5509
5510 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5511 0, 0);
5512 }
5513
5514 DEFUN (aggregate_address_summary_only,
5515 aggregate_address_summary_only_cmd,
5516 "aggregate-address A.B.C.D/M summary-only",
5517 "Configure BGP aggregate entries\n"
5518 "Aggregate prefix\n"
5519 "Filter more specific routes from updates\n")
5520 {
5521 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5522 AGGREGATE_SUMMARY_ONLY, 0);
5523 }
5524
5525 DEFUN (aggregate_address_mask_summary_only,
5526 aggregate_address_mask_summary_only_cmd,
5527 "aggregate-address A.B.C.D A.B.C.D summary-only",
5528 "Configure BGP aggregate entries\n"
5529 "Aggregate address\n"
5530 "Aggregate mask\n"
5531 "Filter more specific routes from updates\n")
5532 {
5533 int ret;
5534 char prefix_str[BUFSIZ];
5535
5536 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5537
5538 if (! ret)
5539 {
5540 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5541 return CMD_WARNING;
5542 }
5543
5544 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5545 AGGREGATE_SUMMARY_ONLY, 0);
5546 }
5547
5548 DEFUN (aggregate_address_as_set,
5549 aggregate_address_as_set_cmd,
5550 "aggregate-address A.B.C.D/M as-set",
5551 "Configure BGP aggregate entries\n"
5552 "Aggregate prefix\n"
5553 "Generate AS set path information\n")
5554 {
5555 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5556 0, AGGREGATE_AS_SET);
5557 }
5558
5559 DEFUN (aggregate_address_mask_as_set,
5560 aggregate_address_mask_as_set_cmd,
5561 "aggregate-address A.B.C.D A.B.C.D as-set",
5562 "Configure BGP aggregate entries\n"
5563 "Aggregate address\n"
5564 "Aggregate mask\n"
5565 "Generate AS set path information\n")
5566 {
5567 int ret;
5568 char prefix_str[BUFSIZ];
5569
5570 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5571
5572 if (! ret)
5573 {
5574 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5575 return CMD_WARNING;
5576 }
5577
5578 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5579 0, AGGREGATE_AS_SET);
5580 }
5581
5582
5583 DEFUN (aggregate_address_as_set_summary,
5584 aggregate_address_as_set_summary_cmd,
5585 "aggregate-address A.B.C.D/M as-set summary-only",
5586 "Configure BGP aggregate entries\n"
5587 "Aggregate prefix\n"
5588 "Generate AS set path information\n"
5589 "Filter more specific routes from updates\n")
5590 {
5591 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5592 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5593 }
5594
5595 ALIAS (aggregate_address_as_set_summary,
5596 aggregate_address_summary_as_set_cmd,
5597 "aggregate-address A.B.C.D/M summary-only as-set",
5598 "Configure BGP aggregate entries\n"
5599 "Aggregate prefix\n"
5600 "Filter more specific routes from updates\n"
5601 "Generate AS set path information\n")
5602
5603 DEFUN (aggregate_address_mask_as_set_summary,
5604 aggregate_address_mask_as_set_summary_cmd,
5605 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5606 "Configure BGP aggregate entries\n"
5607 "Aggregate address\n"
5608 "Aggregate mask\n"
5609 "Generate AS set path information\n"
5610 "Filter more specific routes from updates\n")
5611 {
5612 int ret;
5613 char prefix_str[BUFSIZ];
5614
5615 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5616
5617 if (! ret)
5618 {
5619 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5620 return CMD_WARNING;
5621 }
5622
5623 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5624 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5625 }
5626
5627 ALIAS (aggregate_address_mask_as_set_summary,
5628 aggregate_address_mask_summary_as_set_cmd,
5629 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5630 "Configure BGP aggregate entries\n"
5631 "Aggregate address\n"
5632 "Aggregate mask\n"
5633 "Filter more specific routes from updates\n"
5634 "Generate AS set path information\n")
5635
5636 DEFUN (no_aggregate_address,
5637 no_aggregate_address_cmd,
5638 "no aggregate-address A.B.C.D/M",
5639 NO_STR
5640 "Configure BGP aggregate entries\n"
5641 "Aggregate prefix\n")
5642 {
5643 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5644 }
5645
5646 ALIAS (no_aggregate_address,
5647 no_aggregate_address_summary_only_cmd,
5648 "no aggregate-address A.B.C.D/M summary-only",
5649 NO_STR
5650 "Configure BGP aggregate entries\n"
5651 "Aggregate prefix\n"
5652 "Filter more specific routes from updates\n")
5653
5654 ALIAS (no_aggregate_address,
5655 no_aggregate_address_as_set_cmd,
5656 "no aggregate-address A.B.C.D/M as-set",
5657 NO_STR
5658 "Configure BGP aggregate entries\n"
5659 "Aggregate prefix\n"
5660 "Generate AS set path information\n")
5661
5662 ALIAS (no_aggregate_address,
5663 no_aggregate_address_as_set_summary_cmd,
5664 "no aggregate-address A.B.C.D/M as-set summary-only",
5665 NO_STR
5666 "Configure BGP aggregate entries\n"
5667 "Aggregate prefix\n"
5668 "Generate AS set path information\n"
5669 "Filter more specific routes from updates\n")
5670
5671 ALIAS (no_aggregate_address,
5672 no_aggregate_address_summary_as_set_cmd,
5673 "no aggregate-address A.B.C.D/M summary-only as-set",
5674 NO_STR
5675 "Configure BGP aggregate entries\n"
5676 "Aggregate prefix\n"
5677 "Filter more specific routes from updates\n"
5678 "Generate AS set path information\n")
5679
5680 DEFUN (no_aggregate_address_mask,
5681 no_aggregate_address_mask_cmd,
5682 "no aggregate-address A.B.C.D A.B.C.D",
5683 NO_STR
5684 "Configure BGP aggregate entries\n"
5685 "Aggregate address\n"
5686 "Aggregate mask\n")
5687 {
5688 int ret;
5689 char prefix_str[BUFSIZ];
5690
5691 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5692
5693 if (! ret)
5694 {
5695 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5696 return CMD_WARNING;
5697 }
5698
5699 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5700 }
5701
5702 ALIAS (no_aggregate_address_mask,
5703 no_aggregate_address_mask_summary_only_cmd,
5704 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5705 NO_STR
5706 "Configure BGP aggregate entries\n"
5707 "Aggregate address\n"
5708 "Aggregate mask\n"
5709 "Filter more specific routes from updates\n")
5710
5711 ALIAS (no_aggregate_address_mask,
5712 no_aggregate_address_mask_as_set_cmd,
5713 "no aggregate-address A.B.C.D A.B.C.D as-set",
5714 NO_STR
5715 "Configure BGP aggregate entries\n"
5716 "Aggregate address\n"
5717 "Aggregate mask\n"
5718 "Generate AS set path information\n")
5719
5720 ALIAS (no_aggregate_address_mask,
5721 no_aggregate_address_mask_as_set_summary_cmd,
5722 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5723 NO_STR
5724 "Configure BGP aggregate entries\n"
5725 "Aggregate address\n"
5726 "Aggregate mask\n"
5727 "Generate AS set path information\n"
5728 "Filter more specific routes from updates\n")
5729
5730 ALIAS (no_aggregate_address_mask,
5731 no_aggregate_address_mask_summary_as_set_cmd,
5732 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5733 NO_STR
5734 "Configure BGP aggregate entries\n"
5735 "Aggregate address\n"
5736 "Aggregate mask\n"
5737 "Filter more specific routes from updates\n"
5738 "Generate AS set path information\n")
5739
5740 #ifdef HAVE_IPV6
5741 DEFUN (ipv6_aggregate_address,
5742 ipv6_aggregate_address_cmd,
5743 "aggregate-address X:X::X:X/M",
5744 "Configure BGP aggregate entries\n"
5745 "Aggregate prefix\n")
5746 {
5747 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5748 }
5749
5750 DEFUN (ipv6_aggregate_address_summary_only,
5751 ipv6_aggregate_address_summary_only_cmd,
5752 "aggregate-address X:X::X:X/M summary-only",
5753 "Configure BGP aggregate entries\n"
5754 "Aggregate prefix\n"
5755 "Filter more specific routes from updates\n")
5756 {
5757 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5758 AGGREGATE_SUMMARY_ONLY, 0);
5759 }
5760
5761 DEFUN (no_ipv6_aggregate_address,
5762 no_ipv6_aggregate_address_cmd,
5763 "no aggregate-address X:X::X:X/M",
5764 NO_STR
5765 "Configure BGP aggregate entries\n"
5766 "Aggregate prefix\n")
5767 {
5768 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5769 }
5770
5771 DEFUN (no_ipv6_aggregate_address_summary_only,
5772 no_ipv6_aggregate_address_summary_only_cmd,
5773 "no aggregate-address X:X::X:X/M summary-only",
5774 NO_STR
5775 "Configure BGP aggregate entries\n"
5776 "Aggregate prefix\n"
5777 "Filter more specific routes from updates\n")
5778 {
5779 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5780 }
5781
5782 ALIAS (ipv6_aggregate_address,
5783 old_ipv6_aggregate_address_cmd,
5784 "ipv6 bgp aggregate-address X:X::X:X/M",
5785 IPV6_STR
5786 BGP_STR
5787 "Configure BGP aggregate entries\n"
5788 "Aggregate prefix\n")
5789
5790 ALIAS (ipv6_aggregate_address_summary_only,
5791 old_ipv6_aggregate_address_summary_only_cmd,
5792 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5793 IPV6_STR
5794 BGP_STR
5795 "Configure BGP aggregate entries\n"
5796 "Aggregate prefix\n"
5797 "Filter more specific routes from updates\n")
5798
5799 ALIAS (no_ipv6_aggregate_address,
5800 old_no_ipv6_aggregate_address_cmd,
5801 "no ipv6 bgp aggregate-address X:X::X:X/M",
5802 NO_STR
5803 IPV6_STR
5804 BGP_STR
5805 "Configure BGP aggregate entries\n"
5806 "Aggregate prefix\n")
5807
5808 ALIAS (no_ipv6_aggregate_address_summary_only,
5809 old_no_ipv6_aggregate_address_summary_only_cmd,
5810 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5811 NO_STR
5812 IPV6_STR
5813 BGP_STR
5814 "Configure BGP aggregate entries\n"
5815 "Aggregate prefix\n"
5816 "Filter more specific routes from updates\n")
5817 #endif /* HAVE_IPV6 */
5818
5819 /* Redistribute route treatment. */
5820 void
5821 bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
5822 const struct in6_addr *nexthop6, unsigned int ifindex,
5823 u_int32_t metric, u_char type, u_short instance, u_short tag)
5824 {
5825 struct bgp_info *new;
5826 struct bgp_info *bi;
5827 struct bgp_info info;
5828 struct bgp_node *bn;
5829 struct attr attr;
5830 struct attr *new_attr;
5831 afi_t afi;
5832 int ret;
5833 struct bgp_redist *red;
5834
5835 /* Make default attribute. */
5836 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5837 if (nexthop)
5838 attr.nexthop = *nexthop;
5839 attr.nh_ifindex = ifindex;
5840
5841 #ifdef HAVE_IPV6
5842 if (nexthop6)
5843 {
5844 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5845 extra->mp_nexthop_global = *nexthop6;
5846 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
5847 }
5848 #endif
5849
5850 attr.med = metric;
5851 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5852 attr.extra->tag = tag;
5853
5854 afi = family2afi (p->family);
5855
5856 red = bgp_redist_lookup(bgp, afi, type, instance);
5857 if (red)
5858 {
5859 struct attr attr_new;
5860 struct attr_extra extra_new;
5861
5862 /* Copy attribute for modification. */
5863 attr_new.extra = &extra_new;
5864 bgp_attr_dup (&attr_new, &attr);
5865
5866 if (red->redist_metric_flag)
5867 attr_new.med = red->redist_metric;
5868
5869 /* Apply route-map. */
5870 if (red->rmap.name)
5871 {
5872 info.peer = bgp->peer_self;
5873 info.attr = &attr_new;
5874
5875 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5876
5877 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5878
5879 bgp->peer_self->rmap_type = 0;
5880
5881 if (ret == RMAP_DENYMATCH)
5882 {
5883 /* Free uninterned attribute. */
5884 bgp_attr_flush (&attr_new);
5885
5886 /* Unintern original. */
5887 aspath_unintern (&attr.aspath);
5888 bgp_attr_extra_free (&attr);
5889 bgp_redistribute_delete (bgp, p, type, instance);
5890 return;
5891 }
5892 }
5893
5894 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5895 afi, SAFI_UNICAST, p, NULL);
5896
5897 new_attr = bgp_attr_intern (&attr_new);
5898
5899 for (bi = bn->info; bi; bi = bi->next)
5900 if (bi->peer == bgp->peer_self
5901 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5902 break;
5903
5904 if (bi)
5905 {
5906 /* Ensure the (source route) type is updated. */
5907 bi->type = type;
5908 if (attrhash_cmp (bi->attr, new_attr) &&
5909 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5910 {
5911 bgp_attr_unintern (&new_attr);
5912 aspath_unintern (&attr.aspath);
5913 bgp_attr_extra_free (&attr);
5914 bgp_unlock_node (bn);
5915 return;
5916 }
5917 else
5918 {
5919 /* The attribute is changed. */
5920 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5921
5922 /* Rewrite BGP route information. */
5923 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5924 bgp_info_restore(bn, bi);
5925 else
5926 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5927 bgp_attr_unintern (&bi->attr);
5928 bi->attr = new_attr;
5929 bi->uptime = bgp_clock ();
5930
5931 /* Process change. */
5932 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5933 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5934 bgp_unlock_node (bn);
5935 aspath_unintern (&attr.aspath);
5936 bgp_attr_extra_free (&attr);
5937 return;
5938 }
5939 }
5940
5941 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5942 new_attr, bn);
5943 SET_FLAG (new->flags, BGP_INFO_VALID);
5944
5945 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5946 bgp_info_add (bn, new);
5947 bgp_unlock_node (bn);
5948 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5949 }
5950
5951 /* Unintern original. */
5952 aspath_unintern (&attr.aspath);
5953 bgp_attr_extra_free (&attr);
5954 }
5955
5956 void
5957 bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
5958 {
5959 afi_t afi;
5960 struct bgp_node *rn;
5961 struct bgp_info *ri;
5962 struct bgp_redist *red;
5963
5964 afi = family2afi (p->family);
5965
5966 red = bgp_redist_lookup(bgp, afi, type, instance);
5967 if (red)
5968 {
5969 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5970
5971 for (ri = rn->info; ri; ri = ri->next)
5972 if (ri->peer == bgp->peer_self
5973 && ri->type == type)
5974 break;
5975
5976 if (ri)
5977 {
5978 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5979 bgp_info_delete (rn, ri);
5980 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5981 }
5982 bgp_unlock_node (rn);
5983 }
5984 }
5985
5986 /* Withdraw specified route type's route. */
5987 void
5988 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
5989 {
5990 struct bgp_node *rn;
5991 struct bgp_info *ri;
5992 struct bgp_table *table;
5993
5994 table = bgp->rib[afi][SAFI_UNICAST];
5995
5996 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5997 {
5998 for (ri = rn->info; ri; ri = ri->next)
5999 if (ri->peer == bgp->peer_self
6000 && ri->type == type
6001 && ri->instance == instance)
6002 break;
6003
6004 if (ri)
6005 {
6006 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
6007 bgp_info_delete (rn, ri);
6008 bgp_process (bgp, rn, afi, SAFI_UNICAST);
6009 }
6010 }
6011 }
6012
6013 /* Static function to display route. */
6014 static void
6015 route_vty_out_route (struct prefix *p, struct vty *vty)
6016 {
6017 int len;
6018 u_int32_t destination;
6019 char buf[BUFSIZ];
6020
6021 if (p->family == AF_INET)
6022 {
6023 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6024 destination = ntohl (p->u.prefix4.s_addr);
6025
6026 if ((IN_CLASSC (destination) && p->prefixlen == 24)
6027 || (IN_CLASSB (destination) && p->prefixlen == 16)
6028 || (IN_CLASSA (destination) && p->prefixlen == 8)
6029 || p->u.prefix4.s_addr == 0)
6030 {
6031 /* When mask is natural, mask is not displayed. */
6032 }
6033 else
6034 len += vty_out (vty, "/%d", p->prefixlen);
6035 }
6036 else
6037 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6038 p->prefixlen);
6039
6040 len = 17 - len;
6041 if (len < 1)
6042 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6043 else
6044 vty_out (vty, "%*s", len, " ");
6045 }
6046
6047 enum bgp_display_type
6048 {
6049 normal_list,
6050 };
6051
6052 /* Print the short form route status for a bgp_info */
6053 static void
6054 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
6055 json_object *json_path)
6056 {
6057 if (json_path)
6058 {
6059
6060 /* Route status display. */
6061 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6062 json_object_boolean_true_add(json_path, "removed");
6063
6064 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6065 json_object_boolean_true_add(json_path, "stale");
6066
6067 if (binfo->extra && binfo->extra->suppress)
6068 json_object_boolean_true_add(json_path, "suppressed");
6069
6070 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6071 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6072 json_object_boolean_true_add(json_path, "valid");
6073
6074 /* Selected */
6075 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6076 json_object_boolean_true_add(json_path, "history");
6077
6078 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6079 json_object_boolean_true_add(json_path, "damped");
6080
6081 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6082 json_object_boolean_true_add(json_path, "bestpath");
6083
6084 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6085 json_object_boolean_true_add(json_path, "multipath");
6086
6087 /* Internal route. */
6088 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6089 json_object_string_add(json_path, "pathFrom", "internal");
6090 else
6091 json_object_string_add(json_path, "pathFrom", "external");
6092
6093 return;
6094 }
6095
6096 /* Route status display. */
6097 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6098 vty_out (vty, "R");
6099 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6100 vty_out (vty, "S");
6101 else if (binfo->extra && binfo->extra->suppress)
6102 vty_out (vty, "s");
6103 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6104 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6105 vty_out (vty, "*");
6106 else
6107 vty_out (vty, " ");
6108
6109 /* Selected */
6110 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6111 vty_out (vty, "h");
6112 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6113 vty_out (vty, "d");
6114 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6115 vty_out (vty, ">");
6116 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6117 vty_out (vty, "=");
6118 else
6119 vty_out (vty, " ");
6120
6121 /* Internal route. */
6122 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6123 vty_out (vty, "i");
6124 else
6125 vty_out (vty, " ");
6126 }
6127
6128 /* called from terminal list command */
6129 void
6130 route_vty_out (struct vty *vty, struct prefix *p,
6131 struct bgp_info *binfo, int display, safi_t safi,
6132 json_object *json_paths)
6133 {
6134 struct attr *attr;
6135 json_object *json_path = NULL;
6136 json_object *json_nexthops = NULL;
6137 json_object *json_nexthop_global = NULL;
6138 json_object *json_nexthop_ll = NULL;
6139
6140 if (json_paths)
6141 json_path = json_object_new_object();
6142
6143 /* short status lead text */
6144 route_vty_short_status_out (vty, binfo, json_path);
6145
6146 if (!json_paths)
6147 {
6148 /* print prefix and mask */
6149 if (! display)
6150 route_vty_out_route (p, vty);
6151 else
6152 vty_out (vty, "%*s", 17, " ");
6153 }
6154
6155 /* Print attribute */
6156 attr = binfo->attr;
6157 if (attr)
6158 {
6159 /*
6160 * For ENCAP routes, nexthop address family is not
6161 * neccessarily the same as the prefix address family.
6162 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
6163 */
6164 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN))
6165 {
6166 if (attr->extra)
6167 {
6168 char buf[BUFSIZ];
6169 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
6170
6171 switch (af)
6172 {
6173 case AF_INET:
6174 vty_out (vty, "%s", inet_ntop(af,
6175 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
6176 break;
6177 #if HAVE_IPV6
6178 case AF_INET6:
6179 vty_out (vty, "%s", inet_ntop(af,
6180 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
6181 break;
6182 #endif
6183 default:
6184 vty_out(vty, "?");
6185 break;
6186 }
6187 }
6188 else
6189 vty_out(vty, "?");
6190 }
6191 /* IPv4 Next Hop */
6192 else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6193 {
6194 if (json_paths)
6195 {
6196 json_nexthop_global = json_object_new_object();
6197
6198 if (safi == SAFI_MPLS_VPN)
6199 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6200 else
6201 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6202
6203 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6204 json_object_boolean_true_add(json_nexthop_global, "used");
6205 }
6206 else
6207 {
6208 if (safi == SAFI_MPLS_VPN)
6209 vty_out (vty, "%-16s",
6210 inet_ntoa (attr->extra->mp_nexthop_global_in));
6211 else
6212 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6213 }
6214 }
6215
6216 /* IPv6 Next Hop */
6217 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6218 {
6219 int len;
6220 char buf[BUFSIZ];
6221
6222 if (json_paths)
6223 {
6224 json_nexthop_global = json_object_new_object();
6225 json_object_string_add(json_nexthop_global, "ip",
6226 inet_ntop (AF_INET6,
6227 &attr->extra->mp_nexthop_global,
6228 buf, BUFSIZ));
6229 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6230 json_object_string_add(json_nexthop_global, "scope", "global");
6231
6232 /* We display both LL & GL if both have been received */
6233 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
6234 {
6235 json_nexthop_ll = json_object_new_object();
6236 json_object_string_add(json_nexthop_ll, "ip",
6237 inet_ntop (AF_INET6,
6238 &attr->extra->mp_nexthop_local,
6239 buf, BUFSIZ));
6240 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6241 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6242
6243 if ((IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
6244 &attr->extra->mp_nexthop_local) != 0) &&
6245 !attr->extra->mp_nexthop_prefer_global)
6246 json_object_boolean_true_add(json_nexthop_ll, "used");
6247 else
6248 json_object_boolean_true_add(json_nexthop_global, "used");
6249 }
6250 else
6251 json_object_boolean_true_add(json_nexthop_global, "used");
6252 }
6253 else
6254 {
6255 /* Display LL if LL/Global both in table unless prefer-global is set */
6256 if (((attr->extra->mp_nexthop_len == 32) &&
6257 !attr->extra->mp_nexthop_prefer_global) ||
6258 (binfo->peer->conf_if))
6259 {
6260 if (binfo->peer->conf_if)
6261 {
6262 len = vty_out (vty, "%s",
6263 binfo->peer->conf_if);
6264 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
6265
6266 if (len < 1)
6267 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
6268 else
6269 vty_out (vty, "%*s", len, " ");
6270 }
6271 else
6272 {
6273 len = vty_out (vty, "%s",
6274 inet_ntop (AF_INET6,
6275 &attr->extra->mp_nexthop_local,
6276 buf, BUFSIZ));
6277 len = 16 - len;
6278
6279 if (len < 1)
6280 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6281 else
6282 vty_out (vty, "%*s", len, " ");
6283 }
6284 }
6285 else
6286 {
6287 len = vty_out (vty, "%s",
6288 inet_ntop (AF_INET6,
6289 &attr->extra->mp_nexthop_global,
6290 buf, BUFSIZ));
6291 len = 16 - len;
6292
6293 if (len < 1)
6294 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6295 else
6296 vty_out (vty, "%*s", len, " ");
6297 }
6298 }
6299 }
6300
6301 /* MED/Metric */
6302 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6303 if (json_paths)
6304 json_object_int_add(json_path, "med", attr->med);
6305 else
6306 vty_out (vty, "%10u ", attr->med);
6307 else
6308 if (!json_paths)
6309 vty_out (vty, " ");
6310
6311 /* Local Pref */
6312 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6313 if (json_paths)
6314 json_object_int_add(json_path, "localpref", attr->local_pref);
6315 else
6316 vty_out (vty, "%7u ", attr->local_pref);
6317 else
6318 if (!json_paths)
6319 vty_out (vty, " ");
6320
6321 if (json_paths)
6322 {
6323 if (attr->extra)
6324 json_object_int_add(json_path, "weight", attr->extra->weight);
6325 else
6326 json_object_int_add(json_path, "weight", 0);
6327 }
6328 else
6329 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6330
6331 if (json_paths) {
6332 char buf[BUFSIZ];
6333 json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6334 }
6335
6336 /* Print aspath */
6337 if (attr->aspath)
6338 {
6339 if (json_paths)
6340 json_object_string_add(json_path, "aspath", attr->aspath->str);
6341 else
6342 aspath_print_vty (vty, "%s", attr->aspath, " ");
6343 }
6344
6345 /* Print origin */
6346 if (json_paths)
6347 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6348 else
6349 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6350 }
6351 else
6352 {
6353 if (json_paths)
6354 json_object_string_add(json_path, "alert", "No attributes");
6355 else
6356 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6357 }
6358
6359 if (json_paths)
6360 {
6361 if (json_nexthop_global || json_nexthop_ll)
6362 {
6363 json_nexthops = json_object_new_array();
6364
6365 if (json_nexthop_global)
6366 json_object_array_add(json_nexthops, json_nexthop_global);
6367
6368 if (json_nexthop_ll)
6369 json_object_array_add(json_nexthops, json_nexthop_ll);
6370
6371 json_object_object_add(json_path, "nexthops", json_nexthops);
6372 }
6373
6374 json_object_array_add(json_paths, json_path);
6375 }
6376 else
6377 {
6378 vty_out (vty, "%s", VTY_NEWLINE);
6379 #if ENABLE_BGP_VNC
6380 /* prints an additional line, indented, with VNC info, if present */
6381 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi == SAFI_UNICAST))
6382 rfapi_vty_out_vncinfo(vty, p, binfo, safi);
6383 #endif
6384 }
6385 }
6386
6387 /* called from terminal list command */
6388 void
6389 route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6390 u_char use_json, json_object *json_ar)
6391 {
6392 json_object *json_status = NULL;
6393 json_object *json_net = NULL;
6394 char buff[BUFSIZ];
6395 /* Route status display. */
6396 if (use_json)
6397 {
6398 json_status = json_object_new_object();
6399 json_net = json_object_new_object();
6400 }
6401 else
6402 {
6403 vty_out (vty, "*");
6404 vty_out (vty, ">");
6405 vty_out (vty, " ");
6406 }
6407
6408 /* print prefix and mask */
6409 if (use_json)
6410 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6411 else
6412 route_vty_out_route (p, vty);
6413
6414 /* Print attribute */
6415 if (attr)
6416 {
6417 if (use_json)
6418 {
6419 if (p->family == AF_INET &&
6420 (safi == SAFI_MPLS_VPN ||
6421 safi == SAFI_ENCAP ||
6422 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6423 {
6424 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6425 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6426 else
6427 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6428 }
6429 #ifdef HAVE_IPV6
6430 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6431 {
6432 char buf[BUFSIZ];
6433
6434 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6435 buf, BUFSIZ));
6436 }
6437 #endif /* HAVE_IPV6 */
6438
6439 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6440 json_object_int_add(json_net, "metric", attr->med);
6441
6442 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6443 json_object_int_add(json_net, "localPref", attr->local_pref);
6444
6445 if (attr->extra)
6446 json_object_int_add(json_net, "weight", attr->extra->weight);
6447 else
6448 json_object_int_add(json_net, "weight", 0);
6449
6450 /* Print aspath */
6451 if (attr->aspath)
6452 json_object_string_add(json_net, "asPath", attr->aspath->str);
6453
6454 /* Print origin */
6455 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
6456 }
6457 else
6458 {
6459 if (p->family == AF_INET &&
6460 (safi == SAFI_MPLS_VPN ||
6461 safi == SAFI_ENCAP ||
6462 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6463 {
6464 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6465 vty_out (vty, "%-16s",
6466 inet_ntoa (attr->extra->mp_nexthop_global_in));
6467 else
6468 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6469 }
6470 #ifdef HAVE_IPV6
6471 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6472 {
6473 int len;
6474 char buf[BUFSIZ];
6475
6476 assert (attr->extra);
6477
6478 len = vty_out (vty, "%s",
6479 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6480 buf, BUFSIZ));
6481 len = 16 - len;
6482 if (len < 1)
6483 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6484 else
6485 vty_out (vty, "%*s", len, " ");
6486 }
6487 #endif /* HAVE_IPV6 */
6488 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6489 vty_out (vty, "%10u ", attr->med);
6490 else
6491 vty_out (vty, " ");
6492
6493 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6494 vty_out (vty, "%7u ", attr->local_pref);
6495 else
6496 vty_out (vty, " ");
6497
6498 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6499
6500 /* Print aspath */
6501 if (attr->aspath)
6502 aspath_print_vty (vty, "%s", attr->aspath, " ");
6503
6504 /* Print origin */
6505 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6506 }
6507 }
6508 if (use_json)
6509 {
6510 json_object_boolean_true_add(json_status, "*");
6511 json_object_boolean_true_add(json_status, ">");
6512 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6513 char buf_cut[BUFSIZ];
6514 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6515 }
6516 else
6517 vty_out (vty, "%s", VTY_NEWLINE);
6518 }
6519
6520 void
6521 route_vty_out_tag (struct vty *vty, struct prefix *p,
6522 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
6523 {
6524 json_object *json_out = NULL;
6525 struct attr *attr;
6526 u_int32_t label = 0;
6527
6528 if (!binfo->extra)
6529 return;
6530
6531 if (json)
6532 json_out = json_object_new_object();
6533
6534 /* short status lead text */
6535 route_vty_short_status_out (vty, binfo, json_out);
6536
6537 /* print prefix and mask */
6538 if (json == NULL)
6539 {
6540 if (! display)
6541 route_vty_out_route (p, vty);
6542 else
6543 vty_out (vty, "%*s", 17, " ");
6544 }
6545
6546 /* Print attribute */
6547 attr = binfo->attr;
6548 if (attr)
6549 {
6550 if (p->family == AF_INET
6551 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6552 {
6553 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6554 {
6555 if (json)
6556 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6557 else
6558 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6559 }
6560 else
6561 {
6562 if (json)
6563 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6564 else
6565 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6566 }
6567 }
6568 #ifdef HAVE_IPV6
6569 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6570 {
6571 assert (attr->extra);
6572 char buf_a[BUFSIZ];
6573 char buf_b[BUFSIZ];
6574 char buf_c[BUFSIZ];
6575 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
6576 {
6577 if (json)
6578 json_object_string_add(json_out, "mpNexthopGlobalIn",
6579 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6580 else
6581 vty_out (vty, "%s",
6582 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6583 buf_a, BUFSIZ));
6584 }
6585 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6586 {
6587 if (json)
6588 {
6589 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6590 buf_a, BUFSIZ);
6591 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6592 buf_b, BUFSIZ);
6593 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6594 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6595 }
6596 else
6597 vty_out (vty, "%s(%s)",
6598 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6599 buf_a, BUFSIZ),
6600 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6601 buf_b, BUFSIZ));
6602 }
6603
6604 }
6605 #endif /* HAVE_IPV6 */
6606 }
6607
6608 label = decode_label (binfo->extra->tag);
6609
6610 if (json)
6611 {
6612 if (label)
6613 json_object_int_add(json_out, "notag", label);
6614 json_object_array_add(json, json_out);
6615 }
6616 else
6617 {
6618 vty_out (vty, "notag/%d", label);
6619 vty_out (vty, "%s", VTY_NEWLINE);
6620 }
6621 }
6622
6623 /* dampening route */
6624 static void
6625 damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6626 int display, safi_t safi, u_char use_json, json_object *json)
6627 {
6628 struct attr *attr;
6629 int len;
6630 char timebuf[BGP_UPTIME_LEN];
6631
6632 /* short status lead text */
6633 route_vty_short_status_out (vty, binfo, json);
6634
6635 /* print prefix and mask */
6636 if (!use_json)
6637 {
6638 if (! display)
6639 route_vty_out_route (p, vty);
6640 else
6641 vty_out (vty, "%*s", 17, " ");
6642 }
6643
6644 len = vty_out (vty, "%s", binfo->peer->host);
6645 len = 17 - len;
6646 if (len < 1)
6647 {
6648 if (!use_json)
6649 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6650 }
6651 else
6652 {
6653 if (use_json)
6654 json_object_int_add(json, "peerHost", len);
6655 else
6656 vty_out (vty, "%*s", len, " ");
6657 }
6658
6659 if (use_json)
6660 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6661 else
6662 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6663
6664 /* Print attribute */
6665 attr = binfo->attr;
6666 if (attr)
6667 {
6668 /* Print aspath */
6669 if (attr->aspath)
6670 {
6671 if (use_json)
6672 json_object_string_add(json, "asPath", attr->aspath->str);
6673 else
6674 aspath_print_vty (vty, "%s", attr->aspath, " ");
6675 }
6676
6677 /* Print origin */
6678 if (use_json)
6679 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6680 else
6681 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6682 }
6683 if (!use_json)
6684 vty_out (vty, "%s", VTY_NEWLINE);
6685 }
6686
6687 /* flap route */
6688 static void
6689 flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6690 int display, safi_t safi, u_char use_json, json_object *json)
6691 {
6692 struct attr *attr;
6693 struct bgp_damp_info *bdi;
6694 char timebuf[BGP_UPTIME_LEN];
6695 int len;
6696
6697 if (!binfo->extra)
6698 return;
6699
6700 bdi = binfo->extra->damp_info;
6701
6702 /* short status lead text */
6703 route_vty_short_status_out (vty, binfo, json);
6704
6705 /* print prefix and mask */
6706 if (!use_json)
6707 {
6708 if (! display)
6709 route_vty_out_route (p, vty);
6710 else
6711 vty_out (vty, "%*s", 17, " ");
6712 }
6713
6714 len = vty_out (vty, "%s", binfo->peer->host);
6715 len = 16 - len;
6716 if (len < 1)
6717 {
6718 if (!use_json)
6719 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6720 }
6721 else
6722 {
6723 if (use_json)
6724 json_object_int_add(json, "peerHost", len);
6725 else
6726 vty_out (vty, "%*s", len, " ");
6727 }
6728
6729 len = vty_out (vty, "%d", bdi->flap);
6730 len = 5 - len;
6731 if (len < 1)
6732 {
6733 if (!use_json)
6734 vty_out (vty, " ");
6735 }
6736 else
6737 {
6738 if (use_json)
6739 json_object_int_add(json, "bdiFlap", len);
6740 else
6741 vty_out (vty, "%*s", len, " ");
6742 }
6743
6744 if (use_json)
6745 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6746 else
6747 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6748 timebuf, BGP_UPTIME_LEN, 0, NULL));
6749
6750 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6751 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6752 {
6753 if (use_json)
6754 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6755 else
6756 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6757 }
6758 else
6759 {
6760 if (!use_json)
6761 vty_out (vty, "%*s ", 8, " ");
6762 }
6763
6764 /* Print attribute */
6765 attr = binfo->attr;
6766 if (attr)
6767 {
6768 /* Print aspath */
6769 if (attr->aspath)
6770 {
6771 if (use_json)
6772 json_object_string_add(json, "asPath", attr->aspath->str);
6773 else
6774 aspath_print_vty (vty, "%s", attr->aspath, " ");
6775 }
6776
6777 /* Print origin */
6778 if (use_json)
6779 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6780 else
6781 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6782 }
6783 if (!use_json)
6784 vty_out (vty, "%s", VTY_NEWLINE);
6785 }
6786
6787 static void
6788 route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6789 const char *header, json_object *json_adv_to)
6790 {
6791 char buf1[INET6_ADDRSTRLEN];
6792 json_object *json_peer = NULL;
6793
6794 if (json_adv_to)
6795 {
6796 /* 'advertised-to' is a dictionary of peers we have advertised this
6797 * prefix too. The key is the peer's IP or swpX, the value is the
6798 * hostname if we know it and "" if not.
6799 */
6800 json_peer = json_object_new_object();
6801
6802 if (peer->hostname)
6803 json_object_string_add(json_peer, "hostname", peer->hostname);
6804
6805 if (peer->conf_if)
6806 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6807 else
6808 json_object_object_add(json_adv_to,
6809 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6810 json_peer);
6811 }
6812 else
6813 {
6814 if (*first)
6815 {
6816 vty_out (vty, "%s", header);
6817 *first = 0;
6818 }
6819
6820 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6821 {
6822 if (peer->conf_if)
6823 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6824 else
6825 vty_out (vty, " %s(%s)", peer->hostname,
6826 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6827 }
6828 else
6829 {
6830 if (peer->conf_if)
6831 vty_out (vty, " %s", peer->conf_if);
6832 else
6833 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6834 }
6835 }
6836 }
6837
6838 static void
6839 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6840 struct bgp_info *binfo, afi_t afi, safi_t safi,
6841 json_object *json_paths)
6842 {
6843 char buf[INET6_ADDRSTRLEN];
6844 char buf1[BUFSIZ];
6845 struct attr *attr;
6846 int sockunion_vty_out (struct vty *, union sockunion *);
6847 #ifdef HAVE_CLOCK_MONOTONIC
6848 time_t tbuf;
6849 #endif
6850 json_object *json_bestpath = NULL;
6851 json_object *json_cluster_list = NULL;
6852 json_object *json_cluster_list_list = NULL;
6853 json_object *json_ext_community = NULL;
6854 json_object *json_last_update = NULL;
6855 json_object *json_nexthop_global = NULL;
6856 json_object *json_nexthop_ll = NULL;
6857 json_object *json_nexthops = NULL;
6858 json_object *json_path = NULL;
6859 json_object *json_peer = NULL;
6860 json_object *json_string = NULL;
6861 json_object *json_adv_to = NULL;
6862 int first = 0;
6863 struct listnode *node, *nnode;
6864 struct peer *peer;
6865 int addpath_capable;
6866 int has_adj;
6867 int first_as;
6868
6869 if (json_paths)
6870 {
6871 json_path = json_object_new_object();
6872 json_peer = json_object_new_object();
6873 json_nexthop_global = json_object_new_object();
6874 }
6875
6876 attr = binfo->attr;
6877
6878 if (attr)
6879 {
6880 /* Line1 display AS-path, Aggregator */
6881 if (attr->aspath)
6882 {
6883 if (json_paths)
6884 {
6885 json_object_lock(attr->aspath->json);
6886 json_object_object_add(json_path, "aspath", attr->aspath->json);
6887 }
6888 else
6889 {
6890 if (attr->aspath->segments)
6891 aspath_print_vty (vty, " %s", attr->aspath, "");
6892 else
6893 vty_out (vty, " Local");
6894 }
6895 }
6896
6897 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6898 {
6899 if (json_paths)
6900 json_object_boolean_true_add(json_path, "removed");
6901 else
6902 vty_out (vty, ", (removed)");
6903 }
6904
6905 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6906 {
6907 if (json_paths)
6908 json_object_boolean_true_add(json_path, "stale");
6909 else
6910 vty_out (vty, ", (stale)");
6911 }
6912
6913 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6914 {
6915 if (json_paths)
6916 {
6917 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6918 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
6919 }
6920 else
6921 {
6922 vty_out (vty, ", (aggregated by %u %s)",
6923 attr->extra->aggregator_as,
6924 inet_ntoa (attr->extra->aggregator_addr));
6925 }
6926 }
6927
6928 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6929 {
6930 if (json_paths)
6931 json_object_boolean_true_add(json_path, "rxedFromRrClient");
6932 else
6933 vty_out (vty, ", (Received from a RR-client)");
6934 }
6935
6936 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6937 {
6938 if (json_paths)
6939 json_object_boolean_true_add(json_path, "rxedFromRsClient");
6940 else
6941 vty_out (vty, ", (Received from a RS-client)");
6942 }
6943
6944 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6945 {
6946 if (json_paths)
6947 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
6948 else
6949 vty_out (vty, ", (history entry)");
6950 }
6951 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6952 {
6953 if (json_paths)
6954 json_object_boolean_true_add(json_path, "dampeningSuppressed");
6955 else
6956 vty_out (vty, ", (suppressed due to dampening)");
6957 }
6958
6959 if (!json_paths)
6960 vty_out (vty, "%s", VTY_NEWLINE);
6961
6962 /* Line2 display Next-hop, Neighbor, Router-id */
6963 /* Display the nexthop */
6964 if (p->family == AF_INET &&
6965 (safi == SAFI_MPLS_VPN ||
6966 safi == SAFI_ENCAP ||
6967 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6968 {
6969 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6970 {
6971 if (json_paths)
6972 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6973 else
6974 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6975 }
6976 else
6977 {
6978 if (json_paths)
6979 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6980 else
6981 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6982 }
6983
6984 if (json_paths)
6985 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6986 }
6987 else
6988 {
6989 assert (attr->extra);
6990 if (json_paths)
6991 {
6992 json_object_string_add(json_nexthop_global, "ip",
6993 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6994 buf, INET6_ADDRSTRLEN));
6995 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6996 json_object_string_add(json_nexthop_global, "scope", "global");
6997 }
6998 else
6999 {
7000 vty_out (vty, " %s",
7001 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7002 buf, INET6_ADDRSTRLEN));
7003 }
7004 }
7005
7006 /* Display the IGP cost or 'inaccessible' */
7007 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7008 {
7009 if (json_paths)
7010 json_object_boolean_false_add(json_nexthop_global, "accessible");
7011 else
7012 vty_out (vty, " (inaccessible)");
7013 }
7014 else
7015 {
7016 if (binfo->extra && binfo->extra->igpmetric)
7017 {
7018 if (json_paths)
7019 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
7020 else
7021 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
7022 }
7023
7024 /* IGP cost is 0, display this only for json */
7025 else
7026 {
7027 if (json_paths)
7028 json_object_int_add(json_nexthop_global, "metric", 0);
7029 }
7030
7031 if (json_paths)
7032 json_object_boolean_true_add(json_nexthop_global, "accessible");
7033 }
7034
7035 /* Display peer "from" output */
7036 /* This path was originated locally */
7037 if (binfo->peer == bgp->peer_self)
7038 {
7039
7040 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
7041 {
7042 if (json_paths)
7043 json_object_string_add(json_peer, "peerId", "0.0.0.0");
7044 else
7045 vty_out (vty, " from 0.0.0.0 ");
7046 }
7047 else
7048 {
7049 if (json_paths)
7050 json_object_string_add(json_peer, "peerId", "::");
7051 else
7052 vty_out (vty, " from :: ");
7053 }
7054
7055 if (json_paths)
7056 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
7057 else
7058 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
7059 }
7060
7061 /* We RXed this path from one of our peers */
7062 else
7063 {
7064
7065 if (json_paths)
7066 {
7067 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7068 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7069
7070 if (binfo->peer->hostname)
7071 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
7072
7073 if (binfo->peer->domainname)
7074 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
7075
7076 if (binfo->peer->conf_if)
7077 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
7078 }
7079 else
7080 {
7081 if (binfo->peer->conf_if)
7082 {
7083 if (binfo->peer->hostname &&
7084 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7085 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7086 binfo->peer->conf_if);
7087 else
7088 vty_out (vty, " from %s", binfo->peer->conf_if);
7089 }
7090 else
7091 {
7092 if (binfo->peer->hostname &&
7093 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7094 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7095 binfo->peer->host);
7096 else
7097 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7098 }
7099
7100 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7101 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
7102 else
7103 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7104 }
7105 }
7106
7107 if (!json_paths)
7108 vty_out (vty, "%s", VTY_NEWLINE);
7109
7110 /* display the link-local nexthop */
7111 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
7112 {
7113 if (json_paths)
7114 {
7115 json_nexthop_ll = json_object_new_object();
7116 json_object_string_add(json_nexthop_ll, "ip",
7117 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7118 buf, INET6_ADDRSTRLEN));
7119 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
7120 json_object_string_add(json_nexthop_ll, "scope", "link-local");
7121
7122 json_object_boolean_true_add(json_nexthop_ll, "accessible");
7123
7124 if (!attr->extra->mp_nexthop_prefer_global)
7125 json_object_boolean_true_add(json_nexthop_ll, "used");
7126 else
7127 json_object_boolean_true_add(json_nexthop_global, "used");
7128 }
7129 else
7130 {
7131 vty_out (vty, " (%s) %s%s",
7132 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7133 buf, INET6_ADDRSTRLEN),
7134 attr->extra->mp_nexthop_prefer_global ?
7135 "(prefer-global)" : "(used)",
7136 VTY_NEWLINE);
7137 }
7138 }
7139 /* If we do not have a link-local nexthop then we must flag the global as "used" */
7140 else
7141 {
7142 if (json_paths)
7143 json_object_boolean_true_add(json_nexthop_global, "used");
7144 }
7145
7146 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
7147 if (json_paths)
7148 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
7149 else
7150 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
7151
7152 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
7153 {
7154 if (json_paths)
7155 json_object_int_add(json_path, "med", attr->med);
7156 else
7157 vty_out (vty, ", metric %u", attr->med);
7158 }
7159
7160 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
7161 {
7162 if (json_paths)
7163 json_object_int_add(json_path, "localpref", attr->local_pref);
7164 else
7165 vty_out (vty, ", localpref %u", attr->local_pref);
7166 }
7167 else
7168 {
7169 if (json_paths)
7170 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
7171 else
7172 vty_out (vty, ", localpref %u", bgp->default_local_pref);
7173 }
7174
7175 if (attr->extra && attr->extra->weight != 0)
7176 {
7177 if (json_paths)
7178 json_object_int_add(json_path, "weight", attr->extra->weight);
7179 else
7180 vty_out (vty, ", weight %u", attr->extra->weight);
7181 }
7182
7183 if (attr->extra && attr->extra->tag != 0)
7184 {
7185 if (json_paths)
7186 json_object_int_add(json_path, "tag", attr->extra->tag);
7187 else
7188 vty_out (vty, ", tag %d", attr->extra->tag);
7189 }
7190
7191 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7192 {
7193 if (json_paths)
7194 json_object_boolean_false_add(json_path, "valid");
7195 else
7196 vty_out (vty, ", invalid");
7197 }
7198 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
7199 {
7200 if (json_paths)
7201 json_object_boolean_true_add(json_path, "valid");
7202 else
7203 vty_out (vty, ", valid");
7204 }
7205
7206 if (binfo->peer != bgp->peer_self)
7207 {
7208 if (binfo->peer->as == binfo->peer->local_as)
7209 {
7210 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7211 {
7212 if (json_paths)
7213 json_object_string_add(json_peer, "type", "confed-internal");
7214 else
7215 vty_out (vty, ", confed-internal");
7216 }
7217 else
7218 {
7219 if (json_paths)
7220 json_object_string_add(json_peer, "type", "internal");
7221 else
7222 vty_out (vty, ", internal");
7223 }
7224 }
7225 else
7226 {
7227 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
7228 {
7229 if (json_paths)
7230 json_object_string_add(json_peer, "type", "confed-external");
7231 else
7232 vty_out (vty, ", confed-external");
7233 }
7234 else
7235 {
7236 if (json_paths)
7237 json_object_string_add(json_peer, "type", "external");
7238 else
7239 vty_out (vty, ", external");
7240 }
7241 }
7242 }
7243 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
7244 {
7245 if (json_paths)
7246 {
7247 json_object_boolean_true_add(json_path, "aggregated");
7248 json_object_boolean_true_add(json_path, "local");
7249 }
7250 else
7251 {
7252 vty_out (vty, ", aggregated, local");
7253 }
7254 }
7255 else if (binfo->type != ZEBRA_ROUTE_BGP)
7256 {
7257 if (json_paths)
7258 json_object_boolean_true_add(json_path, "sourced");
7259 else
7260 vty_out (vty, ", sourced");
7261 }
7262 else
7263 {
7264 if (json_paths)
7265 {
7266 json_object_boolean_true_add(json_path, "sourced");
7267 json_object_boolean_true_add(json_path, "local");
7268 }
7269 else
7270 {
7271 vty_out (vty, ", sourced, local");
7272 }
7273 }
7274
7275 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
7276 {
7277 if (json_paths)
7278 json_object_boolean_true_add(json_path, "atomicAggregate");
7279 else
7280 vty_out (vty, ", atomic-aggregate");
7281 }
7282
7283 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7284 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7285 bgp_info_mpath_count (binfo)))
7286 {
7287 if (json_paths)
7288 json_object_boolean_true_add(json_path, "multipath");
7289 else
7290 vty_out (vty, ", multipath");
7291 }
7292
7293 // Mark the bestpath(s)
7294 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
7295 {
7296 first_as = aspath_get_firstas(attr->aspath);
7297
7298 if (json_paths)
7299 {
7300 if (!json_bestpath)
7301 json_bestpath = json_object_new_object();
7302 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
7303 }
7304 else
7305 {
7306 if (first_as)
7307 vty_out (vty, ", bestpath-from-AS %d", first_as);
7308 else
7309 vty_out (vty, ", bestpath-from-AS Local");
7310 }
7311 }
7312
7313 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
7314 {
7315 if (json_paths)
7316 {
7317 if (!json_bestpath)
7318 json_bestpath = json_object_new_object();
7319 json_object_boolean_true_add(json_bestpath, "overall");
7320 }
7321 else
7322 vty_out (vty, ", best");
7323 }
7324
7325 if (json_bestpath)
7326 json_object_object_add(json_path, "bestpath", json_bestpath);
7327
7328 if (!json_paths)
7329 vty_out (vty, "%s", VTY_NEWLINE);
7330
7331 /* Line 4 display Community */
7332 if (attr->community)
7333 {
7334 if (json_paths)
7335 {
7336 json_object_lock(attr->community->json);
7337 json_object_object_add(json_path, "community", attr->community->json);
7338 }
7339 else
7340 {
7341 vty_out (vty, " Community: %s%s", attr->community->str,
7342 VTY_NEWLINE);
7343 }
7344 }
7345
7346 /* Line 5 display Extended-community */
7347 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
7348 {
7349 if (json_paths)
7350 {
7351 json_ext_community = json_object_new_object();
7352 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
7353 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
7354 }
7355 else
7356 {
7357 vty_out (vty, " Extended Community: %s%s",
7358 attr->extra->ecommunity->str, VTY_NEWLINE);
7359 }
7360 }
7361
7362 /* Line 6 display Originator, Cluster-id */
7363 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7364 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7365 {
7366 assert (attr->extra);
7367 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7368 {
7369 if (json_paths)
7370 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
7371 else
7372 vty_out (vty, " Originator: %s",
7373 inet_ntoa (attr->extra->originator_id));
7374 }
7375
7376 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7377 {
7378 int i;
7379
7380 if (json_paths)
7381 {
7382 json_cluster_list = json_object_new_object();
7383 json_cluster_list_list = json_object_new_array();
7384
7385 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7386 {
7387 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
7388 json_object_array_add(json_cluster_list_list, json_string);
7389 }
7390
7391 /* struct cluster_list does not have "str" variable like
7392 * aspath and community do. Add this someday if someone
7393 * asks for it.
7394 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7395 */
7396 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
7397 json_object_object_add(json_path, "clusterList", json_cluster_list);
7398 }
7399 else
7400 {
7401 vty_out (vty, ", Cluster list: ");
7402
7403 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7404 {
7405 vty_out (vty, "%s ",
7406 inet_ntoa (attr->extra->cluster->list[i]));
7407 }
7408 }
7409 }
7410
7411 if (!json_paths)
7412 vty_out (vty, "%s", VTY_NEWLINE);
7413 }
7414
7415 if (binfo->extra && binfo->extra->damp_info)
7416 bgp_damp_info_vty (vty, binfo, json_path);
7417
7418 /* Line 7 display Addpath IDs */
7419 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
7420 {
7421 if (json_paths)
7422 {
7423 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7424 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
7425 }
7426 else
7427 {
7428 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7429 binfo->addpath_rx_id, binfo->addpath_tx_id,
7430 VTY_NEWLINE);
7431 }
7432 }
7433
7434 /* If we used addpath to TX a non-bestpath we need to display
7435 * "Advertised to" on a path-by-path basis */
7436 if (bgp->addpath_tx_used[afi][safi])
7437 {
7438 first = 1;
7439
7440 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7441 {
7442 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7443 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7444
7445 if ((addpath_capable && has_adj) ||
7446 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7447 {
7448 if (json_path && !json_adv_to)
7449 json_adv_to = json_object_new_object();
7450
7451 route_vty_out_advertised_to(vty, peer, &first,
7452 " Advertised to:",
7453 json_adv_to);
7454 }
7455 }
7456
7457 if (json_path)
7458 {
7459 if (json_adv_to)
7460 {
7461 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7462 }
7463 }
7464 else
7465 {
7466 if (!first)
7467 {
7468 vty_out (vty, "%s", VTY_NEWLINE);
7469 }
7470 }
7471 }
7472
7473 /* Line 8 display Uptime */
7474 #ifdef HAVE_CLOCK_MONOTONIC
7475 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
7476 if (json_paths)
7477 {
7478 json_last_update = json_object_new_object();
7479 json_object_int_add(json_last_update, "epoch", tbuf);
7480 json_object_string_add(json_last_update, "string", ctime(&tbuf));
7481 json_object_object_add(json_path, "lastUpdate", json_last_update);
7482 }
7483 else
7484 vty_out (vty, " Last update: %s", ctime(&tbuf));
7485 #else
7486 if (json_paths)
7487 {
7488 json_last_update = json_object_new_object();
7489 json_object_int_add(json_last_update, "epoch", tbuf);
7490 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
7491 json_object_object_add(json_path, "lastUpdate", json_last_update);
7492 }
7493 else
7494 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
7495 #endif /* HAVE_CLOCK_MONOTONIC */
7496 }
7497
7498 /* We've constructed the json object for this path, add it to the json
7499 * array of paths
7500 */
7501 if (json_paths)
7502 {
7503 if (json_nexthop_global || json_nexthop_ll)
7504 {
7505 json_nexthops = json_object_new_array();
7506
7507 if (json_nexthop_global)
7508 json_object_array_add(json_nexthops, json_nexthop_global);
7509
7510 if (json_nexthop_ll)
7511 json_object_array_add(json_nexthops, json_nexthop_ll);
7512
7513 json_object_object_add(json_path, "nexthops", json_nexthops);
7514 }
7515
7516 json_object_object_add(json_path, "peer", json_peer);
7517 json_object_array_add(json_paths, json_path);
7518 }
7519 else
7520 vty_out (vty, "%s", VTY_NEWLINE);
7521 }
7522
7523 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
7524 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7525 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7526
7527 enum bgp_show_type
7528 {
7529 bgp_show_type_normal,
7530 bgp_show_type_regexp,
7531 bgp_show_type_prefix_list,
7532 bgp_show_type_filter_list,
7533 bgp_show_type_route_map,
7534 bgp_show_type_neighbor,
7535 bgp_show_type_cidr_only,
7536 bgp_show_type_prefix_longer,
7537 bgp_show_type_community_all,
7538 bgp_show_type_community,
7539 bgp_show_type_community_exact,
7540 bgp_show_type_community_list,
7541 bgp_show_type_community_list_exact,
7542 bgp_show_type_flap_statistics,
7543 bgp_show_type_flap_address,
7544 bgp_show_type_flap_prefix,
7545 bgp_show_type_flap_cidr_only,
7546 bgp_show_type_flap_regexp,
7547 bgp_show_type_flap_filter_list,
7548 bgp_show_type_flap_prefix_list,
7549 bgp_show_type_flap_prefix_longer,
7550 bgp_show_type_flap_route_map,
7551 bgp_show_type_flap_neighbor,
7552 bgp_show_type_dampend_paths,
7553 bgp_show_type_damp_neighbor
7554 };
7555
7556 static int
7557 bgp_show_prefix_list (struct vty *vty, const char *name,
7558 const char *prefix_list_str, afi_t afi,
7559 safi_t safi, enum bgp_show_type type);
7560 static int
7561 bgp_show_filter_list (struct vty *vty, const char *name,
7562 const char *filter, afi_t afi,
7563 safi_t safi, enum bgp_show_type type);
7564 static int
7565 bgp_show_route_map (struct vty *vty, const char *name,
7566 const char *rmap_str, afi_t afi,
7567 safi_t safi, enum bgp_show_type type);
7568 static int
7569 bgp_show_community_list (struct vty *vty, const char *name,
7570 const char *com, int exact,
7571 afi_t afi, safi_t safi);
7572 static int
7573 bgp_show_prefix_longer (struct vty *vty, const char *name,
7574 const char *prefix, afi_t afi,
7575 safi_t safi, enum bgp_show_type type);
7576
7577 static int
7578 bgp_show_table (struct vty *vty, struct bgp_table *table,
7579 struct in_addr *router_id, enum bgp_show_type type,
7580 void *output_arg, u_char use_json, json_object *json)
7581 {
7582 struct bgp_info *ri;
7583 struct bgp_node *rn;
7584 int header = 1;
7585 int display;
7586 unsigned long output_count;
7587 unsigned long total_count;
7588 struct prefix *p;
7589 char buf[BUFSIZ];
7590 char buf2[BUFSIZ];
7591 json_object *json_paths = NULL;
7592 json_object *json_routes = NULL;
7593
7594 if (use_json)
7595 {
7596 if (json == NULL)
7597 json = json_object_new_object();
7598
7599 json_object_int_add(json, "tableVersion", table->version);
7600 json_object_string_add(json, "routerId", inet_ntoa (*router_id));
7601 json_routes = json_object_new_object();
7602 }
7603
7604 /* This is first entry point, so reset total line. */
7605 output_count = 0;
7606 total_count = 0;
7607
7608 /* Start processing of routes. */
7609 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7610 if (rn->info != NULL)
7611 {
7612 display = 0;
7613
7614 if (use_json)
7615 json_paths = json_object_new_array();
7616 else
7617 json_paths = NULL;
7618
7619 for (ri = rn->info; ri; ri = ri->next)
7620 {
7621 total_count++;
7622 if (type == bgp_show_type_flap_statistics
7623 || type == bgp_show_type_flap_address
7624 || type == bgp_show_type_flap_prefix
7625 || type == bgp_show_type_flap_cidr_only
7626 || type == bgp_show_type_flap_regexp
7627 || type == bgp_show_type_flap_filter_list
7628 || type == bgp_show_type_flap_prefix_list
7629 || type == bgp_show_type_flap_prefix_longer
7630 || type == bgp_show_type_flap_route_map
7631 || type == bgp_show_type_flap_neighbor
7632 || type == bgp_show_type_dampend_paths
7633 || type == bgp_show_type_damp_neighbor)
7634 {
7635 if (!(ri->extra && ri->extra->damp_info))
7636 continue;
7637 }
7638 if (type == bgp_show_type_regexp
7639 || type == bgp_show_type_flap_regexp)
7640 {
7641 regex_t *regex = output_arg;
7642
7643 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7644 continue;
7645 }
7646 if (type == bgp_show_type_prefix_list
7647 || type == bgp_show_type_flap_prefix_list)
7648 {
7649 struct prefix_list *plist = output_arg;
7650
7651 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7652 continue;
7653 }
7654 if (type == bgp_show_type_filter_list
7655 || type == bgp_show_type_flap_filter_list)
7656 {
7657 struct as_list *as_list = output_arg;
7658
7659 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7660 continue;
7661 }
7662 if (type == bgp_show_type_route_map
7663 || type == bgp_show_type_flap_route_map)
7664 {
7665 struct route_map *rmap = output_arg;
7666 struct bgp_info binfo;
7667 struct attr dummy_attr;
7668 struct attr_extra dummy_extra;
7669 int ret;
7670
7671 dummy_attr.extra = &dummy_extra;
7672 bgp_attr_dup (&dummy_attr, ri->attr);
7673
7674 binfo.peer = ri->peer;
7675 binfo.attr = &dummy_attr;
7676
7677 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7678 if (ret == RMAP_DENYMATCH)
7679 continue;
7680 }
7681 if (type == bgp_show_type_neighbor
7682 || type == bgp_show_type_flap_neighbor
7683 || type == bgp_show_type_damp_neighbor)
7684 {
7685 union sockunion *su = output_arg;
7686
7687 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7688 continue;
7689 }
7690 if (type == bgp_show_type_cidr_only
7691 || type == bgp_show_type_flap_cidr_only)
7692 {
7693 u_int32_t destination;
7694
7695 destination = ntohl (rn->p.u.prefix4.s_addr);
7696 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7697 continue;
7698 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7699 continue;
7700 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7701 continue;
7702 }
7703 if (type == bgp_show_type_prefix_longer
7704 || type == bgp_show_type_flap_prefix_longer)
7705 {
7706 struct prefix *p = output_arg;
7707
7708 if (! prefix_match (p, &rn->p))
7709 continue;
7710 }
7711 if (type == bgp_show_type_community_all)
7712 {
7713 if (! ri->attr->community)
7714 continue;
7715 }
7716 if (type == bgp_show_type_community)
7717 {
7718 struct community *com = output_arg;
7719
7720 if (! ri->attr->community ||
7721 ! community_match (ri->attr->community, com))
7722 continue;
7723 }
7724 if (type == bgp_show_type_community_exact)
7725 {
7726 struct community *com = output_arg;
7727
7728 if (! ri->attr->community ||
7729 ! community_cmp (ri->attr->community, com))
7730 continue;
7731 }
7732 if (type == bgp_show_type_community_list)
7733 {
7734 struct community_list *list = output_arg;
7735
7736 if (! community_list_match (ri->attr->community, list))
7737 continue;
7738 }
7739 if (type == bgp_show_type_community_list_exact)
7740 {
7741 struct community_list *list = output_arg;
7742
7743 if (! community_list_exact_match (ri->attr->community, list))
7744 continue;
7745 }
7746 if (type == bgp_show_type_flap_address
7747 || type == bgp_show_type_flap_prefix)
7748 {
7749 struct prefix *p = output_arg;
7750
7751 if (! prefix_match (&rn->p, p))
7752 continue;
7753
7754 if (type == bgp_show_type_flap_prefix)
7755 if (p->prefixlen != rn->p.prefixlen)
7756 continue;
7757 }
7758 if (type == bgp_show_type_dampend_paths
7759 || type == bgp_show_type_damp_neighbor)
7760 {
7761 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7762 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7763 continue;
7764 }
7765
7766 if (!use_json && header)
7767 {
7768 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE);
7769 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7770 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7771 if (type == bgp_show_type_dampend_paths
7772 || type == bgp_show_type_damp_neighbor)
7773 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7774 else if (type == bgp_show_type_flap_statistics
7775 || type == bgp_show_type_flap_address
7776 || type == bgp_show_type_flap_prefix
7777 || type == bgp_show_type_flap_cidr_only
7778 || type == bgp_show_type_flap_regexp
7779 || type == bgp_show_type_flap_filter_list
7780 || type == bgp_show_type_flap_prefix_list
7781 || type == bgp_show_type_flap_prefix_longer
7782 || type == bgp_show_type_flap_route_map
7783 || type == bgp_show_type_flap_neighbor)
7784 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7785 else
7786 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7787 header = 0;
7788 }
7789
7790 if (type == bgp_show_type_dampend_paths
7791 || type == bgp_show_type_damp_neighbor)
7792 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7793 else if (type == bgp_show_type_flap_statistics
7794 || type == bgp_show_type_flap_address
7795 || type == bgp_show_type_flap_prefix
7796 || type == bgp_show_type_flap_cidr_only
7797 || type == bgp_show_type_flap_regexp
7798 || type == bgp_show_type_flap_filter_list
7799 || type == bgp_show_type_flap_prefix_list
7800 || type == bgp_show_type_flap_prefix_longer
7801 || type == bgp_show_type_flap_route_map
7802 || type == bgp_show_type_flap_neighbor)
7803 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7804 else
7805 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7806 display++;
7807 }
7808
7809 if (display)
7810 {
7811 output_count++;
7812 if (use_json)
7813 {
7814 p = &rn->p;
7815 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7816 json_object_object_add(json_routes, buf2, json_paths);
7817 }
7818 }
7819 }
7820
7821 if (use_json)
7822 {
7823 /* This can produce a LOT of text so do not use
7824 * JSON_C_TO_STRING_PRETTY here
7825 */
7826 json_object_object_add(json, "routes", json_routes);
7827 vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
7828 json_object_free(json);
7829 }
7830 else
7831 {
7832 /* No route is displayed */
7833 if (output_count == 0)
7834 {
7835 if (type == bgp_show_type_normal)
7836 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
7837 }
7838 else
7839 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
7840 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
7841 }
7842
7843 return CMD_SUCCESS;
7844 }
7845
7846 static int
7847 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
7848 enum bgp_show_type type, void *output_arg, u_char use_json)
7849 {
7850 struct bgp_table *table;
7851
7852 if (bgp == NULL)
7853 {
7854 bgp = bgp_get_default ();
7855 }
7856
7857 if (bgp == NULL)
7858 {
7859 if (!use_json)
7860 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7861 return CMD_WARNING;
7862 }
7863
7864 table = bgp->rib[afi][safi];
7865
7866 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg,
7867 use_json, NULL);
7868 }
7869
7870 static void
7871 bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7872 u_char use_json)
7873 {
7874 struct listnode *node, *nnode;
7875 struct bgp *bgp;
7876 struct bgp_table *table;
7877 json_object *json = NULL;
7878 int is_first = 1;
7879
7880 if (use_json)
7881 vty_out (vty, "{%s", VTY_NEWLINE);
7882
7883 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7884 {
7885 if (use_json)
7886 {
7887 if (!(json = json_object_new_object()))
7888 {
7889 zlog_err("Unable to allocate memory for JSON object");
7890 vty_out (vty,
7891 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
7892 VTY_NEWLINE);
7893 return;
7894 }
7895 json_object_int_add(json, "vrfId",
7896 (bgp->vrf_id == VRF_UNKNOWN)
7897 ? -1 : bgp->vrf_id);
7898 json_object_string_add(json, "vrfName",
7899 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7900 ? "Default" : bgp->name);
7901 if (! is_first)
7902 vty_out (vty, ",%s", VTY_NEWLINE);
7903 else
7904 is_first = 0;
7905
7906 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7907 ? "Default" : bgp->name);
7908 }
7909 else
7910 {
7911 vty_out (vty, "%sInstance %s:%s",
7912 VTY_NEWLINE,
7913 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7914 ? "Default" : bgp->name,
7915 VTY_NEWLINE);
7916 }
7917 table = bgp->rib[afi][safi];
7918 bgp_show_table (vty, table, &bgp->router_id,
7919 bgp_show_type_normal, NULL, use_json, json);
7920
7921 }
7922
7923 if (use_json)
7924 vty_out (vty, "}%s", VTY_NEWLINE);
7925 }
7926
7927 /* Header of detailed BGP route information */
7928 static void
7929 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7930 struct bgp_node *rn,
7931 struct prefix_rd *prd, afi_t afi, safi_t safi,
7932 json_object *json)
7933 {
7934 struct bgp_info *ri;
7935 struct prefix *p;
7936 struct peer *peer;
7937 struct listnode *node, *nnode;
7938 char buf1[INET6_ADDRSTRLEN];
7939 char buf2[INET6_ADDRSTRLEN];
7940 int count = 0;
7941 int best = 0;
7942 int suppress = 0;
7943 int no_export = 0;
7944 int no_advertise = 0;
7945 int local_as = 0;
7946 int first = 1;
7947 json_object *json_adv_to = NULL;
7948
7949 p = &rn->p;
7950
7951 if (json)
7952 {
7953 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7954 json_object_int_add(json, "prefixlen", p->prefixlen);
7955 }
7956 else
7957 {
7958 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7959 ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ?
7960 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7961 safi == SAFI_MPLS_VPN ? ":" : "",
7962 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7963 p->prefixlen, VTY_NEWLINE);
7964 }
7965
7966 for (ri = rn->info; ri; ri = ri->next)
7967 {
7968 count++;
7969 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7970 {
7971 best = count;
7972 if (ri->extra && ri->extra->suppress)
7973 suppress = 1;
7974 if (ri->attr->community != NULL)
7975 {
7976 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7977 no_advertise = 1;
7978 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7979 no_export = 1;
7980 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7981 local_as = 1;
7982 }
7983 }
7984 }
7985
7986 if (!json)
7987 {
7988 vty_out (vty, "Paths: (%d available", count);
7989 if (best)
7990 {
7991 vty_out (vty, ", best #%d", best);
7992 if (safi == SAFI_UNICAST)
7993 vty_out (vty, ", table %s",
7994 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7995 ? "Default-IP-Routing-Table" : bgp->name);
7996 }
7997 else
7998 vty_out (vty, ", no best path");
7999
8000 if (no_advertise)
8001 vty_out (vty, ", not advertised to any peer");
8002 else if (no_export)
8003 vty_out (vty, ", not advertised to EBGP peer");
8004 else if (local_as)
8005 vty_out (vty, ", not advertised outside local AS");
8006
8007 if (suppress)
8008 vty_out (vty, ", Advertisements suppressed by an aggregate.");
8009 vty_out (vty, ")%s", VTY_NEWLINE);
8010 }
8011
8012 /* If we are not using addpath then we can display Advertised to and that will
8013 * show what peers we advertised the bestpath to. If we are using addpath
8014 * though then we must display Advertised to on a path-by-path basis. */
8015 if (!bgp->addpath_tx_used[afi][safi])
8016 {
8017 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
8018 {
8019 if (bgp_adj_out_lookup (peer, rn, 0))
8020 {
8021 if (json && !json_adv_to)
8022 json_adv_to = json_object_new_object();
8023
8024 route_vty_out_advertised_to(vty, peer, &first,
8025 " Advertised to non peer-group peers:\n ",
8026 json_adv_to);
8027 }
8028 }
8029
8030 if (json)
8031 {
8032 if (json_adv_to)
8033 {
8034 json_object_object_add(json, "advertisedTo", json_adv_to);
8035 }
8036 }
8037 else
8038 {
8039 if (first)
8040 vty_out (vty, " Not advertised to any peer");
8041 vty_out (vty, "%s", VTY_NEWLINE);
8042 }
8043 }
8044 }
8045
8046 /* Display specified route of BGP table. */
8047 static int
8048 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
8049 struct bgp_table *rib, const char *ip_str,
8050 afi_t afi, safi_t safi, struct prefix_rd *prd,
8051 int prefix_check, enum bgp_path_type pathtype,
8052 u_char use_json)
8053 {
8054 int ret;
8055 int header;
8056 int display = 0;
8057 struct prefix match;
8058 struct bgp_node *rn;
8059 struct bgp_node *rm;
8060 struct bgp_info *ri;
8061 struct bgp_table *table;
8062 json_object *json = NULL;
8063 json_object *json_paths = NULL;
8064
8065 /* Check IP address argument. */
8066 ret = str2prefix (ip_str, &match);
8067 if (! ret)
8068 {
8069 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
8070 return CMD_WARNING;
8071 }
8072
8073 match.family = afi2family (afi);
8074
8075 if (use_json)
8076 {
8077 json = json_object_new_object();
8078 json_paths = json_object_new_array();
8079 }
8080
8081 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
8082 {
8083 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
8084 {
8085 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8086 continue;
8087
8088 if ((table = rn->info) != NULL)
8089 {
8090 header = 1;
8091
8092 if ((rm = bgp_node_match (table, &match)) != NULL)
8093 {
8094 if (prefix_check && rm->p.prefixlen != match.prefixlen)
8095 {
8096 bgp_unlock_node (rm);
8097 continue;
8098 }
8099
8100 for (ri = rm->info; ri; ri = ri->next)
8101 {
8102 if (header)
8103 {
8104 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
8105 AFI_IP, safi, json);
8106 header = 0;
8107 }
8108 display++;
8109
8110 if (pathtype == BGP_PATH_ALL ||
8111 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8112 (pathtype == BGP_PATH_MULTIPATH &&
8113 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8114 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths);
8115 }
8116
8117 bgp_unlock_node (rm);
8118 }
8119 }
8120 }
8121 }
8122 else
8123 {
8124 header = 1;
8125
8126 if ((rn = bgp_node_match (rib, &match)) != NULL)
8127 {
8128 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8129 {
8130 for (ri = rn->info; ri; ri = ri->next)
8131 {
8132 if (header)
8133 {
8134 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
8135 header = 0;
8136 }
8137 display++;
8138
8139 if (pathtype == BGP_PATH_ALL ||
8140 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8141 (pathtype == BGP_PATH_MULTIPATH &&
8142 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8143 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
8144 }
8145 }
8146
8147 bgp_unlock_node (rn);
8148 }
8149 }
8150
8151 if (use_json)
8152 {
8153 if (display)
8154 json_object_object_add(json, "paths", json_paths);
8155
8156 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
8157 json_object_free(json);
8158 }
8159 else
8160 {
8161 if (!display)
8162 {
8163 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
8164 return CMD_WARNING;
8165 }
8166 }
8167
8168 return CMD_SUCCESS;
8169 }
8170
8171 /* Display specified route of Main RIB */
8172 static int
8173 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
8174 afi_t afi, safi_t safi, struct prefix_rd *prd,
8175 int prefix_check, enum bgp_path_type pathtype,
8176 u_char use_json)
8177 {
8178 struct bgp *bgp;
8179
8180 /* BGP structure lookup. */
8181 if (view_name)
8182 {
8183 bgp = bgp_lookup_by_name (view_name);
8184 if (bgp == NULL)
8185 {
8186 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
8187 return CMD_WARNING;
8188 }
8189 }
8190 else
8191 {
8192 bgp = bgp_get_default ();
8193 if (bgp == NULL)
8194 {
8195 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8196 return CMD_WARNING;
8197 }
8198 }
8199
8200 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
8201 afi, safi, prd, prefix_check, pathtype,
8202 use_json);
8203 }
8204
8205 /* BGP route print out function. */
8206 DEFUN (show_ip_bgp,
8207 show_ip_bgp_cmd,
8208 "show ip bgp {json}",
8209 SHOW_STR
8210 IP_STR
8211 BGP_STR
8212 "JavaScript Object Notation\n")
8213 {
8214 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8215 }
8216
8217 DEFUN (show_ip_bgp_ipv4,
8218 show_ip_bgp_ipv4_cmd,
8219 "show ip bgp ipv4 (unicast|multicast) {json}",
8220 SHOW_STR
8221 IP_STR
8222 BGP_STR
8223 "Address family\n"
8224 "Address Family modifier\n"
8225 "Address Family modifier\n"
8226 "JavaScript Object Notation\n")
8227 {
8228 u_char uj = use_json(argc, argv);
8229
8230 if (strncmp (argv[0], "m", 1) == 0)
8231 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
8232 NULL, uj);
8233
8234 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
8235 }
8236
8237 ALIAS (show_ip_bgp_ipv4,
8238 show_bgp_ipv4_safi_cmd,
8239 "show bgp ipv4 (unicast|multicast) {json}",
8240 SHOW_STR
8241 BGP_STR
8242 "Address family\n"
8243 "Address Family modifier\n"
8244 "Address Family modifier\n"
8245 "JavaScript Object Notation\n")
8246
8247 DEFUN (show_ip_bgp_route,
8248 show_ip_bgp_route_cmd,
8249 "show ip bgp A.B.C.D {json}",
8250 SHOW_STR
8251 IP_STR
8252 BGP_STR
8253 "Network in the BGP routing table to display\n"
8254 "JavaScript Object Notation\n")
8255 {
8256 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8257 }
8258
8259 DEFUN (show_ip_bgp_route_pathtype,
8260 show_ip_bgp_route_pathtype_cmd,
8261 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
8262 SHOW_STR
8263 IP_STR
8264 BGP_STR
8265 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8266 "Display only the bestpath\n"
8267 "Display only multipaths\n"
8268 "JavaScript Object Notation\n")
8269 {
8270 u_char uj = use_json(argc, argv);
8271
8272 if (strncmp (argv[1], "b", 1) == 0)
8273 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8274 else
8275 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8276 }
8277
8278 DEFUN (show_bgp_ipv4_safi_route_pathtype,
8279 show_bgp_ipv4_safi_route_pathtype_cmd,
8280 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}",
8281 SHOW_STR
8282 BGP_STR
8283 "Address family\n"
8284 "Address Family modifier\n"
8285 "Address Family modifier\n"
8286 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8287 "Display only the bestpath\n"
8288 "Display only multipaths\n"
8289 "JavaScript Object Notation\n")
8290 {
8291 u_char uj = use_json(argc, argv);
8292
8293 if (strncmp (argv[0], "m", 1) == 0)
8294 if (strncmp (argv[2], "b", 1) == 0)
8295 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8296 else
8297 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8298 else
8299 if (strncmp (argv[2], "b", 1) == 0)
8300 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8301 else
8302 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8303 }
8304
8305 DEFUN (show_bgp_ipv4_prefix,
8306 show_bgp_ipv4_prefix_cmd,
8307 "show bgp ipv4 A.B.C.D/M {json}",
8308 SHOW_STR
8309 BGP_STR
8310 IP_STR
8311 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8312 JSON_STR)
8313 {
8314 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc, argv));
8315 }
8316
8317 DEFUN (show_bgp_ipv6_route,
8318 show_bgp_ipv6_route_cmd,
8319 "show bgp ipv6 X:X::X:X {json}",
8320 SHOW_STR
8321 BGP_STR
8322 "Address family\n"
8323 "Network in the BGP routing table to display\n"
8324 JSON_STR)
8325 {
8326 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
8327 }
8328
8329 DEFUN (show_bgp_ipv6_prefix,
8330 show_bgp_ipv6_prefix_cmd,
8331 "show bgp ipv6 X:X::X:X/M {json}",
8332 SHOW_STR
8333 BGP_STR
8334 IP_STR
8335 "IPv6 prefix <network>/<length>\n"
8336 JSON_STR)
8337 {
8338 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc,argv));
8339 }
8340
8341 DEFUN (show_ip_bgp_ipv4_route,
8342 show_ip_bgp_ipv4_route_cmd,
8343 "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}",
8344 SHOW_STR
8345 IP_STR
8346 BGP_STR
8347 "Address family\n"
8348 "Address Family modifier\n"
8349 "Address Family modifier\n"
8350 "Network in the BGP routing table to display\n"
8351 "JavaScript Object Notation\n")
8352 {
8353 u_char uj = use_json(argc, argv);
8354
8355 if (strncmp (argv[0], "m", 1) == 0)
8356 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
8357
8358 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
8359 }
8360
8361 ALIAS (show_ip_bgp_ipv4_route,
8362 show_bgp_ipv4_safi_route_cmd,
8363 "show bgp ipv4 (unicast|multicast) A.B.C.D {json}",
8364 SHOW_STR
8365 BGP_STR
8366 "Address family\n"
8367 "Address Family modifier\n"
8368 "Address Family modifier\n"
8369 "Network in the BGP routing table to display\n"
8370 "JavaScript Object Notation\n")
8371
8372 DEFUN (show_ip_bgp_vpnv4_all_route,
8373 show_ip_bgp_vpnv4_all_route_cmd,
8374 "show ip bgp vpnv4 all A.B.C.D {json}",
8375 SHOW_STR
8376 IP_STR
8377 BGP_STR
8378 "Display VPNv4 NLRI specific information\n"
8379 "Display information about all VPNv4 NLRIs\n"
8380 "Network in the BGP routing table to display\n"
8381 "JavaScript Object Notation\n")
8382 {
8383 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8384 }
8385
8386 DEFUN (show_bgp_ipv4_vpn_route,
8387 show_bgp_ipv4_vpn_route_cmd,
8388 "show bgp ipv4 vpn A.B.C.D {json}",
8389 SHOW_STR
8390 BGP_STR
8391 "Address Family\n"
8392 "Display VPN NLRI specific information\n"
8393 "Network in the BGP routing table to display\n"
8394 JSON_STR)
8395 {
8396 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
8397 }
8398
8399 DEFUN (show_bgp_ipv6_vpn_route,
8400 show_bgp_ipv6_vpn_route_cmd,
8401 "show bgp ipv6 vpn X:X::X:X {json}",
8402 SHOW_STR
8403 BGP_STR
8404 "Address Family\n"
8405 "Display VPN NLRI specific information\n"
8406 "Network in the BGP routing table to display\n"
8407 JSON_STR)
8408 {
8409 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
8410 }
8411
8412 DEFUN (show_bgp_ipv4_vpn_rd_route,
8413 show_bgp_ipv4_vpn_rd_route_cmd,
8414 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
8415 SHOW_STR
8416 BGP_STR
8417 IP_STR
8418 "Display VPN NLRI specific information\n"
8419 "Display information for a route distinguisher\n"
8420 "VPN Route Distinguisher\n"
8421 "Network in the BGP routing table to display\n"
8422 JSON_STR)
8423 {
8424 int ret;
8425 struct prefix_rd prd;
8426
8427 ret = str2prefix_rd (argv[0], &prd);
8428 if (! ret)
8429 {
8430 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8431 return CMD_WARNING;
8432 }
8433 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8434 }
8435
8436 DEFUN (show_bgp_ipv6_vpn_rd_route,
8437 show_bgp_ipv6_vpn_rd_route_cmd,
8438 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X {json}",
8439 SHOW_STR
8440 BGP_STR
8441 "Address Family\n"
8442 "Display VPN NLRI specific information\n"
8443 "Display information for a route distinguisher\n"
8444 "VPN Route Distinguisher\n"
8445 "Network in the BGP routing table to display\n"
8446 JSON_STR)
8447 {
8448 int ret;
8449 struct prefix_rd prd;
8450
8451 ret = str2prefix_rd (argv[0], &prd);
8452 if (! ret)
8453 {
8454 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8455 return CMD_WARNING;
8456 }
8457 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8458 }
8459
8460 DEFUN (show_ip_bgp_vpnv4_rd_route,
8461 show_ip_bgp_vpnv4_rd_route_cmd,
8462 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
8463 SHOW_STR
8464 IP_STR
8465 BGP_STR
8466 "Display VPNv4 NLRI specific information\n"
8467 "Display information for a route distinguisher\n"
8468 "VPN Route Distinguisher\n"
8469 "Network in the BGP routing table to display\n"
8470 "JavaScript Object Notation\n")
8471 {
8472 int ret;
8473 struct prefix_rd prd;
8474 u_char uj= use_json(argc, argv);
8475
8476 ret = str2prefix_rd (argv[0], &prd);
8477 if (! ret)
8478 {
8479 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8480 return CMD_WARNING;
8481 }
8482 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj);
8483 }
8484
8485 DEFUN (show_ip_bgp_prefix,
8486 show_ip_bgp_prefix_cmd,
8487 "show ip bgp A.B.C.D/M {json}",
8488 SHOW_STR
8489 IP_STR
8490 BGP_STR
8491 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8492 "JavaScript Object Notation\n")
8493 {
8494 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8495 }
8496
8497 DEFUN (show_ip_bgp_prefix_pathtype,
8498 show_ip_bgp_prefix_pathtype_cmd,
8499 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
8500 SHOW_STR
8501 IP_STR
8502 BGP_STR
8503 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8504 "Display only the bestpath\n"
8505 "Display only multipaths\n"
8506 "JavaScript Object Notation\n")
8507 {
8508 u_char uj = use_json(argc, argv);
8509 if (strncmp (argv[1], "b", 1) == 0)
8510 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8511 else
8512 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8513 }
8514
8515 DEFUN (show_ip_bgp_ipv4_prefix,
8516 show_ip_bgp_ipv4_prefix_cmd,
8517 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
8518 SHOW_STR
8519 IP_STR
8520 BGP_STR
8521 "Address family\n"
8522 "Address Family modifier\n"
8523 "Address Family modifier\n"
8524 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8525 "JavaScript Object Notation\n")
8526 {
8527 u_char uj = use_json(argc, argv);
8528
8529 if (strncmp (argv[0], "m", 1) == 0)
8530 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
8531
8532 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
8533 }
8534
8535 ALIAS (show_ip_bgp_ipv4_prefix,
8536 show_bgp_ipv4_safi_prefix_cmd,
8537 "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}",
8538 SHOW_STR
8539 BGP_STR
8540 "Address family\n"
8541 "Address Family modifier\n"
8542 "Address Family modifier\n"
8543 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8544 "JavaScript Object Notation\n")
8545
8546 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8547 show_ip_bgp_ipv4_prefix_pathtype_cmd,
8548 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
8549 SHOW_STR
8550 IP_STR
8551 BGP_STR
8552 "Address family\n"
8553 "Address Family modifier\n"
8554 "Address Family modifier\n"
8555 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8556 "Display only the bestpath\n"
8557 "Display only multipaths\n"
8558 "JavaScript Object Notation\n")
8559 {
8560 u_char uj = use_json(argc, argv);
8561
8562 if (strncmp (argv[0], "m", 1) == 0)
8563 if (strncmp (argv[2], "b", 1) == 0)
8564 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8565 else
8566 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8567 else
8568 if (strncmp (argv[2], "b", 1) == 0)
8569 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8570 else
8571 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8572 }
8573
8574 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8575 show_bgp_ipv4_safi_prefix_pathtype_cmd,
8576 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}",
8577 SHOW_STR
8578 BGP_STR
8579 "Address family\n"
8580 "Address Family modifier\n"
8581 "Address Family modifier\n"
8582 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8583 "Display only the bestpath\n"
8584 "Display only multipaths\n"
8585 "JavaScript Object Notation\n")
8586
8587 DEFUN (show_ip_bgp_vpnv4_all_prefix,
8588 show_ip_bgp_vpnv4_all_prefix_cmd,
8589 "show ip bgp vpnv4 all A.B.C.D/M {json}",
8590 SHOW_STR
8591 IP_STR
8592 BGP_STR
8593 "Display VPNv4 NLRI specific information\n"
8594 "Display information about all VPNv4 NLRIs\n"
8595 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8596 "JavaScript Object Notation\n")
8597 {
8598 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8599 }
8600
8601 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
8602 show_ip_bgp_vpnv4_rd_prefix_cmd,
8603 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
8604 SHOW_STR
8605 IP_STR
8606 BGP_STR
8607 "Display VPNv4 NLRI specific information\n"
8608 "Display information for a route distinguisher\n"
8609 "VPN Route Distinguisher\n"
8610 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8611 "JavaScript Object Notation\n")
8612 {
8613 int ret;
8614 struct prefix_rd prd;
8615
8616 ret = str2prefix_rd (argv[0], &prd);
8617 if (! ret)
8618 {
8619 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8620 return CMD_WARNING;
8621 }
8622 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv));
8623 }
8624
8625 DEFUN (show_ip_bgp_view,
8626 show_ip_bgp_instance_cmd,
8627 "show ip bgp " BGP_INSTANCE_CMD " {json}",
8628 SHOW_STR
8629 IP_STR
8630 BGP_STR
8631 BGP_INSTANCE_HELP_STR
8632 "JavaScript Object Notation\n")
8633 {
8634 struct bgp *bgp;
8635
8636 /* BGP structure lookup. */
8637 bgp = bgp_lookup_by_name (argv[1]);
8638 if (bgp == NULL)
8639 {
8640 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8641 return CMD_WARNING;
8642 }
8643
8644 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8645 }
8646
8647 DEFUN (show_ip_bgp_instance_all,
8648 show_ip_bgp_instance_all_cmd,
8649 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
8650 SHOW_STR
8651 IP_STR
8652 BGP_STR
8653 BGP_INSTANCE_ALL_HELP_STR
8654 "JavaScript Object Notation\n")
8655 {
8656 u_char uj = use_json(argc, argv);
8657
8658 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8659 return CMD_SUCCESS;
8660 }
8661
8662 DEFUN (show_ip_bgp_instance_route,
8663 show_ip_bgp_instance_route_cmd,
8664 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
8665 SHOW_STR
8666 IP_STR
8667 BGP_STR
8668 BGP_INSTANCE_HELP_STR
8669 "Network in the BGP routing table to display\n"
8670 "JavaScript Object Notation\n")
8671 {
8672 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8673 }
8674
8675 DEFUN (show_ip_bgp_instance_route_pathtype,
8676 show_ip_bgp_instance_route_pathtype_cmd,
8677 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
8678 SHOW_STR
8679 IP_STR
8680 BGP_STR
8681 BGP_INSTANCE_HELP_STR
8682 "Network in the BGP routing table to display\n"
8683 "Display only the bestpath\n"
8684 "Display only multipaths\n"
8685 "JavaScript Object Notation\n")
8686 {
8687 u_char uj = use_json(argc, argv);
8688
8689 if (strncmp (argv[3], "b", 1) == 0)
8690 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8691 else
8692 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8693 }
8694
8695 DEFUN (show_ip_bgp_instance_prefix,
8696 show_ip_bgp_instance_prefix_cmd,
8697 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
8698 SHOW_STR
8699 IP_STR
8700 BGP_STR
8701 BGP_INSTANCE_HELP_STR
8702 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8703 "JavaScript Object Notation\n")
8704 {
8705 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8706 }
8707
8708 DEFUN (show_ip_bgp_instance_prefix_pathtype,
8709 show_ip_bgp_instance_prefix_pathtype_cmd,
8710 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
8711 SHOW_STR
8712 IP_STR
8713 BGP_STR
8714 BGP_INSTANCE_HELP_STR
8715 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8716 "Display only the bestpath\n"
8717 "Display only multipaths\n"
8718 "JavaScript Object Notation\n")
8719 {
8720 u_char uj = use_json(argc, argv);
8721 if (strncmp (argv[3], "b", 1) == 0)
8722 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8723 else
8724 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8725 }
8726
8727 #ifdef HAVE_IPV6
8728 DEFUN (show_bgp,
8729 show_bgp_cmd,
8730 "show bgp {json}",
8731 SHOW_STR
8732 BGP_STR
8733 "JavaScript Object Notation\n")
8734 {
8735 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8736 NULL, use_json(argc, argv));
8737 }
8738
8739 ALIAS (show_bgp,
8740 show_bgp_ipv6_cmd,
8741 "show bgp ipv6 {json}",
8742 SHOW_STR
8743 BGP_STR
8744 "Address family\n"
8745 "JavaScript Object Notation\n")
8746
8747 DEFUN (show_bgp_ipv6_safi,
8748 show_bgp_ipv6_safi_cmd,
8749 "show bgp ipv6 (unicast|multicast) {json}",
8750 SHOW_STR
8751 BGP_STR
8752 "Address family\n"
8753 "Address Family modifier\n"
8754 "Address Family modifier\n"
8755 "JavaScript Object Notation\n")
8756 {
8757 u_char uj = use_json(argc, argv);
8758 if (strncmp (argv[0], "m", 1) == 0)
8759 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
8760 NULL, uj);
8761
8762 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj);
8763 }
8764
8765 static void
8766 bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8767 {
8768 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8769 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8770 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8771 }
8772
8773 /* old command */
8774 DEFUN (show_ipv6_bgp,
8775 show_ipv6_bgp_cmd,
8776 "show ipv6 bgp {json}",
8777 SHOW_STR
8778 IP_STR
8779 BGP_STR
8780 "JavaScript Object Notation\n")
8781 {
8782 bgp_show_ipv6_bgp_deprecate_warning(vty);
8783 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8784 NULL, use_json(argc, argv));
8785 }
8786
8787 DEFUN (show_bgp_route,
8788 show_bgp_route_cmd,
8789 "show bgp X:X::X:X {json}",
8790 SHOW_STR
8791 BGP_STR
8792 "Network in the BGP routing table to display\n"
8793 "JavaScript Object Notation\n")
8794 {
8795 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8796 }
8797
8798 DEFUN (show_bgp_ipv6_safi_route,
8799 show_bgp_ipv6_safi_route_cmd,
8800 "show bgp ipv6 (unicast|multicast) X:X::X:X {json}",
8801 SHOW_STR
8802 BGP_STR
8803 "Address family\n"
8804 "Address Family modifier\n"
8805 "Address Family modifier\n"
8806 "Network in the BGP routing table to display\n"
8807 "JavaScript Object Notation\n")
8808 {
8809 u_char uj = use_json(argc, argv);
8810 if (strncmp (argv[0], "m", 1) == 0)
8811 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj);
8812
8813 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj);
8814 }
8815
8816 DEFUN (show_bgp_route_pathtype,
8817 show_bgp_route_pathtype_cmd,
8818 "show bgp X:X::X:X (bestpath|multipath) {json}",
8819 SHOW_STR
8820 BGP_STR
8821 "Network in the BGP routing table to display\n"
8822 "Display only the bestpath\n"
8823 "Display only multipaths\n"
8824 "JavaScript Object Notation\n")
8825 {
8826 u_char uj = use_json(argc, argv);
8827 if (strncmp (argv[1], "b", 1) == 0)
8828 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8829 else
8830 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8831 }
8832
8833 ALIAS (show_bgp_route_pathtype,
8834 show_bgp_ipv6_route_pathtype_cmd,
8835 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
8836 SHOW_STR
8837 BGP_STR
8838 "Address family\n"
8839 "Network in the BGP routing table to display\n"
8840 "Display only the bestpath\n"
8841 "Display only multipaths\n"
8842 "JavaScript Object Notation\n")
8843
8844 DEFUN (show_bgp_ipv6_safi_route_pathtype,
8845 show_bgp_ipv6_safi_route_pathtype_cmd,
8846 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}",
8847 SHOW_STR
8848 BGP_STR
8849 "Address family\n"
8850 "Address Family modifier\n"
8851 "Address Family modifier\n"
8852 "Network in the BGP routing table to display\n"
8853 "Display only the bestpath\n"
8854 "Display only multipaths\n"
8855 "JavaScript Object Notation\n")
8856 {
8857 u_char uj = use_json(argc, argv);
8858 if (strncmp (argv[0], "m", 1) == 0)
8859 if (strncmp (argv[2], "b", 1) == 0)
8860 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8861 else
8862 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8863 else
8864 if (strncmp (argv[2], "b", 1) == 0)
8865 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8866 else
8867 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8868 }
8869
8870 /* old command */
8871 DEFUN (show_ipv6_bgp_route,
8872 show_ipv6_bgp_route_cmd,
8873 "show ipv6 bgp X:X::X:X {json}",
8874 SHOW_STR
8875 IP_STR
8876 BGP_STR
8877 "Network in the BGP routing table to display\n"
8878 "JavaScript Object Notation\n")
8879 {
8880 bgp_show_ipv6_bgp_deprecate_warning(vty);
8881 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8882 }
8883
8884 DEFUN (show_bgp_prefix,
8885 show_bgp_prefix_cmd,
8886 "show bgp X:X::X:X/M {json}",
8887 SHOW_STR
8888 BGP_STR
8889 "IPv6 prefix <network>/<length>\n"
8890 "JavaScript Object Notation\n")
8891 {
8892 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8893 }
8894
8895 DEFUN (show_bgp_ipv6_safi_prefix,
8896 show_bgp_ipv6_safi_prefix_cmd,
8897 "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}",
8898 SHOW_STR
8899 BGP_STR
8900 "Address family\n"
8901 "Address Family modifier\n"
8902 "Address Family modifier\n"
8903 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8904 "JavaScript Object Notation\n")
8905 {
8906 u_char uj = use_json(argc, argv);
8907 if (strncmp (argv[0], "m", 1) == 0)
8908 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj);
8909
8910 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj);
8911 }
8912
8913 DEFUN (show_bgp_prefix_pathtype,
8914 show_bgp_prefix_pathtype_cmd,
8915 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
8916 SHOW_STR
8917 BGP_STR
8918 "IPv6 prefix <network>/<length>\n"
8919 "Display only the bestpath\n"
8920 "Display only multipaths\n"
8921 "JavaScript Object Notation\n")
8922 {
8923 u_char uj = use_json(argc, argv);
8924 if (strncmp (argv[1], "b", 1) == 0)
8925 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8926 else
8927 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8928 }
8929
8930 ALIAS (show_bgp_prefix_pathtype,
8931 show_bgp_ipv6_prefix_pathtype_cmd,
8932 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8933 SHOW_STR
8934 BGP_STR
8935 "Address family\n"
8936 "IPv6 prefix <network>/<length>\n"
8937 "Display only the bestpath\n"
8938 "Display only multipaths\n"
8939 "JavaScript Object Notation\n")
8940
8941 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8942 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8943 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}",
8944 SHOW_STR
8945 BGP_STR
8946 "Address family\n"
8947 "Address Family modifier\n"
8948 "Address Family modifier\n"
8949 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8950 "Display only the bestpath\n"
8951 "Display only multipaths\n"
8952 "JavaScript Object Notation\n")
8953 {
8954 u_char uj = use_json(argc, argv);
8955 if (strncmp (argv[0], "m", 1) == 0)
8956 if (strncmp (argv[2], "b", 1) == 0)
8957 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8958 else
8959 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8960 else
8961 if (strncmp (argv[2], "b", 1) == 0)
8962 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8963 else
8964 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8965 }
8966
8967 /* old command */
8968 DEFUN (show_ipv6_bgp_prefix,
8969 show_ipv6_bgp_prefix_cmd,
8970 "show ipv6 bgp X:X::X:X/M {json}",
8971 SHOW_STR
8972 IP_STR
8973 BGP_STR
8974 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8975 "JavaScript Object Notation\n")
8976 {
8977 bgp_show_ipv6_bgp_deprecate_warning(vty);
8978 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8979 }
8980
8981 DEFUN (show_bgp_view,
8982 show_bgp_instance_cmd,
8983 "show bgp " BGP_INSTANCE_CMD " {json}",
8984 SHOW_STR
8985 BGP_STR
8986 BGP_INSTANCE_HELP_STR
8987 "JavaScript Object Notation\n")
8988 {
8989 struct bgp *bgp;
8990
8991 /* BGP structure lookup. */
8992 bgp = bgp_lookup_by_name (argv[1]);
8993 if (bgp == NULL)
8994 {
8995 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8996 return CMD_WARNING;
8997 }
8998
8999 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
9000 }
9001
9002 DEFUN (show_bgp_instance_all,
9003 show_bgp_instance_all_cmd,
9004 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
9005 SHOW_STR
9006 BGP_STR
9007 BGP_INSTANCE_ALL_HELP_STR
9008 "JavaScript Object Notation\n")
9009 {
9010 u_char uj = use_json(argc, argv);
9011
9012 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
9013 return CMD_SUCCESS;
9014 }
9015
9016 ALIAS (show_bgp_view,
9017 show_bgp_instance_ipv6_cmd,
9018 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
9019 SHOW_STR
9020 BGP_STR
9021 BGP_INSTANCE_HELP_STR
9022 "Address family\n"
9023 "JavaScript Object Notation\n")
9024
9025 DEFUN (show_bgp_instance_route,
9026 show_bgp_instance_route_cmd,
9027 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
9028 SHOW_STR
9029 BGP_STR
9030 BGP_INSTANCE_HELP_STR
9031 "Network in the BGP routing table to display\n"
9032 "JavaScript Object Notation\n")
9033 {
9034 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
9035 }
9036
9037 ALIAS (show_bgp_instance_route,
9038 show_bgp_instance_ipv6_route_cmd,
9039 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
9040 SHOW_STR
9041 BGP_STR
9042 BGP_INSTANCE_HELP_STR
9043 "Address family\n"
9044 "Network in the BGP routing table to display\n"
9045 "JavaScript Object Notation\n")
9046
9047 DEFUN (show_bgp_instance_route_pathtype,
9048 show_bgp_instance_route_pathtype_cmd,
9049 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
9050 SHOW_STR
9051 BGP_STR
9052 BGP_INSTANCE_HELP_STR
9053 "Network in the BGP routing table to display\n"
9054 "Display only the bestpath\n"
9055 "Display only multipaths\n"
9056 "JavaScript Object Notation\n")
9057 {
9058 u_char uj = use_json(argc, argv);
9059 if (strncmp (argv[3], "b", 1) == 0)
9060 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
9061 else
9062 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
9063 }
9064
9065 ALIAS (show_bgp_instance_route_pathtype,
9066 show_bgp_instance_ipv6_route_pathtype_cmd,
9067 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
9068 SHOW_STR
9069 BGP_STR
9070 BGP_INSTANCE_HELP_STR
9071 "Address family\n"
9072 "Network in the BGP routing table to display\n"
9073 "Display only the bestpath\n"
9074 "Display only multipaths\n"
9075 "JavaScript Object Notation\n")
9076
9077 DEFUN (show_bgp_instance_prefix,
9078 show_bgp_instance_prefix_cmd,
9079 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
9080 SHOW_STR
9081 BGP_STR
9082 BGP_INSTANCE_HELP_STR
9083 "IPv6 prefix <network>/<length>\n"
9084 "JavaScript Object Notation\n")
9085 {
9086 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
9087 }
9088
9089 ALIAS (show_bgp_instance_prefix,
9090 show_bgp_instance_ipv6_prefix_cmd,
9091 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
9092 SHOW_STR
9093 BGP_STR
9094 BGP_INSTANCE_HELP_STR
9095 "Address family\n"
9096 "IPv6 prefix <network>/<length>\n"
9097 "JavaScript Object Notation\n")
9098
9099 DEFUN (show_bgp_instance_prefix_pathtype,
9100 show_bgp_instance_prefix_pathtype_cmd,
9101 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
9102 SHOW_STR
9103 BGP_STR
9104 BGP_INSTANCE_HELP_STR
9105 "IPv6 prefix <network>/<length>\n"
9106 "Display only the bestpath\n"
9107 "Display only multipaths\n"
9108 "JavaScript Object Notation\n")
9109 {
9110 u_char uj = use_json(argc, argv);
9111 if (strncmp (argv[3], "b", 1) == 0)
9112 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
9113 else
9114 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
9115 }
9116
9117 ALIAS (show_bgp_instance_prefix_pathtype,
9118 show_bgp_instance_ipv6_prefix_pathtype_cmd,
9119 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
9120 SHOW_STR
9121 BGP_STR
9122 BGP_INSTANCE_HELP_STR
9123 "Address family\n"
9124 "IPv6 prefix <network>/<length>\n"
9125 "Display only the bestpath\n"
9126 "Display only multipaths\n"
9127 "JavaScript Object Notation\n")
9128
9129 DEFUN (show_bgp_instance_prefix_list,
9130 show_bgp_instance_prefix_list_cmd,
9131 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9132 SHOW_STR
9133 BGP_STR
9134 BGP_INSTANCE_HELP_STR
9135 "Display routes conforming to the prefix-list\n"
9136 "IPv6 prefix-list name\n")
9137 {
9138 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9139 bgp_show_type_prefix_list);
9140 }
9141
9142 ALIAS (show_bgp_instance_prefix_list,
9143 show_bgp_instance_ipv6_prefix_list_cmd,
9144 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
9145 SHOW_STR
9146 BGP_STR
9147 BGP_INSTANCE_HELP_STR
9148 "Address family\n"
9149 "Display routes conforming to the prefix-list\n"
9150 "IPv6 prefix-list name\n")
9151
9152 DEFUN (show_bgp_instance_filter_list,
9153 show_bgp_instance_filter_list_cmd,
9154 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
9155 SHOW_STR
9156 BGP_STR
9157 BGP_INSTANCE_HELP_STR
9158 "Display routes conforming to the filter-list\n"
9159 "Regular expression access list name\n")
9160 {
9161 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9162 bgp_show_type_filter_list);
9163 }
9164
9165 ALIAS (show_bgp_instance_filter_list,
9166 show_bgp_instance_ipv6_filter_list_cmd,
9167 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
9168 SHOW_STR
9169 BGP_STR
9170 BGP_INSTANCE_HELP_STR
9171 "Address family\n"
9172 "Display routes conforming to the filter-list\n"
9173 "Regular expression access list name\n")
9174
9175 DEFUN (show_bgp_instance_route_map,
9176 show_bgp_instance_route_map_cmd,
9177 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
9178 SHOW_STR
9179 BGP_STR
9180 BGP_INSTANCE_HELP_STR
9181 "Display routes matching the route-map\n"
9182 "A route-map to match on\n")
9183 {
9184 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9185 bgp_show_type_route_map);
9186 }
9187
9188 ALIAS (show_bgp_instance_route_map,
9189 show_bgp_instance_ipv6_route_map_cmd,
9190 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
9191 SHOW_STR
9192 BGP_STR
9193 BGP_INSTANCE_HELP_STR
9194 "Address family\n"
9195 "Display routes matching the route-map\n"
9196 "A route-map to match on\n")
9197
9198 DEFUN (show_bgp_instance_community_list,
9199 show_bgp_instance_community_list_cmd,
9200 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
9201 SHOW_STR
9202 BGP_STR
9203 BGP_INSTANCE_HELP_STR
9204 "Display routes matching the community-list\n"
9205 "community-list number\n"
9206 "community-list name\n")
9207 {
9208 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
9209 }
9210
9211 ALIAS (show_bgp_instance_community_list,
9212 show_bgp_instance_ipv6_community_list_cmd,
9213 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
9214 SHOW_STR
9215 BGP_STR
9216 BGP_INSTANCE_HELP_STR
9217 "Address family\n"
9218 "Display routes matching the community-list\n"
9219 "community-list number\n"
9220 "community-list name\n")
9221
9222 DEFUN (show_bgp_instance_prefix_longer,
9223 show_bgp_instance_prefix_longer_cmd,
9224 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
9225 SHOW_STR
9226 BGP_STR
9227 BGP_INSTANCE_HELP_STR
9228 "IPv6 prefix <network>/<length>\n"
9229 "Display route and more specific routes\n")
9230 {
9231 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9232 bgp_show_type_prefix_longer);
9233 }
9234
9235 ALIAS (show_bgp_instance_prefix_longer,
9236 show_bgp_instance_ipv6_prefix_longer_cmd,
9237 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
9238 SHOW_STR
9239 BGP_STR
9240 BGP_INSTANCE_HELP_STR
9241 "Address family\n"
9242 "IPv6 prefix <network>/<length>\n"
9243 "Display route and more specific routes\n")
9244
9245 /* old command */
9246 DEFUN (show_ipv6_mbgp,
9247 show_ipv6_mbgp_cmd,
9248 "show ipv6 mbgp {json}",
9249 SHOW_STR
9250 IP_STR
9251 MBGP_STR
9252 "JavaScript Object Notation\n")
9253 {
9254 bgp_show_ipv6_bgp_deprecate_warning(vty);
9255 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
9256 NULL, use_json(argc, argv));
9257 }
9258
9259 /* old command */
9260 DEFUN (show_ipv6_mbgp_route,
9261 show_ipv6_mbgp_route_cmd,
9262 "show ipv6 mbgp X:X::X:X {json}",
9263 SHOW_STR
9264 IP_STR
9265 MBGP_STR
9266 "Network in the MBGP routing table to display\n"
9267 "JavaScript Object Notation\n")
9268 {
9269 bgp_show_ipv6_bgp_deprecate_warning(vty);
9270 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
9271 }
9272
9273 /* old command */
9274 DEFUN (show_ipv6_mbgp_prefix,
9275 show_ipv6_mbgp_prefix_cmd,
9276 "show ipv6 mbgp X:X::X:X/M {json}",
9277 SHOW_STR
9278 IP_STR
9279 MBGP_STR
9280 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9281 "JavaScript Object Notation\n")
9282 {
9283 bgp_show_ipv6_bgp_deprecate_warning(vty);
9284 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
9285 }
9286 #endif
9287
9288
9289 static int
9290 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
9291 safi_t safi, enum bgp_show_type type)
9292 {
9293 int i;
9294 struct buffer *b;
9295 char *regstr;
9296 int first;
9297 regex_t *regex;
9298 int rc;
9299
9300 first = 0;
9301 b = buffer_new (1024);
9302 for (i = 0; i < argc; i++)
9303 {
9304 if (first)
9305 buffer_putc (b, ' ');
9306 else
9307 {
9308 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9309 continue;
9310 first = 1;
9311 }
9312
9313 buffer_putstr (b, argv[i]);
9314 }
9315 buffer_putc (b, '\0');
9316
9317 regstr = buffer_getstr (b);
9318 buffer_free (b);
9319
9320 regex = bgp_regcomp (regstr);
9321 XFREE(MTYPE_TMP, regstr);
9322 if (! regex)
9323 {
9324 vty_out (vty, "Can't compile regexp %s%s", argv[0],
9325 VTY_NEWLINE);
9326 return CMD_WARNING;
9327 }
9328
9329 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
9330 bgp_regex_free (regex);
9331 return rc;
9332 }
9333
9334 DEFUN (show_ip_bgp_regexp,
9335 show_ip_bgp_regexp_cmd,
9336 "show ip bgp regexp .LINE",
9337 SHOW_STR
9338 IP_STR
9339 BGP_STR
9340 "Display routes matching the AS path regular expression\n"
9341 "A regular-expression to match the BGP AS paths\n")
9342 {
9343 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9344 bgp_show_type_regexp);
9345 }
9346
9347 DEFUN (show_ip_bgp_flap_regexp,
9348 show_ip_bgp_flap_regexp_cmd,
9349 "show ip bgp flap-statistics regexp .LINE",
9350 SHOW_STR
9351 IP_STR
9352 BGP_STR
9353 "Display flap statistics of routes\n"
9354 "Display routes matching the AS path regular expression\n"
9355 "A regular-expression to match the BGP AS paths\n")
9356 {
9357 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9358 bgp_show_type_flap_regexp);
9359 }
9360
9361 ALIAS (show_ip_bgp_flap_regexp,
9362 show_ip_bgp_damp_flap_regexp_cmd,
9363 "show ip bgp dampening flap-statistics regexp .LINE",
9364 SHOW_STR
9365 IP_STR
9366 BGP_STR
9367 "Display detailed information about dampening\n"
9368 "Display flap statistics of routes\n"
9369 "Display routes matching the AS path regular expression\n"
9370 "A regular-expression to match the BGP AS paths\n")
9371
9372 DEFUN (show_ip_bgp_ipv4_regexp,
9373 show_ip_bgp_ipv4_regexp_cmd,
9374 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
9375 SHOW_STR
9376 IP_STR
9377 BGP_STR
9378 "Address family\n"
9379 "Address Family modifier\n"
9380 "Address Family modifier\n"
9381 "Display routes matching the AS path regular expression\n"
9382 "A regular-expression to match the BGP AS paths\n")
9383 {
9384 if (strncmp (argv[0], "m", 1) == 0)
9385 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
9386 bgp_show_type_regexp);
9387
9388 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9389 bgp_show_type_regexp);
9390 }
9391
9392 #ifdef HAVE_IPV6
9393 DEFUN (show_bgp_regexp,
9394 show_bgp_regexp_cmd,
9395 "show bgp regexp .LINE",
9396 SHOW_STR
9397 BGP_STR
9398 "Display routes matching the AS path regular expression\n"
9399 "A regular-expression to match the BGP AS paths\n")
9400 {
9401 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9402 bgp_show_type_regexp);
9403 }
9404
9405 ALIAS (show_bgp_regexp,
9406 show_bgp_ipv6_regexp_cmd,
9407 "show bgp ipv6 regexp .LINE",
9408 SHOW_STR
9409 BGP_STR
9410 "Address family\n"
9411 "Display routes matching the AS path regular expression\n"
9412 "A regular-expression to match the BGP AS paths\n")
9413
9414 /* old command */
9415 DEFUN (show_ipv6_bgp_regexp,
9416 show_ipv6_bgp_regexp_cmd,
9417 "show ipv6 bgp regexp .LINE",
9418 SHOW_STR
9419 IP_STR
9420 BGP_STR
9421 "Display routes matching the AS path regular expression\n"
9422 "A regular-expression to match the BGP AS paths\n")
9423 {
9424 bgp_show_ipv6_bgp_deprecate_warning(vty);
9425 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9426 bgp_show_type_regexp);
9427 }
9428
9429 /* old command */
9430 DEFUN (show_ipv6_mbgp_regexp,
9431 show_ipv6_mbgp_regexp_cmd,
9432 "show ipv6 mbgp regexp .LINE",
9433 SHOW_STR
9434 IP_STR
9435 BGP_STR
9436 "Display routes matching the AS path regular expression\n"
9437 "A regular-expression to match the MBGP AS paths\n")
9438 {
9439 bgp_show_ipv6_bgp_deprecate_warning(vty);
9440 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9441 bgp_show_type_regexp);
9442 }
9443 #endif /* HAVE_IPV6 */
9444
9445 static int
9446 bgp_show_prefix_list (struct vty *vty, const char *name,
9447 const char *prefix_list_str, afi_t afi,
9448 safi_t safi, enum bgp_show_type type)
9449 {
9450 struct prefix_list *plist;
9451 struct bgp *bgp = NULL;
9452
9453 if (name && !(bgp = bgp_lookup_by_name(name)))
9454 {
9455 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9456 return CMD_WARNING;
9457 }
9458
9459 plist = prefix_list_lookup (afi, prefix_list_str);
9460 if (plist == NULL)
9461 {
9462 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9463 prefix_list_str, VTY_NEWLINE);
9464 return CMD_WARNING;
9465 }
9466
9467 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
9468 }
9469
9470 DEFUN (show_ip_bgp_prefix_list,
9471 show_ip_bgp_prefix_list_cmd,
9472 "show ip bgp prefix-list WORD",
9473 SHOW_STR
9474 IP_STR
9475 BGP_STR
9476 "Display routes conforming to the prefix-list\n"
9477 "IP prefix-list name\n")
9478 {
9479 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9480 bgp_show_type_prefix_list);
9481 }
9482
9483 DEFUN (show_ip_bgp_instance_prefix_list,
9484 show_ip_bgp_instance_prefix_list_cmd,
9485 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9486 SHOW_STR
9487 IP_STR
9488 BGP_STR
9489 BGP_INSTANCE_HELP_STR
9490 "Display routes conforming to the prefix-list\n"
9491 "IP prefix-list name\n")
9492 {
9493 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9494 bgp_show_type_prefix_list);
9495 }
9496
9497 DEFUN (show_ip_bgp_flap_prefix_list,
9498 show_ip_bgp_flap_prefix_list_cmd,
9499 "show ip bgp flap-statistics prefix-list WORD",
9500 SHOW_STR
9501 IP_STR
9502 BGP_STR
9503 "Display flap statistics of routes\n"
9504 "Display routes conforming to the prefix-list\n"
9505 "IP prefix-list name\n")
9506 {
9507 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9508 bgp_show_type_flap_prefix_list);
9509 }
9510
9511 ALIAS (show_ip_bgp_flap_prefix_list,
9512 show_ip_bgp_damp_flap_prefix_list_cmd,
9513 "show ip bgp dampening flap-statistics prefix-list WORD",
9514 SHOW_STR
9515 IP_STR
9516 BGP_STR
9517 "Display detailed information about dampening\n"
9518 "Display flap statistics of routes\n"
9519 "Display routes conforming to the prefix-list\n"
9520 "IP prefix-list name\n")
9521
9522 DEFUN (show_ip_bgp_ipv4_prefix_list,
9523 show_ip_bgp_ipv4_prefix_list_cmd,
9524 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9525 SHOW_STR
9526 IP_STR
9527 BGP_STR
9528 "Address family\n"
9529 "Address Family modifier\n"
9530 "Address Family modifier\n"
9531 "Display routes conforming to the prefix-list\n"
9532 "IP prefix-list name\n")
9533 {
9534 if (strncmp (argv[0], "m", 1) == 0)
9535 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9536 bgp_show_type_prefix_list);
9537
9538 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9539 bgp_show_type_prefix_list);
9540 }
9541
9542 #ifdef HAVE_IPV6
9543 DEFUN (show_bgp_prefix_list,
9544 show_bgp_prefix_list_cmd,
9545 "show bgp prefix-list WORD",
9546 SHOW_STR
9547 BGP_STR
9548 "Display routes conforming to the prefix-list\n"
9549 "IPv6 prefix-list name\n")
9550 {
9551 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9552 bgp_show_type_prefix_list);
9553 }
9554
9555 ALIAS (show_bgp_prefix_list,
9556 show_bgp_ipv6_prefix_list_cmd,
9557 "show bgp ipv6 prefix-list WORD",
9558 SHOW_STR
9559 BGP_STR
9560 "Address family\n"
9561 "Display routes conforming to the prefix-list\n"
9562 "IPv6 prefix-list name\n")
9563
9564 /* old command */
9565 DEFUN (show_ipv6_bgp_prefix_list,
9566 show_ipv6_bgp_prefix_list_cmd,
9567 "show ipv6 bgp prefix-list WORD",
9568 SHOW_STR
9569 IPV6_STR
9570 BGP_STR
9571 "Display routes matching the prefix-list\n"
9572 "IPv6 prefix-list name\n")
9573 {
9574 bgp_show_ipv6_bgp_deprecate_warning(vty);
9575 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9576 bgp_show_type_prefix_list);
9577 }
9578
9579 /* old command */
9580 DEFUN (show_ipv6_mbgp_prefix_list,
9581 show_ipv6_mbgp_prefix_list_cmd,
9582 "show ipv6 mbgp prefix-list WORD",
9583 SHOW_STR
9584 IPV6_STR
9585 MBGP_STR
9586 "Display routes matching the prefix-list\n"
9587 "IPv6 prefix-list name\n")
9588 {
9589 bgp_show_ipv6_bgp_deprecate_warning(vty);
9590 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9591 bgp_show_type_prefix_list);
9592 }
9593 #endif /* HAVE_IPV6 */
9594
9595 static int
9596 bgp_show_filter_list (struct vty *vty, const char *name,
9597 const char *filter, afi_t afi,
9598 safi_t safi, enum bgp_show_type type)
9599 {
9600 struct as_list *as_list;
9601 struct bgp *bgp = NULL;
9602
9603 if (name && !(bgp = bgp_lookup_by_name(name)))
9604 {
9605 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9606 return CMD_WARNING;
9607 }
9608
9609 as_list = as_list_lookup (filter);
9610 if (as_list == NULL)
9611 {
9612 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9613 return CMD_WARNING;
9614 }
9615
9616 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
9617 }
9618
9619 DEFUN (show_ip_bgp_filter_list,
9620 show_ip_bgp_filter_list_cmd,
9621 "show ip bgp filter-list WORD",
9622 SHOW_STR
9623 IP_STR
9624 BGP_STR
9625 "Display routes conforming to the filter-list\n"
9626 "Regular expression access list name\n")
9627 {
9628 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9629 bgp_show_type_filter_list);
9630 }
9631
9632 DEFUN (show_ip_bgp_instance_filter_list,
9633 show_ip_bgp_instance_filter_list_cmd,
9634 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
9635 SHOW_STR
9636 IP_STR
9637 BGP_STR
9638 BGP_INSTANCE_HELP_STR
9639 "Display routes conforming to the filter-list\n"
9640 "Regular expression access list name\n")
9641 {
9642 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9643 bgp_show_type_filter_list);
9644 }
9645
9646 DEFUN (show_ip_bgp_flap_filter_list,
9647 show_ip_bgp_flap_filter_list_cmd,
9648 "show ip bgp flap-statistics filter-list WORD",
9649 SHOW_STR
9650 IP_STR
9651 BGP_STR
9652 "Display flap statistics of routes\n"
9653 "Display routes conforming to the filter-list\n"
9654 "Regular expression access list name\n")
9655 {
9656 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9657 bgp_show_type_flap_filter_list);
9658 }
9659
9660 ALIAS (show_ip_bgp_flap_filter_list,
9661 show_ip_bgp_damp_flap_filter_list_cmd,
9662 "show ip bgp dampening flap-statistics filter-list WORD",
9663 SHOW_STR
9664 IP_STR
9665 BGP_STR
9666 "Display detailed information about dampening\n"
9667 "Display flap statistics of routes\n"
9668 "Display routes conforming to the filter-list\n"
9669 "Regular expression access list name\n")
9670
9671 DEFUN (show_ip_bgp_ipv4_filter_list,
9672 show_ip_bgp_ipv4_filter_list_cmd,
9673 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9674 SHOW_STR
9675 IP_STR
9676 BGP_STR
9677 "Address family\n"
9678 "Address Family modifier\n"
9679 "Address Family modifier\n"
9680 "Display routes conforming to the filter-list\n"
9681 "Regular expression access list name\n")
9682 {
9683 if (strncmp (argv[0], "m", 1) == 0)
9684 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9685 bgp_show_type_filter_list);
9686
9687 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9688 bgp_show_type_filter_list);
9689 }
9690
9691 #ifdef HAVE_IPV6
9692 DEFUN (show_bgp_filter_list,
9693 show_bgp_filter_list_cmd,
9694 "show bgp filter-list WORD",
9695 SHOW_STR
9696 BGP_STR
9697 "Display routes conforming to the filter-list\n"
9698 "Regular expression access list name\n")
9699 {
9700 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9701 bgp_show_type_filter_list);
9702 }
9703
9704 ALIAS (show_bgp_filter_list,
9705 show_bgp_ipv6_filter_list_cmd,
9706 "show bgp ipv6 filter-list WORD",
9707 SHOW_STR
9708 BGP_STR
9709 "Address family\n"
9710 "Display routes conforming to the filter-list\n"
9711 "Regular expression access list name\n")
9712
9713 /* old command */
9714 DEFUN (show_ipv6_bgp_filter_list,
9715 show_ipv6_bgp_filter_list_cmd,
9716 "show ipv6 bgp filter-list WORD",
9717 SHOW_STR
9718 IPV6_STR
9719 BGP_STR
9720 "Display routes conforming to the filter-list\n"
9721 "Regular expression access list name\n")
9722 {
9723 bgp_show_ipv6_bgp_deprecate_warning(vty);
9724 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9725 bgp_show_type_filter_list);
9726 }
9727
9728 /* old command */
9729 DEFUN (show_ipv6_mbgp_filter_list,
9730 show_ipv6_mbgp_filter_list_cmd,
9731 "show ipv6 mbgp filter-list WORD",
9732 SHOW_STR
9733 IPV6_STR
9734 MBGP_STR
9735 "Display routes conforming to the filter-list\n"
9736 "Regular expression access list name\n")
9737 {
9738 bgp_show_ipv6_bgp_deprecate_warning(vty);
9739 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9740 bgp_show_type_filter_list);
9741 }
9742 #endif /* HAVE_IPV6 */
9743
9744 DEFUN (show_ip_bgp_dampening_info,
9745 show_ip_bgp_dampening_params_cmd,
9746 "show ip bgp dampening parameters",
9747 SHOW_STR
9748 IP_STR
9749 BGP_STR
9750 "Display detailed information about dampening\n"
9751 "Display detail of configured dampening parameters\n")
9752 {
9753 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9754 }
9755
9756
9757 DEFUN (show_ip_bgp_ipv4_dampening_parameters,
9758 show_ip_bgp_ipv4_dampening_parameters_cmd,
9759 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
9760 SHOW_STR
9761 IP_STR
9762 BGP_STR
9763 "Address family\n"
9764 "Address Family modifier\n"
9765 "Address Family modifier\n"
9766 "Display detailed information about dampening\n"
9767 "Display detail of configured dampening parameters\n")
9768 {
9769 if (strncmp(argv[0], "m", 1) == 0)
9770 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
9771
9772 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9773 }
9774
9775
9776 DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
9777 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
9778 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
9779 SHOW_STR
9780 IP_STR
9781 BGP_STR
9782 "Address family\n"
9783 "Address Family modifier\n"
9784 "Address Family modifier\n"
9785 "Display detailed information about dampening\n"
9786 "Display flap statistics of routes\n")
9787 {
9788 if (strncmp(argv[0], "m", 1) == 0)
9789 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9790 bgp_show_type_flap_statistics, NULL, 0);
9791
9792 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9793 bgp_show_type_flap_statistics, NULL, 0);
9794 }
9795
9796 DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
9797 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
9798 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
9799 SHOW_STR
9800 IP_STR
9801 BGP_STR
9802 "Address family\n"
9803 "Address Family modifier\n"
9804 "Address Family modifier\n"
9805 "Display detailed information about dampening\n"
9806 "Display paths suppressed due to dampening\n")
9807 {
9808 if (strncmp(argv[0], "m", 1) == 0)
9809 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9810 bgp_show_type_dampend_paths, NULL, 0);
9811
9812 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9813 bgp_show_type_dampend_paths, NULL, 0);
9814 }
9815
9816 static int
9817 bgp_show_route_map (struct vty *vty, const char *name,
9818 const char *rmap_str, afi_t afi,
9819 safi_t safi, enum bgp_show_type type)
9820 {
9821 struct route_map *rmap;
9822 struct bgp *bgp = NULL;
9823
9824 if (name && !(bgp = bgp_lookup_by_name(name)))
9825 {
9826 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9827 return CMD_WARNING;
9828 }
9829
9830 rmap = route_map_lookup_by_name (rmap_str);
9831 if (! rmap)
9832 {
9833 vty_out (vty, "%% %s is not a valid route-map name%s",
9834 rmap_str, VTY_NEWLINE);
9835 return CMD_WARNING;
9836 }
9837
9838 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
9839 }
9840
9841 DEFUN (show_ip_bgp_route_map,
9842 show_ip_bgp_route_map_cmd,
9843 "show ip bgp route-map WORD",
9844 SHOW_STR
9845 IP_STR
9846 BGP_STR
9847 "Display routes matching the route-map\n"
9848 "A route-map to match on\n")
9849 {
9850 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9851 bgp_show_type_route_map);
9852 }
9853
9854 DEFUN (show_ip_bgp_instance_route_map,
9855 show_ip_bgp_instance_route_map_cmd,
9856 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
9857 SHOW_STR
9858 IP_STR
9859 BGP_STR
9860 BGP_INSTANCE_HELP_STR
9861 "Display routes matching the route-map\n"
9862 "A route-map to match on\n")
9863 {
9864 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9865 bgp_show_type_route_map);
9866 }
9867
9868 DEFUN (show_ip_bgp_flap_route_map,
9869 show_ip_bgp_flap_route_map_cmd,
9870 "show ip bgp flap-statistics route-map WORD",
9871 SHOW_STR
9872 IP_STR
9873 BGP_STR
9874 "Display flap statistics of routes\n"
9875 "Display routes matching the route-map\n"
9876 "A route-map to match on\n")
9877 {
9878 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9879 bgp_show_type_flap_route_map);
9880 }
9881
9882 ALIAS (show_ip_bgp_flap_route_map,
9883 show_ip_bgp_damp_flap_route_map_cmd,
9884 "show ip bgp dampening flap-statistics route-map WORD",
9885 SHOW_STR
9886 IP_STR
9887 BGP_STR
9888 "Display detailed information about dampening\n"
9889 "Display flap statistics of routes\n"
9890 "Display routes matching the route-map\n"
9891 "A route-map to match on\n")
9892
9893 DEFUN (show_ip_bgp_ipv4_route_map,
9894 show_ip_bgp_ipv4_route_map_cmd,
9895 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9896 SHOW_STR
9897 IP_STR
9898 BGP_STR
9899 "Address family\n"
9900 "Address Family modifier\n"
9901 "Address Family modifier\n"
9902 "Display routes matching the route-map\n"
9903 "A route-map to match on\n")
9904 {
9905 if (strncmp (argv[0], "m", 1) == 0)
9906 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
9907 bgp_show_type_route_map);
9908
9909 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
9910 bgp_show_type_route_map);
9911 }
9912
9913 DEFUN (show_bgp_route_map,
9914 show_bgp_route_map_cmd,
9915 "show bgp route-map WORD",
9916 SHOW_STR
9917 BGP_STR
9918 "Display routes matching the route-map\n"
9919 "A route-map to match on\n")
9920 {
9921 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9922 bgp_show_type_route_map);
9923 }
9924
9925 ALIAS (show_bgp_route_map,
9926 show_bgp_ipv6_route_map_cmd,
9927 "show bgp ipv6 route-map WORD",
9928 SHOW_STR
9929 BGP_STR
9930 "Address family\n"
9931 "Display routes matching the route-map\n"
9932 "A route-map to match on\n")
9933
9934 DEFUN (show_ip_bgp_cidr_only,
9935 show_ip_bgp_cidr_only_cmd,
9936 "show ip bgp cidr-only",
9937 SHOW_STR
9938 IP_STR
9939 BGP_STR
9940 "Display only routes with non-natural netmasks\n")
9941 {
9942 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9943 bgp_show_type_cidr_only, NULL, 0);
9944 }
9945
9946 DEFUN (show_ip_bgp_flap_cidr_only,
9947 show_ip_bgp_flap_cidr_only_cmd,
9948 "show ip bgp flap-statistics cidr-only",
9949 SHOW_STR
9950 IP_STR
9951 BGP_STR
9952 "Display flap statistics of routes\n"
9953 "Display only routes with non-natural netmasks\n")
9954 {
9955 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9956 bgp_show_type_flap_cidr_only, NULL, 0);
9957 }
9958
9959 ALIAS (show_ip_bgp_flap_cidr_only,
9960 show_ip_bgp_damp_flap_cidr_only_cmd,
9961 "show ip bgp dampening flap-statistics cidr-only",
9962 SHOW_STR
9963 IP_STR
9964 BGP_STR
9965 "Display detailed information about dampening\n"
9966 "Display flap statistics of routes\n"
9967 "Display only routes with non-natural netmasks\n")
9968
9969 DEFUN (show_ip_bgp_ipv4_cidr_only,
9970 show_ip_bgp_ipv4_cidr_only_cmd,
9971 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9972 SHOW_STR
9973 IP_STR
9974 BGP_STR
9975 "Address family\n"
9976 "Address Family modifier\n"
9977 "Address Family modifier\n"
9978 "Display only routes with non-natural netmasks\n")
9979 {
9980 if (strncmp (argv[0], "m", 1) == 0)
9981 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9982 bgp_show_type_cidr_only, NULL, 0);
9983
9984 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9985 bgp_show_type_cidr_only, NULL, 0);
9986 }
9987
9988 DEFUN (show_ip_bgp_community_all,
9989 show_ip_bgp_community_all_cmd,
9990 "show ip bgp community",
9991 SHOW_STR
9992 IP_STR
9993 BGP_STR
9994 "Display routes matching the communities\n")
9995 {
9996 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9997 bgp_show_type_community_all, NULL, 0);
9998 }
9999
10000 DEFUN (show_ip_bgp_ipv4_community_all,
10001 show_ip_bgp_ipv4_community_all_cmd,
10002 "show ip bgp ipv4 (unicast|multicast) community",
10003 SHOW_STR
10004 IP_STR
10005 BGP_STR
10006 "Address family\n"
10007 "Address Family modifier\n"
10008 "Address Family modifier\n"
10009 "Display routes matching the communities\n")
10010 {
10011 if (strncmp (argv[0], "m", 1) == 0)
10012 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
10013 bgp_show_type_community_all, NULL, 0);
10014
10015 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10016 bgp_show_type_community_all, NULL, 0);
10017 }
10018
10019 #ifdef HAVE_IPV6
10020 DEFUN (show_bgp_community_all,
10021 show_bgp_community_all_cmd,
10022 "show bgp community",
10023 SHOW_STR
10024 BGP_STR
10025 "Display routes matching the communities\n")
10026 {
10027 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
10028 bgp_show_type_community_all, NULL, 0);
10029 }
10030
10031 ALIAS (show_bgp_community_all,
10032 show_bgp_ipv6_community_all_cmd,
10033 "show bgp ipv6 community",
10034 SHOW_STR
10035 BGP_STR
10036 "Address family\n"
10037 "Display routes matching the communities\n")
10038
10039 /* old command */
10040 DEFUN (show_ipv6_bgp_community_all,
10041 show_ipv6_bgp_community_all_cmd,
10042 "show ipv6 bgp community",
10043 SHOW_STR
10044 IPV6_STR
10045 BGP_STR
10046 "Display routes matching the communities\n")
10047 {
10048 bgp_show_ipv6_bgp_deprecate_warning(vty);
10049 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
10050 bgp_show_type_community_all, NULL, 0);
10051 }
10052
10053 /* old command */
10054 DEFUN (show_ipv6_mbgp_community_all,
10055 show_ipv6_mbgp_community_all_cmd,
10056 "show ipv6 mbgp community",
10057 SHOW_STR
10058 IPV6_STR
10059 MBGP_STR
10060 "Display routes matching the communities\n")
10061 {
10062 bgp_show_ipv6_bgp_deprecate_warning(vty);
10063 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
10064 bgp_show_type_community_all, NULL, 0);
10065 }
10066 #endif /* HAVE_IPV6 */
10067
10068 static int
10069 bgp_show_community (struct vty *vty, const char *view_name, int argc,
10070 const char **argv, int exact, afi_t afi, safi_t safi)
10071 {
10072 struct community *com;
10073 struct buffer *b;
10074 struct bgp *bgp;
10075 int i;
10076 char *str;
10077 int first = 0;
10078
10079 /* BGP structure lookup */
10080 if (view_name)
10081 {
10082 bgp = bgp_lookup_by_name (view_name);
10083 if (bgp == NULL)
10084 {
10085 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
10086 return CMD_WARNING;
10087 }
10088 }
10089 else
10090 {
10091 bgp = bgp_get_default ();
10092 if (bgp == NULL)
10093 {
10094 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10095 return CMD_WARNING;
10096 }
10097 }
10098
10099 b = buffer_new (1024);
10100 for (i = 0; i < argc; i++)
10101 {
10102 if (first)
10103 buffer_putc (b, ' ');
10104 else
10105 {
10106 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
10107 continue;
10108 first = 1;
10109 }
10110
10111 buffer_putstr (b, argv[i]);
10112 }
10113 buffer_putc (b, '\0');
10114
10115 str = buffer_getstr (b);
10116 buffer_free (b);
10117
10118 com = community_str2com (str);
10119 XFREE (MTYPE_TMP, str);
10120 if (! com)
10121 {
10122 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
10123 return CMD_WARNING;
10124 }
10125
10126 return bgp_show (vty, bgp, afi, safi,
10127 (exact ? bgp_show_type_community_exact :
10128 bgp_show_type_community), com, 0);
10129 }
10130
10131 DEFUN (show_ip_bgp_community,
10132 show_ip_bgp_community_cmd,
10133 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
10134 SHOW_STR
10135 IP_STR
10136 BGP_STR
10137 "Display routes matching the communities\n"
10138 COMMUNITY_AANN_STR
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 {
10143 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
10144 }
10145
10146 ALIAS (show_ip_bgp_community,
10147 show_ip_bgp_community2_cmd,
10148 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10149 SHOW_STR
10150 IP_STR
10151 BGP_STR
10152 "Display routes matching the communities\n"
10153 COMMUNITY_AANN_STR
10154 "Do not send outside local AS (well-known community)\n"
10155 "Do not advertise to any peer (well-known community)\n"
10156 "Do not export to next AS (well-known community)\n"
10157 COMMUNITY_AANN_STR
10158 "Do not send outside local AS (well-known community)\n"
10159 "Do not advertise to any peer (well-known community)\n"
10160 "Do not export to next AS (well-known community)\n")
10161
10162 ALIAS (show_ip_bgp_community,
10163 show_ip_bgp_community3_cmd,
10164 "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)",
10165 SHOW_STR
10166 IP_STR
10167 BGP_STR
10168 "Display routes matching the communities\n"
10169 COMMUNITY_AANN_STR
10170 "Do not send outside local AS (well-known community)\n"
10171 "Do not advertise to any peer (well-known community)\n"
10172 "Do not export to next AS (well-known community)\n"
10173 COMMUNITY_AANN_STR
10174 "Do not send outside local AS (well-known community)\n"
10175 "Do not advertise to any peer (well-known community)\n"
10176 "Do not export to next AS (well-known community)\n"
10177 COMMUNITY_AANN_STR
10178 "Do not send outside local AS (well-known community)\n"
10179 "Do not advertise to any peer (well-known community)\n"
10180 "Do not export to next AS (well-known community)\n")
10181
10182 ALIAS (show_ip_bgp_community,
10183 show_ip_bgp_community4_cmd,
10184 "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)",
10185 SHOW_STR
10186 IP_STR
10187 BGP_STR
10188 "Display routes matching the communities\n"
10189 COMMUNITY_AANN_STR
10190 "Do not send outside local AS (well-known community)\n"
10191 "Do not advertise to any peer (well-known community)\n"
10192 "Do not export to next AS (well-known community)\n"
10193 COMMUNITY_AANN_STR
10194 "Do not send outside local AS (well-known community)\n"
10195 "Do not advertise to any peer (well-known community)\n"
10196 "Do not export to next AS (well-known community)\n"
10197 COMMUNITY_AANN_STR
10198 "Do not send outside local AS (well-known community)\n"
10199 "Do not advertise to any peer (well-known community)\n"
10200 "Do not export to next AS (well-known community)\n"
10201 COMMUNITY_AANN_STR
10202 "Do not send outside local AS (well-known community)\n"
10203 "Do not advertise to any peer (well-known community)\n"
10204 "Do not export to next AS (well-known community)\n")
10205
10206 DEFUN (show_ip_bgp_ipv4_community,
10207 show_ip_bgp_ipv4_community_cmd,
10208 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10209 SHOW_STR
10210 IP_STR
10211 BGP_STR
10212 "Address family\n"
10213 "Address Family modifier\n"
10214 "Address Family modifier\n"
10215 "Display routes matching the communities\n"
10216 COMMUNITY_AANN_STR
10217 "Do not send outside local AS (well-known community)\n"
10218 "Do not advertise to any peer (well-known community)\n"
10219 "Do not export to next AS (well-known community)\n")
10220 {
10221 if (strncmp (argv[0], "m", 1) == 0)
10222 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
10223
10224 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
10225 }
10226
10227 ALIAS (show_ip_bgp_ipv4_community,
10228 show_ip_bgp_ipv4_community2_cmd,
10229 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10230 SHOW_STR
10231 IP_STR
10232 BGP_STR
10233 "Address family\n"
10234 "Address Family modifier\n"
10235 "Address Family modifier\n"
10236 "Display routes matching the communities\n"
10237 COMMUNITY_AANN_STR
10238 "Do not send outside local AS (well-known community)\n"
10239 "Do not advertise to any peer (well-known community)\n"
10240 "Do not export to next AS (well-known community)\n"
10241 COMMUNITY_AANN_STR
10242 "Do not send outside local AS (well-known community)\n"
10243 "Do not advertise to any peer (well-known community)\n"
10244 "Do not export to next AS (well-known community)\n")
10245
10246 ALIAS (show_ip_bgp_ipv4_community,
10247 show_ip_bgp_ipv4_community3_cmd,
10248 "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)",
10249 SHOW_STR
10250 IP_STR
10251 BGP_STR
10252 "Address family\n"
10253 "Address Family modifier\n"
10254 "Address Family modifier\n"
10255 "Display routes matching the communities\n"
10256 COMMUNITY_AANN_STR
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_AANN_STR
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_AANN_STR
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 ALIAS (show_ip_bgp_ipv4_community,
10270 show_ip_bgp_ipv4_community4_cmd,
10271 "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)",
10272 SHOW_STR
10273 IP_STR
10274 BGP_STR
10275 "Address family\n"
10276 "Address Family modifier\n"
10277 "Address Family modifier\n"
10278 "Display routes matching the communities\n"
10279 COMMUNITY_AANN_STR
10280 "Do not send outside local AS (well-known community)\n"
10281 "Do not advertise to any peer (well-known community)\n"
10282 "Do not export to next AS (well-known community)\n"
10283 COMMUNITY_AANN_STR
10284 "Do not send outside local AS (well-known community)\n"
10285 "Do not advertise to any peer (well-known community)\n"
10286 "Do not export to next AS (well-known community)\n"
10287 COMMUNITY_AANN_STR
10288 "Do not send outside local AS (well-known community)\n"
10289 "Do not advertise to any peer (well-known community)\n"
10290 "Do not export to next AS (well-known community)\n"
10291 COMMUNITY_AANN_STR
10292 "Do not send outside local AS (well-known community)\n"
10293 "Do not advertise to any peer (well-known community)\n"
10294 "Do not export to next AS (well-known community)\n")
10295
10296 DEFUN (show_bgp_instance_afi_safi_community_all,
10297 show_bgp_instance_afi_safi_community_all_cmd,
10298 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
10299 SHOW_STR
10300 BGP_STR
10301 BGP_INSTANCE_HELP_STR
10302 "Address family\n"
10303 "Address family\n"
10304 "Address Family modifier\n"
10305 "Address Family modifier\n"
10306 "Display routes matching the communities\n")
10307 {
10308 int afi;
10309 int safi;
10310 struct bgp *bgp;
10311
10312 /* BGP structure lookup. */
10313 bgp = bgp_lookup_by_name (argv[1]);
10314 if (bgp == NULL)
10315 {
10316 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
10317 return CMD_WARNING;
10318 }
10319
10320 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10321 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10322 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
10323 }
10324
10325 DEFUN (show_bgp_instance_afi_safi_community,
10326 show_bgp_instance_afi_safi_community_cmd,
10327 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10328 SHOW_STR
10329 BGP_STR
10330 BGP_INSTANCE_HELP_STR
10331 "Address family\n"
10332 "Address family\n"
10333 "Address family modifier\n"
10334 "Address family modifier\n"
10335 "Display routes matching the communities\n"
10336 COMMUNITY_AANN_STR
10337 "Do not send outside local AS (well-known community)\n"
10338 "Do not advertise to any peer (well-known community)\n"
10339 "Do not export to next AS (well-known community)\n")
10340 {
10341 int afi;
10342 int safi;
10343
10344 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10345 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10346 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
10347 }
10348
10349 ALIAS (show_bgp_instance_afi_safi_community,
10350 show_bgp_instance_afi_safi_community2_cmd,
10351 "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)",
10352 SHOW_STR
10353 BGP_STR
10354 BGP_INSTANCE_HELP_STR
10355 "Address family\n"
10356 "Address family\n"
10357 "Address family modifier\n"
10358 "Address family modifier\n"
10359 "Display routes matching the communities\n"
10360 COMMUNITY_AANN_STR
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_AANN_STR
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
10369 ALIAS (show_bgp_instance_afi_safi_community,
10370 show_bgp_instance_afi_safi_community3_cmd,
10371 "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)",
10372 SHOW_STR
10373 BGP_STR
10374 BGP_INSTANCE_HELP_STR
10375 "Address family\n"
10376 "Address family\n"
10377 "Address family modifier\n"
10378 "Address family modifier\n"
10379 "Display routes matching the communities\n"
10380 COMMUNITY_AANN_STR
10381 "Do not send outside local AS (well-known community)\n"
10382 "Do not advertise to any peer (well-known community)\n"
10383 "Do not export to next AS (well-known community)\n"
10384 COMMUNITY_AANN_STR
10385 "Do not send outside local AS (well-known community)\n"
10386 "Do not advertise to any peer (well-known community)\n"
10387 "Do not export to next AS (well-known community)\n"
10388 COMMUNITY_AANN_STR
10389 "Do not send outside local AS (well-known community)\n"
10390 "Do not advertise to any peer (well-known community)\n"
10391 "Do not export to next AS (well-known community)\n")
10392
10393 ALIAS (show_bgp_instance_afi_safi_community,
10394 show_bgp_instance_afi_safi_community4_cmd,
10395 "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)",
10396 SHOW_STR
10397 BGP_STR
10398 BGP_INSTANCE_HELP_STR
10399 "Address family\n"
10400 "Address family\n"
10401 "Address family modifier\n"
10402 "Address family modifier\n"
10403 "Display routes matching the communities\n"
10404 COMMUNITY_AANN_STR
10405 "Do not send outside local AS (well-known community)\n"
10406 "Do not advertise to any peer (well-known community)\n"
10407 "Do not export to next AS (well-known community)\n"
10408 COMMUNITY_AANN_STR
10409 "Do not send outside local AS (well-known community)\n"
10410 "Do not advertise to any peer (well-known community)\n"
10411 "Do not export to next AS (well-known community)\n"
10412 COMMUNITY_AANN_STR
10413 "Do not send outside local AS (well-known community)\n"
10414 "Do not advertise to any peer (well-known community)\n"
10415 "Do not export to next AS (well-known community)\n"
10416 COMMUNITY_AANN_STR
10417 "Do not send outside local AS (well-known community)\n"
10418 "Do not advertise to any peer (well-known community)\n"
10419 "Do not export to next AS (well-known community)\n")
10420
10421 DEFUN (show_ip_bgp_community_exact,
10422 show_ip_bgp_community_exact_cmd,
10423 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10424 SHOW_STR
10425 IP_STR
10426 BGP_STR
10427 "Display routes matching the communities\n"
10428 COMMUNITY_AANN_STR
10429 "Do not send outside local AS (well-known community)\n"
10430 "Do not advertise to any peer (well-known community)\n"
10431 "Do not export to next AS (well-known community)\n"
10432 "Exact match of the communities")
10433 {
10434 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10435 }
10436
10437 ALIAS (show_ip_bgp_community_exact,
10438 show_ip_bgp_community2_exact_cmd,
10439 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10440 SHOW_STR
10441 IP_STR
10442 BGP_STR
10443 "Display routes matching the communities\n"
10444 COMMUNITY_AANN_STR
10445 "Do not send outside local AS (well-known community)\n"
10446 "Do not advertise to any peer (well-known community)\n"
10447 "Do not export to next AS (well-known community)\n"
10448 COMMUNITY_AANN_STR
10449 "Do not send outside local AS (well-known community)\n"
10450 "Do not advertise to any peer (well-known community)\n"
10451 "Do not export to next AS (well-known community)\n"
10452 "Exact match of the communities")
10453
10454 ALIAS (show_ip_bgp_community_exact,
10455 show_ip_bgp_community3_exact_cmd,
10456 "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",
10457 SHOW_STR
10458 IP_STR
10459 BGP_STR
10460 "Display routes matching the communities\n"
10461 COMMUNITY_AANN_STR
10462 "Do not send outside local AS (well-known community)\n"
10463 "Do not advertise to any peer (well-known community)\n"
10464 "Do not export to next AS (well-known community)\n"
10465 COMMUNITY_AANN_STR
10466 "Do not send outside local AS (well-known community)\n"
10467 "Do not advertise to any peer (well-known community)\n"
10468 "Do not export to next AS (well-known community)\n"
10469 COMMUNITY_AANN_STR
10470 "Do not send outside local AS (well-known community)\n"
10471 "Do not advertise to any peer (well-known community)\n"
10472 "Do not export to next AS (well-known community)\n"
10473 "Exact match of the communities")
10474
10475 ALIAS (show_ip_bgp_community_exact,
10476 show_ip_bgp_community4_exact_cmd,
10477 "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",
10478 SHOW_STR
10479 IP_STR
10480 BGP_STR
10481 "Display routes matching the communities\n"
10482 COMMUNITY_AANN_STR
10483 "Do not send outside local AS (well-known community)\n"
10484 "Do not advertise to any peer (well-known community)\n"
10485 "Do not export to next AS (well-known community)\n"
10486 COMMUNITY_AANN_STR
10487 "Do not send outside local AS (well-known community)\n"
10488 "Do not advertise to any peer (well-known community)\n"
10489 "Do not export to next AS (well-known community)\n"
10490 COMMUNITY_AANN_STR
10491 "Do not send outside local AS (well-known community)\n"
10492 "Do not advertise to any peer (well-known community)\n"
10493 "Do not export to next AS (well-known community)\n"
10494 COMMUNITY_AANN_STR
10495 "Do not send outside local AS (well-known community)\n"
10496 "Do not advertise to any peer (well-known community)\n"
10497 "Do not export to next AS (well-known community)\n"
10498 "Exact match of the communities")
10499
10500 DEFUN (show_ip_bgp_ipv4_community_exact,
10501 show_ip_bgp_ipv4_community_exact_cmd,
10502 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10503 SHOW_STR
10504 IP_STR
10505 BGP_STR
10506 "Address family\n"
10507 "Address Family modifier\n"
10508 "Address Family modifier\n"
10509 "Display routes matching the communities\n"
10510 COMMUNITY_AANN_STR
10511 "Do not send outside local AS (well-known community)\n"
10512 "Do not advertise to any peer (well-known community)\n"
10513 "Do not export to next AS (well-known community)\n"
10514 "Exact match of the communities")
10515 {
10516 if (strncmp (argv[0], "m", 1) == 0)
10517 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
10518
10519 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10520 }
10521
10522 ALIAS (show_ip_bgp_ipv4_community_exact,
10523 show_ip_bgp_ipv4_community2_exact_cmd,
10524 "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",
10525 SHOW_STR
10526 IP_STR
10527 BGP_STR
10528 "Address family\n"
10529 "Address Family modifier\n"
10530 "Address Family modifier\n"
10531 "Display routes matching the communities\n"
10532 COMMUNITY_AANN_STR
10533 "Do not send outside local AS (well-known community)\n"
10534 "Do not advertise to any peer (well-known community)\n"
10535 "Do not export to next AS (well-known community)\n"
10536 COMMUNITY_AANN_STR
10537 "Do not send outside local AS (well-known community)\n"
10538 "Do not advertise to any peer (well-known community)\n"
10539 "Do not export to next AS (well-known community)\n"
10540 "Exact match of the communities")
10541
10542 ALIAS (show_ip_bgp_ipv4_community_exact,
10543 show_ip_bgp_ipv4_community3_exact_cmd,
10544 "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",
10545 SHOW_STR
10546 IP_STR
10547 BGP_STR
10548 "Address family\n"
10549 "Address Family modifier\n"
10550 "Address Family modifier\n"
10551 "Display routes matching the communities\n"
10552 COMMUNITY_AANN_STR
10553 "Do not send outside local AS (well-known community)\n"
10554 "Do not advertise to any peer (well-known community)\n"
10555 "Do not export to next AS (well-known community)\n"
10556 COMMUNITY_AANN_STR
10557 "Do not send outside local AS (well-known community)\n"
10558 "Do not advertise to any peer (well-known community)\n"
10559 "Do not export to next AS (well-known community)\n"
10560 COMMUNITY_AANN_STR
10561 "Do not send outside local AS (well-known community)\n"
10562 "Do not advertise to any peer (well-known community)\n"
10563 "Do not export to next AS (well-known community)\n"
10564 "Exact match of the communities")
10565
10566 ALIAS (show_ip_bgp_ipv4_community_exact,
10567 show_ip_bgp_ipv4_community4_exact_cmd,
10568 "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",
10569 SHOW_STR
10570 IP_STR
10571 BGP_STR
10572 "Address family\n"
10573 "Address Family modifier\n"
10574 "Address Family modifier\n"
10575 "Display routes matching the communities\n"
10576 COMMUNITY_AANN_STR
10577 "Do not send outside local AS (well-known community)\n"
10578 "Do not advertise to any peer (well-known community)\n"
10579 "Do not export to next AS (well-known community)\n"
10580 COMMUNITY_AANN_STR
10581 "Do not send outside local AS (well-known community)\n"
10582 "Do not advertise to any peer (well-known community)\n"
10583 "Do not export to next AS (well-known community)\n"
10584 COMMUNITY_AANN_STR
10585 "Do not send outside local AS (well-known community)\n"
10586 "Do not advertise to any peer (well-known community)\n"
10587 "Do not export to next AS (well-known community)\n"
10588 COMMUNITY_AANN_STR
10589 "Do not send outside local AS (well-known community)\n"
10590 "Do not advertise to any peer (well-known community)\n"
10591 "Do not export to next AS (well-known community)\n"
10592 "Exact match of the communities")
10593
10594 #ifdef HAVE_IPV6
10595 DEFUN (show_bgp_community,
10596 show_bgp_community_cmd,
10597 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10598 SHOW_STR
10599 BGP_STR
10600 "Display routes matching the communities\n"
10601 COMMUNITY_AANN_STR
10602 "Do not send outside local AS (well-known community)\n"
10603 "Do not advertise to any peer (well-known community)\n"
10604 "Do not export to next AS (well-known community)\n")
10605 {
10606 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10607 }
10608
10609 ALIAS (show_bgp_community,
10610 show_bgp_ipv6_community_cmd,
10611 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10612 SHOW_STR
10613 BGP_STR
10614 "Address family\n"
10615 "Display routes matching the communities\n"
10616 COMMUNITY_AANN_STR
10617 "Do not send outside local AS (well-known community)\n"
10618 "Do not advertise to any peer (well-known community)\n"
10619 "Do not export to next AS (well-known community)\n")
10620
10621 ALIAS (show_bgp_community,
10622 show_bgp_community2_cmd,
10623 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10624 SHOW_STR
10625 BGP_STR
10626 "Display routes matching the communities\n"
10627 COMMUNITY_AANN_STR
10628 "Do not send outside local AS (well-known community)\n"
10629 "Do not advertise to any peer (well-known community)\n"
10630 "Do not export to next AS (well-known community)\n"
10631 COMMUNITY_AANN_STR
10632 "Do not send outside local AS (well-known community)\n"
10633 "Do not advertise to any peer (well-known community)\n"
10634 "Do not export to next AS (well-known community)\n")
10635
10636 ALIAS (show_bgp_community,
10637 show_bgp_ipv6_community2_cmd,
10638 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10639 SHOW_STR
10640 BGP_STR
10641 "Address family\n"
10642 "Display routes matching the communities\n"
10643 COMMUNITY_AANN_STR
10644 "Do not send outside local AS (well-known community)\n"
10645 "Do not advertise to any peer (well-known community)\n"
10646 "Do not export to next AS (well-known community)\n"
10647 COMMUNITY_AANN_STR
10648 "Do not send outside local AS (well-known community)\n"
10649 "Do not advertise to any peer (well-known community)\n"
10650 "Do not export to next AS (well-known community)\n")
10651
10652 ALIAS (show_bgp_community,
10653 show_bgp_community3_cmd,
10654 "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)",
10655 SHOW_STR
10656 BGP_STR
10657 "Display routes matching the communities\n"
10658 COMMUNITY_AANN_STR
10659 "Do not send outside local AS (well-known community)\n"
10660 "Do not advertise to any peer (well-known community)\n"
10661 "Do not export to next AS (well-known community)\n"
10662 COMMUNITY_AANN_STR
10663 "Do not send outside local AS (well-known community)\n"
10664 "Do not advertise to any peer (well-known community)\n"
10665 "Do not export to next AS (well-known community)\n"
10666 COMMUNITY_AANN_STR
10667 "Do not send outside local AS (well-known community)\n"
10668 "Do not advertise to any peer (well-known community)\n"
10669 "Do not export to next AS (well-known community)\n")
10670
10671 ALIAS (show_bgp_community,
10672 show_bgp_ipv6_community3_cmd,
10673 "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)",
10674 SHOW_STR
10675 BGP_STR
10676 "Address family\n"
10677 "Display routes matching the communities\n"
10678 COMMUNITY_AANN_STR
10679 "Do not send outside local AS (well-known community)\n"
10680 "Do not advertise to any peer (well-known community)\n"
10681 "Do not export to next AS (well-known community)\n"
10682 COMMUNITY_AANN_STR
10683 "Do not send outside local AS (well-known community)\n"
10684 "Do not advertise to any peer (well-known community)\n"
10685 "Do not export to next AS (well-known community)\n"
10686 COMMUNITY_AANN_STR
10687 "Do not send outside local AS (well-known community)\n"
10688 "Do not advertise to any peer (well-known community)\n"
10689 "Do not export to next AS (well-known community)\n")
10690
10691 ALIAS (show_bgp_community,
10692 show_bgp_community4_cmd,
10693 "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)",
10694 SHOW_STR
10695 BGP_STR
10696 "Display routes matching the communities\n"
10697 COMMUNITY_AANN_STR
10698 "Do not send outside local AS (well-known community)\n"
10699 "Do not advertise to any peer (well-known community)\n"
10700 "Do not export to next AS (well-known community)\n"
10701 COMMUNITY_AANN_STR
10702 "Do not send outside local AS (well-known community)\n"
10703 "Do not advertise to any peer (well-known community)\n"
10704 "Do not export to next AS (well-known community)\n"
10705 COMMUNITY_AANN_STR
10706 "Do not send outside local AS (well-known community)\n"
10707 "Do not advertise to any peer (well-known community)\n"
10708 "Do not export to next AS (well-known community)\n"
10709 COMMUNITY_AANN_STR
10710 "Do not send outside local AS (well-known community)\n"
10711 "Do not advertise to any peer (well-known community)\n"
10712 "Do not export to next AS (well-known community)\n")
10713
10714 ALIAS (show_bgp_community,
10715 show_bgp_ipv6_community4_cmd,
10716 "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)",
10717 SHOW_STR
10718 BGP_STR
10719 "Address family\n"
10720 "Display routes matching the communities\n"
10721 COMMUNITY_AANN_STR
10722 "Do not send outside local AS (well-known community)\n"
10723 "Do not advertise to any peer (well-known community)\n"
10724 "Do not export to next AS (well-known community)\n"
10725 COMMUNITY_AANN_STR
10726 "Do not send outside local AS (well-known community)\n"
10727 "Do not advertise to any peer (well-known community)\n"
10728 "Do not export to next AS (well-known community)\n"
10729 COMMUNITY_AANN_STR
10730 "Do not send outside local AS (well-known community)\n"
10731 "Do not advertise to any peer (well-known community)\n"
10732 "Do not export to next AS (well-known community)\n"
10733 COMMUNITY_AANN_STR
10734 "Do not send outside local AS (well-known community)\n"
10735 "Do not advertise to any peer (well-known community)\n"
10736 "Do not export to next AS (well-known community)\n")
10737
10738 /* old command */
10739 DEFUN (show_ipv6_bgp_community,
10740 show_ipv6_bgp_community_cmd,
10741 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10742 SHOW_STR
10743 IPV6_STR
10744 BGP_STR
10745 "Display routes matching the communities\n"
10746 COMMUNITY_AANN_STR
10747 "Do not send outside local AS (well-known community)\n"
10748 "Do not advertise to any peer (well-known community)\n"
10749 "Do not export to next AS (well-known community)\n")
10750 {
10751 bgp_show_ipv6_bgp_deprecate_warning(vty);
10752 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10753 }
10754
10755 /* old command */
10756 ALIAS (show_ipv6_bgp_community,
10757 show_ipv6_bgp_community2_cmd,
10758 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10759 SHOW_STR
10760 IPV6_STR
10761 BGP_STR
10762 "Display routes matching the communities\n"
10763 COMMUNITY_AANN_STR
10764 "Do not send outside local AS (well-known community)\n"
10765 "Do not advertise to any peer (well-known community)\n"
10766 "Do not export to next AS (well-known community)\n"
10767 COMMUNITY_AANN_STR
10768 "Do not send outside local AS (well-known community)\n"
10769 "Do not advertise to any peer (well-known community)\n"
10770 "Do not export to next AS (well-known community)\n")
10771
10772 /* old command */
10773 ALIAS (show_ipv6_bgp_community,
10774 show_ipv6_bgp_community3_cmd,
10775 "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)",
10776 SHOW_STR
10777 IPV6_STR
10778 BGP_STR
10779 "Display routes matching the communities\n"
10780 COMMUNITY_AANN_STR
10781 "Do not send outside local AS (well-known community)\n"
10782 "Do not advertise to any peer (well-known community)\n"
10783 "Do not export to next AS (well-known community)\n"
10784 COMMUNITY_AANN_STR
10785 "Do not send outside local AS (well-known community)\n"
10786 "Do not advertise to any peer (well-known community)\n"
10787 "Do not export to next AS (well-known community)\n"
10788 COMMUNITY_AANN_STR
10789 "Do not send outside local AS (well-known community)\n"
10790 "Do not advertise to any peer (well-known community)\n"
10791 "Do not export to next AS (well-known community)\n")
10792
10793 /* old command */
10794 ALIAS (show_ipv6_bgp_community,
10795 show_ipv6_bgp_community4_cmd,
10796 "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)",
10797 SHOW_STR
10798 IPV6_STR
10799 BGP_STR
10800 "Display routes matching the communities\n"
10801 COMMUNITY_AANN_STR
10802 "Do not send outside local AS (well-known community)\n"
10803 "Do not advertise to any peer (well-known community)\n"
10804 "Do not export to next AS (well-known community)\n"
10805 COMMUNITY_AANN_STR
10806 "Do not send outside local AS (well-known community)\n"
10807 "Do not advertise to any peer (well-known community)\n"
10808 "Do not export to next AS (well-known community)\n"
10809 COMMUNITY_AANN_STR
10810 "Do not send outside local AS (well-known community)\n"
10811 "Do not advertise to any peer (well-known community)\n"
10812 "Do not export to next AS (well-known community)\n"
10813 COMMUNITY_AANN_STR
10814 "Do not send outside local AS (well-known community)\n"
10815 "Do not advertise to any peer (well-known community)\n"
10816 "Do not export to next AS (well-known community)\n")
10817
10818 DEFUN (show_bgp_community_exact,
10819 show_bgp_community_exact_cmd,
10820 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10821 SHOW_STR
10822 BGP_STR
10823 "Display routes matching the communities\n"
10824 COMMUNITY_AANN_STR
10825 "Do not send outside local AS (well-known community)\n"
10826 "Do not advertise to any peer (well-known community)\n"
10827 "Do not export to next AS (well-known community)\n"
10828 "Exact match of the communities")
10829 {
10830 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10831 }
10832
10833 ALIAS (show_bgp_community_exact,
10834 show_bgp_ipv6_community_exact_cmd,
10835 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10836 SHOW_STR
10837 BGP_STR
10838 "Address family\n"
10839 "Display routes matching the communities\n"
10840 COMMUNITY_AANN_STR
10841 "Do not send outside local AS (well-known community)\n"
10842 "Do not advertise to any peer (well-known community)\n"
10843 "Do not export to next AS (well-known community)\n"
10844 "Exact match of the communities")
10845
10846 ALIAS (show_bgp_community_exact,
10847 show_bgp_community2_exact_cmd,
10848 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10849 SHOW_STR
10850 BGP_STR
10851 "Display routes matching the communities\n"
10852 COMMUNITY_AANN_STR
10853 "Do not send outside local AS (well-known community)\n"
10854 "Do not advertise to any peer (well-known community)\n"
10855 "Do not export to next AS (well-known community)\n"
10856 COMMUNITY_AANN_STR
10857 "Do not send outside local AS (well-known community)\n"
10858 "Do not advertise to any peer (well-known community)\n"
10859 "Do not export to next AS (well-known community)\n"
10860 "Exact match of the communities")
10861
10862 ALIAS (show_bgp_community_exact,
10863 show_bgp_ipv6_community2_exact_cmd,
10864 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10865 SHOW_STR
10866 BGP_STR
10867 "Address family\n"
10868 "Display routes matching the communities\n"
10869 COMMUNITY_AANN_STR
10870 "Do not send outside local AS (well-known community)\n"
10871 "Do not advertise to any peer (well-known community)\n"
10872 "Do not export to next AS (well-known community)\n"
10873 COMMUNITY_AANN_STR
10874 "Do not send outside local AS (well-known community)\n"
10875 "Do not advertise to any peer (well-known community)\n"
10876 "Do not export to next AS (well-known community)\n"
10877 "Exact match of the communities")
10878
10879 ALIAS (show_bgp_community_exact,
10880 show_bgp_community3_exact_cmd,
10881 "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",
10882 SHOW_STR
10883 BGP_STR
10884 "Display routes matching the communities\n"
10885 COMMUNITY_AANN_STR
10886 "Do not send outside local AS (well-known community)\n"
10887 "Do not advertise to any peer (well-known community)\n"
10888 "Do not export to next AS (well-known community)\n"
10889 COMMUNITY_AANN_STR
10890 "Do not send outside local AS (well-known community)\n"
10891 "Do not advertise to any peer (well-known community)\n"
10892 "Do not export to next AS (well-known community)\n"
10893 COMMUNITY_AANN_STR
10894 "Do not send outside local AS (well-known community)\n"
10895 "Do not advertise to any peer (well-known community)\n"
10896 "Do not export to next AS (well-known community)\n"
10897 "Exact match of the communities")
10898
10899 ALIAS (show_bgp_community_exact,
10900 show_bgp_ipv6_community3_exact_cmd,
10901 "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",
10902 SHOW_STR
10903 BGP_STR
10904 "Address family\n"
10905 "Display routes matching the communities\n"
10906 COMMUNITY_AANN_STR
10907 "Do not send outside local AS (well-known community)\n"
10908 "Do not advertise to any peer (well-known community)\n"
10909 "Do not export to next AS (well-known community)\n"
10910 COMMUNITY_AANN_STR
10911 "Do not send outside local AS (well-known community)\n"
10912 "Do not advertise to any peer (well-known community)\n"
10913 "Do not export to next AS (well-known community)\n"
10914 COMMUNITY_AANN_STR
10915 "Do not send outside local AS (well-known community)\n"
10916 "Do not advertise to any peer (well-known community)\n"
10917 "Do not export to next AS (well-known community)\n"
10918 "Exact match of the communities")
10919
10920 ALIAS (show_bgp_community_exact,
10921 show_bgp_community4_exact_cmd,
10922 "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",
10923 SHOW_STR
10924 BGP_STR
10925 "Display routes matching the communities\n"
10926 COMMUNITY_AANN_STR
10927 "Do not send outside local AS (well-known community)\n"
10928 "Do not advertise to any peer (well-known community)\n"
10929 "Do not export to next AS (well-known community)\n"
10930 COMMUNITY_AANN_STR
10931 "Do not send outside local AS (well-known community)\n"
10932 "Do not advertise to any peer (well-known community)\n"
10933 "Do not export to next AS (well-known community)\n"
10934 COMMUNITY_AANN_STR
10935 "Do not send outside local AS (well-known community)\n"
10936 "Do not advertise to any peer (well-known community)\n"
10937 "Do not export to next AS (well-known community)\n"
10938 COMMUNITY_AANN_STR
10939 "Do not send outside local AS (well-known community)\n"
10940 "Do not advertise to any peer (well-known community)\n"
10941 "Do not export to next AS (well-known community)\n"
10942 "Exact match of the communities")
10943
10944 ALIAS (show_bgp_community_exact,
10945 show_bgp_ipv6_community4_exact_cmd,
10946 "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",
10947 SHOW_STR
10948 BGP_STR
10949 "Address family\n"
10950 "Display routes matching the communities\n"
10951 COMMUNITY_AANN_STR
10952 "Do not send outside local AS (well-known community)\n"
10953 "Do not advertise to any peer (well-known community)\n"
10954 "Do not export to next AS (well-known community)\n"
10955 COMMUNITY_AANN_STR
10956 "Do not send outside local AS (well-known community)\n"
10957 "Do not advertise to any peer (well-known community)\n"
10958 "Do not export to next AS (well-known community)\n"
10959 COMMUNITY_AANN_STR
10960 "Do not send outside local AS (well-known community)\n"
10961 "Do not advertise to any peer (well-known community)\n"
10962 "Do not export to next AS (well-known community)\n"
10963 COMMUNITY_AANN_STR
10964 "Do not send outside local AS (well-known community)\n"
10965 "Do not advertise to any peer (well-known community)\n"
10966 "Do not export to next AS (well-known community)\n"
10967 "Exact match of the communities")
10968
10969 /* old command */
10970 DEFUN (show_ipv6_bgp_community_exact,
10971 show_ipv6_bgp_community_exact_cmd,
10972 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10973 SHOW_STR
10974 IPV6_STR
10975 BGP_STR
10976 "Display routes matching the communities\n"
10977 COMMUNITY_AANN_STR
10978 "Do not send outside local AS (well-known community)\n"
10979 "Do not advertise to any peer (well-known community)\n"
10980 "Do not export to next AS (well-known community)\n"
10981 "Exact match of the communities")
10982 {
10983 bgp_show_ipv6_bgp_deprecate_warning(vty);
10984 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10985 }
10986
10987 /* old command */
10988 ALIAS (show_ipv6_bgp_community_exact,
10989 show_ipv6_bgp_community2_exact_cmd,
10990 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10991 SHOW_STR
10992 IPV6_STR
10993 BGP_STR
10994 "Display routes matching the communities\n"
10995 COMMUNITY_AANN_STR
10996 "Do not send outside local AS (well-known community)\n"
10997 "Do not advertise to any peer (well-known community)\n"
10998 "Do not export to next AS (well-known community)\n"
10999 COMMUNITY_AANN_STR
11000 "Do not send outside local AS (well-known community)\n"
11001 "Do not advertise to any peer (well-known community)\n"
11002 "Do not export to next AS (well-known community)\n"
11003 "Exact match of the communities")
11004
11005 /* old command */
11006 ALIAS (show_ipv6_bgp_community_exact,
11007 show_ipv6_bgp_community3_exact_cmd,
11008 "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",
11009 SHOW_STR
11010 IPV6_STR
11011 BGP_STR
11012 "Display routes matching the communities\n"
11013 COMMUNITY_AANN_STR
11014 "Do not send outside local AS (well-known community)\n"
11015 "Do not advertise to any peer (well-known community)\n"
11016 "Do not export to next AS (well-known community)\n"
11017 COMMUNITY_AANN_STR
11018 "Do not send outside local AS (well-known community)\n"
11019 "Do not advertise to any peer (well-known community)\n"
11020 "Do not export to next AS (well-known community)\n"
11021 COMMUNITY_AANN_STR
11022 "Do not send outside local AS (well-known community)\n"
11023 "Do not advertise to any peer (well-known community)\n"
11024 "Do not export to next AS (well-known community)\n"
11025 "Exact match of the communities")
11026
11027 /* old command */
11028 ALIAS (show_ipv6_bgp_community_exact,
11029 show_ipv6_bgp_community4_exact_cmd,
11030 "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",
11031 SHOW_STR
11032 IPV6_STR
11033 BGP_STR
11034 "Display routes matching the communities\n"
11035 COMMUNITY_AANN_STR
11036 "Do not send outside local AS (well-known community)\n"
11037 "Do not advertise to any peer (well-known community)\n"
11038 "Do not export to next AS (well-known community)\n"
11039 COMMUNITY_AANN_STR
11040 "Do not send outside local AS (well-known community)\n"
11041 "Do not advertise to any peer (well-known community)\n"
11042 "Do not export to next AS (well-known community)\n"
11043 COMMUNITY_AANN_STR
11044 "Do not send outside local AS (well-known community)\n"
11045 "Do not advertise to any peer (well-known community)\n"
11046 "Do not export to next AS (well-known community)\n"
11047 COMMUNITY_AANN_STR
11048 "Do not send outside local AS (well-known community)\n"
11049 "Do not advertise to any peer (well-known community)\n"
11050 "Do not export to next AS (well-known community)\n"
11051 "Exact match of the communities")
11052
11053 /* old command */
11054 DEFUN (show_ipv6_mbgp_community,
11055 show_ipv6_mbgp_community_cmd,
11056 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
11057 SHOW_STR
11058 IPV6_STR
11059 MBGP_STR
11060 "Display routes matching the communities\n"
11061 COMMUNITY_AANN_STR
11062 "Do not send outside local AS (well-known community)\n"
11063 "Do not advertise to any peer (well-known community)\n"
11064 "Do not export to next AS (well-known community)\n")
11065 {
11066 bgp_show_ipv6_bgp_deprecate_warning(vty);
11067 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
11068 }
11069
11070 /* old command */
11071 ALIAS (show_ipv6_mbgp_community,
11072 show_ipv6_mbgp_community2_cmd,
11073 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
11074 SHOW_STR
11075 IPV6_STR
11076 MBGP_STR
11077 "Display routes matching the communities\n"
11078 COMMUNITY_AANN_STR
11079 "Do not send outside local AS (well-known community)\n"
11080 "Do not advertise to any peer (well-known community)\n"
11081 "Do not export to next AS (well-known community)\n"
11082 COMMUNITY_AANN_STR
11083 "Do not send outside local AS (well-known community)\n"
11084 "Do not advertise to any peer (well-known community)\n"
11085 "Do not export to next AS (well-known community)\n")
11086
11087 /* old command */
11088 ALIAS (show_ipv6_mbgp_community,
11089 show_ipv6_mbgp_community3_cmd,
11090 "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)",
11091 SHOW_STR
11092 IPV6_STR
11093 MBGP_STR
11094 "Display routes matching the communities\n"
11095 COMMUNITY_AANN_STR
11096 "Do not send outside local AS (well-known community)\n"
11097 "Do not advertise to any peer (well-known community)\n"
11098 "Do not export to next AS (well-known community)\n"
11099 COMMUNITY_AANN_STR
11100 "Do not send outside local AS (well-known community)\n"
11101 "Do not advertise to any peer (well-known community)\n"
11102 "Do not export to next AS (well-known community)\n"
11103 COMMUNITY_AANN_STR
11104 "Do not send outside local AS (well-known community)\n"
11105 "Do not advertise to any peer (well-known community)\n"
11106 "Do not export to next AS (well-known community)\n")
11107
11108 /* old command */
11109 ALIAS (show_ipv6_mbgp_community,
11110 show_ipv6_mbgp_community4_cmd,
11111 "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)",
11112 SHOW_STR
11113 IPV6_STR
11114 MBGP_STR
11115 "Display routes matching the communities\n"
11116 COMMUNITY_AANN_STR
11117 "Do not send outside local AS (well-known community)\n"
11118 "Do not advertise to any peer (well-known community)\n"
11119 "Do not export to next AS (well-known community)\n"
11120 COMMUNITY_AANN_STR
11121 "Do not send outside local AS (well-known community)\n"
11122 "Do not advertise to any peer (well-known community)\n"
11123 "Do not export to next AS (well-known community)\n"
11124 COMMUNITY_AANN_STR
11125 "Do not send outside local AS (well-known community)\n"
11126 "Do not advertise to any peer (well-known community)\n"
11127 "Do not export to next AS (well-known community)\n"
11128 COMMUNITY_AANN_STR
11129 "Do not send outside local AS (well-known community)\n"
11130 "Do not advertise to any peer (well-known community)\n"
11131 "Do not export to next AS (well-known community)\n")
11132
11133 /* old command */
11134 DEFUN (show_ipv6_mbgp_community_exact,
11135 show_ipv6_mbgp_community_exact_cmd,
11136 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
11137 SHOW_STR
11138 IPV6_STR
11139 MBGP_STR
11140 "Display routes matching the communities\n"
11141 COMMUNITY_AANN_STR
11142 "Do not send outside local AS (well-known community)\n"
11143 "Do not advertise to any peer (well-known community)\n"
11144 "Do not export to next AS (well-known community)\n"
11145 "Exact match of the communities")
11146 {
11147 bgp_show_ipv6_bgp_deprecate_warning(vty);
11148 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
11149 }
11150
11151 /* old command */
11152 ALIAS (show_ipv6_mbgp_community_exact,
11153 show_ipv6_mbgp_community2_exact_cmd,
11154 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
11155 SHOW_STR
11156 IPV6_STR
11157 MBGP_STR
11158 "Display routes matching the communities\n"
11159 COMMUNITY_AANN_STR
11160 "Do not send outside local AS (well-known community)\n"
11161 "Do not advertise to any peer (well-known community)\n"
11162 "Do not export to next AS (well-known community)\n"
11163 COMMUNITY_AANN_STR
11164 "Do not send outside local AS (well-known community)\n"
11165 "Do not advertise to any peer (well-known community)\n"
11166 "Do not export to next AS (well-known community)\n"
11167 "Exact match of the communities")
11168
11169 /* old command */
11170 ALIAS (show_ipv6_mbgp_community_exact,
11171 show_ipv6_mbgp_community3_exact_cmd,
11172 "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",
11173 SHOW_STR
11174 IPV6_STR
11175 MBGP_STR
11176 "Display routes matching the communities\n"
11177 COMMUNITY_AANN_STR
11178 "Do not send outside local AS (well-known community)\n"
11179 "Do not advertise to any peer (well-known community)\n"
11180 "Do not export to next AS (well-known community)\n"
11181 COMMUNITY_AANN_STR
11182 "Do not send outside local AS (well-known community)\n"
11183 "Do not advertise to any peer (well-known community)\n"
11184 "Do not export to next AS (well-known community)\n"
11185 COMMUNITY_AANN_STR
11186 "Do not send outside local AS (well-known community)\n"
11187 "Do not advertise to any peer (well-known community)\n"
11188 "Do not export to next AS (well-known community)\n"
11189 "Exact match of the communities")
11190
11191 /* old command */
11192 ALIAS (show_ipv6_mbgp_community_exact,
11193 show_ipv6_mbgp_community4_exact_cmd,
11194 "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",
11195 SHOW_STR
11196 IPV6_STR
11197 MBGP_STR
11198 "Display routes matching the communities\n"
11199 COMMUNITY_AANN_STR
11200 "Do not send outside local AS (well-known community)\n"
11201 "Do not advertise to any peer (well-known community)\n"
11202 "Do not export to next AS (well-known community)\n"
11203 COMMUNITY_AANN_STR
11204 "Do not send outside local AS (well-known community)\n"
11205 "Do not advertise to any peer (well-known community)\n"
11206 "Do not export to next AS (well-known community)\n"
11207 COMMUNITY_AANN_STR
11208 "Do not send outside local AS (well-known community)\n"
11209 "Do not advertise to any peer (well-known community)\n"
11210 "Do not export to next AS (well-known community)\n"
11211 COMMUNITY_AANN_STR
11212 "Do not send outside local AS (well-known community)\n"
11213 "Do not advertise to any peer (well-known community)\n"
11214 "Do not export to next AS (well-known community)\n"
11215 "Exact match of the communities")
11216 #endif /* HAVE_IPV6 */
11217
11218 static int
11219 bgp_show_community_list (struct vty *vty, const char *name,
11220 const char *com, int exact,
11221 afi_t afi, safi_t safi)
11222 {
11223 struct community_list *list;
11224 struct bgp *bgp = NULL;
11225
11226 if (name && !(bgp = bgp_lookup_by_name(name)))
11227 {
11228 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11229 return CMD_WARNING;
11230 }
11231
11232 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
11233 if (list == NULL)
11234 {
11235 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11236 VTY_NEWLINE);
11237 return CMD_WARNING;
11238 }
11239
11240 return bgp_show (vty, bgp, afi, safi,
11241 (exact ? bgp_show_type_community_list_exact :
11242 bgp_show_type_community_list), list, 0);
11243 }
11244
11245 DEFUN (show_ip_bgp_community_list,
11246 show_ip_bgp_community_list_cmd,
11247 "show ip bgp community-list (<1-500>|WORD)",
11248 SHOW_STR
11249 IP_STR
11250 BGP_STR
11251 "Display routes matching the community-list\n"
11252 "community-list number\n"
11253 "community-list name\n")
11254 {
11255 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
11256 }
11257
11258 DEFUN (show_ip_bgp_instance_community_list,
11259 show_ip_bgp_instance_community_list_cmd,
11260 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
11261 SHOW_STR
11262 IP_STR
11263 BGP_STR
11264 BGP_INSTANCE_HELP_STR
11265 "Display routes matching the community-list\n"
11266 "community-list number\n"
11267 "community-list name\n")
11268 {
11269 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
11270 }
11271
11272 DEFUN (show_ip_bgp_ipv4_community_list,
11273 show_ip_bgp_ipv4_community_list_cmd,
11274 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11275 SHOW_STR
11276 IP_STR
11277 BGP_STR
11278 "Address family\n"
11279 "Address Family modifier\n"
11280 "Address Family modifier\n"
11281 "Display routes matching the community-list\n"
11282 "community-list number\n"
11283 "community-list name\n")
11284 {
11285 if (strncmp (argv[0], "m", 1) == 0)
11286 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11287
11288 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_UNICAST);
11289 }
11290
11291 DEFUN (show_ip_bgp_community_list_exact,
11292 show_ip_bgp_community_list_exact_cmd,
11293 "show ip bgp community-list (<1-500>|WORD) exact-match",
11294 SHOW_STR
11295 IP_STR
11296 BGP_STR
11297 "Display routes matching the community-list\n"
11298 "community-list number\n"
11299 "community-list name\n"
11300 "Exact match of the communities\n")
11301 {
11302 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
11303 }
11304
11305 DEFUN (show_ip_bgp_ipv4_community_list_exact,
11306 show_ip_bgp_ipv4_community_list_exact_cmd,
11307 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11308 SHOW_STR
11309 IP_STR
11310 BGP_STR
11311 "Address family\n"
11312 "Address Family modifier\n"
11313 "Address Family modifier\n"
11314 "Display routes matching the community-list\n"
11315 "community-list number\n"
11316 "community-list name\n"
11317 "Exact match of the communities\n")
11318 {
11319 if (strncmp (argv[0], "m", 1) == 0)
11320 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11321
11322 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_UNICAST);
11323 }
11324
11325 #ifdef HAVE_IPV6
11326 DEFUN (show_bgp_community_list,
11327 show_bgp_community_list_cmd,
11328 "show bgp community-list (<1-500>|WORD)",
11329 SHOW_STR
11330 BGP_STR
11331 "Display routes matching the community-list\n"
11332 "community-list number\n"
11333 "community-list name\n")
11334 {
11335 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11336 }
11337
11338 ALIAS (show_bgp_community_list,
11339 show_bgp_ipv6_community_list_cmd,
11340 "show bgp ipv6 community-list (<1-500>|WORD)",
11341 SHOW_STR
11342 BGP_STR
11343 "Address family\n"
11344 "Display routes matching the community-list\n"
11345 "community-list number\n"
11346 "community-list name\n")
11347
11348 /* old command */
11349 DEFUN (show_ipv6_bgp_community_list,
11350 show_ipv6_bgp_community_list_cmd,
11351 "show ipv6 bgp community-list WORD",
11352 SHOW_STR
11353 IPV6_STR
11354 BGP_STR
11355 "Display routes matching the community-list\n"
11356 "community-list name\n")
11357 {
11358 bgp_show_ipv6_bgp_deprecate_warning(vty);
11359 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11360 }
11361
11362 /* old command */
11363 DEFUN (show_ipv6_mbgp_community_list,
11364 show_ipv6_mbgp_community_list_cmd,
11365 "show ipv6 mbgp community-list WORD",
11366 SHOW_STR
11367 IPV6_STR
11368 MBGP_STR
11369 "Display routes matching the community-list\n"
11370 "community-list name\n")
11371 {
11372 bgp_show_ipv6_bgp_deprecate_warning(vty);
11373 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11374 }
11375
11376 DEFUN (show_bgp_community_list_exact,
11377 show_bgp_community_list_exact_cmd,
11378 "show bgp community-list (<1-500>|WORD) exact-match",
11379 SHOW_STR
11380 BGP_STR
11381 "Display routes matching the community-list\n"
11382 "community-list number\n"
11383 "community-list name\n"
11384 "Exact match of the communities\n")
11385 {
11386 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11387 }
11388
11389 ALIAS (show_bgp_community_list_exact,
11390 show_bgp_ipv6_community_list_exact_cmd,
11391 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11392 SHOW_STR
11393 BGP_STR
11394 "Address family\n"
11395 "Display routes matching the community-list\n"
11396 "community-list number\n"
11397 "community-list name\n"
11398 "Exact match of the communities\n")
11399
11400 /* old command */
11401 DEFUN (show_ipv6_bgp_community_list_exact,
11402 show_ipv6_bgp_community_list_exact_cmd,
11403 "show ipv6 bgp community-list WORD exact-match",
11404 SHOW_STR
11405 IPV6_STR
11406 BGP_STR
11407 "Display routes matching the community-list\n"
11408 "community-list name\n"
11409 "Exact match of the communities\n")
11410 {
11411 bgp_show_ipv6_bgp_deprecate_warning(vty);
11412 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11413 }
11414
11415 /* old command */
11416 DEFUN (show_ipv6_mbgp_community_list_exact,
11417 show_ipv6_mbgp_community_list_exact_cmd,
11418 "show ipv6 mbgp community-list WORD exact-match",
11419 SHOW_STR
11420 IPV6_STR
11421 MBGP_STR
11422 "Display routes matching the community-list\n"
11423 "community-list name\n"
11424 "Exact match of the communities\n")
11425 {
11426 bgp_show_ipv6_bgp_deprecate_warning(vty);
11427 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11428 }
11429 #endif /* HAVE_IPV6 */
11430
11431 static int
11432 bgp_show_prefix_longer (struct vty *vty, const char *name,
11433 const char *prefix, afi_t afi,
11434 safi_t safi, enum bgp_show_type type)
11435 {
11436 int ret;
11437 struct prefix *p;
11438 struct bgp *bgp = NULL;
11439
11440 if (name && !(bgp = bgp_lookup_by_name(name)))
11441 {
11442 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11443 return CMD_WARNING;
11444 }
11445
11446 p = prefix_new();
11447
11448 ret = str2prefix (prefix, p);
11449 if (! ret)
11450 {
11451 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11452 return CMD_WARNING;
11453 }
11454
11455 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
11456 prefix_free(p);
11457 return ret;
11458 }
11459
11460 DEFUN (show_ip_bgp_prefix_longer,
11461 show_ip_bgp_prefix_longer_cmd,
11462 "show ip bgp A.B.C.D/M longer-prefixes",
11463 SHOW_STR
11464 IP_STR
11465 BGP_STR
11466 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11467 "Display route and more specific routes\n")
11468 {
11469 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11470 bgp_show_type_prefix_longer);
11471 }
11472
11473 DEFUN (show_ip_bgp_instance_prefix_longer,
11474 show_ip_bgp_instance_prefix_longer_cmd,
11475 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
11476 SHOW_STR
11477 IP_STR
11478 BGP_STR
11479 BGP_INSTANCE_HELP_STR
11480 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11481 "Display route and more specific routes\n")
11482 {
11483 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
11484 bgp_show_type_prefix_longer);
11485 }
11486
11487 DEFUN (show_ip_bgp_flap_prefix_longer,
11488 show_ip_bgp_flap_prefix_longer_cmd,
11489 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11490 SHOW_STR
11491 IP_STR
11492 BGP_STR
11493 "Display flap statistics of routes\n"
11494 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11495 "Display route and more specific routes\n")
11496 {
11497 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11498 bgp_show_type_flap_prefix_longer);
11499 }
11500
11501 ALIAS (show_ip_bgp_flap_prefix_longer,
11502 show_ip_bgp_damp_flap_prefix_longer_cmd,
11503 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11504 SHOW_STR
11505 IP_STR
11506 BGP_STR
11507 "Display detailed information about dampening\n"
11508 "Display flap statistics of routes\n"
11509 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11510 "Display route and more specific routes\n")
11511
11512 DEFUN (show_ip_bgp_ipv4_prefix_longer,
11513 show_ip_bgp_ipv4_prefix_longer_cmd,
11514 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11515 SHOW_STR
11516 IP_STR
11517 BGP_STR
11518 "Address family\n"
11519 "Address Family modifier\n"
11520 "Address Family modifier\n"
11521 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11522 "Display route and more specific routes\n")
11523 {
11524 if (strncmp (argv[0], "m", 1) == 0)
11525 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST,
11526 bgp_show_type_prefix_longer);
11527
11528 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST,
11529 bgp_show_type_prefix_longer);
11530 }
11531
11532 DEFUN (show_ip_bgp_flap_address,
11533 show_ip_bgp_flap_address_cmd,
11534 "show ip bgp flap-statistics A.B.C.D",
11535 SHOW_STR
11536 IP_STR
11537 BGP_STR
11538 "Display flap statistics of routes\n"
11539 "Network in the BGP routing table to display\n")
11540 {
11541 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11542 bgp_show_type_flap_address);
11543 }
11544
11545 ALIAS (show_ip_bgp_flap_address,
11546 show_ip_bgp_damp_flap_address_cmd,
11547 "show ip bgp dampening flap-statistics A.B.C.D",
11548 SHOW_STR
11549 IP_STR
11550 BGP_STR
11551 "Display detailed information about dampening\n"
11552 "Display flap statistics of routes\n"
11553 "Network in the BGP routing table to display\n")
11554
11555 DEFUN (show_ip_bgp_flap_prefix,
11556 show_ip_bgp_flap_prefix_cmd,
11557 "show ip bgp flap-statistics A.B.C.D/M",
11558 SHOW_STR
11559 IP_STR
11560 BGP_STR
11561 "Display flap statistics of routes\n"
11562 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11563 {
11564 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11565 bgp_show_type_flap_prefix);
11566 }
11567
11568 ALIAS (show_ip_bgp_flap_prefix,
11569 show_ip_bgp_damp_flap_prefix_cmd,
11570 "show ip bgp dampening flap-statistics A.B.C.D/M",
11571 SHOW_STR
11572 IP_STR
11573 BGP_STR
11574 "Display detailed information about dampening\n"
11575 "Display flap statistics of routes\n"
11576 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11577
11578 #ifdef HAVE_IPV6
11579 DEFUN (show_bgp_prefix_longer,
11580 show_bgp_prefix_longer_cmd,
11581 "show bgp X:X::X:X/M longer-prefixes",
11582 SHOW_STR
11583 BGP_STR
11584 "IPv6 prefix <network>/<length>\n"
11585 "Display route and more specific routes\n")
11586 {
11587 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11588 bgp_show_type_prefix_longer);
11589 }
11590
11591 ALIAS (show_bgp_prefix_longer,
11592 show_bgp_ipv6_prefix_longer_cmd,
11593 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11594 SHOW_STR
11595 BGP_STR
11596 "Address family\n"
11597 "IPv6 prefix <network>/<length>\n"
11598 "Display route and more specific routes\n")
11599
11600 /* old command */
11601 DEFUN (show_ipv6_bgp_prefix_longer,
11602 show_ipv6_bgp_prefix_longer_cmd,
11603 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11604 SHOW_STR
11605 IPV6_STR
11606 BGP_STR
11607 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11608 "Display route and more specific routes\n")
11609 {
11610 bgp_show_ipv6_bgp_deprecate_warning(vty);
11611 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11612 bgp_show_type_prefix_longer);
11613 }
11614
11615 /* old command */
11616 DEFUN (show_ipv6_mbgp_prefix_longer,
11617 show_ipv6_mbgp_prefix_longer_cmd,
11618 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11619 SHOW_STR
11620 IPV6_STR
11621 MBGP_STR
11622 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11623 "Display route and more specific routes\n")
11624 {
11625 bgp_show_ipv6_bgp_deprecate_warning(vty);
11626 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
11627 bgp_show_type_prefix_longer);
11628 }
11629 #endif /* HAVE_IPV6 */
11630
11631 static struct peer *
11632 peer_lookup_in_view (struct vty *vty, const char *view_name,
11633 const char *ip_str, u_char use_json)
11634 {
11635 int ret;
11636 struct bgp *bgp;
11637 struct peer *peer;
11638 union sockunion su;
11639
11640 /* BGP structure lookup. */
11641 if (view_name)
11642 {
11643 bgp = bgp_lookup_by_name (view_name);
11644 if (! bgp)
11645 {
11646 if (use_json)
11647 {
11648 json_object *json_no = NULL;
11649 json_no = json_object_new_object();
11650 json_object_string_add(json_no, "warning", "Can't find BGP view");
11651 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11652 json_object_free(json_no);
11653 }
11654 else
11655 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
11656 return NULL;
11657 }
11658 }
11659 else
11660 {
11661 bgp = bgp_get_default ();
11662 if (! bgp)
11663 {
11664 if (use_json)
11665 {
11666 json_object *json_no = NULL;
11667 json_no = json_object_new_object();
11668 json_object_string_add(json_no, "warning", "No BGP process configured");
11669 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11670 json_object_free(json_no);
11671 }
11672 else
11673 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11674 return NULL;
11675 }
11676 }
11677
11678 /* Get peer sockunion. */
11679 ret = str2sockunion (ip_str, &su);
11680 if (ret < 0)
11681 {
11682 peer = peer_lookup_by_conf_if (bgp, ip_str);
11683 if (!peer)
11684 {
11685 peer = peer_lookup_by_hostname(bgp, ip_str);
11686
11687 if (!peer)
11688 {
11689 if (use_json)
11690 {
11691 json_object *json_no = NULL;
11692 json_no = json_object_new_object();
11693 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11694 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11695 json_object_free(json_no);
11696 }
11697 else
11698 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11699 return NULL;
11700 }
11701 }
11702 return peer;
11703 }
11704
11705 /* Peer structure lookup. */
11706 peer = peer_lookup (bgp, &su);
11707 if (! peer)
11708 {
11709 if (use_json)
11710 {
11711 json_object *json_no = NULL;
11712 json_no = json_object_new_object();
11713 json_object_string_add(json_no, "warning","No such neighbor");
11714 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11715 json_object_free(json_no);
11716 }
11717 else
11718 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11719 return NULL;
11720 }
11721
11722 return peer;
11723 }
11724
11725 enum bgp_stats
11726 {
11727 BGP_STATS_MAXBITLEN = 0,
11728 BGP_STATS_RIB,
11729 BGP_STATS_PREFIXES,
11730 BGP_STATS_TOTPLEN,
11731 BGP_STATS_UNAGGREGATEABLE,
11732 BGP_STATS_MAX_AGGREGATEABLE,
11733 BGP_STATS_AGGREGATES,
11734 BGP_STATS_SPACE,
11735 BGP_STATS_ASPATH_COUNT,
11736 BGP_STATS_ASPATH_MAXHOPS,
11737 BGP_STATS_ASPATH_TOTHOPS,
11738 BGP_STATS_ASPATH_MAXSIZE,
11739 BGP_STATS_ASPATH_TOTSIZE,
11740 BGP_STATS_ASN_HIGHEST,
11741 BGP_STATS_MAX,
11742 };
11743
11744 static const char *table_stats_strs[] =
11745 {
11746 [BGP_STATS_PREFIXES] = "Total Prefixes",
11747 [BGP_STATS_TOTPLEN] = "Average prefix length",
11748 [BGP_STATS_RIB] = "Total Advertisements",
11749 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11750 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11751 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11752 [BGP_STATS_SPACE] = "Address space advertised",
11753 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11754 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11755 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11756 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11757 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11758 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11759 [BGP_STATS_MAX] = NULL,
11760 };
11761
11762 struct bgp_table_stats
11763 {
11764 struct bgp_table *table;
11765 unsigned long long counts[BGP_STATS_MAX];
11766 };
11767
11768 #if 0
11769 #define TALLY_SIGFIG 100000
11770 static unsigned long
11771 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11772 {
11773 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11774 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11775 unsigned long ret = newtot / count;
11776
11777 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11778 return ret + 1;
11779 else
11780 return ret;
11781 }
11782 #endif
11783
11784 static int
11785 bgp_table_stats_walker (struct thread *t)
11786 {
11787 struct bgp_node *rn;
11788 struct bgp_node *top;
11789 struct bgp_table_stats *ts = THREAD_ARG (t);
11790 unsigned int space = 0;
11791
11792 if (!(top = bgp_table_top (ts->table)))
11793 return 0;
11794
11795 switch (top->p.family)
11796 {
11797 case AF_INET:
11798 space = IPV4_MAX_BITLEN;
11799 break;
11800 case AF_INET6:
11801 space = IPV6_MAX_BITLEN;
11802 break;
11803 }
11804
11805 ts->counts[BGP_STATS_MAXBITLEN] = space;
11806
11807 for (rn = top; rn; rn = bgp_route_next (rn))
11808 {
11809 struct bgp_info *ri;
11810 struct bgp_node *prn = bgp_node_parent_nolock (rn);
11811 unsigned int rinum = 0;
11812
11813 if (rn == top)
11814 continue;
11815
11816 if (!rn->info)
11817 continue;
11818
11819 ts->counts[BGP_STATS_PREFIXES]++;
11820 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11821
11822 #if 0
11823 ts->counts[BGP_STATS_AVGPLEN]
11824 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11825 ts->counts[BGP_STATS_AVGPLEN],
11826 rn->p.prefixlen);
11827 #endif
11828
11829 /* check if the prefix is included by any other announcements */
11830 while (prn && !prn->info)
11831 prn = bgp_node_parent_nolock (prn);
11832
11833 if (prn == NULL || prn == top)
11834 {
11835 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11836 /* announced address space */
11837 if (space)
11838 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11839 }
11840 else if (prn->info)
11841 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11842
11843 for (ri = rn->info; ri; ri = ri->next)
11844 {
11845 rinum++;
11846 ts->counts[BGP_STATS_RIB]++;
11847
11848 if (ri->attr &&
11849 (CHECK_FLAG (ri->attr->flag,
11850 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11851 ts->counts[BGP_STATS_AGGREGATES]++;
11852
11853 /* as-path stats */
11854 if (ri->attr && ri->attr->aspath)
11855 {
11856 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11857 unsigned int size = aspath_size (ri->attr->aspath);
11858 as_t highest = aspath_highest (ri->attr->aspath);
11859
11860 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11861
11862 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11863 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11864
11865 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11866 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11867
11868 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11869 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11870 #if 0
11871 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11872 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11873 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11874 hops);
11875 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11876 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11877 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11878 size);
11879 #endif
11880 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11881 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11882 }
11883 }
11884 }
11885 return 0;
11886 }
11887
11888 static int
11889 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11890 {
11891 struct bgp_table_stats ts;
11892 unsigned int i;
11893
11894 if (!bgp->rib[afi][safi])
11895 {
11896 vty_out (vty, "%% No RIB exists for the AFI(%d)/SAFI(%d)%s",
11897 afi, safi, VTY_NEWLINE);
11898 return CMD_WARNING;
11899 }
11900
11901 memset (&ts, 0, sizeof (ts));
11902 ts.table = bgp->rib[afi][safi];
11903 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11904
11905 vty_out (vty, "BGP %s RIB statistics%s%s",
11906 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11907
11908 for (i = 0; i < BGP_STATS_MAX; i++)
11909 {
11910 if (!table_stats_strs[i])
11911 continue;
11912
11913 switch (i)
11914 {
11915 #if 0
11916 case BGP_STATS_ASPATH_AVGHOPS:
11917 case BGP_STATS_ASPATH_AVGSIZE:
11918 case BGP_STATS_AVGPLEN:
11919 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11920 vty_out (vty, "%12.2f",
11921 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11922 break;
11923 #endif
11924 case BGP_STATS_ASPATH_TOTHOPS:
11925 case BGP_STATS_ASPATH_TOTSIZE:
11926 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11927 vty_out (vty, "%12.2f",
11928 ts.counts[i] ?
11929 (float)ts.counts[i] /
11930 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11931 : 0);
11932 break;
11933 case BGP_STATS_TOTPLEN:
11934 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11935 vty_out (vty, "%12.2f",
11936 ts.counts[i] ?
11937 (float)ts.counts[i] /
11938 (float)ts.counts[BGP_STATS_PREFIXES]
11939 : 0);
11940 break;
11941 case BGP_STATS_SPACE:
11942 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11943 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11944 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11945 break;
11946 vty_out (vty, "%30s: ", "%% announced ");
11947 vty_out (vty, "%12.2f%s",
11948 100 * (float)ts.counts[BGP_STATS_SPACE] /
11949 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
11950 VTY_NEWLINE);
11951 vty_out (vty, "%30s: ", "/8 equivalent ");
11952 vty_out (vty, "%12.2f%s",
11953 (float)ts.counts[BGP_STATS_SPACE] /
11954 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11955 VTY_NEWLINE);
11956 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11957 break;
11958 vty_out (vty, "%30s: ", "/24 equivalent ");
11959 vty_out (vty, "%12.2f",
11960 (float)ts.counts[BGP_STATS_SPACE] /
11961 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11962 break;
11963 default:
11964 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11965 vty_out (vty, "%12llu", ts.counts[i]);
11966 }
11967
11968 vty_out (vty, "%s", VTY_NEWLINE);
11969 }
11970 return CMD_SUCCESS;
11971 }
11972
11973 static int
11974 bgp_table_stats_vty (struct vty *vty, const char *name,
11975 const char *afi_str, const char *safi_str)
11976 {
11977 struct bgp *bgp;
11978 afi_t afi;
11979 safi_t safi;
11980
11981 if (name)
11982 bgp = bgp_lookup_by_name (name);
11983 else
11984 bgp = bgp_get_default ();
11985
11986 if (!bgp)
11987 {
11988 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11989 return CMD_WARNING;
11990 }
11991 if (strncmp (afi_str, "ipv", 3) == 0)
11992 {
11993 if (strncmp (afi_str, "ipv4", 4) == 0)
11994 afi = AFI_IP;
11995 else if (strncmp (afi_str, "ipv6", 4) == 0)
11996 afi = AFI_IP6;
11997 else
11998 {
11999 vty_out (vty, "%% Invalid address family %s%s",
12000 afi_str, VTY_NEWLINE);
12001 return CMD_WARNING;
12002 }
12003 if (strncmp (safi_str, "m", 1) == 0)
12004 safi = SAFI_MULTICAST;
12005 else if (strncmp (safi_str, "u", 1) == 0)
12006 safi = SAFI_UNICAST;
12007 else if (strncmp (safi_str, "e", 1) == 0)
12008 safi = SAFI_ENCAP;
12009 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
12010 safi = SAFI_MPLS_VPN;
12011 else
12012 {
12013 vty_out (vty, "%% Invalid subsequent address family %s%s",
12014 safi_str, VTY_NEWLINE);
12015 return CMD_WARNING;
12016 }
12017 }
12018 else
12019 {
12020 vty_out (vty, "%% Invalid address family \"%s\"%s",
12021 afi_str, VTY_NEWLINE);
12022 return CMD_WARNING;
12023 }
12024
12025 return bgp_table_stats (vty, bgp, afi, safi);
12026 }
12027
12028 DEFUN (show_bgp_statistics,
12029 show_bgp_statistics_cmd,
12030 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
12031 SHOW_STR
12032 BGP_STR
12033 "Address family\n"
12034 "Address family\n"
12035 "Address Family modifier\n"
12036 "Address Family modifier\n"
12037 "Address Family modifier\n"
12038 "Address Family modifier\n"
12039 "BGP RIB advertisement statistics\n")
12040 {
12041 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12042 }
12043
12044 DEFUN (show_bgp_statistics_view,
12045 show_bgp_statistics_view_cmd,
12046 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast|vpn|encap) statistics",
12047 SHOW_STR
12048 BGP_STR
12049 BGP_INSTANCE_HELP_STR
12050 "Address family\n"
12051 "Address family\n"
12052 "Address Family modifier\n"
12053 "Address Family modifier\n"
12054 "Address Family modifier\n"
12055 "Address Family modifier\n"
12056 "BGP RIB advertisement statistics\n")
12057 {
12058 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
12059 }
12060
12061 enum bgp_pcounts
12062 {
12063 PCOUNT_ADJ_IN = 0,
12064 PCOUNT_DAMPED,
12065 PCOUNT_REMOVED,
12066 PCOUNT_HISTORY,
12067 PCOUNT_STALE,
12068 PCOUNT_VALID,
12069 PCOUNT_ALL,
12070 PCOUNT_COUNTED,
12071 PCOUNT_PFCNT, /* the figure we display to users */
12072 PCOUNT_MAX,
12073 };
12074
12075 static const char *pcount_strs[] =
12076 {
12077 [PCOUNT_ADJ_IN] = "Adj-in",
12078 [PCOUNT_DAMPED] = "Damped",
12079 [PCOUNT_REMOVED] = "Removed",
12080 [PCOUNT_HISTORY] = "History",
12081 [PCOUNT_STALE] = "Stale",
12082 [PCOUNT_VALID] = "Valid",
12083 [PCOUNT_ALL] = "All RIB",
12084 [PCOUNT_COUNTED] = "PfxCt counted",
12085 [PCOUNT_PFCNT] = "Useable",
12086 [PCOUNT_MAX] = NULL,
12087 };
12088
12089 struct peer_pcounts
12090 {
12091 unsigned int count[PCOUNT_MAX];
12092 const struct peer *peer;
12093 const struct bgp_table *table;
12094 };
12095
12096 static int
12097 bgp_peer_count_walker (struct thread *t)
12098 {
12099 struct bgp_node *rn;
12100 struct peer_pcounts *pc = THREAD_ARG (t);
12101 const struct peer *peer = pc->peer;
12102
12103 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
12104 {
12105 struct bgp_adj_in *ain;
12106 struct bgp_info *ri;
12107
12108 for (ain = rn->adj_in; ain; ain = ain->next)
12109 if (ain->peer == peer)
12110 pc->count[PCOUNT_ADJ_IN]++;
12111
12112 for (ri = rn->info; ri; ri = ri->next)
12113 {
12114 char buf[SU_ADDRSTRLEN];
12115
12116 if (ri->peer != peer)
12117 continue;
12118
12119 pc->count[PCOUNT_ALL]++;
12120
12121 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
12122 pc->count[PCOUNT_DAMPED]++;
12123 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
12124 pc->count[PCOUNT_HISTORY]++;
12125 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
12126 pc->count[PCOUNT_REMOVED]++;
12127 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
12128 pc->count[PCOUNT_STALE]++;
12129 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
12130 pc->count[PCOUNT_VALID]++;
12131 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12132 pc->count[PCOUNT_PFCNT]++;
12133
12134 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12135 {
12136 pc->count[PCOUNT_COUNTED]++;
12137 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12138 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
12139 peer->host,
12140 inet_ntop(rn->p.family, &rn->p.u.prefix,
12141 buf, SU_ADDRSTRLEN),
12142 rn->p.prefixlen,
12143 ri->flags);
12144 }
12145 else
12146 {
12147 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12148 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
12149 peer->host,
12150 inet_ntop(rn->p.family, &rn->p.u.prefix,
12151 buf, SU_ADDRSTRLEN),
12152 rn->p.prefixlen,
12153 ri->flags);
12154 }
12155 }
12156 }
12157 return 0;
12158 }
12159
12160 static int
12161 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
12162 {
12163 struct peer_pcounts pcounts = { .peer = peer };
12164 unsigned int i;
12165 json_object *json = NULL;
12166 json_object *json_loop = NULL;
12167
12168 if (use_json)
12169 {
12170 json = json_object_new_object();
12171 json_loop = json_object_new_object();
12172 }
12173
12174 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12175 || !peer->bgp->rib[afi][safi])
12176 {
12177 if (use_json)
12178 {
12179 json_object_string_add(json, "warning", "No such neighbor or address family");
12180 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12181 json_object_free(json);
12182 }
12183 else
12184 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12185
12186 return CMD_WARNING;
12187 }
12188
12189 memset (&pcounts, 0, sizeof(pcounts));
12190 pcounts.peer = peer;
12191 pcounts.table = peer->bgp->rib[afi][safi];
12192
12193 /* in-place call via thread subsystem so as to record execution time
12194 * * stats for the thread-walk (i.e. ensure this can't be blamed on
12195 * * on just vty_read()).
12196 * */
12197 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12198
12199 if (use_json)
12200 {
12201 json_object_string_add(json, "prefixCountsFor", peer->host);
12202 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
12203 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
12204
12205 for (i = 0; i < PCOUNT_MAX; i++)
12206 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
12207
12208 json_object_object_add(json, "ribTableWalkCounters", json_loop);
12209
12210 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12211 {
12212 json_object_string_add(json, "pfxctDriftFor", peer->host);
12213 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
12214 }
12215 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12216 json_object_free(json);
12217 }
12218 else
12219 {
12220
12221 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
12222 {
12223 vty_out (vty, "Prefix counts for %s/%s, %s%s",
12224 peer->hostname, peer->host, afi_safi_print (afi, safi),
12225 VTY_NEWLINE);
12226 }
12227 else
12228 {
12229 vty_out (vty, "Prefix counts for %s, %s%s",
12230 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12231 }
12232
12233 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12234 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12235 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12236
12237 for (i = 0; i < PCOUNT_MAX; i++)
12238 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
12239
12240 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12241 {
12242 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12243 peer->host, VTY_NEWLINE);
12244 vty_out (vty, "Please report this bug, with the above command output%s",
12245 VTY_NEWLINE);
12246 }
12247 }
12248
12249 return CMD_SUCCESS;
12250 }
12251
12252 DEFUN (show_ip_bgp_neighbor_prefix_counts,
12253 show_ip_bgp_neighbor_prefix_counts_cmd,
12254 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12255 SHOW_STR
12256 IP_STR
12257 BGP_STR
12258 "Detailed information on TCP and BGP neighbor connections\n"
12259 "Neighbor to display information about\n"
12260 "Neighbor to display information about\n"
12261 "Neighbor on bgp configured interface\n"
12262 "Display detailed prefix count information\n"
12263 "JavaScript Object Notation\n")
12264 {
12265 struct peer *peer;
12266 u_char uj = use_json(argc, argv);
12267
12268 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12269 if (! peer)
12270 return CMD_WARNING;
12271
12272 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12273 }
12274
12275 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
12276 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
12277 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12278 SHOW_STR
12279 IP_STR
12280 BGP_STR
12281 BGP_INSTANCE_HELP_STR
12282 "Detailed information on TCP and BGP neighbor connections\n"
12283 "Neighbor to display information about\n"
12284 "Neighbor to display information about\n"
12285 "Neighbor on bgp configured interface\n"
12286 "Display detailed prefix count information\n"
12287 "JavaScript Object Notation\n")
12288 {
12289 struct peer *peer;
12290 u_char uj = use_json(argc, argv);
12291
12292 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12293 if (! peer)
12294 return CMD_WARNING;
12295
12296 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12297 }
12298
12299 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12300 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12301 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12302 SHOW_STR
12303 BGP_STR
12304 "Address family\n"
12305 "Detailed information on TCP and BGP neighbor connections\n"
12306 "Neighbor to display information about\n"
12307 "Neighbor to display information about\n"
12308 "Neighbor on bgp configured interface\n"
12309 "Display detailed prefix count information\n"
12310 "JavaScript Object Notation\n")
12311 {
12312 struct peer *peer;
12313 u_char uj = use_json(argc, argv);
12314
12315 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12316 if (! peer)
12317 return CMD_WARNING;
12318
12319 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12320 }
12321
12322 DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
12323 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
12324 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12325 SHOW_STR
12326 BGP_STR
12327 BGP_INSTANCE_HELP_STR
12328 "Address family\n"
12329 "Detailed information on TCP and BGP neighbor connections\n"
12330 "Neighbor to display information about\n"
12331 "Neighbor to display information about\n"
12332 "Neighbor on bgp configured interface\n"
12333 "Display detailed prefix count information\n"
12334 "JavaScript Object Notation\n")
12335 {
12336 struct peer *peer;
12337 u_char uj = use_json(argc, argv);
12338
12339 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12340 if (! peer)
12341 return CMD_WARNING;
12342
12343 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12344 }
12345
12346 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12347 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12348 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12349 SHOW_STR
12350 IP_STR
12351 BGP_STR
12352 "Address family\n"
12353 "Address Family modifier\n"
12354 "Address Family modifier\n"
12355 "Detailed information on TCP and BGP neighbor connections\n"
12356 "Neighbor to display information about\n"
12357 "Neighbor to display information about\n"
12358 "Neighbor on bgp configured interface\n"
12359 "Display detailed prefix count information\n"
12360 "JavaScript Object Notation\n")
12361 {
12362 struct peer *peer;
12363 u_char uj = use_json(argc, argv);
12364
12365 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12366 if (! peer)
12367 return CMD_WARNING;
12368
12369 if (strncmp (argv[0], "m", 1) == 0)
12370 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj);
12371
12372 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12373 }
12374
12375 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12376 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
12377 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12378 SHOW_STR
12379 IP_STR
12380 BGP_STR
12381 "Address family\n"
12382 "Address Family modifier\n"
12383 "Address Family modifier\n"
12384 "Detailed information on TCP and BGP neighbor connections\n"
12385 "Neighbor to display information about\n"
12386 "Neighbor to display information about\n"
12387 "Neighbor on bgp configured interface\n"
12388 "Display detailed prefix count information\n"
12389 "JavaScript Object Notation\n")
12390 {
12391 struct peer *peer;
12392 u_char uj = use_json(argc, argv);
12393
12394 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12395 if (! peer)
12396 return CMD_WARNING;
12397
12398 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
12399 }
12400
12401 static void
12402 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12403 int in, const char *rmap_name, u_char use_json, json_object *json)
12404 {
12405 struct bgp_table *table;
12406 struct bgp_adj_in *ain;
12407 struct bgp_adj_out *adj;
12408 unsigned long output_count;
12409 unsigned long filtered_count;
12410 struct bgp_node *rn;
12411 int header1 = 1;
12412 struct bgp *bgp;
12413 int header2 = 1;
12414 struct attr attr;
12415 struct attr_extra extra;
12416 int ret;
12417 struct update_subgroup *subgrp;
12418 json_object *json_scode = NULL;
12419 json_object *json_ocode = NULL;
12420 json_object *json_ar = NULL;
12421 struct peer_af *paf;
12422
12423 if (use_json)
12424 {
12425 json_scode = json_object_new_object();
12426 json_ocode = json_object_new_object();
12427 json_ar = json_object_new_object();
12428
12429 json_object_string_add(json_scode, "suppressed", "s");
12430 json_object_string_add(json_scode, "damped", "d");
12431 json_object_string_add(json_scode, "history", "h");
12432 json_object_string_add(json_scode, "valid", "*");
12433 json_object_string_add(json_scode, "best", ">");
12434 json_object_string_add(json_scode, "multipath", "=");
12435 json_object_string_add(json_scode, "internal", "i");
12436 json_object_string_add(json_scode, "ribFailure", "r");
12437 json_object_string_add(json_scode, "stale", "S");
12438 json_object_string_add(json_scode, "removed", "R");
12439
12440 json_object_string_add(json_ocode, "igp", "i");
12441 json_object_string_add(json_ocode, "egp", "e");
12442 json_object_string_add(json_ocode, "incomplete", "?");
12443 }
12444
12445 bgp = peer->bgp;
12446
12447 if (! bgp)
12448 {
12449 if (use_json)
12450 {
12451 json_object_string_add(json, "alert", "no BGP");
12452 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12453 json_object_free(json);
12454 }
12455 else
12456 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
12457 return;
12458 }
12459
12460 table = bgp->rib[afi][safi];
12461
12462 output_count = filtered_count = 0;
12463 subgrp = peer_subgroup(peer, afi, safi);
12464
12465 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
12466 {
12467 if (use_json)
12468 {
12469 json_object_int_add(json, "bgpTableVersion", table->version);
12470 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12471 json_object_object_add(json, "bgpStatusCodes", json_scode);
12472 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12473 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
12474 }
12475 else
12476 {
12477 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
12478 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12479 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12480
12481 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12482 VTY_NEWLINE, VTY_NEWLINE);
12483 }
12484 header1 = 0;
12485 }
12486
12487 attr.extra = &extra;
12488 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12489 {
12490 if (in)
12491 {
12492 for (ain = rn->adj_in; ain; ain = ain->next)
12493 {
12494 if (ain->peer == peer)
12495 {
12496 if (header1)
12497 {
12498 if (use_json)
12499 {
12500 json_object_int_add(json, "bgpTableVersion", 0);
12501 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12502 json_object_object_add(json, "bgpStatusCodes", json_scode);
12503 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12504 }
12505 else
12506 {
12507 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12508 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12509 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12510 }
12511 header1 = 0;
12512 }
12513 if (header2)
12514 {
12515 if (!use_json)
12516 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12517 header2 = 0;
12518 }
12519 if (ain->attr)
12520 {
12521 bgp_attr_dup(&attr, ain->attr);
12522 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12523 {
12524 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12525 output_count++;
12526 }
12527 else
12528 filtered_count++;
12529 }
12530 }
12531 }
12532 }
12533 else
12534 {
12535 for (adj = rn->adj_out; adj; adj = adj->next)
12536 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12537 if (paf->peer == peer)
12538 {
12539 if (header1)
12540 {
12541 if (use_json)
12542 {
12543 json_object_int_add(json, "bgpTableVersion", table->version);
12544 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12545 json_object_object_add(json, "bgpStatusCodes", json_scode);
12546 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12547 }
12548 else
12549 {
12550 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12551 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12552 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12553 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12554 }
12555 header1 = 0;
12556 }
12557
12558 if (header2)
12559 {
12560 if (!use_json)
12561 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12562 header2 = 0;
12563 }
12564
12565 if (adj->attr)
12566 {
12567 bgp_attr_dup(&attr, adj->attr);
12568 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12569 if (ret != RMAP_DENY)
12570 {
12571 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12572 output_count++;
12573 }
12574 else
12575 filtered_count++;
12576 }
12577 }
12578 }
12579 }
12580 if (use_json)
12581 json_object_object_add(json, "advertisedRoutes", json_ar);
12582
12583 if (output_count != 0)
12584 {
12585 if (use_json)
12586 json_object_int_add(json, "totalPrefixCounter", output_count);
12587 else
12588 vty_out (vty, "%sTotal number of prefixes %ld%s",
12589 VTY_NEWLINE, output_count, VTY_NEWLINE);
12590 }
12591 if (use_json)
12592 {
12593 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12594 json_object_free(json);
12595 }
12596
12597 }
12598
12599 static int
12600 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12601 int in, const char *rmap_name, u_char use_json)
12602 {
12603 json_object *json = NULL;
12604
12605 if (use_json)
12606 json = json_object_new_object();
12607
12608 if (!peer || !peer->afc[afi][safi])
12609 {
12610 if (use_json)
12611 {
12612 json_object_string_add(json, "warning", "No such neighbor or address family");
12613 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12614 json_object_free(json);
12615 }
12616 else
12617 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12618
12619 return CMD_WARNING;
12620 }
12621
12622 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12623 {
12624 if (use_json)
12625 {
12626 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12627 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12628 json_object_free(json);
12629 }
12630 else
12631 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12632
12633 return CMD_WARNING;
12634 }
12635
12636 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
12637
12638 return CMD_SUCCESS;
12639 }
12640
12641 DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12642 show_ip_bgp_instance_neighbor_advertised_route_cmd,
12643 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12644 SHOW_STR
12645 IP_STR
12646 BGP_STR
12647 BGP_INSTANCE_HELP_STR
12648 "Detailed information on TCP and BGP neighbor connections\n"
12649 "Neighbor to display information about\n"
12650 "Neighbor to display information about\n"
12651 "Display the routes advertised to a BGP neighbor\n"
12652 "JavaScript Object Notation\n")
12653 {
12654 struct peer *peer;
12655 u_char uj = use_json(argc, argv);
12656
12657 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12658 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12659 else
12660 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12661
12662 if (! peer)
12663 return CMD_WARNING;
12664
12665 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
12666 }
12667
12668 DEFUN (show_ip_bgp_neighbor_advertised_route,
12669 show_ip_bgp_neighbor_advertised_route_cmd,
12670 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12671 SHOW_STR
12672 IP_STR
12673 BGP_STR
12674 "Detailed information on TCP and BGP neighbor connections\n"
12675 "Neighbor to display information about\n"
12676 "Neighbor to display information about\n"
12677 "Neighbor on bgp configured interface\n"
12678 "Display the routes advertised to a BGP neighbor\n"
12679 "JavaScript Object Notation\n")
12680
12681 {
12682 struct peer *peer;
12683 const char *rmap_name = NULL;
12684 u_char uj = use_json(argc, argv);
12685
12686 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12687
12688 if (! peer)
12689 return CMD_WARNING;
12690
12691 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12692 || (argc == 3))
12693 rmap_name = argv[1];
12694
12695 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12696 }
12697
12698 ALIAS (show_ip_bgp_neighbor_advertised_route,
12699 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
12700 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12701 SHOW_STR
12702 IP_STR
12703 BGP_STR
12704 "Detailed information on TCP and BGP neighbor connections\n"
12705 "Neighbor to display information about\n"
12706 "Neighbor to display information about\n"
12707 "Neighbor on bgp configured interface\n"
12708 "Display the routes advertised to a BGP neighbor\n"
12709 "JavaScript Object Notation\n")
12710
12711 ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12712 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12713 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12714 SHOW_STR
12715 IP_STR
12716 BGP_STR
12717 BGP_INSTANCE_HELP_STR
12718 "Detailed information on TCP and BGP neighbor connections\n"
12719 "Neighbor to display information about\n"
12720 "Neighbor to display information about\n"
12721 "Neighbor on bgp configured interface\n"
12722 "Display the routes advertised to a BGP neighbor\n"
12723 "JavaScript Object Notation\n")
12724 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12725 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12726 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12727 SHOW_STR
12728 IP_STR
12729 BGP_STR
12730 "Address family\n"
12731 "Address Family modifier\n"
12732 "Address Family modifier\n"
12733 "Detailed information on TCP and BGP neighbor connections\n"
12734 "Neighbor to display information about\n"
12735 "Neighbor to display information about\n"
12736 "Neighbor on bgp configured interface\n"
12737 "Display the routes advertised to a BGP neighbor\n"
12738 "JavaScript Object Notation\n")
12739 {
12740 struct peer *peer;
12741 const char *rmap_name = NULL;
12742 u_char uj = use_json(argc, argv);
12743
12744 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12745 if (! peer)
12746 return CMD_WARNING;
12747
12748 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12749 rmap_name = argv[2];
12750
12751 if (strncmp (argv[0], "m", 1) == 0)
12752 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj);
12753 else
12754 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12755 }
12756
12757 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12758 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
12759 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12760 SHOW_STR
12761 IP_STR
12762 BGP_STR
12763 "Address family\n"
12764 "Address Family modifier\n"
12765 "Address Family modifier\n"
12766 "Detailed information on TCP and BGP neighbor connections\n"
12767 "Neighbor to display information about\n"
12768 "Neighbor to display information about\n"
12769 "Neighbor on bgp configured interface\n"
12770 "Display the routes advertised to a BGP neighbor\n"
12771 "Route-map to control what is displayed\n"
12772 "JavaScript Object Notation\n")
12773
12774 #ifdef HAVE_IPV6
12775 DEFUN (show_bgp_instance_neighbor_advertised_route,
12776 show_bgp_instance_neighbor_advertised_route_cmd,
12777 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12778 SHOW_STR
12779 BGP_STR
12780 BGP_INSTANCE_HELP_STR
12781 "Detailed information on TCP and BGP neighbor connections\n"
12782 "Neighbor to display information about\n"
12783 "Neighbor to display information about\n"
12784 "Neighbor on bgp configured interface\n"
12785 "Display the routes advertised to a BGP neighbor\n"
12786 "JavaScript Object Notation\n")
12787 {
12788 struct peer *peer;
12789 u_char uj = use_json(argc, argv);
12790
12791 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12792 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12793 else
12794 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12795
12796 if (! peer)
12797 return CMD_WARNING;
12798
12799 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
12800 }
12801
12802 ALIAS (show_bgp_instance_neighbor_advertised_route,
12803 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12804 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12805 SHOW_STR
12806 BGP_STR
12807 BGP_INSTANCE_HELP_STR
12808 "Address family\n"
12809 "Detailed information on TCP and BGP neighbor connections\n"
12810 "Neighbor to display information about\n"
12811 "Neighbor to display information about\n"
12812 "Neighbor on bgp configured interface\n"
12813 "Display the routes advertised to a BGP neighbor\n"
12814 "JavaScript Object Notation\n")
12815
12816 DEFUN (show_bgp_neighbor_advertised_route,
12817 show_bgp_neighbor_advertised_route_cmd,
12818 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12819 SHOW_STR
12820 BGP_STR
12821 "Detailed information on TCP and BGP neighbor connections\n"
12822 "Neighbor to display information about\n"
12823 "Neighbor to display information about\n"
12824 "Neighbor on bgp configured interface\n"
12825 "Display the routes advertised to a BGP neighbor\n"
12826 "JavaScript Object Notation\n")
12827
12828 {
12829 struct peer *peer;
12830 const char *rmap_name = NULL;
12831 u_char uj = use_json(argc, argv);
12832
12833 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12834
12835 if (!peer)
12836 return CMD_WARNING;
12837
12838 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12839 rmap_name = argv[1];
12840
12841 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
12842 }
12843
12844 ALIAS (show_bgp_neighbor_advertised_route,
12845 show_bgp_ipv6_neighbor_advertised_route_cmd,
12846 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12847 SHOW_STR
12848 BGP_STR
12849 "Address family\n"
12850 "Detailed information on TCP and BGP neighbor connections\n"
12851 "Neighbor to display information about\n"
12852 "Neighbor to display information about\n"
12853 "Neighbor on bgp configured interface\n"
12854 "Display the routes advertised to a BGP neighbor\n"
12855 "JavaScript Object Notation\n")
12856
12857 /* old command */
12858 ALIAS (show_bgp_neighbor_advertised_route,
12859 ipv6_bgp_neighbor_advertised_route_cmd,
12860 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12861 SHOW_STR
12862 IPV6_STR
12863 BGP_STR
12864 "Detailed information on TCP and BGP neighbor connections\n"
12865 "Neighbor to display information about\n"
12866 "Neighbor to display information about\n"
12867 "Neighbor on bgp configured interface\n"
12868 "Display the routes advertised to a BGP neighbor\n"
12869 "JavaScript Object Notation\n")
12870
12871 /* old command */
12872 DEFUN (ipv6_mbgp_neighbor_advertised_route,
12873 ipv6_mbgp_neighbor_advertised_route_cmd,
12874 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12875 SHOW_STR
12876 IPV6_STR
12877 MBGP_STR
12878 "Detailed information on TCP and BGP neighbor connections\n"
12879 "Neighbor to display information about\n"
12880 "Neighbor to display information about\n"
12881 "Neighbor on bgp configured interface\n"
12882 "Neighbor on bgp configured interface\n"
12883 "Display the routes advertised to a BGP neighbor\n"
12884 "JavaScript Object Notation\n")
12885 {
12886 struct peer *peer;
12887 u_char uj = use_json(argc, argv);
12888
12889 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12890 if (! peer)
12891 return CMD_WARNING;
12892
12893 bgp_show_ipv6_bgp_deprecate_warning(vty);
12894 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
12895 }
12896 #endif /* HAVE_IPV6 */
12897
12898 DEFUN (show_bgp_instance_neighbor_received_routes,
12899 show_bgp_instance_neighbor_received_routes_cmd,
12900 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12901 SHOW_STR
12902 BGP_STR
12903 BGP_INSTANCE_HELP_STR
12904 "Detailed information on TCP and BGP neighbor connections\n"
12905 "Neighbor to display information about\n"
12906 "Neighbor to display information about\n"
12907 "Neighbor on bgp configured interface\n"
12908 "Display the received routes from neighbor\n"
12909 "JavaScript Object Notation\n")
12910 {
12911 struct peer *peer;
12912 u_char uj = use_json(argc, argv);
12913
12914 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12915 if (! peer)
12916 return CMD_WARNING;
12917
12918 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
12919 }
12920
12921 DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12922 show_ip_bgp_instance_neighbor_received_routes_cmd,
12923 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12924 SHOW_STR
12925 IP_STR
12926 BGP_STR
12927 BGP_INSTANCE_HELP_STR
12928 "Detailed information on TCP and BGP neighbor connections\n"
12929 "Neighbor to display information about\n"
12930 "Neighbor to display information about\n"
12931 "Neighbor on bgp configured interface\n"
12932 "Display the received routes from neighbor\n"
12933 "JavaScript Object Notation\n")
12934 {
12935 struct peer *peer;
12936 u_char uj = use_json(argc, argv);
12937
12938 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12939 if (! peer)
12940 return CMD_WARNING;
12941
12942 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
12943 }
12944
12945 ALIAS (show_bgp_instance_neighbor_received_routes,
12946 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12947 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12948 SHOW_STR
12949 BGP_STR
12950 BGP_INSTANCE_HELP_STR
12951 "Address family\n"
12952 "Detailed information on TCP and BGP neighbor connections\n"
12953 "Neighbor to display information about\n"
12954 "Neighbor to display information about\n"
12955 "Neighbor on bgp configured interface\n"
12956 "Display the received routes from neighbor\n"
12957 "JavaScript Object Notation\n")
12958
12959 DEFUN (show_ip_bgp_neighbor_received_routes,
12960 show_ip_bgp_neighbor_received_routes_cmd,
12961 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12962 SHOW_STR
12963 IP_STR
12964 BGP_STR
12965 "Detailed information on TCP and BGP neighbor connections\n"
12966 "Neighbor to display information about\n"
12967 "Neighbor to display information about\n"
12968 "Neighbor on bgp configured interface\n"
12969 "Display the received routes from neighbor\n"
12970 "JavaScript Object Notation\n")
12971
12972 {
12973 struct peer *peer;
12974 const char *rmap_name = NULL;
12975 u_char uj = use_json(argc, argv);
12976
12977 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12978
12979 if (! peer)
12980 return CMD_WARNING;
12981
12982 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12983 rmap_name = argv[1];
12984
12985 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12986 }
12987
12988 ALIAS (show_ip_bgp_neighbor_received_routes,
12989 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12990 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12991 SHOW_STR
12992 IP_STR
12993 BGP_STR
12994 "Detailed information on TCP and BGP neighbor connections\n"
12995 "Neighbor to display information about\n"
12996 "Neighbor to display information about\n"
12997 "Neighbor on bgp configured interface\n"
12998 "Display the received routes from neighbor\n"
12999 "JavaScript Object Notation\n")
13000
13001 ALIAS (show_ip_bgp_instance_neighbor_received_routes,
13002 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
13003 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
13004 SHOW_STR
13005 IP_STR
13006 BGP_STR
13007 BGP_INSTANCE_HELP_STR
13008 "Detailed information on TCP and BGP neighbor connections\n"
13009 "Neighbor to display information about\n"
13010 "Neighbor to display information about\n"
13011 "Neighbor on bgp configured interface\n"
13012 "Display the received routes from neighbor\n"
13013 "JavaScript Object Notation\n")
13014
13015 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
13016 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
13017 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13018 SHOW_STR
13019 IP_STR
13020 BGP_STR
13021 "Address family\n"
13022 "Address Family modifier\n"
13023 "Address Family modifier\n"
13024 "Detailed information on TCP and BGP neighbor connections\n"
13025 "Neighbor to display information about\n"
13026 "Neighbor to display information about\n"
13027 "Neighbor on bgp configured interface\n"
13028 "Display the received routes from neighbor\n"
13029 "JavaScript Object Notation\n")
13030 {
13031 struct peer *peer;
13032 const char *rmap_name = NULL;
13033 u_char uj = use_json(argc, argv);
13034
13035 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13036 if (! peer)
13037 return CMD_WARNING;
13038
13039 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13040 rmap_name = argv[2];
13041
13042 if (strncmp (argv[0], "m", 1) == 0)
13043 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj);
13044 else
13045 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
13046 }
13047
13048 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
13049 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
13050 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
13051 SHOW_STR
13052 IP_STR
13053 BGP_STR
13054 "Address family\n"
13055 "Address Family modifier\n"
13056 "Address Family modifier\n"
13057 "Detailed information on TCP and BGP neighbor connections\n"
13058 "Neighbor to display information about\n"
13059 "Neighbor to display information about\n"
13060 "Neighbor on bgp configured interface\n"
13061 "Display the received routes from neighbor\n"
13062 "JavaScript Object Notation\n")
13063
13064 DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
13065 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
13066 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
13067 SHOW_STR
13068 BGP_STR
13069 BGP_INSTANCE_HELP_STR
13070 "Address family\n"
13071 "Address family\n"
13072 "Address family modifier\n"
13073 "Address family modifier\n"
13074 "Detailed information on TCP and BGP neighbor connections\n"
13075 "Neighbor to display information about\n"
13076 "Neighbor to display information about\n"
13077 "Neighbor on bgp configured interface\n"
13078 "Display the advertised routes to neighbor\n"
13079 "Display the received routes from neighbor\n"
13080 "JavaScript Object Notation\n")
13081 {
13082 int afi;
13083 int safi;
13084 int in;
13085 struct peer *peer;
13086 u_char uj = use_json(argc, argv);
13087
13088 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
13089
13090 if (! peer)
13091 return CMD_WARNING;
13092
13093 afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
13094 safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13095 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
13096
13097 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
13098 }
13099
13100 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
13101 show_ip_bgp_neighbor_received_prefix_filter_cmd,
13102 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13103 SHOW_STR
13104 IP_STR
13105 BGP_STR
13106 "Detailed information on TCP and BGP neighbor connections\n"
13107 "Neighbor to display information about\n"
13108 "Neighbor to display information about\n"
13109 "Neighbor on bgp configured interface\n"
13110 "Display information received from a BGP neighbor\n"
13111 "Display the prefixlist filter\n"
13112 "JavaScript Object Notation\n")
13113 {
13114 char name[BUFSIZ];
13115 union sockunion su;
13116 struct peer *peer;
13117 int count, ret;
13118 u_char uj = use_json(argc, argv);
13119
13120 ret = str2sockunion (argv[0], &su);
13121 if (ret < 0)
13122 {
13123 peer = peer_lookup_by_conf_if (NULL, argv[0]);
13124 if (! peer)
13125 {
13126 if (uj)
13127 {
13128 json_object *json_no = NULL;
13129 json_object *json_sub = NULL;
13130 json_no = json_object_new_object();
13131 json_sub = json_object_new_object();
13132 json_object_string_add(json_no, "warning", "Malformed address or name");
13133 json_object_string_add(json_sub, "warningCause", argv[0]);
13134 json_object_object_add(json_no, "detail", json_sub);
13135 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13136 json_object_free(json_no);
13137 }
13138 else
13139 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
13140 return CMD_WARNING;
13141 }
13142 }
13143 else
13144 {
13145 peer = peer_lookup (NULL, &su);
13146 if (! peer)
13147 {
13148 if (uj)
13149 {
13150 json_object *json_no = NULL;
13151 json_no = json_object_new_object();
13152 json_object_string_add(json_no, "warning", "Peer not found");
13153 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13154 json_object_free(json_no);
13155 }
13156 else
13157 vty_out (vty, "No peer%s", VTY_NEWLINE);
13158 return CMD_WARNING;
13159 }
13160 }
13161
13162 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13163 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13164 if (count)
13165 {
13166 if (!uj)
13167 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13168 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13169 }
13170 else
13171 {
13172 if (uj)
13173 {
13174 json_object *json_no = NULL;
13175 json_no = json_object_new_object();
13176 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13177 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13178 json_object_free(json_no);
13179 }
13180 else
13181 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13182 }
13183
13184 return CMD_SUCCESS;
13185 }
13186
13187 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13188 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13189 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13190 SHOW_STR
13191 IP_STR
13192 BGP_STR
13193 "Address family\n"
13194 "Address Family modifier\n"
13195 "Address Family modifier\n"
13196 "Detailed information on TCP and BGP neighbor connections\n"
13197 "Neighbor to display information about\n"
13198 "Neighbor to display information about\n"
13199 "Neighbor on bgp configured interface\n"
13200 "Display information received from a BGP neighbor\n"
13201 "Display the prefixlist filter\n"
13202 "JavaScript Object Notation\n")
13203 {
13204 char name[BUFSIZ];
13205 union sockunion su;
13206 struct peer *peer;
13207 int count, ret;
13208 u_char uj = use_json(argc, argv);
13209
13210 ret = str2sockunion (argv[1], &su);
13211 if (ret < 0)
13212 {
13213 peer = peer_lookup_by_conf_if (NULL, argv[1]);
13214 if (! peer)
13215 {
13216 if (uj)
13217 {
13218 json_object *json_no = NULL;
13219 json_object *json_sub = NULL;
13220 json_no = json_object_new_object();
13221 json_sub = json_object_new_object();
13222 json_object_string_add(json_no, "warning", "Malformed address or name");
13223 json_object_string_add(json_sub, "warningCause", argv[1]);
13224 json_object_object_add(json_no, "detail", json_sub);
13225 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13226 json_object_free(json_no);
13227 }
13228 else
13229 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
13230 return CMD_WARNING;
13231 }
13232 }
13233 else
13234 {
13235 peer = peer_lookup (NULL, &su);
13236 if (! peer)
13237 {
13238 if (uj)
13239 {
13240 json_object *json_no = NULL;
13241 json_no = json_object_new_object();
13242 json_object_string_add(json_no, "warning", "Peer not found");
13243 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13244 json_object_free(json_no);
13245 }
13246 else
13247 vty_out (vty, "No peer%s", VTY_NEWLINE);
13248 return CMD_WARNING;
13249 }
13250 }
13251
13252 if (strncmp (argv[0], "m", 1) == 0)
13253 {
13254 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
13255 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13256 if (count)
13257 {
13258 if (!uj)
13259 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13260 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13261 }
13262 else
13263 {
13264 if (uj)
13265 {
13266 json_object *json_no = NULL;
13267 json_no = json_object_new_object();
13268 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13269 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13270 json_object_free(json_no);
13271 }
13272 else
13273 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13274 }
13275 }
13276 else
13277 {
13278 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13279 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13280 if (count)
13281 {
13282 if (!uj)
13283 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13284 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13285 }
13286 else
13287 {
13288 if (uj)
13289 {
13290 json_object *json_no = NULL;
13291 json_no = json_object_new_object();
13292 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13293 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13294 json_object_free(json_no);
13295 }
13296 else
13297 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13298 }
13299 }
13300
13301 return CMD_SUCCESS;
13302 }
13303 #ifdef HAVE_IPV6
13304 DEFUN (show_bgp_neighbor_received_routes,
13305 show_bgp_neighbor_received_routes_cmd,
13306 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13307 SHOW_STR
13308 BGP_STR
13309 "Detailed information on TCP and BGP neighbor connections\n"
13310 "Neighbor to display information about\n"
13311 "Neighbor to display information about\n"
13312 "Neighbor on bgp configured interface\n"
13313 "Display the received routes from neighbor\n"
13314 "JavaScript Object Notation\n")
13315 {
13316 struct peer *peer;
13317 const char *rmap_name = NULL;
13318 u_char uj = use_json(argc, argv);
13319
13320 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13321
13322 if (! peer)
13323 return CMD_WARNING;
13324
13325 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
13326 rmap_name = argv[1];
13327
13328 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
13329 }
13330
13331 ALIAS (show_bgp_neighbor_received_routes,
13332 show_bgp_ipv6_neighbor_received_routes_cmd,
13333 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13334 SHOW_STR
13335 BGP_STR
13336 "Address family\n"
13337 "Detailed information on TCP and BGP neighbor connections\n"
13338 "Neighbor to display information about\n"
13339 "Neighbor to display information about\n"
13340 "Neighbor on bgp configured interface\n"
13341 "Display the received routes from neighbor\n"
13342 "JavaScript Object Notation\n")
13343
13344 DEFUN (show_bgp_neighbor_received_prefix_filter,
13345 show_bgp_neighbor_received_prefix_filter_cmd,
13346 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13347 SHOW_STR
13348 BGP_STR
13349 "Detailed information on TCP and BGP neighbor connections\n"
13350 "Neighbor to display information about\n"
13351 "Neighbor to display information about\n"
13352 "Neighbor on bgp configured interface\n"
13353 "Display information received from a BGP neighbor\n"
13354 "Display the prefixlist filter\n"
13355 "JavaScript Object Notation\n")
13356 {
13357 char name[BUFSIZ];
13358 union sockunion su;
13359 struct peer *peer;
13360 int count, ret;
13361 u_char uj = use_json(argc, argv);
13362
13363 ret = str2sockunion (argv[0], &su);
13364 if (ret < 0)
13365 {
13366 peer = peer_lookup_by_conf_if (NULL, argv[0]);
13367 if (! peer)
13368 {
13369 if (uj)
13370 {
13371 json_object *json_no = NULL;
13372 json_object *json_sub = NULL;
13373 json_no = json_object_new_object();
13374 json_sub = json_object_new_object();
13375 json_object_string_add(json_no, "warning", "Malformed address or name");
13376 json_object_string_add(json_sub, "warningCause", argv[0]);
13377 json_object_object_add(json_no, "detail", json_sub);
13378 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13379 json_object_free(json_no);
13380 }
13381 else
13382 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
13383 return CMD_WARNING;
13384 }
13385 }
13386 else
13387 {
13388 peer = peer_lookup (NULL, &su);
13389 if (! peer)
13390 {
13391 if (uj)
13392 {
13393 json_object *json_no = NULL;
13394 json_no = json_object_new_object();
13395 json_object_string_add(json_no, "warning", "No Peer");
13396 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13397 json_object_free(json_no);
13398 }
13399 else
13400 vty_out (vty, "No peer%s", VTY_NEWLINE);
13401 return CMD_WARNING;
13402 }
13403 }
13404
13405 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13406 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13407 if (count)
13408 {
13409 if (!uj)
13410 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13411 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13412 }
13413 else
13414 {
13415 if (uj)
13416 {
13417 json_object *json_no = NULL;
13418 json_no = json_object_new_object();
13419 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13420 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13421 json_object_free(json_no);
13422 }
13423 else
13424 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13425 }
13426
13427 return CMD_SUCCESS;
13428 }
13429
13430 ALIAS (show_bgp_neighbor_received_prefix_filter,
13431 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13432 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13433 SHOW_STR
13434 BGP_STR
13435 "Address family\n"
13436 "Detailed information on TCP and BGP neighbor connections\n"
13437 "Neighbor to display information about\n"
13438 "Neighbor to display information about\n"
13439 "Neighbor on bgp configured interface\n"
13440 "Display information received from a BGP neighbor\n"
13441 "Display the prefixlist filter\n"
13442 "JavaScript Object Notation\n")
13443
13444 /* old command */
13445 ALIAS (show_bgp_neighbor_received_routes,
13446 ipv6_bgp_neighbor_received_routes_cmd,
13447 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13448 SHOW_STR
13449 IPV6_STR
13450 BGP_STR
13451 "Detailed information on TCP and BGP neighbor connections\n"
13452 "Neighbor to display information about\n"
13453 "Neighbor to display information about\n"
13454 "Neighbor on bgp configured interface\n"
13455 "Display the received routes from neighbor\n"
13456 "JavaScript Object Notation\n")
13457
13458 /* old command */
13459 DEFUN (ipv6_mbgp_neighbor_received_routes,
13460 ipv6_mbgp_neighbor_received_routes_cmd,
13461 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13462 SHOW_STR
13463 IPV6_STR
13464 MBGP_STR
13465 "Detailed information on TCP and BGP neighbor connections\n"
13466 "Neighbor to display information about\n"
13467 "Neighbor to display information about\n"
13468 "Neighbor on bgp configured interface\n"
13469 "Display the received routes from neighbor\n"
13470 "JavaScript Object Notation\n")
13471 {
13472 struct peer *peer;
13473 u_char uj = use_json(argc, argv);
13474
13475 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13476 if (! peer)
13477 return CMD_WARNING;
13478
13479 bgp_show_ipv6_bgp_deprecate_warning(vty);
13480 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
13481 }
13482
13483 DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
13484 show_bgp_instance_neighbor_received_prefix_filter_cmd,
13485 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13486 SHOW_STR
13487 BGP_STR
13488 BGP_INSTANCE_HELP_STR
13489 "Detailed information on TCP and BGP neighbor connections\n"
13490 "Neighbor to display information about\n"
13491 "Neighbor to display information about\n"
13492 "Neighbor on bgp configured interface\n"
13493 "Display information received from a BGP neighbor\n"
13494 "Display the prefixlist filter\n"
13495 "JavaScript Object Notation\n")
13496 {
13497 char name[BUFSIZ];
13498 union sockunion su;
13499 struct peer *peer;
13500 struct bgp *bgp;
13501 int count, ret;
13502 u_char uj = use_json(argc, argv);
13503
13504 /* BGP structure lookup. */
13505 bgp = bgp_lookup_by_name (argv[1]);
13506 if (bgp == NULL)
13507 {
13508 if (uj)
13509 {
13510 json_object *json_no = NULL;
13511 json_no = json_object_new_object();
13512 json_object_string_add(json_no, "warning", "Can't find BGP view");
13513 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13514 json_object_free(json_no);
13515 }
13516 else
13517 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
13518 return CMD_WARNING;
13519 }
13520
13521 ret = str2sockunion (argv[2], &su);
13522 if (ret < 0)
13523 {
13524 peer = peer_lookup_by_conf_if (bgp, argv[2]);
13525 if (! peer)
13526 {
13527 if (uj)
13528 {
13529 json_object *json_no = NULL;
13530 json_object *json_sub = NULL;
13531 json_no = json_object_new_object();
13532 json_sub = json_object_new_object();
13533 json_object_string_add(json_no, "warning", "Malformed address or name");
13534 json_object_string_add(json_sub, "warningCause", argv[2]);
13535 json_object_object_add(json_no, "detail", json_sub);
13536 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13537 json_object_free(json_no);
13538 }
13539 else
13540 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
13541 return CMD_WARNING;
13542 }
13543 }
13544 else
13545 {
13546 peer = peer_lookup (bgp, &su);
13547 if (! peer)
13548 {
13549 if (uj)
13550 {
13551 json_object *json_no = NULL;
13552 json_no = json_object_new_object();
13553 json_object_boolean_true_add(json_no, "noPeer");
13554 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13555 json_object_free(json_no);
13556 }
13557 else
13558 vty_out (vty, "No peer%s", VTY_NEWLINE);
13559 return CMD_WARNING;
13560 }
13561
13562 }
13563
13564 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13565 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13566 if (count)
13567 {
13568 if (!uj)
13569 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13570 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13571 }
13572
13573 return CMD_SUCCESS;
13574 }
13575 ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
13576 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
13577 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13578 SHOW_STR
13579 BGP_STR
13580 BGP_INSTANCE_HELP_STR
13581 "Address family\n"
13582 "Detailed information on TCP and BGP neighbor connections\n"
13583 "Neighbor to display information about\n"
13584 "Neighbor to display information about\n"
13585 "Neighbor on bgp configured interface\n"
13586 "Display information received from a BGP neighbor\n"
13587 "Display the prefixlist filter\n"
13588 "JavaScript Object NOtation\n")
13589 #endif /* HAVE_IPV6 */
13590
13591 static int
13592 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
13593 safi_t safi, enum bgp_show_type type, u_char use_json)
13594 {
13595 if (! peer || ! peer->afc[afi][safi])
13596 {
13597 if (use_json)
13598 {
13599 json_object *json_no = NULL;
13600 json_no = json_object_new_object();
13601 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13602 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13603 json_object_free(json_no);
13604 }
13605 else
13606 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
13607 return CMD_WARNING;
13608 }
13609
13610 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
13611 }
13612
13613 DEFUN (show_ip_bgp_neighbor_routes,
13614 show_ip_bgp_neighbor_routes_cmd,
13615 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13616 SHOW_STR
13617 IP_STR
13618 BGP_STR
13619 "Detailed information on TCP and BGP neighbor connections\n"
13620 "Neighbor to display information about\n"
13621 "Neighbor to display information about\n"
13622 "Neighbor on bgp configured interface\n"
13623 "Display routes learned from neighbor\n"
13624 "JavaScript Object Notation\n")
13625 {
13626 struct peer *peer;
13627 u_char uj = use_json(argc, argv);
13628
13629 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13630 if (! peer)
13631 return CMD_WARNING;
13632
13633 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13634 bgp_show_type_neighbor, uj);
13635 }
13636
13637 DEFUN (show_ip_bgp_instance_neighbor_routes,
13638 show_ip_bgp_instance_neighbor_routes_cmd,
13639 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13640 SHOW_STR
13641 IP_STR
13642 BGP_STR
13643 BGP_INSTANCE_HELP_STR
13644 "Detailed information on TCP and BGP neighbor connections\n"
13645 "Neighbor to display information about\n"
13646 "Neighbor to display information about\n"
13647 "Neighbor on bgp configured interface\n"
13648 "Display routes learned from neighbor\n"
13649 "JavaScript Object Notation\n")
13650 {
13651 struct peer *peer;
13652 u_char uj = use_json(argc, argv);
13653
13654 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13655 if (! peer)
13656 return CMD_WARNING;
13657
13658 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13659 bgp_show_type_neighbor, uj);
13660 }
13661
13662 DEFUN (show_ip_bgp_neighbor_flap,
13663 show_ip_bgp_neighbor_flap_cmd,
13664 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13665 SHOW_STR
13666 IP_STR
13667 BGP_STR
13668 "Detailed information on TCP and BGP neighbor connections\n"
13669 "Neighbor to display information about\n"
13670 "Neighbor to display information about\n"
13671 "Neighbor on bgp configured interface\n"
13672 "Display flap statistics of the routes learned from neighbor\n"
13673 "JavaScript Object Notation\n")
13674 {
13675 struct peer *peer;
13676 u_char uj = use_json(argc, argv);
13677
13678 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13679 if (! peer)
13680 return CMD_WARNING;
13681
13682 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13683 bgp_show_type_flap_neighbor, uj);
13684 }
13685
13686 DEFUN (show_ip_bgp_neighbor_damp,
13687 show_ip_bgp_neighbor_damp_cmd,
13688 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13689 SHOW_STR
13690 IP_STR
13691 BGP_STR
13692 "Detailed information on TCP and BGP neighbor connections\n"
13693 "Neighbor to display information about\n"
13694 "Neighbor to display information about\n"
13695 "Neighbor on bgp configured interface\n"
13696 "Display the dampened routes received from neighbor\n"
13697 "JavaScript Object Notation\n")
13698 {
13699 struct peer *peer;
13700 u_char uj = use_json(argc, argv);
13701
13702 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13703 if (! peer)
13704 return CMD_WARNING;
13705
13706 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13707 bgp_show_type_damp_neighbor, uj);
13708 }
13709
13710 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13711 show_ip_bgp_ipv4_neighbor_routes_cmd,
13712 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13713 SHOW_STR
13714 IP_STR
13715 BGP_STR
13716 "Address family\n"
13717 "Address Family modifier\n"
13718 "Address Family modifier\n"
13719 "Detailed information on TCP and BGP neighbor connections\n"
13720 "Neighbor to display information about\n"
13721 "Neighbor to display information about\n"
13722 "Neighbor on bgp configured interface\n"
13723 "Display routes learned from neighbor\n"
13724 "JavaScript Object Notation\n")
13725 {
13726 struct peer *peer;
13727 u_char uj = use_json(argc, argv);
13728
13729 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13730 if (! peer)
13731 return CMD_WARNING;
13732
13733 if (strncmp (argv[0], "m", 1) == 0)
13734 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13735 bgp_show_type_neighbor, uj);
13736
13737 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13738 bgp_show_type_neighbor, uj);
13739 }
13740
13741 #ifdef HAVE_IPV6
13742 DEFUN (show_bgp_instance_neighbor_routes,
13743 show_bgp_instance_neighbor_routes_cmd,
13744 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13745 SHOW_STR
13746 BGP_STR
13747 BGP_INSTANCE_HELP_STR
13748 "Detailed information on TCP and BGP neighbor connections\n"
13749 "Neighbor to display information about\n"
13750 "Neighbor to display information about\n"
13751 "Neighbor on bgp configured interface\n"
13752 "Display routes learned from neighbor\n"
13753 "JavaScript Object Notation\n")
13754 {
13755 struct peer *peer;
13756 u_char uj = use_json(argc, argv);
13757
13758 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13759 if (! peer)
13760 return CMD_WARNING;
13761
13762 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13763 bgp_show_type_neighbor, uj);
13764 }
13765
13766 ALIAS (show_bgp_instance_neighbor_routes,
13767 show_bgp_instance_ipv6_neighbor_routes_cmd,
13768 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13769 SHOW_STR
13770 BGP_STR
13771 BGP_INSTANCE_HELP_STR
13772 "Address family\n"
13773 "Detailed information on TCP and BGP neighbor connections\n"
13774 "Neighbor to display information about\n"
13775 "Neighbor to display information about\n"
13776 "Neighbor on bgp configured interface\n"
13777 "Display routes learned from neighbor\n"
13778 "JavaScript Object Notation\n")
13779
13780 DEFUN (show_bgp_instance_neighbor_damp,
13781 show_bgp_instance_neighbor_damp_cmd,
13782 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13783 SHOW_STR
13784 BGP_STR
13785 BGP_INSTANCE_HELP_STR
13786 "Detailed information on TCP and BGP neighbor connections\n"
13787 "Neighbor to display information about\n"
13788 "Neighbor to display information about\n"
13789 "Neighbor on bgp configured interface\n"
13790 "Display the dampened routes received from neighbor\n"
13791 "JavaScript Object Notation\n")
13792 {
13793 struct peer *peer;
13794 u_char uj = use_json(argc, argv);
13795
13796 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13797 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13798 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13799 else
13800 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13801
13802 if (! peer)
13803 return CMD_WARNING;
13804
13805 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13806 bgp_show_type_damp_neighbor, uj);
13807 }
13808
13809 ALIAS (show_bgp_instance_neighbor_damp,
13810 show_bgp_instance_ipv6_neighbor_damp_cmd,
13811 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13812 SHOW_STR
13813 BGP_STR
13814 BGP_INSTANCE_HELP_STR
13815 "Address family\n"
13816 "Detailed information on TCP and BGP neighbor connections\n"
13817 "Neighbor to display information about\n"
13818 "Neighbor to display information about\n"
13819 "Neighbor on bgp configured interface\n"
13820 "Display the dampened routes received from neighbor\n"
13821 "JavaScript Object Notation\n")
13822
13823 DEFUN (show_bgp_instance_neighbor_flap,
13824 show_bgp_instance_neighbor_flap_cmd,
13825 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13826 SHOW_STR
13827 BGP_STR
13828 BGP_INSTANCE_HELP_STR
13829 "Detailed information on TCP and BGP neighbor connections\n"
13830 "Neighbor to display information about\n"
13831 "Neighbor to display information about\n"
13832 "Neighbor on bgp configured interface\n"
13833 "Display flap statistics of the routes learned from neighbor\n"
13834 "JavaScript Object Notation\n")
13835 {
13836 struct peer *peer;
13837 u_char uj = use_json(argc, argv);
13838
13839 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13840 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13841 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13842 else
13843 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13844
13845 if (! peer)
13846 return CMD_WARNING;
13847
13848 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13849 bgp_show_type_flap_neighbor, uj);
13850 }
13851
13852 ALIAS (show_bgp_instance_neighbor_flap,
13853 show_bgp_instance_ipv6_neighbor_flap_cmd,
13854 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13855 SHOW_STR
13856 BGP_STR
13857 BGP_INSTANCE_HELP_STR
13858 "Address family\n"
13859 "Detailed information on TCP and BGP neighbor connections\n"
13860 "Neighbor to display information about\n"
13861 "Neighbor to display information about\n"
13862 "Neighbor on bgp configured interface\n"
13863 "Display flap statistics of the routes learned from neighbor\n"
13864 "JavaScript Object Notation\n")
13865
13866 DEFUN (show_bgp_neighbor_routes,
13867 show_bgp_neighbor_routes_cmd,
13868 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13869 SHOW_STR
13870 BGP_STR
13871 "Detailed information on TCP and BGP neighbor connections\n"
13872 "Neighbor to display information about\n"
13873 "Neighbor to display information about\n"
13874 "Neighbor on bgp configured interface\n"
13875 "Display routes learned from neighbor\n"
13876 "JavaScript Object Notation\n")
13877 {
13878 struct peer *peer;
13879 u_char uj = use_json(argc, argv);
13880
13881 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13882 if (! peer)
13883 return CMD_WARNING;
13884
13885 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13886 bgp_show_type_neighbor, uj);
13887 }
13888
13889
13890 ALIAS (show_bgp_neighbor_routes,
13891 show_bgp_ipv6_neighbor_routes_cmd,
13892 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13893 SHOW_STR
13894 BGP_STR
13895 "Address family\n"
13896 "Detailed information on TCP and BGP neighbor connections\n"
13897 "Neighbor to display information about\n"
13898 "Neighbor to display information about\n"
13899 "Neighbor on bgp configured interface\n"
13900 "Display routes learned from neighbor\n"
13901 "JavaScript Object Notation\n")
13902
13903 /* old command */
13904 ALIAS (show_bgp_neighbor_routes,
13905 ipv6_bgp_neighbor_routes_cmd,
13906 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13907 SHOW_STR
13908 IPV6_STR
13909 BGP_STR
13910 "Detailed information on TCP and BGP neighbor connections\n"
13911 "Neighbor to display information about\n"
13912 "Neighbor to display information about\n"
13913 "Neighbor on bgp configured interface\n"
13914 "Display routes learned from neighbor\n"
13915 "JavaScript Object Notation\n")
13916
13917 /* old command */
13918 DEFUN (ipv6_mbgp_neighbor_routes,
13919 ipv6_mbgp_neighbor_routes_cmd,
13920 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13921 SHOW_STR
13922 IPV6_STR
13923 MBGP_STR
13924 "Detailed information on TCP and BGP neighbor connections\n"
13925 "Neighbor to display information about\n"
13926 "Neighbor to display information about\n"
13927 "Neighbor on bgp configured interface\n"
13928 "Display routes learned from neighbor\n"
13929 "JavaScript Object Notation\n")
13930 {
13931 struct peer *peer;
13932 u_char uj = use_json(argc, argv);
13933
13934 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13935 if (! peer)
13936 return CMD_WARNING;
13937
13938 bgp_show_ipv6_bgp_deprecate_warning(vty);
13939 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
13940 bgp_show_type_neighbor, uj);
13941 }
13942
13943 ALIAS (show_bgp_instance_neighbor_flap,
13944 show_bgp_neighbor_flap_cmd,
13945 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13946 SHOW_STR
13947 BGP_STR
13948 "Detailed information on TCP and BGP neighbor connections\n"
13949 "Neighbor to display information about\n"
13950 "Neighbor to display information about\n"
13951 "Neighbor on bgp configured interface\n"
13952 "Display flap statistics of the routes learned from neighbor\n"
13953 "JavaScript Object Notation\n")
13954
13955 ALIAS (show_bgp_instance_neighbor_flap,
13956 show_bgp_ipv6_neighbor_flap_cmd,
13957 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13958 SHOW_STR
13959 BGP_STR
13960 "Address family\n"
13961 "Detailed information on TCP and BGP neighbor connections\n"
13962 "Neighbor to display information about\n"
13963 "Neighbor to display information about\n"
13964 "Neighbor on bgp configured interface\n"
13965 "Display flap statistics of the routes learned from neighbor\n"
13966 "JavaScript Object Notation\n")
13967
13968 ALIAS (show_bgp_instance_neighbor_damp,
13969 show_bgp_neighbor_damp_cmd,
13970 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13971 SHOW_STR
13972 BGP_STR
13973 "Detailed information on TCP and BGP neighbor connections\n"
13974 "Neighbor to display information about\n"
13975 "Neighbor to display information about\n"
13976 "Neighbor on bgp configured interface\n"
13977 "Display the dampened routes received from neighbor\n"
13978 "JavaScript Object Notation\n")
13979
13980 ALIAS (show_bgp_instance_neighbor_damp,
13981 show_bgp_ipv6_neighbor_damp_cmd,
13982 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13983 SHOW_STR
13984 BGP_STR
13985 "Address family\n"
13986 "Detailed information on TCP and BGP neighbor connections\n"
13987 "Neighbor to display information about\n"
13988 "Neighbor to display information about\n"
13989 "Neighbor on bgp configured interface\n"
13990 "Display the dampened routes received from neighbor\n"
13991 "JavaScript Object Notation\n")
13992
13993 #endif /* HAVE_IPV6 */
13994
13995 struct bgp_table *bgp_distance_table;
13996
13997 struct bgp_distance
13998 {
13999 /* Distance value for the IP source prefix. */
14000 u_char distance;
14001
14002 /* Name of the access-list to be matched. */
14003 char *access_list;
14004 };
14005
14006 static struct bgp_distance *
14007 bgp_distance_new (void)
14008 {
14009 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
14010 }
14011
14012 static void
14013 bgp_distance_free (struct bgp_distance *bdistance)
14014 {
14015 XFREE (MTYPE_BGP_DISTANCE, bdistance);
14016 }
14017
14018 static int
14019 bgp_distance_set (struct vty *vty, const char *distance_str,
14020 const char *ip_str, const char *access_list_str)
14021 {
14022 int ret;
14023 struct prefix_ipv4 p;
14024 u_char distance;
14025 struct bgp_node *rn;
14026 struct bgp_distance *bdistance;
14027
14028 ret = str2prefix_ipv4 (ip_str, &p);
14029 if (ret == 0)
14030 {
14031 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14032 return CMD_WARNING;
14033 }
14034
14035 distance = atoi (distance_str);
14036
14037 /* Get BGP distance node. */
14038 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
14039 if (rn->info)
14040 {
14041 bdistance = rn->info;
14042 bgp_unlock_node (rn);
14043 }
14044 else
14045 {
14046 bdistance = bgp_distance_new ();
14047 rn->info = bdistance;
14048 }
14049
14050 /* Set distance value. */
14051 bdistance->distance = distance;
14052
14053 /* Reset access-list configuration. */
14054 if (bdistance->access_list)
14055 {
14056 XFREE(MTYPE_AS_LIST, bdistance->access_list);
14057 bdistance->access_list = NULL;
14058 }
14059 if (access_list_str)
14060 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
14061
14062 return CMD_SUCCESS;
14063 }
14064
14065 static int
14066 bgp_distance_unset (struct vty *vty, const char *distance_str,
14067 const char *ip_str, const char *access_list_str)
14068 {
14069 int ret;
14070 int distance;
14071 struct prefix_ipv4 p;
14072 struct bgp_node *rn;
14073 struct bgp_distance *bdistance;
14074
14075 ret = str2prefix_ipv4 (ip_str, &p);
14076 if (ret == 0)
14077 {
14078 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14079 return CMD_WARNING;
14080 }
14081
14082 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
14083 if (! rn)
14084 {
14085 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
14086 return CMD_WARNING;
14087 }
14088
14089 bdistance = rn->info;
14090 distance = atoi(distance_str);
14091
14092 if (bdistance->distance != distance)
14093 {
14094 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
14095 return CMD_WARNING;
14096 }
14097
14098 if (bdistance->access_list)
14099 XFREE(MTYPE_AS_LIST, bdistance->access_list);
14100 bgp_distance_free (bdistance);
14101
14102 rn->info = NULL;
14103 bgp_unlock_node (rn);
14104 bgp_unlock_node (rn);
14105
14106 return CMD_SUCCESS;
14107 }
14108
14109 /* Apply BGP information to distance method. */
14110 u_char
14111 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
14112 {
14113 struct bgp_node *rn;
14114 struct prefix_ipv4 q;
14115 struct peer *peer;
14116 struct bgp_distance *bdistance;
14117 struct access_list *alist;
14118 struct bgp_static *bgp_static;
14119
14120 if (! bgp)
14121 return 0;
14122
14123 if (p->family != AF_INET)
14124 return 0;
14125
14126 peer = rinfo->peer;
14127
14128 if (peer->su.sa.sa_family != AF_INET)
14129 return 0;
14130
14131 memset (&q, 0, sizeof (struct prefix_ipv4));
14132 q.family = AF_INET;
14133 q.prefix = peer->su.sin.sin_addr;
14134 q.prefixlen = IPV4_MAX_BITLEN;
14135
14136 /* Check source address. */
14137 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
14138 if (rn)
14139 {
14140 bdistance = rn->info;
14141 bgp_unlock_node (rn);
14142
14143 if (bdistance->access_list)
14144 {
14145 alist = access_list_lookup (AFI_IP, bdistance->access_list);
14146 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
14147 return bdistance->distance;
14148 }
14149 else
14150 return bdistance->distance;
14151 }
14152
14153 /* Backdoor check. */
14154 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
14155 if (rn)
14156 {
14157 bgp_static = rn->info;
14158 bgp_unlock_node (rn);
14159
14160 if (bgp_static->backdoor)
14161 {
14162 if (bgp->distance_local)
14163 return bgp->distance_local;
14164 else
14165 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14166 }
14167 }
14168
14169 if (peer->sort == BGP_PEER_EBGP)
14170 {
14171 if (bgp->distance_ebgp)
14172 return bgp->distance_ebgp;
14173 return ZEBRA_EBGP_DISTANCE_DEFAULT;
14174 }
14175 else
14176 {
14177 if (bgp->distance_ibgp)
14178 return bgp->distance_ibgp;
14179 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14180 }
14181 }
14182
14183 DEFUN (bgp_distance,
14184 bgp_distance_cmd,
14185 "distance bgp <1-255> <1-255> <1-255>",
14186 "Define an administrative distance\n"
14187 "BGP distance\n"
14188 "Distance for routes external to the AS\n"
14189 "Distance for routes internal to the AS\n"
14190 "Distance for local routes\n")
14191 {
14192 struct bgp *bgp;
14193
14194 bgp = vty->index;
14195
14196 bgp->distance_ebgp = atoi (argv[0]);
14197 bgp->distance_ibgp = atoi (argv[1]);
14198 bgp->distance_local = atoi (argv[2]);
14199 return CMD_SUCCESS;
14200 }
14201
14202 DEFUN (no_bgp_distance,
14203 no_bgp_distance_cmd,
14204 "no distance bgp <1-255> <1-255> <1-255>",
14205 NO_STR
14206 "Define an administrative distance\n"
14207 "BGP distance\n"
14208 "Distance for routes external to the AS\n"
14209 "Distance for routes internal to the AS\n"
14210 "Distance for local routes\n")
14211 {
14212 struct bgp *bgp;
14213
14214 bgp = vty->index;
14215
14216 bgp->distance_ebgp= 0;
14217 bgp->distance_ibgp = 0;
14218 bgp->distance_local = 0;
14219 return CMD_SUCCESS;
14220 }
14221
14222 ALIAS (no_bgp_distance,
14223 no_bgp_distance2_cmd,
14224 "no distance bgp",
14225 NO_STR
14226 "Define an administrative distance\n"
14227 "BGP distance\n")
14228
14229 DEFUN (bgp_distance_source,
14230 bgp_distance_source_cmd,
14231 "distance <1-255> A.B.C.D/M",
14232 "Define an administrative distance\n"
14233 "Administrative distance\n"
14234 "IP source prefix\n")
14235 {
14236 bgp_distance_set (vty, argv[0], argv[1], NULL);
14237 return CMD_SUCCESS;
14238 }
14239
14240 DEFUN (no_bgp_distance_source,
14241 no_bgp_distance_source_cmd,
14242 "no distance <1-255> A.B.C.D/M",
14243 NO_STR
14244 "Define an administrative distance\n"
14245 "Administrative distance\n"
14246 "IP source prefix\n")
14247 {
14248 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14249 return CMD_SUCCESS;
14250 }
14251
14252 DEFUN (bgp_distance_source_access_list,
14253 bgp_distance_source_access_list_cmd,
14254 "distance <1-255> A.B.C.D/M WORD",
14255 "Define an administrative distance\n"
14256 "Administrative distance\n"
14257 "IP source prefix\n"
14258 "Access list name\n")
14259 {
14260 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14261 return CMD_SUCCESS;
14262 }
14263
14264 DEFUN (no_bgp_distance_source_access_list,
14265 no_bgp_distance_source_access_list_cmd,
14266 "no distance <1-255> A.B.C.D/M WORD",
14267 NO_STR
14268 "Define an administrative distance\n"
14269 "Administrative distance\n"
14270 "IP source prefix\n"
14271 "Access list name\n")
14272 {
14273 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14274 return CMD_SUCCESS;
14275 }
14276
14277 DEFUN (bgp_damp_set,
14278 bgp_damp_set_cmd,
14279 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14280 "BGP Specific commands\n"
14281 "Enable route-flap dampening\n"
14282 "Half-life time for the penalty\n"
14283 "Value to start reusing a route\n"
14284 "Value to start suppressing a route\n"
14285 "Maximum duration to suppress a stable route\n")
14286 {
14287 struct bgp *bgp;
14288 int half = DEFAULT_HALF_LIFE * 60;
14289 int reuse = DEFAULT_REUSE;
14290 int suppress = DEFAULT_SUPPRESS;
14291 int max = 4 * half;
14292
14293 if (argc == 4)
14294 {
14295 half = atoi (argv[0]) * 60;
14296 reuse = atoi (argv[1]);
14297 suppress = atoi (argv[2]);
14298 max = atoi (argv[3]) * 60;
14299 }
14300 else if (argc == 1)
14301 {
14302 half = atoi (argv[0]) * 60;
14303 max = 4 * half;
14304 }
14305
14306 bgp = vty->index;
14307
14308 if (suppress < reuse)
14309 {
14310 vty_out (vty, "Suppress value cannot be less than reuse value %s",
14311 VTY_NEWLINE);
14312 return 0;
14313 }
14314
14315 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14316 half, reuse, suppress, max);
14317 }
14318
14319 ALIAS (bgp_damp_set,
14320 bgp_damp_set2_cmd,
14321 "bgp dampening <1-45>",
14322 "BGP Specific commands\n"
14323 "Enable route-flap dampening\n"
14324 "Half-life time for the penalty\n")
14325
14326 ALIAS (bgp_damp_set,
14327 bgp_damp_set3_cmd,
14328 "bgp dampening",
14329 "BGP Specific commands\n"
14330 "Enable route-flap dampening\n")
14331
14332 DEFUN (bgp_damp_unset,
14333 bgp_damp_unset_cmd,
14334 "no bgp dampening",
14335 NO_STR
14336 "BGP Specific commands\n"
14337 "Enable route-flap dampening\n")
14338 {
14339 struct bgp *bgp;
14340
14341 bgp = vty->index;
14342 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14343 }
14344
14345 ALIAS (bgp_damp_unset,
14346 bgp_damp_unset2_cmd,
14347 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14348 NO_STR
14349 "BGP Specific commands\n"
14350 "Enable route-flap dampening\n"
14351 "Half-life time for the penalty\n"
14352 "Value to start reusing a route\n"
14353 "Value to start suppressing a route\n"
14354 "Maximum duration to suppress a stable route\n")
14355
14356 ALIAS (bgp_damp_unset,
14357 bgp_damp_unset3_cmd,
14358 "no bgp dampening <1-45>",
14359 NO_STR
14360 "BGP Specific commands\n"
14361 "Enable route-flap dampening\n"
14362 "Half-life time for the penalty\n")
14363
14364 DEFUN (show_ip_bgp_dampened_paths,
14365 show_ip_bgp_dampened_paths_cmd,
14366 "show ip bgp dampened-paths",
14367 SHOW_STR
14368 IP_STR
14369 BGP_STR
14370 "Display paths suppressed due to dampening\n")
14371 {
14372 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
14373 NULL, 0);
14374 }
14375
14376 ALIAS (show_ip_bgp_dampened_paths,
14377 show_ip_bgp_damp_dampened_paths_cmd,
14378 "show ip bgp dampening dampened-paths",
14379 SHOW_STR
14380 IP_STR
14381 BGP_STR
14382 "Display detailed information about dampening\n"
14383 "Display paths suppressed due to dampening\n")
14384
14385 DEFUN (show_ip_bgp_flap_statistics,
14386 show_ip_bgp_flap_statistics_cmd,
14387 "show ip bgp flap-statistics",
14388 SHOW_STR
14389 IP_STR
14390 BGP_STR
14391 "Display flap statistics of routes\n")
14392 {
14393 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
14394 bgp_show_type_flap_statistics, NULL, 0);
14395 }
14396
14397 ALIAS (show_ip_bgp_flap_statistics,
14398 show_ip_bgp_damp_flap_statistics_cmd,
14399 "show ip bgp dampening flap-statistics",
14400 SHOW_STR
14401 IP_STR
14402 BGP_STR
14403 "Display detailed information about dampening\n"
14404 "Display flap statistics of routes\n")
14405
14406 /* Display specified route of BGP table. */
14407 static int
14408 bgp_clear_damp_route (struct vty *vty, const char *view_name,
14409 const char *ip_str, afi_t afi, safi_t safi,
14410 struct prefix_rd *prd, int prefix_check)
14411 {
14412 int ret;
14413 struct prefix match;
14414 struct bgp_node *rn;
14415 struct bgp_node *rm;
14416 struct bgp_info *ri;
14417 struct bgp_info *ri_temp;
14418 struct bgp *bgp;
14419 struct bgp_table *table;
14420
14421 /* BGP structure lookup. */
14422 if (view_name)
14423 {
14424 bgp = bgp_lookup_by_name (view_name);
14425 if (bgp == NULL)
14426 {
14427 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
14428 return CMD_WARNING;
14429 }
14430 }
14431 else
14432 {
14433 bgp = bgp_get_default ();
14434 if (bgp == NULL)
14435 {
14436 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14437 return CMD_WARNING;
14438 }
14439 }
14440
14441 /* Check IP address argument. */
14442 ret = str2prefix (ip_str, &match);
14443 if (! ret)
14444 {
14445 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14446 return CMD_WARNING;
14447 }
14448
14449 match.family = afi2family (afi);
14450
14451 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
14452 {
14453 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
14454 {
14455 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14456 continue;
14457
14458 if ((table = rn->info) != NULL)
14459 if ((rm = bgp_node_match (table, &match)) != NULL)
14460 {
14461 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14462 {
14463 ri = rm->info;
14464 while (ri)
14465 {
14466 if (ri->extra && ri->extra->damp_info)
14467 {
14468 ri_temp = ri->next;
14469 bgp_damp_info_free (ri->extra->damp_info, 1);
14470 ri = ri_temp;
14471 }
14472 else
14473 ri = ri->next;
14474 }
14475 }
14476
14477 bgp_unlock_node (rm);
14478 }
14479 }
14480 }
14481 else
14482 {
14483 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
14484 {
14485 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14486 {
14487 ri = rn->info;
14488 while (ri)
14489 {
14490 if (ri->extra && ri->extra->damp_info)
14491 {
14492 ri_temp = ri->next;
14493 bgp_damp_info_free (ri->extra->damp_info, 1);
14494 ri = ri_temp;
14495 }
14496 else
14497 ri = ri->next;
14498 }
14499 }
14500
14501 bgp_unlock_node (rn);
14502 }
14503 }
14504
14505 return CMD_SUCCESS;
14506 }
14507
14508 DEFUN (clear_ip_bgp_dampening,
14509 clear_ip_bgp_dampening_cmd,
14510 "clear ip bgp dampening",
14511 CLEAR_STR
14512 IP_STR
14513 BGP_STR
14514 "Clear route flap dampening information\n")
14515 {
14516 bgp_damp_info_clean ();
14517 return CMD_SUCCESS;
14518 }
14519
14520 DEFUN (clear_ip_bgp_dampening_prefix,
14521 clear_ip_bgp_dampening_prefix_cmd,
14522 "clear ip bgp dampening A.B.C.D/M",
14523 CLEAR_STR
14524 IP_STR
14525 BGP_STR
14526 "Clear route flap dampening information\n"
14527 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14528 {
14529 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14530 SAFI_UNICAST, NULL, 1);
14531 }
14532
14533 DEFUN (clear_ip_bgp_dampening_address,
14534 clear_ip_bgp_dampening_address_cmd,
14535 "clear ip bgp dampening A.B.C.D",
14536 CLEAR_STR
14537 IP_STR
14538 BGP_STR
14539 "Clear route flap dampening information\n"
14540 "Network to clear damping information\n")
14541 {
14542 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14543 SAFI_UNICAST, NULL, 0);
14544 }
14545
14546 DEFUN (clear_ip_bgp_dampening_address_mask,
14547 clear_ip_bgp_dampening_address_mask_cmd,
14548 "clear ip bgp dampening A.B.C.D A.B.C.D",
14549 CLEAR_STR
14550 IP_STR
14551 BGP_STR
14552 "Clear route flap dampening information\n"
14553 "Network to clear damping information\n"
14554 "Network mask\n")
14555 {
14556 int ret;
14557 char prefix_str[BUFSIZ];
14558
14559 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14560 if (! ret)
14561 {
14562 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14563 return CMD_WARNING;
14564 }
14565
14566 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14567 SAFI_UNICAST, NULL, 0);
14568 }
14569
14570 /* also used for encap safi */
14571 static int
14572 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14573 afi_t afi, safi_t safi, int *write)
14574 {
14575 struct bgp_node *prn;
14576 struct bgp_node *rn;
14577 struct bgp_table *table;
14578 struct prefix *p;
14579 struct prefix_rd *prd;
14580 struct bgp_static *bgp_static;
14581 u_int32_t label;
14582 char buf[SU_ADDRSTRLEN];
14583 char rdbuf[RD_ADDRSTRLEN];
14584
14585 /* Network configuration. */
14586 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14587 if ((table = prn->info) != NULL)
14588 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14589 if ((bgp_static = rn->info) != NULL)
14590 {
14591 p = &rn->p;
14592 prd = (struct prefix_rd *) &prn->p;
14593
14594 /* "address-family" display. */
14595 bgp_config_write_family_header (vty, afi, safi, write);
14596
14597 /* "network" configuration display. */
14598 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14599 label = decode_label (bgp_static->tag);
14600
14601 vty_out (vty, " network %s/%d rd %s tag %d",
14602 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14603 p->prefixlen,
14604 rdbuf, label);
14605 vty_out (vty, "%s", VTY_NEWLINE);
14606 }
14607 return 0;
14608 }
14609
14610 /* Configuration of static route announcement and aggregate
14611 information. */
14612 int
14613 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14614 afi_t afi, safi_t safi, int *write)
14615 {
14616 struct bgp_node *rn;
14617 struct prefix *p;
14618 struct bgp_static *bgp_static;
14619 struct bgp_aggregate *bgp_aggregate;
14620 char buf[SU_ADDRSTRLEN];
14621
14622 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
14623 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14624
14625 /* Network configuration. */
14626 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14627 if ((bgp_static = rn->info) != NULL)
14628 {
14629 p = &rn->p;
14630
14631 /* "address-family" display. */
14632 bgp_config_write_family_header (vty, afi, safi, write);
14633
14634 /* "network" configuration display. */
14635 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14636 {
14637 u_int32_t destination;
14638 struct in_addr netmask;
14639
14640 destination = ntohl (p->u.prefix4.s_addr);
14641 masklen2ip (p->prefixlen, &netmask);
14642 vty_out (vty, " network %s",
14643 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14644
14645 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14646 || (IN_CLASSB (destination) && p->prefixlen == 16)
14647 || (IN_CLASSA (destination) && p->prefixlen == 8)
14648 || p->u.prefix4.s_addr == 0)
14649 {
14650 /* Natural mask is not display. */
14651 }
14652 else
14653 vty_out (vty, " mask %s", inet_ntoa (netmask));
14654 }
14655 else
14656 {
14657 vty_out (vty, " network %s/%d",
14658 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14659 p->prefixlen);
14660 }
14661
14662 if (bgp_static->rmap.name)
14663 vty_out (vty, " route-map %s", bgp_static->rmap.name);
14664 else
14665 {
14666 if (bgp_static->backdoor)
14667 vty_out (vty, " backdoor");
14668 }
14669
14670 vty_out (vty, "%s", VTY_NEWLINE);
14671 }
14672
14673 /* Aggregate-address configuration. */
14674 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14675 if ((bgp_aggregate = rn->info) != NULL)
14676 {
14677 p = &rn->p;
14678
14679 /* "address-family" display. */
14680 bgp_config_write_family_header (vty, afi, safi, write);
14681
14682 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14683 {
14684 struct in_addr netmask;
14685
14686 masklen2ip (p->prefixlen, &netmask);
14687 vty_out (vty, " aggregate-address %s %s",
14688 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14689 inet_ntoa (netmask));
14690 }
14691 else
14692 {
14693 vty_out (vty, " aggregate-address %s/%d",
14694 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14695 p->prefixlen);
14696 }
14697
14698 if (bgp_aggregate->as_set)
14699 vty_out (vty, " as-set");
14700
14701 if (bgp_aggregate->summary_only)
14702 vty_out (vty, " summary-only");
14703
14704 vty_out (vty, "%s", VTY_NEWLINE);
14705 }
14706
14707 return 0;
14708 }
14709
14710 int
14711 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
14712 {
14713 struct bgp_node *rn;
14714 struct bgp_distance *bdistance;
14715
14716 /* Distance configuration. */
14717 if (bgp->distance_ebgp
14718 && bgp->distance_ibgp
14719 && bgp->distance_local
14720 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
14721 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
14722 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
14723 vty_out (vty, " distance bgp %d %d %d%s",
14724 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
14725 VTY_NEWLINE);
14726
14727 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
14728 if ((bdistance = rn->info) != NULL)
14729 {
14730 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
14731 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
14732 bdistance->access_list ? bdistance->access_list : "",
14733 VTY_NEWLINE);
14734 }
14735
14736 return 0;
14737 }
14738
14739 /* Allocate routing table structure and install commands. */
14740 void
14741 bgp_route_init (void)
14742 {
14743 /* Init BGP distance table. */
14744 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
14745
14746 /* IPv4 BGP commands. */
14747 install_element (BGP_NODE, &bgp_table_map_cmd);
14748 install_element (BGP_NODE, &bgp_network_cmd);
14749 install_element (BGP_NODE, &bgp_network_mask_cmd);
14750 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14751 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14752 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14753 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14754 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14755 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14756 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
14757 install_element (BGP_NODE, &no_bgp_table_map_cmd);
14758 install_element (BGP_NODE, &no_bgp_network_cmd);
14759 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14760 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14761 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14762 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14763 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14764 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14765 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14766 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14767
14768 install_element (BGP_NODE, &aggregate_address_cmd);
14769 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14770 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14771 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14772 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14773 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14774 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14775 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14776 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14777 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14778 install_element (BGP_NODE, &no_aggregate_address_cmd);
14779 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14780 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14781 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14782 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14783 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14784 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14785 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14786 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14787 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14788
14789 /* IPv4 unicast configuration. */
14790 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
14791 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14792 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14793 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14794 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14795 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14796 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
14797 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
14798 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
14799 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14800 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14801 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14802 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14803 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14804
14805 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14806 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14807 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14808 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14809 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14810 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14811 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14812 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14813 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14814 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14815 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14816 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14817 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14818 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14819 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14820 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14821 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14822 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14823 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14824 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14825
14826 /* IPv4 multicast configuration. */
14827 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
14828 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14829 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14830 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14831 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14832 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14833 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
14834 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
14835 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14836 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14837 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14838 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14839 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14840 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14841 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14842 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14843 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14844 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14845 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14846 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14847 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14848 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14849 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14850 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14851 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14852 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14853 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14854 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14855 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14856 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14857 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14858 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14859 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14860 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14861
14862 install_element (VIEW_NODE, &show_ip_bgp_cmd);
14863 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
14864 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
14865 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
14866 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
14867 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
14868 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
14869 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14870 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14871 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14872 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
14873 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
14874 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
14875 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14876 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14877 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
14878 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14879 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14880 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14881 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14882 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14883 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14884 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14885 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14886
14887 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14888 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14889 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14890 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14891 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14892 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14893 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
14894 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14895 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14896 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
14897 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14898 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14899 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14900 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14901 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14902 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14903 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14904 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14905 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14906 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14907 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14908 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14909 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
14910 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14911 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14912 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14913 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14914 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14915 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14916 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14917 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14918 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14919 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14920 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14921 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14922 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14923 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14924 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
14925 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14926 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14927 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14928 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14929 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14930 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14931 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14932 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14933 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14934 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14935 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14936 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14937 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14938 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14939 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14940 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14941 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14942 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14943 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14944 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
14945 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14946 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14947 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14948 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14949 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
14950 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
14951 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14952 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
14953 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
14954 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
14955 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14956 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
14957 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14958 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
14959 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14960 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14961 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
14962 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14963 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14964 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
14965 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14966 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14967 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14968 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
14969 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14970 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
14971 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14972 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
14973
14974 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
14975 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
14976 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14977 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
14978 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14979 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14980 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
14981 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
14982 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
14983 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
14984 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
14985 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14986 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14987 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14988 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14989 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14990 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14991 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
14992 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
14993 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_route_cmd);
14994 install_element (RESTRICTED_NODE, &show_ip_bgp_instance_prefix_cmd);
14995 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
14996 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
14997 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
14998 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
14999 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
15000 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
15001 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
15002 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
15003 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
15004 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community_cmd);
15005 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community2_cmd);
15006 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community3_cmd);
15007 install_element (RESTRICTED_NODE, &show_bgp_instance_afi_safi_community4_cmd);
15008 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
15009 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
15010 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
15011 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
15012 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
15013 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
15014 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
15015 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
15016
15017 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
15018 install_element (ENABLE_NODE, &show_ip_bgp_instance_cmd);
15019 install_element (ENABLE_NODE, &show_ip_bgp_instance_all_cmd);
15020 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
15021 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
15022 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
15023 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_cmd);
15024 install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd);
15025 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
15026 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
15027 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
15028 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
15029 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
15030 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
15031 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
15032 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_cmd);
15033 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
15034 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
15035 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
15036 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
15037 install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd);
15038 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
15039 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
15040 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
15041
15042 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
15043 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
15044 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
15045 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_list_cmd);
15046 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
15047 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
15048 install_element (ENABLE_NODE, &show_ip_bgp_instance_filter_list_cmd);
15049 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
15050 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
15051 install_element (ENABLE_NODE, &show_ip_bgp_instance_route_map_cmd);
15052 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
15053 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
15054 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
15055 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
15056 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
15057 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
15058 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
15059 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
15060 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
15061 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
15062 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
15063 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
15064 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
15065 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
15066 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community_cmd);
15067 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community2_cmd);
15068 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community3_cmd);
15069 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_community4_cmd);
15070 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
15071 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
15072 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
15073 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
15074 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
15075 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
15076 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
15077 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
15078 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
15079 install_element (ENABLE_NODE, &show_ip_bgp_instance_community_list_cmd);
15080 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
15081 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
15082 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
15083 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
15084 install_element (ENABLE_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
15085 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
15086 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
15087 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
15088 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
15089 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
15090 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
15091 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
15092 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
15093 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
15094 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
15095 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
15096 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
15097 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
15098 install_element (ENABLE_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
15099 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
15100 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
15101 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
15102 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
15103 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
15104 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
15105 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
15106 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
15107 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
15108 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
15109 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
15110 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
15111 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
15112 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
15113 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
15114 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
15115 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
15116 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
15117 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
15118 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
15119 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
15120 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
15121 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
15122 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
15123 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
15124 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
15125 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
15126 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
15127 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
15128 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
15129 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
15130
15131 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
15132 install_element (ENABLE_NODE, &show_bgp_ipv4_prefix_cmd);
15133 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
15134 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
15135 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
15136 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_route_cmd);
15137
15138 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
15139 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
15140 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
15141 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_route_cmd);
15142
15143 /* BGP dampening clear commands */
15144 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
15145 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
15146 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
15147 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
15148
15149 /* prefix count */
15150 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
15151 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
15152 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
15153 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
15154 #ifdef HAVE_IPV6
15155 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
15156 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
15157
15158 /* New config IPv6 BGP commands. */
15159 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
15160 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
15161 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
15162 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
15163 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
15164 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
15165
15166 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
15167 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
15168 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
15169 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
15170
15171 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
15172 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
15173
15174 /* Old config IPv6 BGP commands. */
15175 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
15176 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
15177
15178 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
15179 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
15180 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
15181 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
15182
15183 install_element (VIEW_NODE, &show_bgp_cmd);
15184 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
15185 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
15186 install_element (VIEW_NODE, &show_bgp_route_cmd);
15187 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
15188 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
15189 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
15190 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15191 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
15192 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
15193 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
15194 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
15195 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
15196 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15197 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
15198 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
15199 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
15200 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
15201 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
15202 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
15203 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
15204 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
15205 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
15206 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
15207 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
15208 install_element (VIEW_NODE, &show_bgp_community_cmd);
15209 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
15210 install_element (VIEW_NODE, &show_bgp_community2_cmd);
15211 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
15212 install_element (VIEW_NODE, &show_bgp_community3_cmd);
15213 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
15214 install_element (VIEW_NODE, &show_bgp_community4_cmd);
15215 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
15216 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
15217 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
15218 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
15219 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
15220 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
15221 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
15222 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
15223 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
15224 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
15225 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
15226 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
15227 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
15228 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
15229 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
15230 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
15231 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
15232 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
15233 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
15234 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
15235 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
15236 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
15237 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
15238 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
15239 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
15240 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
15241 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
15242 install_element (VIEW_NODE, &show_bgp_instance_cmd);
15243 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
15244 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
15245 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
15246 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
15247 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
15248 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
15249 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
15250 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
15251 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
15252 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
15253 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
15254 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
15255 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
15256 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
15257 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
15258 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
15259 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
15260 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
15261 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
15262 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
15263 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
15264 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
15265 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
15266 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
15267 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
15268 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
15269 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
15270 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
15271 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
15272 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
15273 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
15274 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
15275
15276 /* Restricted:
15277 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
15278 */
15279 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
15280 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
15281 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
15282 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
15283 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15284 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
15285 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
15286 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
15287 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
15288 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
15289 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15290 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
15291 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
15292 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
15293 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
15294 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
15295 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
15296 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
15297 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
15298 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
15299 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
15300 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
15301 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
15302 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
15303 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
15304 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
15305 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
15306 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
15307 install_element (RESTRICTED_NODE, &show_bgp_instance_route_cmd);
15308 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_cmd);
15309 install_element (RESTRICTED_NODE, &show_bgp_instance_route_pathtype_cmd);
15310 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
15311 install_element (RESTRICTED_NODE, &show_bgp_instance_prefix_cmd);
15312 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_prefix_cmd);
15313 install_element (RESTRICTED_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
15314 install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
15315
15316 install_element (ENABLE_NODE, &show_bgp_cmd);
15317 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
15318 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
15319 install_element (ENABLE_NODE, &show_bgp_route_cmd);
15320 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
15321 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
15322 install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd);
15323 install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd);
15324 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
15325 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
15326 install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd);
15327 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
15328 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
15329 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
15330 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
15331 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
15332 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
15333 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
15334 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
15335 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
15336 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
15337 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
15338 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
15339 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
15340 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
15341 install_element (ENABLE_NODE, &show_bgp_community_cmd);
15342 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
15343 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
15344 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
15345 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
15346 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
15347 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
15348 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
15349 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
15350 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
15351 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
15352 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
15353 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
15354 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
15355 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
15356 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
15357 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
15358 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
15359 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
15360 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
15361 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
15362 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
15363 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
15364 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
15365 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
15366 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
15367 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
15368 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
15369 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
15370 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
15371 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
15372 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
15373 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
15374 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
15375 install_element (ENABLE_NODE, &show_bgp_instance_cmd);
15376 install_element (ENABLE_NODE, &show_bgp_instance_all_cmd);
15377 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_cmd);
15378 install_element (ENABLE_NODE, &show_bgp_instance_route_cmd);
15379 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_cmd);
15380 install_element (ENABLE_NODE, &show_bgp_instance_route_pathtype_cmd);
15381 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
15382 install_element (ENABLE_NODE, &show_bgp_instance_prefix_cmd);
15383 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_cmd);
15384 install_element (ENABLE_NODE, &show_bgp_instance_prefix_pathtype_cmd);
15385 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
15386 install_element (ENABLE_NODE, &show_bgp_instance_prefix_list_cmd);
15387 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
15388 install_element (ENABLE_NODE, &show_bgp_instance_filter_list_cmd);
15389 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
15390 install_element (ENABLE_NODE, &show_bgp_instance_route_map_cmd);
15391 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_route_map_cmd);
15392 install_element (ENABLE_NODE, &show_bgp_instance_community_list_cmd);
15393 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_community_list_cmd);
15394 install_element (ENABLE_NODE, &show_bgp_instance_prefix_longer_cmd);
15395 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
15396 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
15397 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
15398 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
15399 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
15400 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_routes_cmd);
15401 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
15402 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
15403 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
15404 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_flap_cmd);
15405 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
15406 install_element (ENABLE_NODE, &show_bgp_instance_neighbor_damp_cmd);
15407 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
15408
15409 /* Statistics */
15410 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
15411 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
15412 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
15413 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
15414
15415 /* old command */
15416 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
15417 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
15418 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
15419 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
15420 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
15421 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
15422 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
15423 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
15424 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
15425 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
15426 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
15427 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
15428 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
15429 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
15430 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
15431 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
15432 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15433 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15434 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
15435 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
15436 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
15437 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
15438 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15439 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
15440 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
15441 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
15442 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
15443 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
15444 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
15445 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
15446 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15447 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15448 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15449 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15450 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15451 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15452
15453 /* old command */
15454 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
15455 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
15456 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
15457 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
15458 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
15459 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
15460 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
15461 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
15462 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
15463 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
15464 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
15465 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
15466 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
15467 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
15468 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
15469 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
15470 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15471 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15472 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
15473 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
15474 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
15475 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
15476 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15477 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
15478 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
15479 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
15480 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
15481 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
15482 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
15483 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
15484 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15485 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15486 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15487 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
15488 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15489 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15490
15491 /* old command */
15492 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15493 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15494 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15495 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15496
15497 /* old command */
15498 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15499 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15500 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15501 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15502
15503 /* old command */
15504 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
15505 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
15506 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15507 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15508 #endif /* HAVE_IPV6 */
15509
15510 install_element (BGP_NODE, &bgp_distance_cmd);
15511 install_element (BGP_NODE, &no_bgp_distance_cmd);
15512 install_element (BGP_NODE, &no_bgp_distance2_cmd);
15513 install_element (BGP_NODE, &bgp_distance_source_cmd);
15514 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15515 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15516 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
15517
15518 install_element (BGP_NODE, &bgp_damp_set_cmd);
15519 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15520 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15521 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15522 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
15523 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
15524 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15525 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15526 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15527 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15528 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
15529 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
15530
15531 /* IPv4 Multicast Mode */
15532 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
15533 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
15534 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
15535 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
15536 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
15537 }
15538
15539 void
15540 bgp_route_finish (void)
15541 {
15542 bgp_table_unlock (bgp_distance_table);
15543 bgp_distance_table = NULL;
15544 }