]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
bgpd: convert 'show_ip_bgp_vpnv4' to afi/safi form (Issue #61)
[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 "log.h"
31 #include "routemap.h"
32 #include "buffer.h"
33 #include "sockunion.h"
34 #include "plist.h"
35 #include "thread.h"
36 #include "workqueue.h"
37 #include "queue.h"
38 #include "memory.h"
39
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_table.h"
42 #include "bgpd/bgp_route.h"
43 #include "bgpd/bgp_attr.h"
44 #include "bgpd/bgp_debug.h"
45 #include "bgpd/bgp_aspath.h"
46 #include "bgpd/bgp_regex.h"
47 #include "bgpd/bgp_community.h"
48 #include "bgpd/bgp_ecommunity.h"
49 #include "bgpd/bgp_clist.h"
50 #include "bgpd/bgp_packet.h"
51 #include "bgpd/bgp_filter.h"
52 #include "bgpd/bgp_fsm.h"
53 #include "bgpd/bgp_mplsvpn.h"
54 #include "bgpd/bgp_nexthop.h"
55 #include "bgpd/bgp_damp.h"
56 #include "bgpd/bgp_advertise.h"
57 #include "bgpd/bgp_zebra.h"
58 #include "bgpd/bgp_vty.h"
59 #include "bgpd/bgp_mpath.h"
60 #include "bgpd/bgp_nht.h"
61 #include "bgpd/bgp_updgrp.h"
62 #include "bgpd/bgp_vty.h"
63
64 #if ENABLE_BGP_VNC
65 #include "bgpd/rfapi/rfapi_backend.h"
66 #include "bgpd/rfapi/vnc_import_bgp.h"
67 #include "bgpd/rfapi/vnc_export_bgp.h"
68 #endif
69
70 /* Extern from bgp_dump.c */
71 extern const char *bgp_origin_str[];
72 extern const char *bgp_origin_long_str[];
73
74 struct bgp_node *
75 bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
76 struct prefix_rd *prd)
77 {
78 struct bgp_node *rn;
79 struct bgp_node *prn = NULL;
80
81 assert (table);
82 if (!table)
83 return NULL;
84
85 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
86 {
87 prn = bgp_node_get (table, (struct prefix *) prd);
88
89 if (prn->info == NULL)
90 prn->info = bgp_table_init (afi, safi);
91 else
92 bgp_unlock_node (prn);
93 table = prn->info;
94 }
95
96 rn = bgp_node_get (table, p);
97
98 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
99 rn->prn = prn;
100
101 return rn;
102 }
103
104 /* Allocate bgp_info_extra */
105 static struct bgp_info_extra *
106 bgp_info_extra_new (void)
107 {
108 struct bgp_info_extra *new;
109 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
110 return new;
111 }
112
113 static void
114 bgp_info_extra_free (struct bgp_info_extra **extra)
115 {
116 if (extra && *extra)
117 {
118 if ((*extra)->damp_info)
119 bgp_damp_info_free ((*extra)->damp_info, 0);
120
121 (*extra)->damp_info = NULL;
122
123 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
124
125 *extra = NULL;
126 }
127 }
128
129 /* Get bgp_info extra information for the given bgp_info, lazy allocated
130 * if required.
131 */
132 struct bgp_info_extra *
133 bgp_info_extra_get (struct bgp_info *ri)
134 {
135 if (!ri->extra)
136 ri->extra = bgp_info_extra_new();
137 return ri->extra;
138 }
139
140 /* Allocate new bgp info structure. */
141 struct bgp_info *
142 bgp_info_new (void)
143 {
144 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
145 }
146
147 /* Free bgp route information. */
148 static void
149 bgp_info_free (struct bgp_info *binfo)
150 {
151 if (binfo->attr)
152 bgp_attr_unintern (&binfo->attr);
153
154 bgp_unlink_nexthop(binfo);
155 bgp_info_extra_free (&binfo->extra);
156 bgp_info_mpath_free (&binfo->mpath);
157
158 peer_unlock (binfo->peer); /* bgp_info peer reference */
159
160 XFREE (MTYPE_BGP_ROUTE, binfo);
161 }
162
163 struct bgp_info *
164 bgp_info_lock (struct bgp_info *binfo)
165 {
166 binfo->lock++;
167 return binfo;
168 }
169
170 struct bgp_info *
171 bgp_info_unlock (struct bgp_info *binfo)
172 {
173 assert (binfo && binfo->lock > 0);
174 binfo->lock--;
175
176 if (binfo->lock == 0)
177 {
178 #if 0
179 zlog_debug ("%s: unlocked and freeing", __func__);
180 zlog_backtrace (LOG_DEBUG);
181 #endif
182 bgp_info_free (binfo);
183 return NULL;
184 }
185
186 #if 0
187 if (binfo->lock == 1)
188 {
189 zlog_debug ("%s: unlocked to 1", __func__);
190 zlog_backtrace (LOG_DEBUG);
191 }
192 #endif
193
194 return binfo;
195 }
196
197 void
198 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
199 {
200 struct bgp_info *top;
201
202 top = rn->info;
203
204 ri->next = rn->info;
205 ri->prev = NULL;
206 if (top)
207 top->prev = ri;
208 rn->info = ri;
209
210 bgp_info_lock (ri);
211 bgp_lock_node (rn);
212 peer_lock (ri->peer); /* bgp_info peer reference */
213 }
214
215 /* Do the actual removal of info from RIB, for use by bgp_process
216 completion callback *only* */
217 static void
218 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
219 {
220 if (ri->next)
221 ri->next->prev = ri->prev;
222 if (ri->prev)
223 ri->prev->next = ri->next;
224 else
225 rn->info = ri->next;
226
227 bgp_info_mpath_dequeue (ri);
228 bgp_info_unlock (ri);
229 bgp_unlock_node (rn);
230 }
231
232 void
233 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
234 {
235 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
236 /* set of previous already took care of pcount */
237 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
238 }
239
240 /* undo the effects of a previous call to bgp_info_delete; typically
241 called when a route is deleted and then quickly re-added before the
242 deletion has been processed */
243 void
244 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
245 {
246 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
247 /* unset of previous already took care of pcount */
248 SET_FLAG (ri->flags, BGP_INFO_VALID);
249 }
250
251 /* Adjust pcount as required */
252 static void
253 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
254 {
255 struct bgp_table *table;
256
257 assert (rn && bgp_node_table (rn));
258 assert (ri && ri->peer && ri->peer->bgp);
259
260 table = bgp_node_table (rn);
261
262 if (ri->peer == ri->peer->bgp->peer_self)
263 return;
264
265 if (!BGP_INFO_COUNTABLE (ri)
266 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
267 {
268
269 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
270
271 /* slight hack, but more robust against errors. */
272 if (ri->peer->pcount[table->afi][table->safi])
273 ri->peer->pcount[table->afi][table->safi]--;
274 else
275 {
276 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
277 __func__, ri->peer->host);
278 zlog_backtrace (LOG_WARNING);
279 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
280 }
281 }
282 else if (BGP_INFO_COUNTABLE (ri)
283 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
284 {
285 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
286 ri->peer->pcount[table->afi][table->safi]++;
287 }
288 }
289
290
291 /* Set/unset bgp_info flags, adjusting any other state as needed.
292 * This is here primarily to keep prefix-count in check.
293 */
294 void
295 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
296 {
297 SET_FLAG (ri->flags, flag);
298
299 /* early bath if we know it's not a flag that changes countability state */
300 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
301 return;
302
303 bgp_pcount_adjust (rn, ri);
304 }
305
306 void
307 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
308 {
309 UNSET_FLAG (ri->flags, flag);
310
311 /* early bath if we know it's not a flag that changes countability state */
312 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
313 return;
314
315 bgp_pcount_adjust (rn, ri);
316 }
317
318 /* Get MED value. If MED value is missing and "bgp bestpath
319 missing-as-worst" is specified, treat it as the worst value. */
320 static u_int32_t
321 bgp_med_value (struct attr *attr, struct bgp *bgp)
322 {
323 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
324 return attr->med;
325 else
326 {
327 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
328 return BGP_MED_MAX;
329 else
330 return 0;
331 }
332 }
333
334 void
335 bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf)
336 {
337 if (ri->addpath_rx_id)
338 sprintf(buf, "path %s (addpath rxid %d)", ri->peer->host, ri->addpath_rx_id);
339 else
340 sprintf(buf, "path %s", ri->peer->host);
341 }
342
343 /* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */
344 static int
345 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
346 int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
347 const char *pfx_buf)
348 {
349 struct attr *newattr, *existattr;
350 struct attr_extra *newattre, *existattre;
351 bgp_peer_sort_t new_sort;
352 bgp_peer_sort_t exist_sort;
353 u_int32_t new_pref;
354 u_int32_t exist_pref;
355 u_int32_t new_med;
356 u_int32_t exist_med;
357 u_int32_t new_weight;
358 u_int32_t exist_weight;
359 uint32_t newm, existm;
360 struct in_addr new_id;
361 struct in_addr exist_id;
362 int new_cluster;
363 int exist_cluster;
364 int internal_as_route;
365 int confed_as_route;
366 int ret;
367 char new_buf[PATH_ADDPATH_STR_BUFFER];
368 char exist_buf[PATH_ADDPATH_STR_BUFFER];
369
370 *paths_eq = 0;
371
372 /* 0. Null check. */
373 if (new == NULL)
374 {
375 if (debug)
376 zlog_debug("%s: new is NULL", pfx_buf);
377 return 0;
378 }
379
380 if (debug)
381 bgp_info_path_with_addpath_rx_str (new, new_buf);
382
383 if (exist == NULL)
384 {
385 if (debug)
386 zlog_debug("%s: %s is the initial bestpath", pfx_buf, new_buf);
387 return 1;
388 }
389
390 if (debug)
391 {
392 bgp_info_path_with_addpath_rx_str (exist, exist_buf);
393 zlog_debug("%s: Comparing %s flags 0x%x with %s flags 0x%x",
394 pfx_buf, new_buf, new->flags, exist_buf, exist->flags);
395 }
396
397 newattr = new->attr;
398 existattr = exist->attr;
399 newattre = newattr->extra;
400 existattre = existattr->extra;
401
402 /* 1. Weight check. */
403 new_weight = exist_weight = 0;
404
405 if (newattre)
406 new_weight = newattre->weight;
407 if (existattre)
408 exist_weight = existattre->weight;
409
410 if (new_weight > exist_weight)
411 {
412 if (debug)
413 zlog_debug("%s: %s wins over %s due to weight %d > %d",
414 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
415 return 1;
416 }
417
418 if (new_weight < exist_weight)
419 {
420 if (debug)
421 zlog_debug("%s: %s loses to %s due to weight %d < %d",
422 pfx_buf, new_buf, exist_buf, new_weight, exist_weight);
423 return 0;
424 }
425
426 /* 2. Local preference check. */
427 new_pref = exist_pref = bgp->default_local_pref;
428
429 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
430 new_pref = newattr->local_pref;
431 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
432 exist_pref = existattr->local_pref;
433
434 if (new_pref > exist_pref)
435 {
436 if (debug)
437 zlog_debug("%s: %s wins over %s due to localpref %d > %d",
438 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
439 return 1;
440 }
441
442 if (new_pref < exist_pref)
443 {
444 if (debug)
445 zlog_debug("%s: %s loses to %s due to localpref %d < %d",
446 pfx_buf, new_buf, exist_buf, new_pref, exist_pref);
447 return 0;
448 }
449
450 /* 3. Local route check. We prefer:
451 * - BGP_ROUTE_STATIC
452 * - BGP_ROUTE_AGGREGATE
453 * - BGP_ROUTE_REDISTRIBUTE
454 */
455 if (! (new->sub_type == BGP_ROUTE_NORMAL))
456 {
457 if (debug)
458 zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type",
459 pfx_buf, new_buf, exist_buf);
460 return 1;
461 }
462
463 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
464 {
465 if (debug)
466 zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type",
467 pfx_buf, new_buf, exist_buf);
468 return 0;
469 }
470
471 /* 4. AS path length check. */
472 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
473 {
474 int exist_hops = aspath_count_hops (existattr->aspath);
475 int exist_confeds = aspath_count_confeds (existattr->aspath);
476
477 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
478 {
479 int aspath_hops;
480
481 aspath_hops = aspath_count_hops (newattr->aspath);
482 aspath_hops += aspath_count_confeds (newattr->aspath);
483
484 if ( aspath_hops < (exist_hops + exist_confeds))
485 {
486 if (debug)
487 zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
488 pfx_buf, new_buf, exist_buf,
489 aspath_hops, (exist_hops + exist_confeds));
490 return 1;
491 }
492
493 if ( aspath_hops > (exist_hops + exist_confeds))
494 {
495 if (debug)
496 zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
497 pfx_buf, new_buf, exist_buf,
498 aspath_hops, (exist_hops + exist_confeds));
499 return 0;
500 }
501 }
502 else
503 {
504 int newhops = aspath_count_hops (newattr->aspath);
505
506 if (newhops < exist_hops)
507 {
508 if (debug)
509 zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d",
510 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
511 return 1;
512 }
513
514 if (newhops > exist_hops)
515 {
516 if (debug)
517 zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d",
518 pfx_buf, new_buf, exist_buf, newhops, exist_hops);
519 return 0;
520 }
521 }
522 }
523
524 /* 5. Origin check. */
525 if (newattr->origin < existattr->origin)
526 {
527 if (debug)
528 zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
529 pfx_buf, new_buf, exist_buf,
530 bgp_origin_long_str[newattr->origin],
531 bgp_origin_long_str[existattr->origin]);
532 return 1;
533 }
534
535 if (newattr->origin > existattr->origin)
536 {
537 if (debug)
538 zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
539 pfx_buf, new_buf, exist_buf,
540 bgp_origin_long_str[newattr->origin],
541 bgp_origin_long_str[existattr->origin]);
542 return 0;
543 }
544
545 /* 6. MED check. */
546 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
547 && aspath_count_hops (existattr->aspath) == 0);
548 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
549 && aspath_count_confeds (existattr->aspath) > 0
550 && aspath_count_hops (newattr->aspath) == 0
551 && aspath_count_hops (existattr->aspath) == 0);
552
553 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
554 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
555 && confed_as_route)
556 || aspath_cmp_left (newattr->aspath, existattr->aspath)
557 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
558 || internal_as_route)
559 {
560 new_med = bgp_med_value (new->attr, bgp);
561 exist_med = bgp_med_value (exist->attr, bgp);
562
563 if (new_med < exist_med)
564 {
565 if (debug)
566 zlog_debug("%s: %s wins over %s due to MED %d < %d",
567 pfx_buf, new_buf, exist_buf, new_med, exist_med);
568 return 1;
569 }
570
571 if (new_med > exist_med)
572 {
573 if (debug)
574 zlog_debug("%s: %s loses to %s due to MED %d > %d",
575 pfx_buf, new_buf, exist_buf, new_med, exist_med);
576 return 0;
577 }
578 }
579
580 /* 7. Peer type check. */
581 new_sort = new->peer->sort;
582 exist_sort = exist->peer->sort;
583
584 if (new_sort == BGP_PEER_EBGP
585 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
586 {
587 if (debug)
588 zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer",
589 pfx_buf, new_buf, exist_buf);
590 return 1;
591 }
592
593 if (exist_sort == BGP_PEER_EBGP
594 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
595 {
596 if (debug)
597 zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer",
598 pfx_buf, new_buf, exist_buf);
599 return 0;
600 }
601
602 /* 8. IGP metric check. */
603 newm = existm = 0;
604
605 if (new->extra)
606 newm = new->extra->igpmetric;
607 if (exist->extra)
608 existm = exist->extra->igpmetric;
609
610 if (newm < existm)
611 {
612 if (debug)
613 zlog_debug("%s: %s wins over %s due to IGP metric %d < %d",
614 pfx_buf, new_buf, exist_buf, newm, existm);
615 ret = 1;
616 }
617
618 if (newm > existm)
619 {
620 if (debug)
621 zlog_debug("%s: %s loses to %s due to IGP metric %d > %d",
622 pfx_buf, new_buf, exist_buf, newm, existm);
623 ret = 0;
624 }
625
626 /* 9. Same IGP metric. Compare the cluster list length as
627 representative of IGP hops metric. Rewrite the metric value
628 pair (newm, existm) with the cluster list length. Prefer the
629 path with smaller cluster list length. */
630 if (newm == existm)
631 {
632 if (peer_sort (new->peer) == BGP_PEER_IBGP
633 && peer_sort (exist->peer) == BGP_PEER_IBGP
634 && (mpath_cfg == NULL ||
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 int ret;
873 ret = bgp_info_cmp (bgp, new, exist, &paths_eq, NULL, 0, __func__);
874
875 if (paths_eq)
876 ret = 0;
877 else
878 {
879 if (ret == 1)
880 ret = -1;
881 else
882 ret = 1;
883 }
884 return ret;
885 }
886
887 static enum filter_type
888 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
889 afi_t afi, safi_t safi)
890 {
891 struct bgp_filter *filter;
892
893 filter = &peer->filter[afi][safi];
894
895 #define FILTER_EXIST_WARN(F,f,filter) \
896 if (BGP_DEBUG (update, UPDATE_IN) \
897 && !(F ## _IN (filter))) \
898 zlog_warn ("%s: Could not find configured input %s-list %s!", \
899 peer->host, #f, F ## _IN_NAME(filter));
900
901 if (DISTRIBUTE_IN_NAME (filter)) {
902 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
903
904 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
905 return FILTER_DENY;
906 }
907
908 if (PREFIX_LIST_IN_NAME (filter)) {
909 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
910
911 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
912 return FILTER_DENY;
913 }
914
915 if (FILTER_LIST_IN_NAME (filter)) {
916 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
917
918 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
919 return FILTER_DENY;
920 }
921
922 return FILTER_PERMIT;
923 #undef FILTER_EXIST_WARN
924 }
925
926 static enum filter_type
927 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
928 afi_t afi, safi_t safi)
929 {
930 struct bgp_filter *filter;
931
932 filter = &peer->filter[afi][safi];
933
934 #define FILTER_EXIST_WARN(F,f,filter) \
935 if (BGP_DEBUG (update, UPDATE_OUT) \
936 && !(F ## _OUT (filter))) \
937 zlog_warn ("%s: Could not find configured output %s-list %s!", \
938 peer->host, #f, F ## _OUT_NAME(filter));
939
940 if (DISTRIBUTE_OUT_NAME (filter)) {
941 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
942
943 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
944 return FILTER_DENY;
945 }
946
947 if (PREFIX_LIST_OUT_NAME (filter)) {
948 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
949
950 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
951 return FILTER_DENY;
952 }
953
954 if (FILTER_LIST_OUT_NAME (filter)) {
955 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
956
957 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
958 return FILTER_DENY;
959 }
960
961 return FILTER_PERMIT;
962 #undef FILTER_EXIST_WARN
963 }
964
965 /* If community attribute includes no_export then return 1. */
966 static int
967 bgp_community_filter (struct peer *peer, struct attr *attr)
968 {
969 if (attr->community)
970 {
971 /* NO_ADVERTISE check. */
972 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
973 return 1;
974
975 /* NO_EXPORT check. */
976 if (peer->sort == BGP_PEER_EBGP &&
977 community_include (attr->community, COMMUNITY_NO_EXPORT))
978 return 1;
979
980 /* NO_EXPORT_SUBCONFED check. */
981 if (peer->sort == BGP_PEER_EBGP
982 || peer->sort == BGP_PEER_CONFED)
983 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
984 return 1;
985 }
986 return 0;
987 }
988
989 /* Route reflection loop check. */
990 static int
991 bgp_cluster_filter (struct peer *peer, struct attr *attr)
992 {
993 struct in_addr cluster_id;
994
995 if (attr->extra && attr->extra->cluster)
996 {
997 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
998 cluster_id = peer->bgp->cluster_id;
999 else
1000 cluster_id = peer->bgp->router_id;
1001
1002 if (cluster_loop_check (attr->extra->cluster, cluster_id))
1003 return 1;
1004 }
1005 return 0;
1006 }
1007
1008 static int
1009 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1010 afi_t afi, safi_t safi, const char *rmap_name)
1011 {
1012 struct bgp_filter *filter;
1013 struct bgp_info info;
1014 route_map_result_t ret;
1015 struct route_map *rmap = NULL;
1016
1017 filter = &peer->filter[afi][safi];
1018
1019 /* Apply default weight value. */
1020 if (peer->weight[afi][safi])
1021 (bgp_attr_extra_get (attr))->weight = peer->weight[afi][safi];
1022
1023 if (rmap_name)
1024 {
1025 rmap = route_map_lookup_by_name(rmap_name);
1026
1027 if (rmap == NULL)
1028 return RMAP_DENY;
1029 }
1030 else
1031 {
1032 if (ROUTE_MAP_IN_NAME(filter))
1033 {
1034 rmap = ROUTE_MAP_IN (filter);
1035
1036 if (rmap == NULL)
1037 return RMAP_DENY;
1038 }
1039 }
1040
1041 /* Route map apply. */
1042 if (rmap)
1043 {
1044 /* Duplicate current value to new strucutre for modification. */
1045 info.peer = peer;
1046 info.attr = attr;
1047
1048 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
1049
1050 /* Apply BGP route map to the attribute. */
1051 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1052
1053 peer->rmap_type = 0;
1054
1055 if (ret == RMAP_DENYMATCH)
1056 {
1057 /* Free newly generated AS path and community by route-map. */
1058 bgp_attr_flush (attr);
1059 return RMAP_DENY;
1060 }
1061 }
1062 return RMAP_PERMIT;
1063 }
1064
1065 static int
1066 bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
1067 afi_t afi, safi_t safi, const char *rmap_name)
1068 {
1069 struct bgp_filter *filter;
1070 struct bgp_info info;
1071 route_map_result_t ret;
1072 struct route_map *rmap = NULL;
1073
1074 filter = &peer->filter[afi][safi];
1075
1076 /* Apply default weight value. */
1077 if (peer->weight[afi][safi])
1078 (bgp_attr_extra_get (attr))->weight = peer->weight[afi][safi];
1079
1080 if (rmap_name)
1081 {
1082 rmap = route_map_lookup_by_name(rmap_name);
1083
1084 if (rmap == NULL)
1085 return RMAP_DENY;
1086 }
1087 else
1088 {
1089 if (ROUTE_MAP_OUT_NAME(filter))
1090 {
1091 rmap = ROUTE_MAP_OUT (filter);
1092
1093 if (rmap == NULL)
1094 return RMAP_DENY;
1095 }
1096 }
1097
1098 /* Route map apply. */
1099 if (rmap)
1100 {
1101 /* Duplicate current value to new strucutre for modification. */
1102 info.peer = peer;
1103 info.attr = attr;
1104
1105 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1106
1107 /* Apply BGP route map to the attribute. */
1108 ret = route_map_apply (rmap, p, RMAP_BGP, &info);
1109
1110 peer->rmap_type = 0;
1111
1112 if (ret == RMAP_DENYMATCH)
1113 /* caller has multiple error paths with bgp_attr_flush() */
1114 return RMAP_DENY;
1115 }
1116 return RMAP_PERMIT;
1117 }
1118
1119 /* If this is an EBGP peer with remove-private-AS */
1120 static void
1121 bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
1122 struct peer *peer, struct attr *attr)
1123 {
1124 if (peer->sort == BGP_PEER_EBGP &&
1125 (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1126 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) ||
1127 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) ||
1128 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)))
1129 {
1130 // Take action on the entire aspath
1131 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) ||
1132 peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
1133 {
1134 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
1135 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1136
1137 // The entire aspath consists of private ASNs so create an empty aspath
1138 else if (aspath_private_as_check (attr->aspath))
1139 attr->aspath = aspath_empty_get ();
1140
1141 // There are some public and some private ASNs, remove the private ASNs
1142 else
1143 attr->aspath = aspath_remove_private_asns (attr->aspath);
1144 }
1145
1146 // 'all' was not specified so the entire aspath must be private ASNs
1147 // for us to do anything
1148 else if (aspath_private_as_check (attr->aspath))
1149 {
1150 if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
1151 attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as);
1152 else
1153 attr->aspath = aspath_empty_get ();
1154 }
1155 }
1156 }
1157
1158 /* If this is an EBGP peer with as-override */
1159 static void
1160 bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
1161 struct peer *peer, struct attr *attr)
1162 {
1163 if (peer->sort == BGP_PEER_EBGP &&
1164 peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE))
1165 {
1166 if (aspath_single_asn_check (attr->aspath, peer->as))
1167 attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as);
1168 }
1169 }
1170
1171 static void
1172 subgroup_announce_reset_nhop (u_char family, struct attr *attr)
1173 {
1174 if (family == AF_INET)
1175 attr->nexthop.s_addr = 0;
1176 #ifdef HAVE_IPV6
1177 if (family == AF_INET6)
1178 memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
1179 #endif
1180 }
1181
1182 int
1183 subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp,
1184 struct prefix *p, struct attr *attr)
1185 {
1186 struct bgp_filter *filter;
1187 struct peer *from;
1188 struct peer *peer;
1189 struct peer *onlypeer;
1190 struct bgp *bgp;
1191 struct attr *riattr;
1192 struct peer_af *paf;
1193 char buf[SU_ADDRSTRLEN];
1194 int ret;
1195 int transparent;
1196 int reflect;
1197 afi_t afi;
1198 safi_t safi;
1199 int samepeer_safe = 0; /* for synthetic mplsvpns routes */
1200
1201 if (DISABLE_BGP_ANNOUNCE)
1202 return 0;
1203
1204 afi = SUBGRP_AFI(subgrp);
1205 safi = SUBGRP_SAFI(subgrp);
1206 peer = SUBGRP_PEER(subgrp);
1207 onlypeer = NULL;
1208 if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL))
1209 onlypeer = SUBGRP_PFIRST(subgrp)->peer;
1210
1211 from = ri->peer;
1212 filter = &peer->filter[afi][safi];
1213 bgp = SUBGRP_INST(subgrp);
1214 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1215
1216 #if ENABLE_BGP_VNC
1217 if (((afi == AFI_IP) || (afi == AFI_IP6)) && (safi == SAFI_MPLS_VPN) &&
1218 ((ri->type == ZEBRA_ROUTE_BGP_DIRECT) ||
1219 (ri->type == ZEBRA_ROUTE_BGP_DIRECT_EXT))) {
1220
1221 /*
1222 * direct and direct_ext type routes originate internally even
1223 * though they can have peer pointers that reference other systems
1224 */
1225 char buf[BUFSIZ];
1226 prefix2str(p, buf, BUFSIZ);
1227 zlog_debug("%s: pfx %s bgp_direct->vpn route peer safe", __func__, buf);
1228 samepeer_safe = 1;
1229 }
1230 #endif
1231
1232 /* With addpath we may be asked to TX all kinds of paths so make sure
1233 * ri is valid */
1234 if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) ||
1235 CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) ||
1236 CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
1237 {
1238 return 0;
1239 }
1240
1241 /* If this is not the bestpath then check to see if there is an enabled addpath
1242 * feature that requires us to advertise it */
1243 if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1244 {
1245 if (! bgp_addpath_tx_path(peer, afi, safi, ri))
1246 {
1247 return 0;
1248 }
1249 }
1250
1251 /* Aggregate-address suppress check. */
1252 if (ri->extra && ri->extra->suppress)
1253 if (! UNSUPPRESS_MAP_NAME (filter))
1254 {
1255 return 0;
1256 }
1257
1258 /* Do not send back route to sender. */
1259 if (onlypeer && from == onlypeer)
1260 {
1261 return 0;
1262 }
1263
1264 /* Do not send the default route in the BGP table if the neighbor is
1265 * configured for default-originate */
1266 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1267 {
1268 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1269 return 0;
1270 #ifdef HAVE_IPV6
1271 else if (p->family == AF_INET6 && p->prefixlen == 0)
1272 return 0;
1273 #endif /* HAVE_IPV6 */
1274 }
1275
1276 /* Transparency check. */
1277 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
1278 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
1279 transparent = 1;
1280 else
1281 transparent = 0;
1282
1283 /* If community is not disabled check the no-export and local. */
1284 if (! transparent && bgp_community_filter (peer, riattr))
1285 {
1286 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1287 zlog_debug ("subgrpannouncecheck: community filter check fail");
1288 return 0;
1289 }
1290
1291 /* If the attribute has originator-id and it is same as remote
1292 peer's id. */
1293 if (onlypeer &&
1294 riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) &&
1295 (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id)))
1296 {
1297 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1298 zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as "
1299 "remote router-id",
1300 onlypeer->host,
1301 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1302 p->prefixlen);
1303 return 0;
1304 }
1305
1306 /* ORF prefix-list filter check */
1307 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1308 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1309 || CHECK_FLAG (peer->af_cap[afi][safi],
1310 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1311 if (peer->orf_plist[afi][safi])
1312 {
1313 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
1314 {
1315 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1316 zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF",
1317 peer->host,
1318 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1319 p->prefixlen);
1320 return 0;
1321 }
1322 }
1323
1324 /* Output filter check. */
1325 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1326 {
1327 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1328 zlog_debug ("%s [Update:SEND] %s/%d is filtered",
1329 peer->host,
1330 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1331 p->prefixlen);
1332 return 0;
1333 }
1334
1335 #ifdef BGP_SEND_ASPATH_CHECK
1336 /* AS path loop check. */
1337 if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as))
1338 {
1339 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1340 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u "
1341 "that is part of AS path.",
1342 onlypeer->host, onlypeer->as);
1343 return 0;
1344 }
1345 #endif /* BGP_SEND_ASPATH_CHECK */
1346
1347 /* If we're a CONFED we need to loop check the CONFED ID too */
1348 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1349 {
1350 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1351 {
1352 if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
1353 zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u"
1354 " is AS path.",
1355 peer->host,
1356 bgp->confed_id);
1357 return 0;
1358 }
1359 }
1360
1361 /* Route-Reflect check. */
1362 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1363 reflect = 1;
1364 else
1365 reflect = 0;
1366
1367 /* IBGP reflection check. */
1368 if (reflect && !samepeer_safe)
1369 {
1370 /* A route from a Client peer. */
1371 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
1372 {
1373 /* Reflect to all the Non-Client peers and also to the
1374 Client peers other than the originator. Originator check
1375 is already done. So there is noting to do. */
1376 /* no bgp client-to-client reflection check. */
1377 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
1378 if (CHECK_FLAG (peer->af_flags[afi][safi],
1379 PEER_FLAG_REFLECTOR_CLIENT))
1380 return 0;
1381 }
1382 else
1383 {
1384 /* A route from a Non-client peer. Reflect to all other
1385 clients. */
1386 if (! CHECK_FLAG (peer->af_flags[afi][safi],
1387 PEER_FLAG_REFLECTOR_CLIENT))
1388 return 0;
1389 }
1390 }
1391
1392 /* For modify attribute, copy it to temporary structure. */
1393 bgp_attr_dup (attr, riattr);
1394
1395 /* If local-preference is not set. */
1396 if ((peer->sort == BGP_PEER_IBGP
1397 || peer->sort == BGP_PEER_CONFED)
1398 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
1399 {
1400 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1401 attr->local_pref = bgp->default_local_pref;
1402 }
1403
1404 /* If originator-id is not set and the route is to be reflected,
1405 set the originator id */
1406 if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
1407 {
1408 attr->extra = bgp_attr_extra_get(attr);
1409 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
1410 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
1411 }
1412
1413 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
1414 if (peer->sort == BGP_PEER_EBGP
1415 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1416 {
1417 if (from != bgp->peer_self && ! transparent
1418 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
1419 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
1420 }
1421
1422 /* Since the nexthop attribute can vary per peer, it is not explicitly set
1423 * in announce check, only certain flags and length (or number of nexthops
1424 * -- for IPv6/MP_REACH) are set here in order to guide the update formation
1425 * code in setting the nexthop(s) on a per peer basis in reformat_peer().
1426 * Typically, the source nexthop in the attribute is preserved but in the
1427 * scenarios where we know it will always be overwritten, we reset the
1428 * nexthop to "0" in an attempt to achieve better Update packing. An
1429 * example of this is when a prefix from each of 2 IBGP peers needs to be
1430 * announced to an EBGP peer (and they have the same attributes barring
1431 * their nexthop).
1432 */
1433 if (reflect)
1434 SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
1435
1436 #ifdef HAVE_IPV6
1437 #define NEXTHOP_IS_V6 (\
1438 (safi != SAFI_ENCAP && \
1439 (p->family == AF_INET6 || peer_cap_enhe(peer))) || \
1440 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
1441
1442 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1443 * the peer (group) is configured to receive link-local nexthop unchanged
1444 * and it is available in the prefix OR we're not reflecting the route and
1445 * the peer (group) to whom we're going to announce is on a shared network
1446 * and this is either a self-originated route or the peer is EBGP.
1447 */
1448 if (NEXTHOP_IS_V6)
1449 {
1450 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
1451 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1452 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1453 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1454 (!reflect && peer->shared_network &&
1455 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
1456 {
1457 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
1458 }
1459
1460 /* Clear off link-local nexthop in source, whenever it is not needed to
1461 * ensure more prefixes share the same attribute for announcement.
1462 */
1463 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1464 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1465 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1466 }
1467 #endif /* HAVE_IPV6 */
1468
1469 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1470 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1471
1472 /* Route map & unsuppress-map apply. */
1473 if (ROUTE_MAP_OUT_NAME (filter)
1474 || (ri->extra && ri->extra->suppress) )
1475 {
1476 struct bgp_info info;
1477 struct attr dummy_attr;
1478 struct attr_extra dummy_extra;
1479
1480 dummy_attr.extra = &dummy_extra;
1481
1482 info.peer = peer;
1483 info.attr = attr;
1484 /* don't confuse inbound and outbound setting */
1485 RESET_FLAG(attr->rmap_change_flags);
1486
1487 /*
1488 * The route reflector is not allowed to modify the attributes
1489 * of the reflected IBGP routes unless explicitly allowed.
1490 */
1491 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1492 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1493 {
1494 bgp_attr_dup (&dummy_attr, attr);
1495 info.attr = &dummy_attr;
1496 }
1497
1498 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1499
1500 if (ri->extra && ri->extra->suppress)
1501 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1502 else
1503 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1504
1505 peer->rmap_type = 0;
1506
1507 if (ret == RMAP_DENYMATCH)
1508 {
1509 bgp_attr_flush (attr);
1510 return 0;
1511 }
1512 }
1513
1514 /* After route-map has been applied, we check to see if the nexthop to
1515 * be carried in the attribute (that is used for the announcement) can
1516 * be cleared off or not. We do this in all cases where we would be
1517 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1518 * the global nexthop here; the link-local nexthop would have been cleared
1519 * already, and if not, it is required by the update formation code.
1520 * Also see earlier comments in this function.
1521 */
1522 /*
1523 * If route-map has performed some operation on the nexthop or the peer
1524 * configuration says to pass it unchanged, we cannot reset the nexthop
1525 * here, so only attempt to do it if these aren't true. Note that the
1526 * route-map handler itself might have cleared the nexthop, if for example,
1527 * it is configured as 'peer-address'.
1528 */
1529 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1530 riattr->rmap_change_flags) &&
1531 !transparent &&
1532 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
1533 {
1534 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
1535 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1536 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
1537 {
1538 if (!reflect ||
1539 CHECK_FLAG (peer->af_flags[afi][safi],
1540 PEER_FLAG_FORCE_NEXTHOP_SELF))
1541 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1542 AF_INET6 : p->family), attr);
1543 }
1544 else if (peer->sort == BGP_PEER_EBGP)
1545 {
1546 /* Can also reset the nexthop if announcing to EBGP, but only if
1547 * no peer in the subgroup is on a shared subnet.
1548 * Note: 3rd party nexthop currently implemented for IPv4 only.
1549 */
1550 SUBGRP_FOREACH_PEER (subgrp, paf)
1551 {
1552 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1553 break;
1554 }
1555 if (!paf)
1556 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
1557 }
1558 /* If IPv6/MP and nexthop does not have any override and happens to
1559 * be a link-local address, reset it so that we don't pass along the
1560 * source's link-local IPv6 address to recipients who may not be on
1561 * the same interface.
1562 */
1563 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1564 {
1565 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1566 subgroup_announce_reset_nhop (AF_INET6, attr);
1567 }
1568 }
1569
1570 return 1;
1571 }
1572
1573 struct bgp_info_pair
1574 {
1575 struct bgp_info *old;
1576 struct bgp_info *new;
1577 };
1578
1579 static void
1580 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1581 struct bgp_maxpaths_cfg *mpath_cfg,
1582 struct bgp_info_pair *result)
1583 {
1584 struct bgp_info *new_select;
1585 struct bgp_info *old_select;
1586 struct bgp_info *ri;
1587 struct bgp_info *ri1;
1588 struct bgp_info *ri2;
1589 struct bgp_info *nextri = NULL;
1590 int paths_eq, do_mpath, debug;
1591 struct list mp_list;
1592 char pfx_buf[PREFIX2STR_BUFFER];
1593 char path_buf[PATH_ADDPATH_STR_BUFFER];
1594
1595 bgp_mp_list_init (&mp_list);
1596 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
1597
1598 debug = bgp_debug_bestpath(&rn->p);
1599
1600 if (debug)
1601 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1602
1603 /* bgp deterministic-med */
1604 new_select = NULL;
1605 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1606 {
1607
1608 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1609 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1610 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1611
1612 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1613 {
1614 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1615 continue;
1616 if (BGP_INFO_HOLDDOWN (ri1))
1617 continue;
1618 if (ri1->peer && ri1->peer != bgp->peer_self)
1619 if (ri1->peer->status != Established)
1620 continue;
1621
1622 new_select = ri1;
1623 if (ri1->next)
1624 {
1625 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1626 {
1627 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1628 continue;
1629 if (BGP_INFO_HOLDDOWN (ri2))
1630 continue;
1631 if (ri2->peer &&
1632 ri2->peer != bgp->peer_self &&
1633 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1634 if (ri2->peer->status != Established)
1635 continue;
1636
1637 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1638 || aspath_cmp_left_confed (ri1->attr->aspath,
1639 ri2->attr->aspath))
1640 {
1641 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1642 mpath_cfg, debug, pfx_buf))
1643 {
1644 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1645 new_select = ri2;
1646 }
1647
1648 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1649 }
1650 }
1651 }
1652 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1653 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1654
1655 if (debug)
1656 {
1657 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1658 zlog_debug("%s: %s is the bestpath from AS %d",
1659 pfx_buf, path_buf, aspath_get_first_as(new_select->attr->aspath));
1660 }
1661 }
1662 }
1663
1664 /* Check old selected route and new selected route. */
1665 old_select = NULL;
1666 new_select = NULL;
1667 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1668 {
1669 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1670 old_select = ri;
1671
1672 if (BGP_INFO_HOLDDOWN (ri))
1673 {
1674 /* reap REMOVED routes, if needs be
1675 * selected route must stay for a while longer though
1676 */
1677 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1678 && (ri != old_select))
1679 bgp_info_reap (rn, ri);
1680
1681 continue;
1682 }
1683
1684 if (ri->peer &&
1685 ri->peer != bgp->peer_self &&
1686 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1687 if (ri->peer->status != Established)
1688 continue;
1689
1690 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1691 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1692 {
1693 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1694 continue;
1695 }
1696
1697 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1698
1699 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
1700 {
1701 new_select = ri;
1702 }
1703 }
1704
1705 /* Now that we know which path is the bestpath see if any of the other paths
1706 * qualify as multipaths
1707 */
1708 if (debug)
1709 {
1710 if (new_select)
1711 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1712 else
1713 sprintf (path_buf, "NONE");
1714 zlog_debug("%s: After path selection, newbest is %s oldbest was %s",
1715 pfx_buf, path_buf,
1716 old_select ? old_select->peer->host : "NONE");
1717 }
1718
1719 if (do_mpath && new_select)
1720 {
1721 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1722 {
1723
1724 if (debug)
1725 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1726
1727 if (ri == new_select)
1728 {
1729 if (debug)
1730 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1731 pfx_buf, path_buf);
1732 bgp_mp_list_add (&mp_list, ri);
1733 continue;
1734 }
1735
1736 if (BGP_INFO_HOLDDOWN (ri))
1737 continue;
1738
1739 if (ri->peer &&
1740 ri->peer != bgp->peer_self &&
1741 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1742 if (ri->peer->status != Established)
1743 continue;
1744
1745 if (!bgp_info_nexthop_cmp (ri, new_select))
1746 {
1747 if (debug)
1748 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1749 pfx_buf, path_buf);
1750 continue;
1751 }
1752
1753 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
1754
1755 if (paths_eq)
1756 {
1757 if (debug)
1758 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1759 pfx_buf, path_buf);
1760 bgp_mp_list_add (&mp_list, ri);
1761 }
1762 }
1763 }
1764
1765 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1766 bgp_info_mpath_aggregate_update (new_select, old_select);
1767 bgp_mp_list_clear (&mp_list);
1768
1769 result->old = old_select;
1770 result->new = new_select;
1771
1772 return;
1773 }
1774
1775 /*
1776 * A new route/change in bestpath of an existing route. Evaluate the path
1777 * for advertisement to the subgroup.
1778 */
1779 int
1780 subgroup_process_announce_selected (struct update_subgroup *subgrp,
1781 struct bgp_info *selected,
1782 struct bgp_node *rn,
1783 u_int32_t addpath_tx_id)
1784 {
1785 struct prefix *p;
1786 struct peer *onlypeer;
1787 struct attr attr;
1788 struct attr_extra extra;
1789 afi_t afi;
1790 safi_t safi;
1791
1792 p = &rn->p;
1793 afi = SUBGRP_AFI(subgrp);
1794 safi = SUBGRP_SAFI(subgrp);
1795 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1796 (SUBGRP_PFIRST(subgrp))->peer : NULL);
1797
1798 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1799 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1800 PEER_STATUS_ORF_WAIT_REFRESH))
1801 return 0;
1802
1803 memset(&extra, 0, sizeof(struct attr_extra));
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 int do_loop_check = 1;
2359 #if ENABLE_BGP_VNC
2360 int vnc_implicit_withdraw = 0;
2361 #endif
2362
2363 memset (&new_attr, 0, sizeof(struct attr));
2364 memset (&new_extra, 0, sizeof(struct attr_extra));
2365
2366 bgp = peer->bgp;
2367 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2368
2369 /* When peer's soft reconfiguration enabled. Record input packet in
2370 Adj-RIBs-In. */
2371 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2372 && peer != bgp->peer_self)
2373 bgp_adj_in_set (rn, peer, attr, addpath_id);
2374
2375 /* Check previously received route. */
2376 for (ri = rn->info; ri; ri = ri->next)
2377 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2378 ri->addpath_rx_id == addpath_id)
2379 break;
2380
2381 /* AS path local-as loop check. */
2382 if (peer->change_local_as)
2383 {
2384 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2385 aspath_loop_count = 1;
2386
2387 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2388 {
2389 reason = "as-path contains our own AS;";
2390 goto filtered;
2391 }
2392 }
2393
2394 /* If the peer is configured for "allowas-in origin" and the last ASN in the
2395 * as-path is our ASN then we do not need to call aspath_loop_check
2396 */
2397 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN_ORIGIN))
2398 if (aspath_get_last_as(attr->aspath) == bgp->as)
2399 do_loop_check = 0;
2400
2401 /* AS path loop check. */
2402 if (do_loop_check)
2403 {
2404 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2405 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2406 && aspath_loop_check(attr->aspath, bgp->confed_id) > peer->allowas_in[afi][safi]))
2407 {
2408 reason = "as-path contains our own AS;";
2409 goto filtered;
2410 }
2411 }
2412
2413 /* Route reflector originator ID check. */
2414 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2415 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2416 {
2417 reason = "originator is us;";
2418 goto filtered;
2419 }
2420
2421 /* Route reflector cluster ID check. */
2422 if (bgp_cluster_filter (peer, attr))
2423 {
2424 reason = "reflected from the same cluster;";
2425 goto filtered;
2426 }
2427
2428 /* Apply incoming filter. */
2429 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2430 {
2431 reason = "filter;";
2432 goto filtered;
2433 }
2434
2435 new_attr.extra = &new_extra;
2436 bgp_attr_dup (&new_attr, attr);
2437
2438 /* Apply incoming route-map.
2439 * NB: new_attr may now contain newly allocated values from route-map "set"
2440 * commands, so we need bgp_attr_flush in the error paths, until we intern
2441 * the attr (which takes over the memory references) */
2442 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2443 {
2444 reason = "route-map;";
2445 bgp_attr_flush (&new_attr);
2446 goto filtered;
2447 }
2448
2449 /* next hop check. */
2450 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
2451 {
2452 reason = "martian or self next-hop;";
2453 bgp_attr_flush (&new_attr);
2454 goto filtered;
2455 }
2456
2457 attr_new = bgp_attr_intern (&new_attr);
2458
2459 /* If the update is implicit withdraw. */
2460 if (ri)
2461 {
2462 ri->uptime = bgp_clock ();
2463
2464 /* Same attribute comes in. */
2465 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2466 && attrhash_cmp (ri->attr, attr_new))
2467 {
2468 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2469 && peer->sort == BGP_PEER_EBGP
2470 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2471 {
2472 if (bgp_debug_update(peer, p, NULL, 1))
2473 {
2474 bgp_info_addpath_rx_str(addpath_id, buf2);
2475 zlog_debug ("%s rcvd %s/%d%s",
2476 peer->host,
2477 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2478 p->prefixlen, buf2);
2479 }
2480
2481 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2482 {
2483 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2484 bgp_process (bgp, rn, afi, safi);
2485 }
2486 }
2487 else /* Duplicate - odd */
2488 {
2489 if (bgp_debug_update(peer, p, NULL, 1))
2490 {
2491 if (!peer->rcvd_attr_printed)
2492 {
2493 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2494 peer->rcvd_attr_printed = 1;
2495 }
2496
2497 bgp_info_addpath_rx_str(addpath_id, buf2);
2498 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
2499 peer->host,
2500 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2501 p->prefixlen, buf2);
2502 }
2503
2504 /* graceful restart STALE flag unset. */
2505 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2506 {
2507 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2508 bgp_process (bgp, rn, afi, safi);
2509 }
2510 }
2511
2512 bgp_unlock_node (rn);
2513 bgp_attr_unintern (&attr_new);
2514
2515 return 0;
2516 }
2517
2518 /* Withdraw/Announce before we fully processed the withdraw */
2519 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2520 {
2521 if (bgp_debug_update(peer, p, NULL, 1))
2522 {
2523 bgp_info_addpath_rx_str(addpath_id, buf2);
2524 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2525 peer->host,
2526 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2527 p->prefixlen, buf2);
2528 }
2529 bgp_info_restore (rn, ri);
2530 }
2531
2532 /* Received Logging. */
2533 if (bgp_debug_update(peer, p, NULL, 1))
2534 {
2535 bgp_info_addpath_rx_str(addpath_id, buf2);
2536 zlog_debug ("%s rcvd %s/%d%s",
2537 peer->host,
2538 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2539 p->prefixlen, buf2);
2540 }
2541
2542 /* graceful restart STALE flag unset. */
2543 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2544 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2545
2546 /* The attribute is changed. */
2547 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2548
2549 /* implicit withdraw, decrement aggregate and pcount here.
2550 * only if update is accepted, they'll increment below.
2551 */
2552 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2553
2554 /* Update bgp route dampening information. */
2555 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2556 && peer->sort == BGP_PEER_EBGP)
2557 {
2558 /* This is implicit withdraw so we should update dampening
2559 information. */
2560 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2561 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2562 }
2563 #if ENABLE_BGP_VNC
2564 if (safi == SAFI_MPLS_VPN) {
2565 struct bgp_node *prn = NULL;
2566 struct bgp_table *table = NULL;
2567
2568 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2569 if (prn->info) {
2570 table = (struct bgp_table *)(prn->info);
2571
2572 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2573 bgp,
2574 prd,
2575 table,
2576 p,
2577 ri);
2578 }
2579 bgp_unlock_node(prn);
2580 }
2581 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2582 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2583 /*
2584 * Implicit withdraw case.
2585 */
2586 ++vnc_implicit_withdraw;
2587 vnc_import_bgp_del_route(bgp, p, ri);
2588 vnc_import_bgp_exterior_del_route(bgp, p, ri);
2589 }
2590 }
2591 #endif
2592
2593 /* Update to new attribute. */
2594 bgp_attr_unintern (&ri->attr);
2595 ri->attr = attr_new;
2596
2597 /* Update MPLS tag. */
2598 if (safi == SAFI_MPLS_VPN)
2599 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2600
2601 #if ENABLE_BGP_VNC
2602 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
2603 {
2604 if (vnc_implicit_withdraw)
2605 {
2606 /*
2607 * Add back the route with its new attributes (e.g., nexthop).
2608 * The route is still selected, until the route selection
2609 * queued by bgp_process actually runs. We have to make this
2610 * update to the VNC side immediately to avoid racing against
2611 * configuration changes (e.g., route-map changes) which
2612 * trigger re-importation of the entire RIB.
2613 */
2614 vnc_import_bgp_add_route(bgp, p, ri);
2615 vnc_import_bgp_exterior_add_route(bgp, p, ri);
2616 }
2617 }
2618 #endif
2619
2620 /* Update bgp route dampening information. */
2621 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2622 && peer->sort == BGP_PEER_EBGP)
2623 {
2624 /* Now we do normal update dampening. */
2625 ret = bgp_damp_update (ri, rn, afi, safi);
2626 if (ret == BGP_DAMP_SUPPRESSED)
2627 {
2628 bgp_unlock_node (rn);
2629 return 0;
2630 }
2631 }
2632
2633 /* Nexthop reachability check. */
2634 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2635 {
2636 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2637 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2638 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2639 connected = 1;
2640 else
2641 connected = 0;
2642
2643 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
2644 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2645 else
2646 {
2647 if (BGP_DEBUG(nht, NHT))
2648 {
2649 char buf1[INET6_ADDRSTRLEN];
2650 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2651 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2652 }
2653 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2654 }
2655 }
2656 else
2657 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2658
2659 #if ENABLE_BGP_VNC
2660 if (safi == SAFI_MPLS_VPN)
2661 {
2662 struct bgp_node *prn = NULL;
2663 struct bgp_table *table = NULL;
2664
2665 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2666 if (prn->info)
2667 {
2668 table = (struct bgp_table *)(prn->info);
2669
2670 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2671 bgp,
2672 prd,
2673 table,
2674 p,
2675 ri);
2676 }
2677 bgp_unlock_node(prn);
2678 }
2679 #endif
2680
2681 /* Process change. */
2682 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2683
2684 bgp_process (bgp, rn, afi, safi);
2685 bgp_unlock_node (rn);
2686
2687 return 0;
2688 } // End of implicit withdraw
2689
2690 /* Received Logging. */
2691 if (bgp_debug_update(peer, p, NULL, 1))
2692 {
2693 if (!peer->rcvd_attr_printed)
2694 {
2695 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2696 peer->rcvd_attr_printed = 1;
2697 }
2698
2699 bgp_info_addpath_rx_str(addpath_id, buf2);
2700 zlog_debug ("%s rcvd %s/%d%s",
2701 peer->host,
2702 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2703 p->prefixlen, buf2);
2704 }
2705
2706 /* Make new BGP info. */
2707 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2708
2709 /* Update MPLS tag. */
2710 if (safi == SAFI_MPLS_VPN)
2711 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2712
2713 /* Nexthop reachability check. */
2714 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2715 {
2716 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2717 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2718 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2719 connected = 1;
2720 else
2721 connected = 0;
2722
2723 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
2724 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2725 else
2726 {
2727 if (BGP_DEBUG(nht, NHT))
2728 {
2729 char buf1[INET6_ADDRSTRLEN];
2730 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2731 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2732 }
2733 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2734 }
2735 }
2736 else
2737 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2738
2739 /* Addpath ID */
2740 new->addpath_rx_id = addpath_id;
2741
2742 /* Increment prefix */
2743 bgp_aggregate_increment (bgp, p, new, afi, safi);
2744
2745 /* Register new BGP information. */
2746 bgp_info_add (rn, new);
2747
2748 /* route_node_get lock */
2749 bgp_unlock_node (rn);
2750
2751 #if ENABLE_BGP_VNC
2752 if (safi == SAFI_MPLS_VPN)
2753 {
2754 struct bgp_node *prn = NULL;
2755 struct bgp_table *table = NULL;
2756
2757 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2758 if (prn->info)
2759 {
2760 table = (struct bgp_table *)(prn->info);
2761
2762 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2763 bgp,
2764 prd,
2765 table,
2766 p,
2767 new);
2768 }
2769 bgp_unlock_node(prn);
2770 }
2771 #endif
2772
2773 /* If maximum prefix count is configured and current prefix
2774 count exeed it. */
2775 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2776 return -1;
2777
2778 /* Process change. */
2779 bgp_process (bgp, rn, afi, safi);
2780
2781 return 0;
2782
2783 /* This BGP update is filtered. Log the reason then update BGP
2784 entry. */
2785 filtered:
2786 if (bgp_debug_update(peer, p, NULL, 1))
2787 {
2788 if (!peer->rcvd_attr_printed)
2789 {
2790 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2791 peer->rcvd_attr_printed = 1;
2792 }
2793
2794 bgp_info_addpath_rx_str(addpath_id, buf2);
2795 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
2796 peer->host,
2797 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2798 p->prefixlen, buf2, reason);
2799 }
2800
2801 if (ri)
2802 bgp_rib_remove (rn, ri, peer, afi, safi);
2803
2804 bgp_unlock_node (rn);
2805
2806 return 0;
2807 }
2808
2809 int
2810 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2811 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2812 struct prefix_rd *prd, u_char *tag)
2813 {
2814 struct bgp *bgp;
2815 char buf[SU_ADDRSTRLEN];
2816 char buf2[30];
2817 struct bgp_node *rn;
2818 struct bgp_info *ri;
2819
2820 bgp = peer->bgp;
2821
2822 /* Lookup node. */
2823 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2824
2825 /* If peer is soft reconfiguration enabled. Record input packet for
2826 * further calculation.
2827 *
2828 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2829 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2830 * the iteration over all RS clients.
2831 * Since we need to remove the entry from adj_in anyway, do that first and
2832 * if there was no entry, we don't need to do anything more.
2833 */
2834 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2835 && peer != bgp->peer_self)
2836 if (!bgp_adj_in_unset (rn, peer, addpath_id))
2837 {
2838 if (bgp_debug_update (peer, p, NULL, 1))
2839 zlog_debug ("%s withdrawing route %s/%d "
2840 "not in adj-in", peer->host,
2841 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2842 p->prefixlen);
2843 bgp_unlock_node (rn);
2844 return 0;
2845 }
2846
2847 /* Lookup withdrawn route. */
2848 for (ri = rn->info; ri; ri = ri->next)
2849 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2850 ri->addpath_rx_id == addpath_id)
2851 break;
2852
2853 /* Logging. */
2854 if (bgp_debug_update(peer, p, NULL, 1))
2855 {
2856 bgp_info_addpath_rx_str(addpath_id, buf2);
2857 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2858 peer->host,
2859 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2860 p->prefixlen, buf2);
2861 }
2862
2863 /* Withdraw specified route from routing table. */
2864 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2865 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
2866 else if (bgp_debug_update(peer, p, NULL, 1))
2867 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2868 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2869 p->prefixlen);
2870
2871 /* Unlock bgp_node_get() lock. */
2872 bgp_unlock_node (rn);
2873
2874 return 0;
2875 }
2876
2877 void
2878 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2879 {
2880 struct update_subgroup *subgrp;
2881 subgrp = peer_subgroup(peer, afi, safi);
2882 subgroup_default_originate(subgrp, withdraw);
2883 }
2884
2885
2886 /*
2887 * bgp_stop_announce_route_timer
2888 */
2889 void
2890 bgp_stop_announce_route_timer (struct peer_af *paf)
2891 {
2892 if (!paf->t_announce_route)
2893 return;
2894
2895 THREAD_TIMER_OFF (paf->t_announce_route);
2896 }
2897
2898 /*
2899 * bgp_announce_route_timer_expired
2900 *
2901 * Callback that is invoked when the route announcement timer for a
2902 * peer_af expires.
2903 */
2904 static int
2905 bgp_announce_route_timer_expired (struct thread *t)
2906 {
2907 struct peer_af *paf;
2908 struct peer *peer;
2909
2910 paf = THREAD_ARG (t);
2911 peer = paf->peer;
2912
2913 assert (paf->t_announce_route);
2914 paf->t_announce_route = NULL;
2915
2916 if (peer->status != Established)
2917 return 0;
2918
2919 if (!peer->afc_nego[paf->afi][paf->safi])
2920 return 0;
2921
2922 peer_af_announce_route (paf, 1);
2923 return 0;
2924 }
2925
2926 /*
2927 * bgp_announce_route
2928 *
2929 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2930 */
2931 void
2932 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2933 {
2934 struct peer_af *paf;
2935 struct update_subgroup *subgrp;
2936
2937 paf = peer_af_find (peer, afi, safi);
2938 if (!paf)
2939 return;
2940 subgrp = PAF_SUBGRP(paf);
2941
2942 /*
2943 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2944 * or a refresh has already been triggered.
2945 */
2946 if (!subgrp || paf->t_announce_route)
2947 return;
2948
2949 /*
2950 * Start a timer to stagger/delay the announce. This serves
2951 * two purposes - announcement can potentially be combined for
2952 * multiple peers and the announcement doesn't happen in the
2953 * vty context.
2954 */
2955 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
2956 bgp_announce_route_timer_expired, paf,
2957 (subgrp->peer_count == 1) ?
2958 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2959 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2960 }
2961
2962 /*
2963 * Announce routes from all AF tables to a peer.
2964 *
2965 * This should ONLY be called when there is a need to refresh the
2966 * routes to the peer based on a policy change for this peer alone
2967 * or a route refresh request received from the peer.
2968 * The operation will result in splitting the peer from its existing
2969 * subgroups and putting it in new subgroups.
2970 */
2971 void
2972 bgp_announce_route_all (struct peer *peer)
2973 {
2974 afi_t afi;
2975 safi_t safi;
2976
2977 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2978 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2979 bgp_announce_route (peer, afi, safi);
2980 }
2981
2982 static void
2983 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2984 struct bgp_table *table, struct prefix_rd *prd)
2985 {
2986 int ret;
2987 struct bgp_node *rn;
2988 struct bgp_adj_in *ain;
2989
2990 if (! table)
2991 table = peer->bgp->rib[afi][safi];
2992
2993 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2994 for (ain = rn->adj_in; ain; ain = ain->next)
2995 {
2996 if (ain->peer == peer)
2997 {
2998 struct bgp_info *ri = rn->info;
2999 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
3000
3001 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
3002 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
3003 prd, tag, 1);
3004
3005 if (ret < 0)
3006 {
3007 bgp_unlock_node (rn);
3008 return;
3009 }
3010 }
3011 }
3012 }
3013
3014 void
3015 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3016 {
3017 struct bgp_node *rn;
3018 struct bgp_table *table;
3019
3020 if (peer->status != Established)
3021 return;
3022
3023 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
3024 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
3025 else
3026 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3027 rn = bgp_route_next (rn))
3028 if ((table = rn->info) != NULL)
3029 {
3030 struct prefix_rd prd;
3031 prd.family = AF_UNSPEC;
3032 prd.prefixlen = 64;
3033 memcpy(&prd.val, rn->p.u.val, 8);
3034
3035 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3036 }
3037 }
3038
3039
3040 struct bgp_clear_node_queue
3041 {
3042 struct bgp_node *rn;
3043 };
3044
3045 static wq_item_status
3046 bgp_clear_route_node (struct work_queue *wq, void *data)
3047 {
3048 struct bgp_clear_node_queue *cnq = data;
3049 struct bgp_node *rn = cnq->rn;
3050 struct peer *peer = wq->spec.data;
3051 struct bgp_info *ri;
3052 afi_t afi = bgp_node_table (rn)->afi;
3053 safi_t safi = bgp_node_table (rn)->safi;
3054
3055 assert (rn && peer);
3056
3057 /* It is possible that we have multiple paths for a prefix from a peer
3058 * if that peer is using AddPath.
3059 */
3060 for (ri = rn->info; ri; ri = ri->next)
3061 if (ri->peer == peer)
3062 {
3063 /* graceful restart STALE flag set. */
3064 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3065 && peer->nsf[afi][safi]
3066 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
3067 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3068 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
3069 else
3070 bgp_rib_remove (rn, ri, peer, afi, safi);
3071 }
3072 return WQ_SUCCESS;
3073 }
3074
3075 static void
3076 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
3077 {
3078 struct bgp_clear_node_queue *cnq = data;
3079 struct bgp_node *rn = cnq->rn;
3080 struct bgp_table *table = bgp_node_table (rn);
3081
3082 bgp_unlock_node (rn);
3083 bgp_table_unlock (table);
3084 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
3085 }
3086
3087 static void
3088 bgp_clear_node_complete (struct work_queue *wq)
3089 {
3090 struct peer *peer = wq->spec.data;
3091
3092 /* Tickle FSM to start moving again */
3093 BGP_EVENT_ADD (peer, Clearing_Completed);
3094
3095 peer_unlock (peer); /* bgp_clear_route */
3096 }
3097
3098 static void
3099 bgp_clear_node_queue_init (struct peer *peer)
3100 {
3101 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
3102
3103 snprintf (wname, sizeof(wname), "clear %s", peer->host);
3104 #undef CLEAR_QUEUE_NAME_LEN
3105
3106 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
3107 {
3108 zlog_err ("%s: Failed to allocate work queue", __func__);
3109 exit (1);
3110 }
3111 peer->clear_node_queue->spec.hold = 10;
3112 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3113 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3114 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3115 peer->clear_node_queue->spec.max_retries = 0;
3116
3117 /* we only 'lock' this peer reference when the queue is actually active */
3118 peer->clear_node_queue->spec.data = peer;
3119 }
3120
3121 static void
3122 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
3123 struct bgp_table *table)
3124 {
3125 struct bgp_node *rn;
3126 int force = bm->process_main_queue ? 0 : 1;
3127
3128 if (! table)
3129 table = peer->bgp->rib[afi][safi];
3130
3131 /* If still no table => afi/safi isn't configured at all or smth. */
3132 if (! table)
3133 return;
3134
3135 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3136 {
3137 struct bgp_info *ri, *next;
3138 struct bgp_adj_in *ain;
3139 struct bgp_adj_in *ain_next;
3140
3141 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3142 * queued for every clearing peer, regardless of whether it is
3143 * relevant to the peer at hand.
3144 *
3145 * Overview: There are 3 different indices which need to be
3146 * scrubbed, potentially, when a peer is removed:
3147 *
3148 * 1 peer's routes visible via the RIB (ie accepted routes)
3149 * 2 peer's routes visible by the (optional) peer's adj-in index
3150 * 3 other routes visible by the peer's adj-out index
3151 *
3152 * 3 there is no hurry in scrubbing, once the struct peer is
3153 * removed from bgp->peer, we could just GC such deleted peer's
3154 * adj-outs at our leisure.
3155 *
3156 * 1 and 2 must be 'scrubbed' in some way, at least made
3157 * invisible via RIB index before peer session is allowed to be
3158 * brought back up. So one needs to know when such a 'search' is
3159 * complete.
3160 *
3161 * Ideally:
3162 *
3163 * - there'd be a single global queue or a single RIB walker
3164 * - rather than tracking which route_nodes still need to be
3165 * examined on a peer basis, we'd track which peers still
3166 * aren't cleared
3167 *
3168 * Given that our per-peer prefix-counts now should be reliable,
3169 * this may actually be achievable. It doesn't seem to be a huge
3170 * problem at this time,
3171 *
3172 * It is possible that we have multiple paths for a prefix from a peer
3173 * if that peer is using AddPath.
3174 */
3175 ain = rn->adj_in;
3176 while (ain)
3177 {
3178 ain_next = ain->next;
3179
3180 if (ain->peer == peer)
3181 {
3182 bgp_adj_in_remove (rn, ain);
3183 bgp_unlock_node (rn);
3184 }
3185
3186 ain = ain_next;
3187 }
3188
3189 for (ri = rn->info; ri; ri = next)
3190 {
3191 next = ri->next;
3192 if (ri->peer != peer)
3193 continue;
3194
3195 if (force)
3196 bgp_info_reap (rn, ri);
3197 else
3198 {
3199 struct bgp_clear_node_queue *cnq;
3200
3201 /* both unlocked in bgp_clear_node_queue_del */
3202 bgp_table_lock (bgp_node_table (rn));
3203 bgp_lock_node (rn);
3204 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3205 sizeof (struct bgp_clear_node_queue));
3206 cnq->rn = rn;
3207 work_queue_add (peer->clear_node_queue, cnq);
3208 break;
3209 }
3210 }
3211 }
3212 return;
3213 }
3214
3215 void
3216 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
3217 {
3218 struct bgp_node *rn;
3219 struct bgp_table *table;
3220
3221 if (peer->clear_node_queue == NULL)
3222 bgp_clear_node_queue_init (peer);
3223
3224 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3225 * Idle until it receives a Clearing_Completed event. This protects
3226 * against peers which flap faster than we can we clear, which could
3227 * lead to:
3228 *
3229 * a) race with routes from the new session being installed before
3230 * clear_route_node visits the node (to delete the route of that
3231 * peer)
3232 * b) resource exhaustion, clear_route_node likely leads to an entry
3233 * on the process_main queue. Fast-flapping could cause that queue
3234 * to grow and grow.
3235 */
3236
3237 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3238 * the unlock will happen upon work-queue completion; other wise, the
3239 * unlock happens at the end of this function.
3240 */
3241 if (!peer->clear_node_queue->thread)
3242 peer_lock (peer);
3243
3244 if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP)
3245 bgp_clear_route_table (peer, afi, safi, NULL);
3246 else
3247 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3248 rn = bgp_route_next (rn))
3249 if ((table = rn->info) != NULL)
3250 bgp_clear_route_table (peer, afi, safi, table);
3251
3252 /* unlock if no nodes got added to the clear-node-queue. */
3253 if (!peer->clear_node_queue->thread)
3254 peer_unlock (peer);
3255
3256 }
3257
3258 void
3259 bgp_clear_route_all (struct peer *peer)
3260 {
3261 afi_t afi;
3262 safi_t safi;
3263
3264 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3265 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3266 bgp_clear_route (peer, afi, safi);
3267
3268 #if ENABLE_BGP_VNC
3269 rfapiProcessPeerDown(peer);
3270 #endif
3271 }
3272
3273 void
3274 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3275 {
3276 struct bgp_table *table;
3277 struct bgp_node *rn;
3278 struct bgp_adj_in *ain;
3279 struct bgp_adj_in *ain_next;
3280
3281 table = peer->bgp->rib[afi][safi];
3282
3283 /* It is possible that we have multiple paths for a prefix from a peer
3284 * if that peer is using AddPath.
3285 */
3286 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3287 {
3288 ain = rn->adj_in;
3289
3290 while (ain)
3291 {
3292 ain_next = ain->next;
3293
3294 if (ain->peer == peer)
3295 {
3296 bgp_adj_in_remove (rn, ain);
3297 bgp_unlock_node (rn);
3298 }
3299
3300 ain = ain_next;
3301 }
3302 }
3303 }
3304
3305 void
3306 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3307 {
3308 struct bgp_node *rn;
3309 struct bgp_info *ri;
3310 struct bgp_table *table;
3311
3312 table = peer->bgp->rib[afi][safi];
3313
3314 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3315 {
3316 for (ri = rn->info; ri; ri = ri->next)
3317 if (ri->peer == peer)
3318 {
3319 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3320 bgp_rib_remove (rn, ri, peer, afi, safi);
3321 break;
3322 }
3323 }
3324 }
3325
3326 static void
3327 bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3328 {
3329 struct bgp_node *rn;
3330 struct bgp_info *ri;
3331 struct bgp_info *next;
3332
3333 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3334 for (ri = rn->info; ri; ri = next)
3335 {
3336 next = ri->next;
3337 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3338 && ri->type == ZEBRA_ROUTE_BGP
3339 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3340 ri->sub_type == BGP_ROUTE_AGGREGATE))
3341 {
3342 #if ENABLE_BGP_VNC
3343 if (table->owner && table->owner->bgp)
3344 vnc_import_bgp_del_route(table->owner->bgp, &rn->p, ri);
3345 #endif
3346 bgp_zebra_withdraw (&rn->p, ri, safi);
3347 bgp_info_reap (rn, ri);
3348 }
3349 }
3350 }
3351
3352 /* Delete all kernel routes. */
3353 void
3354 bgp_cleanup_routes (struct bgp *bgp)
3355 {
3356 afi_t afi;
3357
3358 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3359 {
3360 struct bgp_node *rn;
3361
3362 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
3363
3364 /*
3365 * VPN and ENCAP tables are two-level (RD is top level)
3366 */
3367 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3368 rn = bgp_route_next (rn))
3369 {
3370 if (rn->info)
3371 {
3372 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3373 bgp_table_finish ((struct bgp_table **)&(rn->info));
3374 rn->info = NULL;
3375 bgp_unlock_node(rn);
3376 }
3377 }
3378
3379 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3380 rn = bgp_route_next (rn))
3381 {
3382 if (rn->info)
3383 {
3384 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3385 bgp_table_finish ((struct bgp_table **)&(rn->info));
3386 rn->info = NULL;
3387 bgp_unlock_node(rn);
3388 }
3389 }
3390 }
3391 }
3392
3393 void
3394 bgp_reset (void)
3395 {
3396 vty_reset ();
3397 bgp_zclient_reset ();
3398 access_list_reset ();
3399 prefix_list_reset ();
3400 }
3401
3402 static int
3403 bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3404 {
3405 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3406 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3407 }
3408
3409 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3410 value. */
3411 int
3412 bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3413 struct bgp_nlri *packet)
3414 {
3415 u_char *pnt;
3416 u_char *lim;
3417 struct prefix p;
3418 int psize;
3419 int ret;
3420 afi_t afi;
3421 safi_t safi;
3422 int addpath_encoded;
3423 u_int32_t addpath_id;
3424
3425 /* Check peer status. */
3426 if (peer->status != Established)
3427 return 0;
3428
3429 pnt = packet->nlri;
3430 lim = pnt + packet->length;
3431 afi = packet->afi;
3432 safi = packet->safi;
3433 addpath_id = 0;
3434 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3435
3436 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3437 syntactic validity. If the field is syntactically incorrect,
3438 then the Error Subcode is set to Invalid Network Field. */
3439 for (; pnt < lim; pnt += psize)
3440 {
3441 /* Clear prefix structure. */
3442 memset (&p, 0, sizeof (struct prefix));
3443
3444 if (addpath_encoded)
3445 {
3446
3447 /* When packet overflow occurs return immediately. */
3448 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3449 return -1;
3450
3451 addpath_id = ntohl(*((uint32_t*) pnt));
3452 pnt += BGP_ADDPATH_ID_LEN;
3453 }
3454
3455 /* Fetch prefix length. */
3456 p.prefixlen = *pnt++;
3457 /* afi/safi validity already verified by caller, bgp_update_receive */
3458 p.family = afi2family (afi);
3459
3460 /* Prefix length check. */
3461 if (p.prefixlen > prefix_blen (&p) * 8)
3462 {
3463 zlog_err("%s [Error] Update packet error (wrong perfix length %d for afi %u)",
3464 peer->host, p.prefixlen, packet->afi);
3465 return -1;
3466 }
3467
3468 /* Packet size overflow check. */
3469 psize = PSIZE (p.prefixlen);
3470
3471 /* When packet overflow occur return immediately. */
3472 if (pnt + psize > lim)
3473 {
3474 zlog_err("%s [Error] Update packet error (prefix length %d overflows packet)",
3475 peer->host, p.prefixlen);
3476 return -1;
3477 }
3478
3479 /* Defensive coding, double-check the psize fits in a struct prefix */
3480 if (psize > (ssize_t) sizeof(p.u))
3481 {
3482 zlog_err("%s [Error] Update packet error (prefix length %d too large for prefix storage %zu)",
3483 peer->host, p.prefixlen, sizeof(p.u));
3484 return -1;
3485 }
3486
3487 /* Fetch prefix from NLRI packet. */
3488 memcpy (&p.u.prefix, pnt, psize);
3489
3490 /* Check address. */
3491 if (afi == AFI_IP && safi == SAFI_UNICAST)
3492 {
3493 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3494 {
3495 /* From RFC4271 Section 6.3:
3496 *
3497 * If a prefix in the NLRI field is semantically incorrect
3498 * (e.g., an unexpected multicast IP address), an error SHOULD
3499 * be logged locally, and the prefix SHOULD be ignored.
3500 */
3501 zlog_err ("%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3502 peer->host, inet_ntoa (p.u.prefix4));
3503 continue;
3504 }
3505 }
3506
3507 #ifdef HAVE_IPV6
3508 /* Check address. */
3509 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3510 {
3511 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3512 {
3513 char buf[BUFSIZ];
3514
3515 zlog_err ("%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3516 peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3517
3518 continue;
3519 }
3520 if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3521 {
3522 char buf[BUFSIZ];
3523
3524 zlog_err ("%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3525 peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3526
3527 continue;
3528 }
3529 }
3530 #endif /* HAVE_IPV6 */
3531
3532 /* Normal process. */
3533 if (attr)
3534 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3535 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3536 else
3537 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3538 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3539
3540 /* Address family configuration mismatch or maximum-prefix count
3541 overflow. */
3542 if (ret < 0)
3543 return -1;
3544 }
3545
3546 /* Packet length consistency check. */
3547 if (pnt != lim)
3548 {
3549 zlog_err ("%s [Error] Update packet error (prefix length mismatch with total length)",
3550 peer->host);
3551 return -1;
3552 }
3553
3554 return 0;
3555 }
3556
3557 static struct bgp_static *
3558 bgp_static_new (void)
3559 {
3560 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3561 }
3562
3563 static void
3564 bgp_static_free (struct bgp_static *bgp_static)
3565 {
3566 if (bgp_static->rmap.name)
3567 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3568 XFREE (MTYPE_BGP_STATIC, bgp_static);
3569 }
3570
3571 static void
3572 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3573 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3574 {
3575 struct bgp_node *rn;
3576 struct bgp_info *ri;
3577 struct bgp_info *new;
3578 struct bgp_info info;
3579 struct attr attr;
3580 struct attr *attr_new;
3581 int ret;
3582 #if ENABLE_BGP_VNC
3583 int vnc_implicit_withdraw = 0;
3584 #endif
3585
3586 assert (bgp_static);
3587 if (!bgp_static)
3588 return;
3589
3590 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3591
3592 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3593
3594 attr.nexthop = bgp_static->igpnexthop;
3595 attr.med = bgp_static->igpmetric;
3596 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3597
3598 if (bgp_static->atomic)
3599 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3600
3601 /* Apply route-map. */
3602 if (bgp_static->rmap.name)
3603 {
3604 struct attr attr_tmp = attr;
3605 info.peer = bgp->peer_self;
3606 info.attr = &attr_tmp;
3607
3608 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3609
3610 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3611
3612 bgp->peer_self->rmap_type = 0;
3613
3614 if (ret == RMAP_DENYMATCH)
3615 {
3616 /* Free uninterned attribute. */
3617 bgp_attr_flush (&attr_tmp);
3618
3619 /* Unintern original. */
3620 aspath_unintern (&attr.aspath);
3621 bgp_attr_extra_free (&attr);
3622 bgp_static_withdraw (bgp, p, afi, safi);
3623 return;
3624 }
3625 attr_new = bgp_attr_intern (&attr_tmp);
3626 }
3627 else
3628 attr_new = bgp_attr_intern (&attr);
3629
3630 for (ri = rn->info; ri; ri = ri->next)
3631 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3632 && ri->sub_type == BGP_ROUTE_STATIC)
3633 break;
3634
3635 if (ri)
3636 {
3637 if (attrhash_cmp (ri->attr, attr_new) &&
3638 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3639 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
3640 {
3641 bgp_unlock_node (rn);
3642 bgp_attr_unintern (&attr_new);
3643 aspath_unintern (&attr.aspath);
3644 bgp_attr_extra_free (&attr);
3645 return;
3646 }
3647 else
3648 {
3649 /* The attribute is changed. */
3650 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3651
3652 /* Rewrite BGP route information. */
3653 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3654 bgp_info_restore(rn, ri);
3655 else
3656 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3657 #if ENABLE_BGP_VNC
3658 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3659 {
3660 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
3661 {
3662 /*
3663 * Implicit withdraw case.
3664 * We have to do this before ri is changed
3665 */
3666 ++vnc_implicit_withdraw;
3667 vnc_import_bgp_del_route(bgp, p, ri);
3668 vnc_import_bgp_exterior_del_route(bgp, p, ri);
3669 }
3670 }
3671 #endif
3672 bgp_attr_unintern (&ri->attr);
3673 ri->attr = attr_new;
3674 ri->uptime = bgp_clock ();
3675 #if ENABLE_BGP_VNC
3676 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3677 {
3678 if (vnc_implicit_withdraw)
3679 {
3680 vnc_import_bgp_add_route(bgp, p, ri);
3681 vnc_import_bgp_exterior_add_route(bgp, p, ri);
3682 }
3683 }
3684 #endif
3685
3686 /* Nexthop reachability check. */
3687 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3688 {
3689 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
3690 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3691 else
3692 {
3693 if (BGP_DEBUG(nht, NHT))
3694 {
3695 char buf1[INET6_ADDRSTRLEN];
3696 inet_ntop(p->family, &p->u.prefix, buf1,
3697 INET6_ADDRSTRLEN);
3698 zlog_debug("%s(%s): Route not in table, not advertising",
3699 __FUNCTION__, buf1);
3700 }
3701 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3702 }
3703 }
3704 else
3705 {
3706 /* Delete the NHT structure if any, if we're toggling between
3707 * enabling/disabling import check. We deregister the route
3708 * from NHT to avoid overloading NHT and the process interaction
3709 */
3710 bgp_unlink_nexthop(ri);
3711 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3712 }
3713 /* Process change. */
3714 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3715 bgp_process (bgp, rn, afi, safi);
3716 bgp_unlock_node (rn);
3717 aspath_unintern (&attr.aspath);
3718 bgp_attr_extra_free (&attr);
3719 return;
3720 }
3721 }
3722
3723 /* Make new BGP info. */
3724 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3725 rn);
3726 /* Nexthop reachability check. */
3727 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3728 {
3729 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
3730 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3731 else
3732 {
3733 if (BGP_DEBUG(nht, NHT))
3734 {
3735 char buf1[INET6_ADDRSTRLEN];
3736 inet_ntop(p->family, &p->u.prefix, buf1,
3737 INET6_ADDRSTRLEN);
3738 zlog_debug("%s(%s): Route not in table, not advertising",
3739 __FUNCTION__, buf1);
3740 }
3741 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3742 }
3743 }
3744 else
3745 {
3746 /* Delete the NHT structure if any, if we're toggling between
3747 * enabling/disabling import check. We deregister the route
3748 * from NHT to avoid overloading NHT and the process interaction
3749 */
3750 bgp_unlink_nexthop(new);
3751
3752 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3753 }
3754
3755 /* Aggregate address increment. */
3756 bgp_aggregate_increment (bgp, p, new, afi, safi);
3757
3758 /* Register new BGP information. */
3759 bgp_info_add (rn, new);
3760
3761 /* route_node_get lock */
3762 bgp_unlock_node (rn);
3763
3764 /* Process change. */
3765 bgp_process (bgp, rn, afi, safi);
3766
3767 /* Unintern original. */
3768 aspath_unintern (&attr.aspath);
3769 bgp_attr_extra_free (&attr);
3770 }
3771
3772 void
3773 bgp_static_update (struct bgp *bgp, struct prefix *p,
3774 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3775 {
3776 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3777 }
3778
3779 void
3780 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3781 safi_t safi)
3782 {
3783 struct bgp_node *rn;
3784 struct bgp_info *ri;
3785
3786 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3787
3788 /* Check selected route and self inserted route. */
3789 for (ri = rn->info; ri; ri = ri->next)
3790 if (ri->peer == bgp->peer_self
3791 && ri->type == ZEBRA_ROUTE_BGP
3792 && ri->sub_type == BGP_ROUTE_STATIC)
3793 break;
3794
3795 /* Withdraw static BGP route from routing table. */
3796 if (ri)
3797 {
3798 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3799 bgp_unlink_nexthop(ri);
3800 bgp_info_delete (rn, ri);
3801 bgp_process (bgp, rn, afi, safi);
3802 }
3803
3804 /* Unlock bgp_node_lookup. */
3805 bgp_unlock_node (rn);
3806 }
3807
3808 /*
3809 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3810 */
3811 static void
3812 bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3813 safi_t safi, struct prefix_rd *prd, u_char *tag)
3814 {
3815 struct bgp_node *rn;
3816 struct bgp_info *ri;
3817
3818 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3819
3820 /* Check selected route and self inserted route. */
3821 for (ri = rn->info; ri; ri = ri->next)
3822 if (ri->peer == bgp->peer_self
3823 && ri->type == ZEBRA_ROUTE_BGP
3824 && ri->sub_type == BGP_ROUTE_STATIC)
3825 break;
3826
3827 /* Withdraw static BGP route from routing table. */
3828 if (ri)
3829 {
3830 #if ENABLE_BGP_VNC
3831 rfapiProcessWithdraw(
3832 ri->peer,
3833 NULL,
3834 p,
3835 prd,
3836 ri->attr,
3837 afi,
3838 safi,
3839 ri->type,
3840 1); /* Kill, since it is an administrative change */
3841 #endif
3842 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3843 bgp_info_delete (rn, ri);
3844 bgp_process (bgp, rn, afi, safi);
3845 }
3846
3847 /* Unlock bgp_node_lookup. */
3848 bgp_unlock_node (rn);
3849 }
3850
3851 static void
3852 bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3853 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3854 {
3855 struct bgp_node *rn;
3856 struct bgp_info *new;
3857 struct attr *attr_new;
3858 struct attr attr = { 0 };
3859 struct bgp_info *ri;
3860 #if ENABLE_BGP_VNC
3861 u_int32_t label = 0;
3862 #endif
3863
3864 assert (bgp_static);
3865
3866 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3867
3868 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3869
3870 attr.nexthop = bgp_static->igpnexthop;
3871 attr.med = bgp_static->igpmetric;
3872 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3873
3874 /* Apply route-map. */
3875 if (bgp_static->rmap.name)
3876 {
3877 struct attr attr_tmp = attr;
3878 struct bgp_info info;
3879 int ret;
3880
3881 info.peer = bgp->peer_self;
3882 info.attr = &attr_tmp;
3883
3884 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3885
3886 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3887
3888 bgp->peer_self->rmap_type = 0;
3889
3890 if (ret == RMAP_DENYMATCH)
3891 {
3892 /* Free uninterned attribute. */
3893 bgp_attr_flush (&attr_tmp);
3894
3895 /* Unintern original. */
3896 aspath_unintern (&attr.aspath);
3897 bgp_attr_extra_free (&attr);
3898 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3899 bgp_static->tag);
3900 return;
3901 }
3902
3903 attr_new = bgp_attr_intern (&attr_tmp);
3904 }
3905 else
3906 {
3907 attr_new = bgp_attr_intern (&attr);
3908 }
3909
3910 for (ri = rn->info; ri; ri = ri->next)
3911 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3912 && ri->sub_type == BGP_ROUTE_STATIC)
3913 break;
3914
3915 if (ri)
3916 {
3917 if (attrhash_cmp (ri->attr, attr_new) &&
3918 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3919 {
3920 bgp_unlock_node (rn);
3921 bgp_attr_unintern (&attr_new);
3922 aspath_unintern (&attr.aspath);
3923 bgp_attr_extra_free (&attr);
3924 return;
3925 }
3926 else
3927 {
3928 /* The attribute is changed. */
3929 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3930
3931 /* Rewrite BGP route information. */
3932 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3933 bgp_info_restore(rn, ri);
3934 else
3935 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3936 bgp_attr_unintern (&ri->attr);
3937 ri->attr = attr_new;
3938 ri->uptime = bgp_clock ();
3939 #if ENABLE_BGP_VNC
3940 if (ri->extra)
3941 label = decode_label (ri->extra->tag);
3942 #endif
3943
3944 /* Process change. */
3945 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3946 bgp_process (bgp, rn, afi, safi);
3947 #if ENABLE_BGP_VNC
3948 rfapiProcessUpdate(ri->peer, NULL, p, &bgp_static->prd,
3949 ri->attr, afi, safi,
3950 ri->type, ri->sub_type, &label);
3951 #endif
3952 bgp_unlock_node (rn);
3953 aspath_unintern (&attr.aspath);
3954 bgp_attr_extra_free (&attr);
3955 return;
3956 }
3957 }
3958
3959
3960 /* Make new BGP info. */
3961 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3962 rn);
3963 SET_FLAG (new->flags, BGP_INFO_VALID);
3964 new->extra = bgp_info_extra_new();
3965 memcpy (new->extra->tag, bgp_static->tag, 3);
3966 #if ENABLE_BGP_VNC
3967 label = decode_label (bgp_static->tag);
3968 #endif
3969
3970 /* Aggregate address increment. */
3971 bgp_aggregate_increment (bgp, p, new, afi, safi);
3972
3973 /* Register new BGP information. */
3974 bgp_info_add (rn, new);
3975
3976 /* route_node_get lock */
3977 bgp_unlock_node (rn);
3978
3979 /* Process change. */
3980 bgp_process (bgp, rn, afi, safi);
3981
3982 #if ENABLE_BGP_VNC
3983 rfapiProcessUpdate(new->peer, NULL, p, &bgp_static->prd,
3984 new->attr, afi, safi,
3985 new->type, new->sub_type, &label);
3986 #endif
3987
3988 /* Unintern original. */
3989 aspath_unintern (&attr.aspath);
3990 bgp_attr_extra_free (&attr);
3991 }
3992
3993 /* Configure static BGP network. When user don't run zebra, static
3994 route should be installed as valid. */
3995 static int
3996 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3997 afi_t afi, safi_t safi, const char *rmap, int backdoor)
3998 {
3999 int ret;
4000 struct prefix p;
4001 struct bgp_static *bgp_static;
4002 struct bgp_node *rn;
4003 u_char need_update = 0;
4004
4005 /* Convert IP prefix string to struct prefix. */
4006 ret = str2prefix (ip_str, &p);
4007 if (! ret)
4008 {
4009 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4010 return CMD_WARNING;
4011 }
4012 #ifdef HAVE_IPV6
4013 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4014 {
4015 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4016 VTY_NEWLINE);
4017 return CMD_WARNING;
4018 }
4019 #endif /* HAVE_IPV6 */
4020
4021 apply_mask (&p);
4022
4023 /* Set BGP static route configuration. */
4024 rn = bgp_node_get (bgp->route[afi][safi], &p);
4025
4026 if (rn->info)
4027 {
4028 /* Configuration change. */
4029 bgp_static = rn->info;
4030
4031 /* Check previous routes are installed into BGP. */
4032 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4033 need_update = 1;
4034
4035 bgp_static->backdoor = backdoor;
4036
4037 if (rmap)
4038 {
4039 if (bgp_static->rmap.name)
4040 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4041 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4042 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4043 }
4044 else
4045 {
4046 if (bgp_static->rmap.name)
4047 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4048 bgp_static->rmap.name = NULL;
4049 bgp_static->rmap.map = NULL;
4050 bgp_static->valid = 0;
4051 }
4052 bgp_unlock_node (rn);
4053 }
4054 else
4055 {
4056 /* New configuration. */
4057 bgp_static = bgp_static_new ();
4058 bgp_static->backdoor = backdoor;
4059 bgp_static->valid = 0;
4060 bgp_static->igpmetric = 0;
4061 bgp_static->igpnexthop.s_addr = 0;
4062
4063 if (rmap)
4064 {
4065 if (bgp_static->rmap.name)
4066 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4067 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4068 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4069 }
4070 rn->info = bgp_static;
4071 }
4072
4073 bgp_static->valid = 1;
4074 if (need_update)
4075 bgp_static_withdraw (bgp, &p, afi, safi);
4076
4077 if (! bgp_static->backdoor)
4078 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4079
4080 return CMD_SUCCESS;
4081 }
4082
4083 /* Configure static BGP network. */
4084 static int
4085 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4086 afi_t afi, safi_t safi)
4087 {
4088 int ret;
4089 struct prefix p;
4090 struct bgp_static *bgp_static;
4091 struct bgp_node *rn;
4092
4093 /* Convert IP prefix string to struct prefix. */
4094 ret = str2prefix (ip_str, &p);
4095 if (! ret)
4096 {
4097 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4098 return CMD_WARNING;
4099 }
4100 #ifdef HAVE_IPV6
4101 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4102 {
4103 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4104 VTY_NEWLINE);
4105 return CMD_WARNING;
4106 }
4107 #endif /* HAVE_IPV6 */
4108
4109 apply_mask (&p);
4110
4111 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4112 if (! rn)
4113 {
4114 vty_out (vty, "%% Can't find specified static route configuration.%s",
4115 VTY_NEWLINE);
4116 return CMD_WARNING;
4117 }
4118
4119 bgp_static = rn->info;
4120
4121 /* Update BGP RIB. */
4122 if (! bgp_static->backdoor)
4123 bgp_static_withdraw (bgp, &p, afi, safi);
4124
4125 /* Clear configuration. */
4126 bgp_static_free (bgp_static);
4127 rn->info = NULL;
4128 bgp_unlock_node (rn);
4129 bgp_unlock_node (rn);
4130
4131 return CMD_SUCCESS;
4132 }
4133
4134 void
4135 bgp_static_add (struct bgp *bgp)
4136 {
4137 afi_t afi;
4138 safi_t safi;
4139 struct bgp_node *rn;
4140 struct bgp_node *rm;
4141 struct bgp_table *table;
4142 struct bgp_static *bgp_static;
4143
4144 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4145 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4146 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4147 if (rn->info != NULL)
4148 {
4149 if (safi == SAFI_MPLS_VPN)
4150 {
4151 table = rn->info;
4152
4153 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4154 {
4155 bgp_static = rn->info;
4156 bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
4157 }
4158 }
4159 else
4160 {
4161 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
4162 }
4163 }
4164 }
4165
4166 /* Called from bgp_delete(). Delete all static routes from the BGP
4167 instance. */
4168 void
4169 bgp_static_delete (struct bgp *bgp)
4170 {
4171 afi_t afi;
4172 safi_t safi;
4173 struct bgp_node *rn;
4174 struct bgp_node *rm;
4175 struct bgp_table *table;
4176 struct bgp_static *bgp_static;
4177
4178 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4179 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4180 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4181 if (rn->info != NULL)
4182 {
4183 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
4184 {
4185 table = rn->info;
4186
4187 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4188 {
4189 bgp_static = rn->info;
4190 bgp_static_withdraw_safi (bgp, &rm->p,
4191 AFI_IP, safi,
4192 (struct prefix_rd *)&rn->p,
4193 bgp_static->tag);
4194 bgp_static_free (bgp_static);
4195 rn->info = NULL;
4196 bgp_unlock_node (rn);
4197 }
4198 }
4199 else
4200 {
4201 bgp_static = rn->info;
4202 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4203 bgp_static_free (bgp_static);
4204 rn->info = NULL;
4205 bgp_unlock_node (rn);
4206 }
4207 }
4208 }
4209
4210 void
4211 bgp_static_redo_import_check (struct bgp *bgp)
4212 {
4213 afi_t afi;
4214 safi_t safi;
4215 struct bgp_node *rn;
4216 struct bgp_static *bgp_static;
4217
4218 /* Use this flag to force reprocessing of the route */
4219 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4220 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4221 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4222 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4223 if (rn->info != NULL)
4224 {
4225 bgp_static = rn->info;
4226 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
4227 }
4228 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4229 }
4230
4231 static void
4232 bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
4233 {
4234 struct bgp_table *table;
4235 struct bgp_node *rn;
4236 struct bgp_info *ri;
4237
4238 table = bgp->rib[afi][safi];
4239 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4240 {
4241 for (ri = rn->info; ri; ri = ri->next)
4242 {
4243 if (ri->peer == bgp->peer_self &&
4244 ((ri->type == ZEBRA_ROUTE_BGP &&
4245 ri->sub_type == BGP_ROUTE_STATIC) ||
4246 (ri->type != ZEBRA_ROUTE_BGP &&
4247 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
4248 {
4249 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
4250 bgp_unlink_nexthop(ri);
4251 bgp_info_delete (rn, ri);
4252 bgp_process (bgp, rn, afi, safi);
4253 }
4254 }
4255 }
4256 }
4257
4258 /*
4259 * Purge all networks and redistributed routes from routing table.
4260 * Invoked upon the instance going down.
4261 */
4262 void
4263 bgp_purge_static_redist_routes (struct bgp *bgp)
4264 {
4265 afi_t afi;
4266 safi_t safi;
4267
4268 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4269 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4270 bgp_purge_af_static_redist_routes (bgp, afi, safi);
4271 }
4272
4273 /*
4274 * gpz 110624
4275 * Currently this is used to set static routes for VPN and ENCAP.
4276 * I think it can probably be factored with bgp_static_set.
4277 */
4278 int
4279 bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4280 const char *rd_str, const char *tag_str,
4281 const char *rmap_str)
4282 {
4283 int ret;
4284 struct prefix p;
4285 struct prefix_rd prd;
4286 struct bgp *bgp;
4287 struct bgp_node *prn;
4288 struct bgp_node *rn;
4289 struct bgp_table *table;
4290 struct bgp_static *bgp_static;
4291 u_char tag[3];
4292
4293 bgp = vty->index;
4294
4295 ret = str2prefix (ip_str, &p);
4296 if (! ret)
4297 {
4298 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4299 return CMD_WARNING;
4300 }
4301 apply_mask (&p);
4302
4303 ret = str2prefix_rd (rd_str, &prd);
4304 if (! ret)
4305 {
4306 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4307 return CMD_WARNING;
4308 }
4309
4310 ret = str2tag (tag_str, tag);
4311 if (! ret)
4312 {
4313 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4314 return CMD_WARNING;
4315 }
4316
4317 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4318 (struct prefix *)&prd);
4319 if (prn->info == NULL)
4320 prn->info = bgp_table_init (AFI_IP, safi);
4321 else
4322 bgp_unlock_node (prn);
4323 table = prn->info;
4324
4325 rn = bgp_node_get (table, &p);
4326
4327 if (rn->info)
4328 {
4329 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4330 bgp_unlock_node (rn);
4331 }
4332 else
4333 {
4334 /* New configuration. */
4335 bgp_static = bgp_static_new ();
4336 bgp_static->backdoor = 0;
4337 bgp_static->valid = 0;
4338 bgp_static->igpmetric = 0;
4339 bgp_static->igpnexthop.s_addr = 0;
4340 memcpy(bgp_static->tag, tag, 3);
4341 bgp_static->prd = prd;
4342
4343 if (rmap_str)
4344 {
4345 if (bgp_static->rmap.name)
4346 free (bgp_static->rmap.name);
4347 bgp_static->rmap.name = strdup (rmap_str);
4348 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4349 }
4350 rn->info = bgp_static;
4351
4352 bgp_static->valid = 1;
4353 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
4354 }
4355
4356 return CMD_SUCCESS;
4357 }
4358
4359 /* Configure static BGP network. */
4360 int
4361 bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4362 const char *rd_str, const char *tag_str)
4363 {
4364 int ret;
4365 struct bgp *bgp;
4366 struct prefix p;
4367 struct prefix_rd prd;
4368 struct bgp_node *prn;
4369 struct bgp_node *rn;
4370 struct bgp_table *table;
4371 struct bgp_static *bgp_static;
4372 u_char tag[3];
4373
4374 bgp = vty->index;
4375
4376 /* Convert IP prefix string to struct prefix. */
4377 ret = str2prefix (ip_str, &p);
4378 if (! ret)
4379 {
4380 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4381 return CMD_WARNING;
4382 }
4383 apply_mask (&p);
4384
4385 ret = str2prefix_rd (rd_str, &prd);
4386 if (! ret)
4387 {
4388 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4389 return CMD_WARNING;
4390 }
4391
4392 ret = str2tag (tag_str, tag);
4393 if (! ret)
4394 {
4395 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4396 return CMD_WARNING;
4397 }
4398
4399 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4400 (struct prefix *)&prd);
4401 if (prn->info == NULL)
4402 prn->info = bgp_table_init (AFI_IP, safi);
4403 else
4404 bgp_unlock_node (prn);
4405 table = prn->info;
4406
4407 rn = bgp_node_lookup (table, &p);
4408
4409 if (rn)
4410 {
4411 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
4412
4413 bgp_static = rn->info;
4414 bgp_static_free (bgp_static);
4415 rn->info = NULL;
4416 bgp_unlock_node (rn);
4417 bgp_unlock_node (rn);
4418 }
4419 else
4420 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4421
4422 return CMD_SUCCESS;
4423 }
4424
4425 static int
4426 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4427 const char *rmap_name)
4428 {
4429 struct bgp_rmap *rmap;
4430
4431 rmap = &bgp->table_map[afi][safi];
4432 if (rmap_name)
4433 {
4434 if (rmap->name)
4435 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4436 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
4437 rmap->map = route_map_lookup_by_name (rmap_name);
4438 }
4439 else
4440 {
4441 if (rmap->name)
4442 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4443 rmap->name = NULL;
4444 rmap->map = NULL;
4445 }
4446
4447 bgp_zebra_announce_table(bgp, afi, safi);
4448
4449 return CMD_SUCCESS;
4450 }
4451
4452 static int
4453 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4454 const char *rmap_name)
4455 {
4456 struct bgp_rmap *rmap;
4457
4458 rmap = &bgp->table_map[afi][safi];
4459 if (rmap->name)
4460 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4461 rmap->name = NULL;
4462 rmap->map = NULL;
4463
4464 bgp_zebra_announce_table(bgp, afi, safi);
4465
4466 return CMD_SUCCESS;
4467 }
4468
4469 int
4470 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4471 safi_t safi, int *write)
4472 {
4473 if (bgp->table_map[afi][safi].name)
4474 {
4475 bgp_config_write_family_header (vty, afi, safi, write);
4476 vty_out (vty, " table-map %s%s",
4477 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4478 }
4479
4480 return 0;
4481 }
4482
4483 DEFUN (bgp_table_map,
4484 bgp_table_map_cmd,
4485 "table-map WORD",
4486 "BGP table to RIB route download filter\n"
4487 "Name of the route map\n")
4488 {
4489 return bgp_table_map_set (vty, vty->index,
4490 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4491 }
4492 DEFUN (no_bgp_table_map,
4493 no_bgp_table_map_cmd,
4494 "no table-map WORD",
4495 "BGP table to RIB route download filter\n"
4496 "Name of the route map\n")
4497 {
4498 return bgp_table_map_unset (vty, vty->index,
4499 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4500 }
4501
4502 DEFUN (bgp_network,
4503 bgp_network_cmd,
4504 "network A.B.C.D/M",
4505 "Specify a network to announce via BGP\n"
4506 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4507 {
4508 return bgp_static_set (vty, vty->index, argv[0],
4509 AFI_IP, bgp_node_safi (vty), NULL, 0);
4510 }
4511
4512 DEFUN (bgp_network_route_map,
4513 bgp_network_route_map_cmd,
4514 "network A.B.C.D/M route-map WORD",
4515 "Specify a network to announce via BGP\n"
4516 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4517 "Route-map to modify the attributes\n"
4518 "Name of the route map\n")
4519 {
4520 return bgp_static_set (vty, vty->index, argv[0],
4521 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4522 }
4523
4524 DEFUN (bgp_network_backdoor,
4525 bgp_network_backdoor_cmd,
4526 "network A.B.C.D/M backdoor",
4527 "Specify a network to announce via BGP\n"
4528 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4529 "Specify a BGP backdoor route\n")
4530 {
4531 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4532 NULL, 1);
4533 }
4534
4535 DEFUN (bgp_network_mask,
4536 bgp_network_mask_cmd,
4537 "network A.B.C.D mask A.B.C.D",
4538 "Specify a network to announce via BGP\n"
4539 "Network number\n"
4540 "Network mask\n"
4541 "Network mask\n")
4542 {
4543 int ret;
4544 char prefix_str[BUFSIZ];
4545
4546 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4547 if (! ret)
4548 {
4549 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4550 return CMD_WARNING;
4551 }
4552
4553 return bgp_static_set (vty, vty->index, prefix_str,
4554 AFI_IP, bgp_node_safi (vty), NULL, 0);
4555 }
4556
4557 DEFUN (bgp_network_mask_route_map,
4558 bgp_network_mask_route_map_cmd,
4559 "network A.B.C.D mask A.B.C.D route-map WORD",
4560 "Specify a network to announce via BGP\n"
4561 "Network number\n"
4562 "Network mask\n"
4563 "Network mask\n"
4564 "Route-map to modify the attributes\n"
4565 "Name of the route map\n")
4566 {
4567 int ret;
4568 char prefix_str[BUFSIZ];
4569
4570 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4571 if (! ret)
4572 {
4573 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4574 return CMD_WARNING;
4575 }
4576
4577 return bgp_static_set (vty, vty->index, prefix_str,
4578 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4579 }
4580
4581 DEFUN (bgp_network_mask_backdoor,
4582 bgp_network_mask_backdoor_cmd,
4583 "network A.B.C.D mask A.B.C.D backdoor",
4584 "Specify a network to announce via BGP\n"
4585 "Network number\n"
4586 "Network mask\n"
4587 "Network mask\n"
4588 "Specify a BGP backdoor route\n")
4589 {
4590 int ret;
4591 char prefix_str[BUFSIZ];
4592
4593 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4594 if (! ret)
4595 {
4596 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4597 return CMD_WARNING;
4598 }
4599
4600 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4601 NULL, 1);
4602 }
4603
4604 DEFUN (bgp_network_mask_natural,
4605 bgp_network_mask_natural_cmd,
4606 "network A.B.C.D",
4607 "Specify a network to announce via BGP\n"
4608 "Network number\n")
4609 {
4610 int ret;
4611 char prefix_str[BUFSIZ];
4612
4613 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4614 if (! ret)
4615 {
4616 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4617 return CMD_WARNING;
4618 }
4619
4620 return bgp_static_set (vty, vty->index, prefix_str,
4621 AFI_IP, bgp_node_safi (vty), NULL, 0);
4622 }
4623
4624 DEFUN (bgp_network_mask_natural_route_map,
4625 bgp_network_mask_natural_route_map_cmd,
4626 "network A.B.C.D route-map WORD",
4627 "Specify a network to announce via BGP\n"
4628 "Network number\n"
4629 "Route-map to modify the attributes\n"
4630 "Name of the route map\n")
4631 {
4632 int ret;
4633 char prefix_str[BUFSIZ];
4634
4635 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4636 if (! ret)
4637 {
4638 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4639 return CMD_WARNING;
4640 }
4641
4642 return bgp_static_set (vty, vty->index, prefix_str,
4643 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4644 }
4645
4646 DEFUN (bgp_network_mask_natural_backdoor,
4647 bgp_network_mask_natural_backdoor_cmd,
4648 "network A.B.C.D backdoor",
4649 "Specify a network to announce via BGP\n"
4650 "Network number\n"
4651 "Specify a BGP backdoor route\n")
4652 {
4653 int ret;
4654 char prefix_str[BUFSIZ];
4655
4656 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4657 if (! ret)
4658 {
4659 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4660 return CMD_WARNING;
4661 }
4662
4663 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4664 NULL, 1);
4665 }
4666
4667 DEFUN (no_bgp_network,
4668 no_bgp_network_cmd,
4669 "no network A.B.C.D/M",
4670 NO_STR
4671 "Specify a network to announce via BGP\n"
4672 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4673 {
4674 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4675 bgp_node_safi (vty));
4676 }
4677
4678 ALIAS (no_bgp_network,
4679 no_bgp_network_route_map_cmd,
4680 "no network A.B.C.D/M route-map WORD",
4681 NO_STR
4682 "Specify a network to announce via BGP\n"
4683 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4684 "Route-map to modify the attributes\n"
4685 "Name of the route map\n")
4686
4687 ALIAS (no_bgp_network,
4688 no_bgp_network_backdoor_cmd,
4689 "no network A.B.C.D/M backdoor",
4690 NO_STR
4691 "Specify a network to announce via BGP\n"
4692 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4693 "Specify a BGP backdoor route\n")
4694
4695 DEFUN (no_bgp_network_mask,
4696 no_bgp_network_mask_cmd,
4697 "no network A.B.C.D mask A.B.C.D",
4698 NO_STR
4699 "Specify a network to announce via BGP\n"
4700 "Network number\n"
4701 "Network mask\n"
4702 "Network mask\n")
4703 {
4704 int ret;
4705 char prefix_str[BUFSIZ];
4706
4707 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4708 if (! ret)
4709 {
4710 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4711 return CMD_WARNING;
4712 }
4713
4714 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4715 bgp_node_safi (vty));
4716 }
4717
4718 ALIAS (no_bgp_network_mask,
4719 no_bgp_network_mask_route_map_cmd,
4720 "no network A.B.C.D mask A.B.C.D route-map WORD",
4721 NO_STR
4722 "Specify a network to announce via BGP\n"
4723 "Network number\n"
4724 "Network mask\n"
4725 "Network mask\n"
4726 "Route-map to modify the attributes\n"
4727 "Name of the route map\n")
4728
4729 ALIAS (no_bgp_network_mask,
4730 no_bgp_network_mask_backdoor_cmd,
4731 "no network A.B.C.D mask A.B.C.D backdoor",
4732 NO_STR
4733 "Specify a network to announce via BGP\n"
4734 "Network number\n"
4735 "Network mask\n"
4736 "Network mask\n"
4737 "Specify a BGP backdoor route\n")
4738
4739 DEFUN (no_bgp_network_mask_natural,
4740 no_bgp_network_mask_natural_cmd,
4741 "no network A.B.C.D",
4742 NO_STR
4743 "Specify a network to announce via BGP\n"
4744 "Network number\n")
4745 {
4746 int ret;
4747 char prefix_str[BUFSIZ];
4748
4749 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4750 if (! ret)
4751 {
4752 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4753 return CMD_WARNING;
4754 }
4755
4756 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4757 bgp_node_safi (vty));
4758 }
4759
4760 ALIAS (no_bgp_network_mask_natural,
4761 no_bgp_network_mask_natural_route_map_cmd,
4762 "no network A.B.C.D route-map WORD",
4763 NO_STR
4764 "Specify a network to announce via BGP\n"
4765 "Network number\n"
4766 "Route-map to modify the attributes\n"
4767 "Name of the route map\n")
4768
4769 ALIAS (no_bgp_network_mask_natural,
4770 no_bgp_network_mask_natural_backdoor_cmd,
4771 "no network A.B.C.D backdoor",
4772 NO_STR
4773 "Specify a network to announce via BGP\n"
4774 "Network number\n"
4775 "Specify a BGP backdoor route\n")
4776
4777 #ifdef HAVE_IPV6
4778 DEFUN (ipv6_bgp_network,
4779 ipv6_bgp_network_cmd,
4780 "network X:X::X:X/M",
4781 "Specify a network to announce via BGP\n"
4782 "IPv6 prefix <network>/<length>\n")
4783 {
4784 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4785 NULL, 0);
4786 }
4787
4788 DEFUN (ipv6_bgp_network_route_map,
4789 ipv6_bgp_network_route_map_cmd,
4790 "network X:X::X:X/M route-map WORD",
4791 "Specify a network to announce via BGP\n"
4792 "IPv6 prefix <network>/<length>\n"
4793 "Route-map to modify the attributes\n"
4794 "Name of the route map\n")
4795 {
4796 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4797 bgp_node_safi (vty), argv[1], 0);
4798 }
4799
4800 DEFUN (no_ipv6_bgp_network,
4801 no_ipv6_bgp_network_cmd,
4802 "no network X:X::X:X/M",
4803 NO_STR
4804 "Specify a network to announce via BGP\n"
4805 "IPv6 prefix <network>/<length>\n")
4806 {
4807 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4808 }
4809
4810 ALIAS (no_ipv6_bgp_network,
4811 no_ipv6_bgp_network_route_map_cmd,
4812 "no network X:X::X:X/M route-map WORD",
4813 NO_STR
4814 "Specify a network to announce via BGP\n"
4815 "IPv6 prefix <network>/<length>\n"
4816 "Route-map to modify the attributes\n"
4817 "Name of the route map\n")
4818
4819 ALIAS (ipv6_bgp_network,
4820 old_ipv6_bgp_network_cmd,
4821 "ipv6 bgp network X:X::X:X/M",
4822 IPV6_STR
4823 BGP_STR
4824 "Specify a network to announce via BGP\n"
4825 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4826
4827 ALIAS (no_ipv6_bgp_network,
4828 old_no_ipv6_bgp_network_cmd,
4829 "no ipv6 bgp network X:X::X:X/M",
4830 NO_STR
4831 IPV6_STR
4832 BGP_STR
4833 "Specify a network to announce via BGP\n"
4834 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4835 #endif /* HAVE_IPV6 */
4836
4837 /* Aggreagete address:
4838
4839 advertise-map Set condition to advertise attribute
4840 as-set Generate AS set path information
4841 attribute-map Set attributes of aggregate
4842 route-map Set parameters of aggregate
4843 summary-only Filter more specific routes from updates
4844 suppress-map Conditionally filter more specific routes from updates
4845 <cr>
4846 */
4847 struct bgp_aggregate
4848 {
4849 /* Summary-only flag. */
4850 u_char summary_only;
4851
4852 /* AS set generation. */
4853 u_char as_set;
4854
4855 /* Route-map for aggregated route. */
4856 struct route_map *map;
4857
4858 /* Suppress-count. */
4859 unsigned long count;
4860
4861 /* SAFI configuration. */
4862 safi_t safi;
4863 };
4864
4865 static struct bgp_aggregate *
4866 bgp_aggregate_new (void)
4867 {
4868 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4869 }
4870
4871 static void
4872 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4873 {
4874 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4875 }
4876
4877 /* Update an aggregate as routes are added/removed from the BGP table */
4878 static void
4879 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4880 afi_t afi, safi_t safi, struct bgp_info *del,
4881 struct bgp_aggregate *aggregate)
4882 {
4883 struct bgp_table *table;
4884 struct bgp_node *top;
4885 struct bgp_node *rn;
4886 u_char origin;
4887 struct aspath *aspath = NULL;
4888 struct aspath *asmerge = NULL;
4889 struct community *community = NULL;
4890 struct community *commerge = NULL;
4891 #if defined(AGGREGATE_NEXTHOP_CHECK)
4892 struct in_addr nexthop;
4893 u_int32_t med = 0;
4894 #endif
4895 struct bgp_info *ri;
4896 struct bgp_info *new;
4897 int first = 1;
4898 unsigned long match = 0;
4899 u_char atomic_aggregate = 0;
4900
4901 /* Record adding route's nexthop and med. */
4902 if (rinew)
4903 {
4904 #if defined(AGGREGATE_NEXTHOP_CHECK)
4905 nexthop = rinew->attr->nexthop;
4906 med = rinew->attr->med;
4907 #endif
4908 }
4909
4910 /* ORIGIN attribute: If at least one route among routes that are
4911 aggregated has ORIGIN with the value INCOMPLETE, then the
4912 aggregated route must have the ORIGIN attribute with the value
4913 INCOMPLETE. Otherwise, if at least one route among routes that
4914 are aggregated has ORIGIN with the value EGP, then the aggregated
4915 route must have the origin attribute with the value EGP. In all
4916 other case the value of the ORIGIN attribute of the aggregated
4917 route is INTERNAL. */
4918 origin = BGP_ORIGIN_IGP;
4919
4920 table = bgp->rib[afi][safi];
4921
4922 top = bgp_node_get (table, p);
4923 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4924 if (rn->p.prefixlen > p->prefixlen)
4925 {
4926 match = 0;
4927
4928 for (ri = rn->info; ri; ri = ri->next)
4929 {
4930 if (BGP_INFO_HOLDDOWN (ri))
4931 continue;
4932
4933 if (del && ri == del)
4934 continue;
4935
4936 if (! rinew && first)
4937 {
4938 #if defined(AGGREGATE_NEXTHOP_CHECK)
4939 nexthop = ri->attr->nexthop;
4940 med = ri->attr->med;
4941 #endif
4942 first = 0;
4943 }
4944
4945 #ifdef AGGREGATE_NEXTHOP_CHECK
4946 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4947 || ri->attr->med != med)
4948 {
4949 if (aspath)
4950 aspath_free (aspath);
4951 if (community)
4952 community_free (community);
4953 bgp_unlock_node (rn);
4954 bgp_unlock_node (top);
4955 return;
4956 }
4957 #endif /* AGGREGATE_NEXTHOP_CHECK */
4958
4959 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4960 atomic_aggregate = 1;
4961
4962 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4963 {
4964 if (aggregate->summary_only)
4965 {
4966 (bgp_info_extra_get (ri))->suppress++;
4967 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4968 match++;
4969 }
4970
4971 aggregate->count++;
4972
4973 if (origin < ri->attr->origin)
4974 origin = ri->attr->origin;
4975
4976 if (aggregate->as_set)
4977 {
4978 if (aspath)
4979 {
4980 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4981 aspath_free (aspath);
4982 aspath = asmerge;
4983 }
4984 else
4985 aspath = aspath_dup (ri->attr->aspath);
4986
4987 if (ri->attr->community)
4988 {
4989 if (community)
4990 {
4991 commerge = community_merge (community,
4992 ri->attr->community);
4993 community = community_uniq_sort (commerge);
4994 community_free (commerge);
4995 }
4996 else
4997 community = community_dup (ri->attr->community);
4998 }
4999 }
5000 }
5001 }
5002 if (match)
5003 bgp_process (bgp, rn, afi, safi);
5004 }
5005 bgp_unlock_node (top);
5006
5007 if (rinew)
5008 {
5009 aggregate->count++;
5010
5011 if (aggregate->summary_only)
5012 (bgp_info_extra_get (rinew))->suppress++;
5013
5014 if (origin < rinew->attr->origin)
5015 origin = rinew->attr->origin;
5016
5017 if (aggregate->as_set)
5018 {
5019 if (aspath)
5020 {
5021 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5022 aspath_free (aspath);
5023 aspath = asmerge;
5024 }
5025 else
5026 aspath = aspath_dup (rinew->attr->aspath);
5027
5028 if (rinew->attr->community)
5029 {
5030 if (community)
5031 {
5032 commerge = community_merge (community,
5033 rinew->attr->community);
5034 community = community_uniq_sort (commerge);
5035 community_free (commerge);
5036 }
5037 else
5038 community = community_dup (rinew->attr->community);
5039 }
5040 }
5041 }
5042
5043 if (aggregate->count > 0)
5044 {
5045 rn = bgp_node_get (table, p);
5046 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5047 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5048 aggregate->as_set,
5049 atomic_aggregate), rn);
5050 SET_FLAG (new->flags, BGP_INFO_VALID);
5051
5052 bgp_info_add (rn, new);
5053 bgp_unlock_node (rn);
5054 bgp_process (bgp, rn, afi, safi);
5055 }
5056 else
5057 {
5058 if (aspath)
5059 aspath_free (aspath);
5060 if (community)
5061 community_free (community);
5062 }
5063 }
5064
5065 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5066 struct bgp_aggregate *);
5067
5068 void
5069 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5070 struct bgp_info *ri, afi_t afi, safi_t safi)
5071 {
5072 struct bgp_node *child;
5073 struct bgp_node *rn;
5074 struct bgp_aggregate *aggregate;
5075 struct bgp_table *table;
5076
5077 /* MPLS-VPN aggregation is not yet supported. */
5078 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5079 return;
5080
5081 table = bgp->aggregate[afi][safi];
5082
5083 /* No aggregates configured. */
5084 if (bgp_table_top_nolock (table) == NULL)
5085 return;
5086
5087 if (p->prefixlen == 0)
5088 return;
5089
5090 if (BGP_INFO_HOLDDOWN (ri))
5091 return;
5092
5093 child = bgp_node_get (table, p);
5094
5095 /* Aggregate address configuration check. */
5096 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5097 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5098 {
5099 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5100 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
5101 }
5102 bgp_unlock_node (child);
5103 }
5104
5105 void
5106 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5107 struct bgp_info *del, afi_t afi, safi_t safi)
5108 {
5109 struct bgp_node *child;
5110 struct bgp_node *rn;
5111 struct bgp_aggregate *aggregate;
5112 struct bgp_table *table;
5113
5114 /* MPLS-VPN aggregation is not yet supported. */
5115 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5116 return;
5117
5118 table = bgp->aggregate[afi][safi];
5119
5120 /* No aggregates configured. */
5121 if (bgp_table_top_nolock (table) == NULL)
5122 return;
5123
5124 if (p->prefixlen == 0)
5125 return;
5126
5127 child = bgp_node_get (table, p);
5128
5129 /* Aggregate address configuration check. */
5130 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5131 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5132 {
5133 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5134 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
5135 }
5136 bgp_unlock_node (child);
5137 }
5138
5139 /* Called via bgp_aggregate_set when the user configures aggregate-address */
5140 static void
5141 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5142 struct bgp_aggregate *aggregate)
5143 {
5144 struct bgp_table *table;
5145 struct bgp_node *top;
5146 struct bgp_node *rn;
5147 struct bgp_info *new;
5148 struct bgp_info *ri;
5149 unsigned long match;
5150 u_char origin = BGP_ORIGIN_IGP;
5151 struct aspath *aspath = NULL;
5152 struct aspath *asmerge = NULL;
5153 struct community *community = NULL;
5154 struct community *commerge = NULL;
5155 u_char atomic_aggregate = 0;
5156
5157 table = bgp->rib[afi][safi];
5158
5159 /* Sanity check. */
5160 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5161 return;
5162 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5163 return;
5164
5165 /* If routes exists below this node, generate aggregate routes. */
5166 top = bgp_node_get (table, p);
5167 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5168 if (rn->p.prefixlen > p->prefixlen)
5169 {
5170 match = 0;
5171
5172 for (ri = rn->info; ri; ri = ri->next)
5173 {
5174 if (BGP_INFO_HOLDDOWN (ri))
5175 continue;
5176
5177 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5178 atomic_aggregate = 1;
5179
5180 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5181 {
5182 /* summary-only aggregate route suppress aggregated
5183 route announcement. */
5184 if (aggregate->summary_only)
5185 {
5186 (bgp_info_extra_get (ri))->suppress++;
5187 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5188 match++;
5189 }
5190
5191 /* If at least one route among routes that are aggregated has
5192 * ORIGIN with the value INCOMPLETE, then the aggregated route
5193 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5194 * Otherwise, if at least one route among routes that are
5195 * aggregated has ORIGIN with the value EGP, then the aggregated
5196 * route MUST have the ORIGIN attribute with the value EGP.
5197 */
5198 if (origin < ri->attr->origin)
5199 origin = ri->attr->origin;
5200
5201 /* as-set aggregate route generate origin, as path,
5202 community aggregation. */
5203 if (aggregate->as_set)
5204 {
5205 if (aspath)
5206 {
5207 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5208 aspath_free (aspath);
5209 aspath = asmerge;
5210 }
5211 else
5212 aspath = aspath_dup (ri->attr->aspath);
5213
5214 if (ri->attr->community)
5215 {
5216 if (community)
5217 {
5218 commerge = community_merge (community,
5219 ri->attr->community);
5220 community = community_uniq_sort (commerge);
5221 community_free (commerge);
5222 }
5223 else
5224 community = community_dup (ri->attr->community);
5225 }
5226 }
5227 aggregate->count++;
5228 }
5229 }
5230
5231 /* If this node is suppressed, process the change. */
5232 if (match)
5233 bgp_process (bgp, rn, afi, safi);
5234 }
5235 bgp_unlock_node (top);
5236
5237 /* Add aggregate route to BGP table. */
5238 if (aggregate->count)
5239 {
5240 rn = bgp_node_get (table, p);
5241 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5242 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5243 aggregate->as_set,
5244 atomic_aggregate), rn);
5245 SET_FLAG (new->flags, BGP_INFO_VALID);
5246
5247 bgp_info_add (rn, new);
5248 bgp_unlock_node (rn);
5249
5250 /* Process change. */
5251 bgp_process (bgp, rn, afi, safi);
5252 }
5253 else
5254 {
5255 if (aspath)
5256 aspath_free (aspath);
5257 if (community)
5258 community_free (community);
5259 }
5260 }
5261
5262 void
5263 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5264 safi_t safi, struct bgp_aggregate *aggregate)
5265 {
5266 struct bgp_table *table;
5267 struct bgp_node *top;
5268 struct bgp_node *rn;
5269 struct bgp_info *ri;
5270 unsigned long match;
5271
5272 table = bgp->rib[afi][safi];
5273
5274 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5275 return;
5276 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5277 return;
5278
5279 /* If routes exists below this node, generate aggregate routes. */
5280 top = bgp_node_get (table, p);
5281 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5282 if (rn->p.prefixlen > p->prefixlen)
5283 {
5284 match = 0;
5285
5286 for (ri = rn->info; ri; ri = ri->next)
5287 {
5288 if (BGP_INFO_HOLDDOWN (ri))
5289 continue;
5290
5291 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5292 {
5293 if (aggregate->summary_only && ri->extra)
5294 {
5295 ri->extra->suppress--;
5296
5297 if (ri->extra->suppress == 0)
5298 {
5299 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5300 match++;
5301 }
5302 }
5303 aggregate->count--;
5304 }
5305 }
5306
5307 /* If this node was suppressed, process the change. */
5308 if (match)
5309 bgp_process (bgp, rn, afi, safi);
5310 }
5311 bgp_unlock_node (top);
5312
5313 /* Delete aggregate route from BGP table. */
5314 rn = bgp_node_get (table, p);
5315
5316 for (ri = rn->info; ri; ri = ri->next)
5317 if (ri->peer == bgp->peer_self
5318 && ri->type == ZEBRA_ROUTE_BGP
5319 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5320 break;
5321
5322 /* Withdraw static BGP route from routing table. */
5323 if (ri)
5324 {
5325 bgp_info_delete (rn, ri);
5326 bgp_process (bgp, rn, afi, safi);
5327 }
5328
5329 /* Unlock bgp_node_lookup. */
5330 bgp_unlock_node (rn);
5331 }
5332
5333 /* Aggregate route attribute. */
5334 #define AGGREGATE_SUMMARY_ONLY 1
5335 #define AGGREGATE_AS_SET 1
5336
5337 static int
5338 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5339 afi_t afi, safi_t safi)
5340 {
5341 int ret;
5342 struct prefix p;
5343 struct bgp_node *rn;
5344 struct bgp *bgp;
5345 struct bgp_aggregate *aggregate;
5346
5347 /* Convert string to prefix structure. */
5348 ret = str2prefix (prefix_str, &p);
5349 if (!ret)
5350 {
5351 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5352 return CMD_WARNING;
5353 }
5354 apply_mask (&p);
5355
5356 /* Get BGP structure. */
5357 bgp = vty->index;
5358
5359 /* Old configuration check. */
5360 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5361 if (! rn)
5362 {
5363 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5364 VTY_NEWLINE);
5365 return CMD_WARNING;
5366 }
5367
5368 aggregate = rn->info;
5369 if (aggregate->safi & SAFI_UNICAST)
5370 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5371 if (aggregate->safi & SAFI_MULTICAST)
5372 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5373
5374 /* Unlock aggregate address configuration. */
5375 rn->info = NULL;
5376 bgp_aggregate_free (aggregate);
5377 bgp_unlock_node (rn);
5378 bgp_unlock_node (rn);
5379
5380 return CMD_SUCCESS;
5381 }
5382
5383 static int
5384 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5385 afi_t afi, safi_t safi,
5386 u_char summary_only, u_char as_set)
5387 {
5388 int ret;
5389 struct prefix p;
5390 struct bgp_node *rn;
5391 struct bgp *bgp;
5392 struct bgp_aggregate *aggregate;
5393
5394 /* Convert string to prefix structure. */
5395 ret = str2prefix (prefix_str, &p);
5396 if (!ret)
5397 {
5398 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5399 return CMD_WARNING;
5400 }
5401 apply_mask (&p);
5402
5403 /* Get BGP structure. */
5404 bgp = vty->index;
5405
5406 /* Old configuration check. */
5407 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5408
5409 if (rn->info)
5410 {
5411 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5412 /* try to remove the old entry */
5413 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5414 if (ret)
5415 {
5416 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5417 bgp_unlock_node (rn);
5418 return CMD_WARNING;
5419 }
5420 }
5421
5422 /* Make aggregate address structure. */
5423 aggregate = bgp_aggregate_new ();
5424 aggregate->summary_only = summary_only;
5425 aggregate->as_set = as_set;
5426 aggregate->safi = safi;
5427 rn->info = aggregate;
5428
5429 /* Aggregate address insert into BGP routing table. */
5430 if (safi & SAFI_UNICAST)
5431 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5432 if (safi & SAFI_MULTICAST)
5433 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5434
5435 return CMD_SUCCESS;
5436 }
5437
5438 DEFUN (aggregate_address,
5439 aggregate_address_cmd,
5440 "aggregate-address A.B.C.D/M",
5441 "Configure BGP aggregate entries\n"
5442 "Aggregate prefix\n")
5443 {
5444 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5445 }
5446
5447 DEFUN (aggregate_address_mask,
5448 aggregate_address_mask_cmd,
5449 "aggregate-address A.B.C.D A.B.C.D",
5450 "Configure BGP aggregate entries\n"
5451 "Aggregate address\n"
5452 "Aggregate mask\n")
5453 {
5454 int ret;
5455 char prefix_str[BUFSIZ];
5456
5457 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5458
5459 if (! ret)
5460 {
5461 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5462 return CMD_WARNING;
5463 }
5464
5465 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5466 0, 0);
5467 }
5468
5469 DEFUN (aggregate_address_summary_only,
5470 aggregate_address_summary_only_cmd,
5471 "aggregate-address A.B.C.D/M summary-only",
5472 "Configure BGP aggregate entries\n"
5473 "Aggregate prefix\n"
5474 "Filter more specific routes from updates\n")
5475 {
5476 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5477 AGGREGATE_SUMMARY_ONLY, 0);
5478 }
5479
5480 DEFUN (aggregate_address_mask_summary_only,
5481 aggregate_address_mask_summary_only_cmd,
5482 "aggregate-address A.B.C.D A.B.C.D summary-only",
5483 "Configure BGP aggregate entries\n"
5484 "Aggregate address\n"
5485 "Aggregate mask\n"
5486 "Filter more specific routes from updates\n")
5487 {
5488 int ret;
5489 char prefix_str[BUFSIZ];
5490
5491 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5492
5493 if (! ret)
5494 {
5495 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5496 return CMD_WARNING;
5497 }
5498
5499 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5500 AGGREGATE_SUMMARY_ONLY, 0);
5501 }
5502
5503 DEFUN (aggregate_address_as_set,
5504 aggregate_address_as_set_cmd,
5505 "aggregate-address A.B.C.D/M as-set",
5506 "Configure BGP aggregate entries\n"
5507 "Aggregate prefix\n"
5508 "Generate AS set path information\n")
5509 {
5510 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5511 0, AGGREGATE_AS_SET);
5512 }
5513
5514 DEFUN (aggregate_address_mask_as_set,
5515 aggregate_address_mask_as_set_cmd,
5516 "aggregate-address A.B.C.D A.B.C.D as-set",
5517 "Configure BGP aggregate entries\n"
5518 "Aggregate address\n"
5519 "Aggregate mask\n"
5520 "Generate AS set path information\n")
5521 {
5522 int ret;
5523 char prefix_str[BUFSIZ];
5524
5525 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5526
5527 if (! ret)
5528 {
5529 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5530 return CMD_WARNING;
5531 }
5532
5533 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5534 0, AGGREGATE_AS_SET);
5535 }
5536
5537
5538 DEFUN (aggregate_address_as_set_summary,
5539 aggregate_address_as_set_summary_cmd,
5540 "aggregate-address A.B.C.D/M as-set summary-only",
5541 "Configure BGP aggregate entries\n"
5542 "Aggregate prefix\n"
5543 "Generate AS set path information\n"
5544 "Filter more specific routes from updates\n")
5545 {
5546 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5547 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5548 }
5549
5550 ALIAS (aggregate_address_as_set_summary,
5551 aggregate_address_summary_as_set_cmd,
5552 "aggregate-address A.B.C.D/M summary-only as-set",
5553 "Configure BGP aggregate entries\n"
5554 "Aggregate prefix\n"
5555 "Filter more specific routes from updates\n"
5556 "Generate AS set path information\n")
5557
5558 DEFUN (aggregate_address_mask_as_set_summary,
5559 aggregate_address_mask_as_set_summary_cmd,
5560 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5561 "Configure BGP aggregate entries\n"
5562 "Aggregate address\n"
5563 "Aggregate mask\n"
5564 "Generate AS set path information\n"
5565 "Filter more specific routes from updates\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 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5580 }
5581
5582 ALIAS (aggregate_address_mask_as_set_summary,
5583 aggregate_address_mask_summary_as_set_cmd,
5584 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5585 "Configure BGP aggregate entries\n"
5586 "Aggregate address\n"
5587 "Aggregate mask\n"
5588 "Filter more specific routes from updates\n"
5589 "Generate AS set path information\n")
5590
5591 DEFUN (no_aggregate_address,
5592 no_aggregate_address_cmd,
5593 "no aggregate-address A.B.C.D/M",
5594 NO_STR
5595 "Configure BGP aggregate entries\n"
5596 "Aggregate prefix\n")
5597 {
5598 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5599 }
5600
5601 ALIAS (no_aggregate_address,
5602 no_aggregate_address_summary_only_cmd,
5603 "no aggregate-address A.B.C.D/M summary-only",
5604 NO_STR
5605 "Configure BGP aggregate entries\n"
5606 "Aggregate prefix\n"
5607 "Filter more specific routes from updates\n")
5608
5609 ALIAS (no_aggregate_address,
5610 no_aggregate_address_as_set_cmd,
5611 "no aggregate-address A.B.C.D/M as-set",
5612 NO_STR
5613 "Configure BGP aggregate entries\n"
5614 "Aggregate prefix\n"
5615 "Generate AS set path information\n")
5616
5617 ALIAS (no_aggregate_address,
5618 no_aggregate_address_as_set_summary_cmd,
5619 "no aggregate-address A.B.C.D/M as-set summary-only",
5620 NO_STR
5621 "Configure BGP aggregate entries\n"
5622 "Aggregate prefix\n"
5623 "Generate AS set path information\n"
5624 "Filter more specific routes from updates\n")
5625
5626 ALIAS (no_aggregate_address,
5627 no_aggregate_address_summary_as_set_cmd,
5628 "no aggregate-address A.B.C.D/M summary-only as-set",
5629 NO_STR
5630 "Configure BGP aggregate entries\n"
5631 "Aggregate prefix\n"
5632 "Filter more specific routes from updates\n"
5633 "Generate AS set path information\n")
5634
5635 DEFUN (no_aggregate_address_mask,
5636 no_aggregate_address_mask_cmd,
5637 "no aggregate-address A.B.C.D A.B.C.D",
5638 NO_STR
5639 "Configure BGP aggregate entries\n"
5640 "Aggregate address\n"
5641 "Aggregate mask\n")
5642 {
5643 int ret;
5644 char prefix_str[BUFSIZ];
5645
5646 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5647
5648 if (! ret)
5649 {
5650 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5651 return CMD_WARNING;
5652 }
5653
5654 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5655 }
5656
5657 ALIAS (no_aggregate_address_mask,
5658 no_aggregate_address_mask_summary_only_cmd,
5659 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5660 NO_STR
5661 "Configure BGP aggregate entries\n"
5662 "Aggregate address\n"
5663 "Aggregate mask\n"
5664 "Filter more specific routes from updates\n")
5665
5666 ALIAS (no_aggregate_address_mask,
5667 no_aggregate_address_mask_as_set_cmd,
5668 "no aggregate-address A.B.C.D A.B.C.D as-set",
5669 NO_STR
5670 "Configure BGP aggregate entries\n"
5671 "Aggregate address\n"
5672 "Aggregate mask\n"
5673 "Generate AS set path information\n")
5674
5675 ALIAS (no_aggregate_address_mask,
5676 no_aggregate_address_mask_as_set_summary_cmd,
5677 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5678 NO_STR
5679 "Configure BGP aggregate entries\n"
5680 "Aggregate address\n"
5681 "Aggregate mask\n"
5682 "Generate AS set path information\n"
5683 "Filter more specific routes from updates\n")
5684
5685 ALIAS (no_aggregate_address_mask,
5686 no_aggregate_address_mask_summary_as_set_cmd,
5687 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5688 NO_STR
5689 "Configure BGP aggregate entries\n"
5690 "Aggregate address\n"
5691 "Aggregate mask\n"
5692 "Filter more specific routes from updates\n"
5693 "Generate AS set path information\n")
5694
5695 #ifdef HAVE_IPV6
5696 DEFUN (ipv6_aggregate_address,
5697 ipv6_aggregate_address_cmd,
5698 "aggregate-address X:X::X:X/M",
5699 "Configure BGP aggregate entries\n"
5700 "Aggregate prefix\n")
5701 {
5702 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5703 }
5704
5705 DEFUN (ipv6_aggregate_address_summary_only,
5706 ipv6_aggregate_address_summary_only_cmd,
5707 "aggregate-address X:X::X:X/M summary-only",
5708 "Configure BGP aggregate entries\n"
5709 "Aggregate prefix\n"
5710 "Filter more specific routes from updates\n")
5711 {
5712 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5713 AGGREGATE_SUMMARY_ONLY, 0);
5714 }
5715
5716 DEFUN (no_ipv6_aggregate_address,
5717 no_ipv6_aggregate_address_cmd,
5718 "no aggregate-address X:X::X:X/M",
5719 NO_STR
5720 "Configure BGP aggregate entries\n"
5721 "Aggregate prefix\n")
5722 {
5723 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5724 }
5725
5726 DEFUN (no_ipv6_aggregate_address_summary_only,
5727 no_ipv6_aggregate_address_summary_only_cmd,
5728 "no aggregate-address X:X::X:X/M summary-only",
5729 NO_STR
5730 "Configure BGP aggregate entries\n"
5731 "Aggregate prefix\n"
5732 "Filter more specific routes from updates\n")
5733 {
5734 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5735 }
5736
5737 ALIAS (ipv6_aggregate_address,
5738 old_ipv6_aggregate_address_cmd,
5739 "ipv6 bgp aggregate-address X:X::X:X/M",
5740 IPV6_STR
5741 BGP_STR
5742 "Configure BGP aggregate entries\n"
5743 "Aggregate prefix\n")
5744
5745 ALIAS (ipv6_aggregate_address_summary_only,
5746 old_ipv6_aggregate_address_summary_only_cmd,
5747 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5748 IPV6_STR
5749 BGP_STR
5750 "Configure BGP aggregate entries\n"
5751 "Aggregate prefix\n"
5752 "Filter more specific routes from updates\n")
5753
5754 ALIAS (no_ipv6_aggregate_address,
5755 old_no_ipv6_aggregate_address_cmd,
5756 "no ipv6 bgp aggregate-address X:X::X:X/M",
5757 NO_STR
5758 IPV6_STR
5759 BGP_STR
5760 "Configure BGP aggregate entries\n"
5761 "Aggregate prefix\n")
5762
5763 ALIAS (no_ipv6_aggregate_address_summary_only,
5764 old_no_ipv6_aggregate_address_summary_only_cmd,
5765 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5766 NO_STR
5767 IPV6_STR
5768 BGP_STR
5769 "Configure BGP aggregate entries\n"
5770 "Aggregate prefix\n"
5771 "Filter more specific routes from updates\n")
5772 #endif /* HAVE_IPV6 */
5773
5774 /* Redistribute route treatment. */
5775 void
5776 bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
5777 const struct in6_addr *nexthop6, unsigned int ifindex,
5778 u_int32_t metric, u_char type, u_short instance, route_tag_t tag)
5779 {
5780 struct bgp_info *new;
5781 struct bgp_info *bi;
5782 struct bgp_info info;
5783 struct bgp_node *bn;
5784 struct attr attr;
5785 struct attr *new_attr;
5786 afi_t afi;
5787 int ret;
5788 struct bgp_redist *red;
5789
5790 /* Make default attribute. */
5791 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5792 if (nexthop)
5793 attr.nexthop = *nexthop;
5794 attr.nh_ifindex = ifindex;
5795
5796 #ifdef HAVE_IPV6
5797 if (nexthop6)
5798 {
5799 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5800 extra->mp_nexthop_global = *nexthop6;
5801 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
5802 }
5803 #endif
5804
5805 attr.med = metric;
5806 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5807 attr.extra->tag = tag;
5808
5809 afi = family2afi (p->family);
5810
5811 red = bgp_redist_lookup(bgp, afi, type, instance);
5812 if (red)
5813 {
5814 struct attr attr_new;
5815 struct attr_extra extra_new;
5816
5817 /* Copy attribute for modification. */
5818 attr_new.extra = &extra_new;
5819 bgp_attr_dup (&attr_new, &attr);
5820
5821 if (red->redist_metric_flag)
5822 attr_new.med = red->redist_metric;
5823
5824 /* Apply route-map. */
5825 if (red->rmap.name)
5826 {
5827 info.peer = bgp->peer_self;
5828 info.attr = &attr_new;
5829
5830 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5831
5832 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5833
5834 bgp->peer_self->rmap_type = 0;
5835
5836 if (ret == RMAP_DENYMATCH)
5837 {
5838 /* Free uninterned attribute. */
5839 bgp_attr_flush (&attr_new);
5840
5841 /* Unintern original. */
5842 aspath_unintern (&attr.aspath);
5843 bgp_attr_extra_free (&attr);
5844 bgp_redistribute_delete (bgp, p, type, instance);
5845 return;
5846 }
5847 }
5848
5849 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5850 afi, SAFI_UNICAST, p, NULL);
5851
5852 new_attr = bgp_attr_intern (&attr_new);
5853
5854 for (bi = bn->info; bi; bi = bi->next)
5855 if (bi->peer == bgp->peer_self
5856 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5857 break;
5858
5859 if (bi)
5860 {
5861 /* Ensure the (source route) type is updated. */
5862 bi->type = type;
5863 if (attrhash_cmp (bi->attr, new_attr) &&
5864 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5865 {
5866 bgp_attr_unintern (&new_attr);
5867 aspath_unintern (&attr.aspath);
5868 bgp_attr_extra_free (&attr);
5869 bgp_unlock_node (bn);
5870 return;
5871 }
5872 else
5873 {
5874 /* The attribute is changed. */
5875 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5876
5877 /* Rewrite BGP route information. */
5878 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5879 bgp_info_restore(bn, bi);
5880 else
5881 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5882 bgp_attr_unintern (&bi->attr);
5883 bi->attr = new_attr;
5884 bi->uptime = bgp_clock ();
5885
5886 /* Process change. */
5887 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5888 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5889 bgp_unlock_node (bn);
5890 aspath_unintern (&attr.aspath);
5891 bgp_attr_extra_free (&attr);
5892 return;
5893 }
5894 }
5895
5896 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5897 new_attr, bn);
5898 SET_FLAG (new->flags, BGP_INFO_VALID);
5899
5900 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5901 bgp_info_add (bn, new);
5902 bgp_unlock_node (bn);
5903 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5904 }
5905
5906 /* Unintern original. */
5907 aspath_unintern (&attr.aspath);
5908 bgp_attr_extra_free (&attr);
5909 }
5910
5911 void
5912 bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
5913 {
5914 afi_t afi;
5915 struct bgp_node *rn;
5916 struct bgp_info *ri;
5917 struct bgp_redist *red;
5918
5919 afi = family2afi (p->family);
5920
5921 red = bgp_redist_lookup(bgp, afi, type, instance);
5922 if (red)
5923 {
5924 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5925
5926 for (ri = rn->info; ri; ri = ri->next)
5927 if (ri->peer == bgp->peer_self
5928 && ri->type == type)
5929 break;
5930
5931 if (ri)
5932 {
5933 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5934 bgp_info_delete (rn, ri);
5935 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5936 }
5937 bgp_unlock_node (rn);
5938 }
5939 }
5940
5941 /* Withdraw specified route type's route. */
5942 void
5943 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
5944 {
5945 struct bgp_node *rn;
5946 struct bgp_info *ri;
5947 struct bgp_table *table;
5948
5949 table = bgp->rib[afi][SAFI_UNICAST];
5950
5951 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5952 {
5953 for (ri = rn->info; ri; ri = ri->next)
5954 if (ri->peer == bgp->peer_self
5955 && ri->type == type
5956 && ri->instance == instance)
5957 break;
5958
5959 if (ri)
5960 {
5961 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5962 bgp_info_delete (rn, ri);
5963 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5964 }
5965 }
5966 }
5967
5968 /* Static function to display route. */
5969 static void
5970 route_vty_out_route (struct prefix *p, struct vty *vty)
5971 {
5972 int len;
5973 u_int32_t destination;
5974 char buf[BUFSIZ];
5975
5976 if (p->family == AF_INET)
5977 {
5978 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5979 destination = ntohl (p->u.prefix4.s_addr);
5980
5981 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5982 || (IN_CLASSB (destination) && p->prefixlen == 16)
5983 || (IN_CLASSA (destination) && p->prefixlen == 8)
5984 || p->u.prefix4.s_addr == 0)
5985 {
5986 /* When mask is natural, mask is not displayed. */
5987 }
5988 else
5989 len += vty_out (vty, "/%d", p->prefixlen);
5990 }
5991 else
5992 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5993 p->prefixlen);
5994
5995 len = 17 - len;
5996 if (len < 1)
5997 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5998 else
5999 vty_out (vty, "%*s", len, " ");
6000 }
6001
6002 enum bgp_display_type
6003 {
6004 normal_list,
6005 };
6006
6007 /* Print the short form route status for a bgp_info */
6008 static void
6009 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
6010 json_object *json_path)
6011 {
6012 if (json_path)
6013 {
6014
6015 /* Route status display. */
6016 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6017 json_object_boolean_true_add(json_path, "removed");
6018
6019 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6020 json_object_boolean_true_add(json_path, "stale");
6021
6022 if (binfo->extra && binfo->extra->suppress)
6023 json_object_boolean_true_add(json_path, "suppressed");
6024
6025 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6026 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6027 json_object_boolean_true_add(json_path, "valid");
6028
6029 /* Selected */
6030 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6031 json_object_boolean_true_add(json_path, "history");
6032
6033 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6034 json_object_boolean_true_add(json_path, "damped");
6035
6036 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6037 json_object_boolean_true_add(json_path, "bestpath");
6038
6039 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6040 json_object_boolean_true_add(json_path, "multipath");
6041
6042 /* Internal route. */
6043 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6044 json_object_string_add(json_path, "pathFrom", "internal");
6045 else
6046 json_object_string_add(json_path, "pathFrom", "external");
6047
6048 return;
6049 }
6050
6051 /* Route status display. */
6052 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6053 vty_out (vty, "R");
6054 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6055 vty_out (vty, "S");
6056 else if (binfo->extra && binfo->extra->suppress)
6057 vty_out (vty, "s");
6058 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6059 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6060 vty_out (vty, "*");
6061 else
6062 vty_out (vty, " ");
6063
6064 /* Selected */
6065 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6066 vty_out (vty, "h");
6067 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6068 vty_out (vty, "d");
6069 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6070 vty_out (vty, ">");
6071 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6072 vty_out (vty, "=");
6073 else
6074 vty_out (vty, " ");
6075
6076 /* Internal route. */
6077 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6078 vty_out (vty, "i");
6079 else
6080 vty_out (vty, " ");
6081 }
6082
6083 /* called from terminal list command */
6084 void
6085 route_vty_out (struct vty *vty, struct prefix *p,
6086 struct bgp_info *binfo, int display, safi_t safi,
6087 json_object *json_paths)
6088 {
6089 struct attr *attr;
6090 json_object *json_path = NULL;
6091 json_object *json_nexthops = NULL;
6092 json_object *json_nexthop_global = NULL;
6093 json_object *json_nexthop_ll = NULL;
6094
6095 if (json_paths)
6096 json_path = json_object_new_object();
6097
6098 /* short status lead text */
6099 route_vty_short_status_out (vty, binfo, json_path);
6100
6101 if (!json_paths)
6102 {
6103 /* print prefix and mask */
6104 if (! display)
6105 route_vty_out_route (p, vty);
6106 else
6107 vty_out (vty, "%*s", 17, " ");
6108 }
6109
6110 /* Print attribute */
6111 attr = binfo->attr;
6112 if (attr)
6113 {
6114 /*
6115 * For ENCAP routes, nexthop address family is not
6116 * neccessarily the same as the prefix address family.
6117 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
6118 */
6119 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN))
6120 {
6121 if (attr->extra)
6122 {
6123 char buf[BUFSIZ];
6124 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
6125
6126 switch (af)
6127 {
6128 case AF_INET:
6129 vty_out (vty, "%s", inet_ntop(af,
6130 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
6131 break;
6132 #if HAVE_IPV6
6133 case AF_INET6:
6134 vty_out (vty, "%s", inet_ntop(af,
6135 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
6136 break;
6137 #endif
6138 default:
6139 vty_out(vty, "?");
6140 break;
6141 }
6142 }
6143 else
6144 vty_out(vty, "?");
6145 }
6146 /* IPv4 Next Hop */
6147 else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6148 {
6149 if (json_paths)
6150 {
6151 json_nexthop_global = json_object_new_object();
6152
6153 if (safi == SAFI_MPLS_VPN)
6154 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6155 else
6156 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6157
6158 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6159 json_object_boolean_true_add(json_nexthop_global, "used");
6160 }
6161 else
6162 {
6163 if (safi == SAFI_MPLS_VPN)
6164 vty_out (vty, "%-16s",
6165 inet_ntoa (attr->extra->mp_nexthop_global_in));
6166 else
6167 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6168 }
6169 }
6170
6171 /* IPv6 Next Hop */
6172 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6173 {
6174 int len;
6175 char buf[BUFSIZ];
6176
6177 if (json_paths)
6178 {
6179 json_nexthop_global = json_object_new_object();
6180 json_object_string_add(json_nexthop_global, "ip",
6181 inet_ntop (AF_INET6,
6182 &attr->extra->mp_nexthop_global,
6183 buf, BUFSIZ));
6184 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6185 json_object_string_add(json_nexthop_global, "scope", "global");
6186
6187 /* We display both LL & GL if both have been received */
6188 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
6189 {
6190 json_nexthop_ll = json_object_new_object();
6191 json_object_string_add(json_nexthop_ll, "ip",
6192 inet_ntop (AF_INET6,
6193 &attr->extra->mp_nexthop_local,
6194 buf, BUFSIZ));
6195 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6196 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6197
6198 if ((IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
6199 &attr->extra->mp_nexthop_local) != 0) &&
6200 !attr->extra->mp_nexthop_prefer_global)
6201 json_object_boolean_true_add(json_nexthop_ll, "used");
6202 else
6203 json_object_boolean_true_add(json_nexthop_global, "used");
6204 }
6205 else
6206 json_object_boolean_true_add(json_nexthop_global, "used");
6207 }
6208 else
6209 {
6210 /* Display LL if LL/Global both in table unless prefer-global is set */
6211 if (((attr->extra->mp_nexthop_len == 32) &&
6212 !attr->extra->mp_nexthop_prefer_global) ||
6213 (binfo->peer->conf_if))
6214 {
6215 if (binfo->peer->conf_if)
6216 {
6217 len = vty_out (vty, "%s",
6218 binfo->peer->conf_if);
6219 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
6220
6221 if (len < 1)
6222 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
6223 else
6224 vty_out (vty, "%*s", len, " ");
6225 }
6226 else
6227 {
6228 len = vty_out (vty, "%s",
6229 inet_ntop (AF_INET6,
6230 &attr->extra->mp_nexthop_local,
6231 buf, BUFSIZ));
6232 len = 16 - len;
6233
6234 if (len < 1)
6235 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6236 else
6237 vty_out (vty, "%*s", len, " ");
6238 }
6239 }
6240 else
6241 {
6242 len = vty_out (vty, "%s",
6243 inet_ntop (AF_INET6,
6244 &attr->extra->mp_nexthop_global,
6245 buf, BUFSIZ));
6246 len = 16 - len;
6247
6248 if (len < 1)
6249 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6250 else
6251 vty_out (vty, "%*s", len, " ");
6252 }
6253 }
6254 }
6255
6256 /* MED/Metric */
6257 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6258 if (json_paths)
6259 json_object_int_add(json_path, "med", attr->med);
6260 else
6261 vty_out (vty, "%10u", attr->med);
6262 else
6263 if (!json_paths)
6264 vty_out (vty, " ");
6265
6266 /* Local Pref */
6267 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6268 if (json_paths)
6269 json_object_int_add(json_path, "localpref", attr->local_pref);
6270 else
6271 vty_out (vty, "%7u", attr->local_pref);
6272 else
6273 if (!json_paths)
6274 vty_out (vty, " ");
6275
6276 if (json_paths)
6277 {
6278 if (attr->extra)
6279 json_object_int_add(json_path, "weight", attr->extra->weight);
6280 else
6281 json_object_int_add(json_path, "weight", 0);
6282 }
6283 else
6284 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6285
6286 if (json_paths) {
6287 char buf[BUFSIZ];
6288 json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6289 }
6290
6291 /* Print aspath */
6292 if (attr->aspath)
6293 {
6294 if (json_paths)
6295 json_object_string_add(json_path, "aspath", attr->aspath->str);
6296 else
6297 aspath_print_vty (vty, "%s", attr->aspath, " ");
6298 }
6299
6300 /* Print origin */
6301 if (json_paths)
6302 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6303 else
6304 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6305 }
6306 else
6307 {
6308 if (json_paths)
6309 json_object_string_add(json_path, "alert", "No attributes");
6310 else
6311 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6312 }
6313
6314 if (json_paths)
6315 {
6316 if (json_nexthop_global || json_nexthop_ll)
6317 {
6318 json_nexthops = json_object_new_array();
6319
6320 if (json_nexthop_global)
6321 json_object_array_add(json_nexthops, json_nexthop_global);
6322
6323 if (json_nexthop_ll)
6324 json_object_array_add(json_nexthops, json_nexthop_ll);
6325
6326 json_object_object_add(json_path, "nexthops", json_nexthops);
6327 }
6328
6329 json_object_array_add(json_paths, json_path);
6330 }
6331 else
6332 {
6333 vty_out (vty, "%s", VTY_NEWLINE);
6334 #if ENABLE_BGP_VNC
6335 /* prints an additional line, indented, with VNC info, if present */
6336 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
6337 rfapi_vty_out_vncinfo(vty, p, binfo, safi);
6338 #endif
6339 }
6340 }
6341
6342 /* called from terminal list command */
6343 void
6344 route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6345 u_char use_json, json_object *json_ar)
6346 {
6347 json_object *json_status = NULL;
6348 json_object *json_net = NULL;
6349 char buff[BUFSIZ];
6350 /* Route status display. */
6351 if (use_json)
6352 {
6353 json_status = json_object_new_object();
6354 json_net = json_object_new_object();
6355 }
6356 else
6357 {
6358 vty_out (vty, "*");
6359 vty_out (vty, ">");
6360 vty_out (vty, " ");
6361 }
6362
6363 /* print prefix and mask */
6364 if (use_json)
6365 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6366 else
6367 route_vty_out_route (p, vty);
6368
6369 /* Print attribute */
6370 if (attr)
6371 {
6372 if (use_json)
6373 {
6374 if (p->family == AF_INET &&
6375 (safi == SAFI_MPLS_VPN ||
6376 safi == SAFI_ENCAP ||
6377 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6378 {
6379 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6380 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6381 else
6382 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6383 }
6384 #ifdef HAVE_IPV6
6385 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6386 {
6387 char buf[BUFSIZ];
6388
6389 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6390 buf, BUFSIZ));
6391 }
6392 #endif /* HAVE_IPV6 */
6393
6394 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6395 json_object_int_add(json_net, "metric", attr->med);
6396
6397 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6398 json_object_int_add(json_net, "localPref", attr->local_pref);
6399
6400 if (attr->extra)
6401 json_object_int_add(json_net, "weight", attr->extra->weight);
6402 else
6403 json_object_int_add(json_net, "weight", 0);
6404
6405 /* Print aspath */
6406 if (attr->aspath)
6407 json_object_string_add(json_net, "asPath", attr->aspath->str);
6408
6409 /* Print origin */
6410 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
6411 }
6412 else
6413 {
6414 if (p->family == AF_INET &&
6415 (safi == SAFI_MPLS_VPN ||
6416 safi == SAFI_ENCAP ||
6417 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6418 {
6419 if (attr->extra &&
6420 (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP))
6421 vty_out (vty, "%-16s",
6422 inet_ntoa (attr->extra->mp_nexthop_global_in));
6423 else
6424 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6425 }
6426 #ifdef HAVE_IPV6
6427 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6428 {
6429 int len;
6430 char buf[BUFSIZ];
6431 if (attr->extra)
6432 {
6433 len = vty_out (vty, "%s",
6434 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6435 buf, BUFSIZ));
6436 len = 16 - len;
6437 }
6438 else
6439 len = 0;
6440 if (len < 1)
6441 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6442 else
6443 vty_out (vty, "%*s", len, " ");
6444 }
6445 #endif /* HAVE_IPV6 */
6446 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6447 vty_out (vty, "%10u", attr->med);
6448 else
6449 vty_out (vty, " ");
6450
6451 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6452 vty_out (vty, "%7u", attr->local_pref);
6453 else
6454 vty_out (vty, " ");
6455
6456 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6457
6458 /* Print aspath */
6459 if (attr->aspath)
6460 aspath_print_vty (vty, "%s", attr->aspath, " ");
6461
6462 /* Print origin */
6463 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6464 }
6465 }
6466 if (use_json)
6467 {
6468 json_object_boolean_true_add(json_status, "*");
6469 json_object_boolean_true_add(json_status, ">");
6470 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6471 char buf_cut[BUFSIZ];
6472 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6473 }
6474 else
6475 vty_out (vty, "%s", VTY_NEWLINE);
6476 }
6477
6478 void
6479 route_vty_out_tag (struct vty *vty, struct prefix *p,
6480 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
6481 {
6482 json_object *json_out = NULL;
6483 struct attr *attr;
6484 u_int32_t label = 0;
6485
6486 if (!binfo->extra)
6487 return;
6488
6489 if (json)
6490 json_out = json_object_new_object();
6491
6492 /* short status lead text */
6493 route_vty_short_status_out (vty, binfo, json_out);
6494
6495 /* print prefix and mask */
6496 if (json == NULL)
6497 {
6498 if (! display)
6499 route_vty_out_route (p, vty);
6500 else
6501 vty_out (vty, "%*s", 17, " ");
6502 }
6503
6504 /* Print attribute */
6505 attr = binfo->attr;
6506 if (attr)
6507 {
6508 if (p->family == AF_INET
6509 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6510 {
6511 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6512 {
6513 if (json)
6514 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6515 else
6516 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6517 }
6518 else
6519 {
6520 if (json)
6521 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6522 else
6523 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6524 }
6525 }
6526 #ifdef HAVE_IPV6
6527 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6528 {
6529 assert (attr->extra);
6530 char buf_a[BUFSIZ];
6531 char buf_b[BUFSIZ];
6532 char buf_c[BUFSIZ];
6533 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
6534 {
6535 if (json)
6536 json_object_string_add(json_out, "mpNexthopGlobalIn",
6537 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6538 else
6539 vty_out (vty, "%s",
6540 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6541 buf_a, BUFSIZ));
6542 }
6543 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6544 {
6545 if (json)
6546 {
6547 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6548 buf_a, BUFSIZ);
6549 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6550 buf_b, BUFSIZ);
6551 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6552 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6553 }
6554 else
6555 vty_out (vty, "%s(%s)",
6556 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6557 buf_a, BUFSIZ),
6558 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6559 buf_b, BUFSIZ));
6560 }
6561
6562 }
6563 #endif /* HAVE_IPV6 */
6564 }
6565
6566 label = decode_label (binfo->extra->tag);
6567
6568 if (json)
6569 {
6570 if (label)
6571 json_object_int_add(json_out, "notag", label);
6572 json_object_array_add(json, json_out);
6573 }
6574 else
6575 {
6576 vty_out (vty, "notag/%d", label);
6577 vty_out (vty, "%s", VTY_NEWLINE);
6578 }
6579 }
6580
6581 /* dampening route */
6582 static void
6583 damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6584 int display, safi_t safi, u_char use_json, json_object *json)
6585 {
6586 struct attr *attr;
6587 int len;
6588 char timebuf[BGP_UPTIME_LEN];
6589
6590 /* short status lead text */
6591 route_vty_short_status_out (vty, binfo, json);
6592
6593 /* print prefix and mask */
6594 if (!use_json)
6595 {
6596 if (! display)
6597 route_vty_out_route (p, vty);
6598 else
6599 vty_out (vty, "%*s", 17, " ");
6600 }
6601
6602 len = vty_out (vty, "%s", binfo->peer->host);
6603 len = 17 - len;
6604 if (len < 1)
6605 {
6606 if (!use_json)
6607 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6608 }
6609 else
6610 {
6611 if (use_json)
6612 json_object_int_add(json, "peerHost", len);
6613 else
6614 vty_out (vty, "%*s", len, " ");
6615 }
6616
6617 if (use_json)
6618 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6619 else
6620 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6621
6622 /* Print attribute */
6623 attr = binfo->attr;
6624 if (attr)
6625 {
6626 /* Print aspath */
6627 if (attr->aspath)
6628 {
6629 if (use_json)
6630 json_object_string_add(json, "asPath", attr->aspath->str);
6631 else
6632 aspath_print_vty (vty, "%s", attr->aspath, " ");
6633 }
6634
6635 /* Print origin */
6636 if (use_json)
6637 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6638 else
6639 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6640 }
6641 if (!use_json)
6642 vty_out (vty, "%s", VTY_NEWLINE);
6643 }
6644
6645 /* flap route */
6646 static void
6647 flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6648 int display, safi_t safi, u_char use_json, json_object *json)
6649 {
6650 struct attr *attr;
6651 struct bgp_damp_info *bdi;
6652 char timebuf[BGP_UPTIME_LEN];
6653 int len;
6654
6655 if (!binfo->extra)
6656 return;
6657
6658 bdi = binfo->extra->damp_info;
6659
6660 /* short status lead text */
6661 route_vty_short_status_out (vty, binfo, json);
6662
6663 /* print prefix and mask */
6664 if (!use_json)
6665 {
6666 if (! display)
6667 route_vty_out_route (p, vty);
6668 else
6669 vty_out (vty, "%*s", 17, " ");
6670 }
6671
6672 len = vty_out (vty, "%s", binfo->peer->host);
6673 len = 16 - len;
6674 if (len < 1)
6675 {
6676 if (!use_json)
6677 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6678 }
6679 else
6680 {
6681 if (use_json)
6682 json_object_int_add(json, "peerHost", len);
6683 else
6684 vty_out (vty, "%*s", len, " ");
6685 }
6686
6687 len = vty_out (vty, "%d", bdi->flap);
6688 len = 5 - len;
6689 if (len < 1)
6690 {
6691 if (!use_json)
6692 vty_out (vty, " ");
6693 }
6694 else
6695 {
6696 if (use_json)
6697 json_object_int_add(json, "bdiFlap", len);
6698 else
6699 vty_out (vty, "%*s", len, " ");
6700 }
6701
6702 if (use_json)
6703 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6704 else
6705 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6706 timebuf, BGP_UPTIME_LEN, 0, NULL));
6707
6708 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6709 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6710 {
6711 if (use_json)
6712 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6713 else
6714 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6715 }
6716 else
6717 {
6718 if (!use_json)
6719 vty_out (vty, "%*s ", 8, " ");
6720 }
6721
6722 /* Print attribute */
6723 attr = binfo->attr;
6724 if (attr)
6725 {
6726 /* Print aspath */
6727 if (attr->aspath)
6728 {
6729 if (use_json)
6730 json_object_string_add(json, "asPath", attr->aspath->str);
6731 else
6732 aspath_print_vty (vty, "%s", attr->aspath, " ");
6733 }
6734
6735 /* Print origin */
6736 if (use_json)
6737 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6738 else
6739 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6740 }
6741 if (!use_json)
6742 vty_out (vty, "%s", VTY_NEWLINE);
6743 }
6744
6745 static void
6746 route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6747 const char *header, json_object *json_adv_to)
6748 {
6749 char buf1[INET6_ADDRSTRLEN];
6750 json_object *json_peer = NULL;
6751
6752 if (json_adv_to)
6753 {
6754 /* 'advertised-to' is a dictionary of peers we have advertised this
6755 * prefix too. The key is the peer's IP or swpX, the value is the
6756 * hostname if we know it and "" if not.
6757 */
6758 json_peer = json_object_new_object();
6759
6760 if (peer->hostname)
6761 json_object_string_add(json_peer, "hostname", peer->hostname);
6762
6763 if (peer->conf_if)
6764 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6765 else
6766 json_object_object_add(json_adv_to,
6767 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6768 json_peer);
6769 }
6770 else
6771 {
6772 if (*first)
6773 {
6774 vty_out (vty, "%s", header);
6775 *first = 0;
6776 }
6777
6778 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6779 {
6780 if (peer->conf_if)
6781 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6782 else
6783 vty_out (vty, " %s(%s)", peer->hostname,
6784 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6785 }
6786 else
6787 {
6788 if (peer->conf_if)
6789 vty_out (vty, " %s", peer->conf_if);
6790 else
6791 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6792 }
6793 }
6794 }
6795
6796 static void
6797 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6798 struct bgp_info *binfo, afi_t afi, safi_t safi,
6799 json_object *json_paths)
6800 {
6801 char buf[INET6_ADDRSTRLEN];
6802 char buf1[BUFSIZ];
6803 struct attr *attr;
6804 int sockunion_vty_out (struct vty *, union sockunion *);
6805 #ifdef HAVE_CLOCK_MONOTONIC
6806 time_t tbuf;
6807 #endif
6808 json_object *json_bestpath = NULL;
6809 json_object *json_cluster_list = NULL;
6810 json_object *json_cluster_list_list = NULL;
6811 json_object *json_ext_community = NULL;
6812 json_object *json_last_update = NULL;
6813 json_object *json_nexthop_global = NULL;
6814 json_object *json_nexthop_ll = NULL;
6815 json_object *json_nexthops = NULL;
6816 json_object *json_path = NULL;
6817 json_object *json_peer = NULL;
6818 json_object *json_string = NULL;
6819 json_object *json_adv_to = NULL;
6820 int first = 0;
6821 struct listnode *node, *nnode;
6822 struct peer *peer;
6823 int addpath_capable;
6824 int has_adj;
6825 unsigned int first_as;
6826
6827 if (json_paths)
6828 {
6829 json_path = json_object_new_object();
6830 json_peer = json_object_new_object();
6831 json_nexthop_global = json_object_new_object();
6832 }
6833
6834 attr = binfo->attr;
6835
6836 if (attr)
6837 {
6838 /* Line1 display AS-path, Aggregator */
6839 if (attr->aspath)
6840 {
6841 if (json_paths)
6842 {
6843 json_object_lock(attr->aspath->json);
6844 json_object_object_add(json_path, "aspath", attr->aspath->json);
6845 }
6846 else
6847 {
6848 if (attr->aspath->segments)
6849 aspath_print_vty (vty, " %s", attr->aspath, "");
6850 else
6851 vty_out (vty, " Local");
6852 }
6853 }
6854
6855 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6856 {
6857 if (json_paths)
6858 json_object_boolean_true_add(json_path, "removed");
6859 else
6860 vty_out (vty, ", (removed)");
6861 }
6862
6863 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6864 {
6865 if (json_paths)
6866 json_object_boolean_true_add(json_path, "stale");
6867 else
6868 vty_out (vty, ", (stale)");
6869 }
6870
6871 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6872 {
6873 if (json_paths)
6874 {
6875 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6876 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
6877 }
6878 else
6879 {
6880 vty_out (vty, ", (aggregated by %u %s)",
6881 attr->extra->aggregator_as,
6882 inet_ntoa (attr->extra->aggregator_addr));
6883 }
6884 }
6885
6886 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6887 {
6888 if (json_paths)
6889 json_object_boolean_true_add(json_path, "rxedFromRrClient");
6890 else
6891 vty_out (vty, ", (Received from a RR-client)");
6892 }
6893
6894 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6895 {
6896 if (json_paths)
6897 json_object_boolean_true_add(json_path, "rxedFromRsClient");
6898 else
6899 vty_out (vty, ", (Received from a RS-client)");
6900 }
6901
6902 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6903 {
6904 if (json_paths)
6905 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
6906 else
6907 vty_out (vty, ", (history entry)");
6908 }
6909 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6910 {
6911 if (json_paths)
6912 json_object_boolean_true_add(json_path, "dampeningSuppressed");
6913 else
6914 vty_out (vty, ", (suppressed due to dampening)");
6915 }
6916
6917 if (!json_paths)
6918 vty_out (vty, "%s", VTY_NEWLINE);
6919
6920 /* Line2 display Next-hop, Neighbor, Router-id */
6921 /* Display the nexthop */
6922 if (p->family == AF_INET &&
6923 (safi == SAFI_MPLS_VPN ||
6924 safi == SAFI_ENCAP ||
6925 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6926 {
6927 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6928 {
6929 if (json_paths)
6930 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6931 else
6932 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6933 }
6934 else
6935 {
6936 if (json_paths)
6937 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6938 else
6939 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6940 }
6941
6942 if (json_paths)
6943 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6944 }
6945 else
6946 {
6947 assert (attr->extra);
6948 if (json_paths)
6949 {
6950 json_object_string_add(json_nexthop_global, "ip",
6951 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6952 buf, INET6_ADDRSTRLEN));
6953 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6954 json_object_string_add(json_nexthop_global, "scope", "global");
6955 }
6956 else
6957 {
6958 vty_out (vty, " %s",
6959 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6960 buf, INET6_ADDRSTRLEN));
6961 }
6962 }
6963
6964 /* Display the IGP cost or 'inaccessible' */
6965 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6966 {
6967 if (json_paths)
6968 json_object_boolean_false_add(json_nexthop_global, "accessible");
6969 else
6970 vty_out (vty, " (inaccessible)");
6971 }
6972 else
6973 {
6974 if (binfo->extra && binfo->extra->igpmetric)
6975 {
6976 if (json_paths)
6977 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
6978 else
6979 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
6980 }
6981
6982 /* IGP cost is 0, display this only for json */
6983 else
6984 {
6985 if (json_paths)
6986 json_object_int_add(json_nexthop_global, "metric", 0);
6987 }
6988
6989 if (json_paths)
6990 json_object_boolean_true_add(json_nexthop_global, "accessible");
6991 }
6992
6993 /* Display peer "from" output */
6994 /* This path was originated locally */
6995 if (binfo->peer == bgp->peer_self)
6996 {
6997
6998 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6999 {
7000 if (json_paths)
7001 json_object_string_add(json_peer, "peerId", "0.0.0.0");
7002 else
7003 vty_out (vty, " from 0.0.0.0 ");
7004 }
7005 else
7006 {
7007 if (json_paths)
7008 json_object_string_add(json_peer, "peerId", "::");
7009 else
7010 vty_out (vty, " from :: ");
7011 }
7012
7013 if (json_paths)
7014 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
7015 else
7016 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
7017 }
7018
7019 /* We RXed this path from one of our peers */
7020 else
7021 {
7022
7023 if (json_paths)
7024 {
7025 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7026 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7027
7028 if (binfo->peer->hostname)
7029 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
7030
7031 if (binfo->peer->domainname)
7032 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
7033
7034 if (binfo->peer->conf_if)
7035 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
7036 }
7037 else
7038 {
7039 if (binfo->peer->conf_if)
7040 {
7041 if (binfo->peer->hostname &&
7042 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7043 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7044 binfo->peer->conf_if);
7045 else
7046 vty_out (vty, " from %s", binfo->peer->conf_if);
7047 }
7048 else
7049 {
7050 if (binfo->peer->hostname &&
7051 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7052 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7053 binfo->peer->host);
7054 else
7055 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7056 }
7057
7058 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7059 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
7060 else
7061 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7062 }
7063 }
7064
7065 if (!json_paths)
7066 vty_out (vty, "%s", VTY_NEWLINE);
7067
7068 /* display the link-local nexthop */
7069 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
7070 {
7071 if (json_paths)
7072 {
7073 json_nexthop_ll = json_object_new_object();
7074 json_object_string_add(json_nexthop_ll, "ip",
7075 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7076 buf, INET6_ADDRSTRLEN));
7077 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
7078 json_object_string_add(json_nexthop_ll, "scope", "link-local");
7079
7080 json_object_boolean_true_add(json_nexthop_ll, "accessible");
7081
7082 if (!attr->extra->mp_nexthop_prefer_global)
7083 json_object_boolean_true_add(json_nexthop_ll, "used");
7084 else
7085 json_object_boolean_true_add(json_nexthop_global, "used");
7086 }
7087 else
7088 {
7089 vty_out (vty, " (%s) %s%s",
7090 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7091 buf, INET6_ADDRSTRLEN),
7092 attr->extra->mp_nexthop_prefer_global ?
7093 "(prefer-global)" : "(used)",
7094 VTY_NEWLINE);
7095 }
7096 }
7097 /* If we do not have a link-local nexthop then we must flag the global as "used" */
7098 else
7099 {
7100 if (json_paths)
7101 json_object_boolean_true_add(json_nexthop_global, "used");
7102 }
7103
7104 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
7105 if (json_paths)
7106 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
7107 else
7108 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
7109
7110 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
7111 {
7112 if (json_paths)
7113 json_object_int_add(json_path, "med", attr->med);
7114 else
7115 vty_out (vty, ", metric %u", attr->med);
7116 }
7117
7118 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
7119 {
7120 if (json_paths)
7121 json_object_int_add(json_path, "localpref", attr->local_pref);
7122 else
7123 vty_out (vty, ", localpref %u", attr->local_pref);
7124 }
7125 else
7126 {
7127 if (json_paths)
7128 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
7129 else
7130 vty_out (vty, ", localpref %u", bgp->default_local_pref);
7131 }
7132
7133 if (attr->extra && attr->extra->weight != 0)
7134 {
7135 if (json_paths)
7136 json_object_int_add(json_path, "weight", attr->extra->weight);
7137 else
7138 vty_out (vty, ", weight %u", attr->extra->weight);
7139 }
7140
7141 if (attr->extra && attr->extra->tag != 0)
7142 {
7143 if (json_paths)
7144 json_object_int_add(json_path, "tag", attr->extra->tag);
7145 else
7146 vty_out (vty, ", tag %"ROUTE_TAG_PRI, attr->extra->tag);
7147 }
7148
7149 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7150 {
7151 if (json_paths)
7152 json_object_boolean_false_add(json_path, "valid");
7153 else
7154 vty_out (vty, ", invalid");
7155 }
7156 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
7157 {
7158 if (json_paths)
7159 json_object_boolean_true_add(json_path, "valid");
7160 else
7161 vty_out (vty, ", valid");
7162 }
7163
7164 if (binfo->peer != bgp->peer_self)
7165 {
7166 if (binfo->peer->as == binfo->peer->local_as)
7167 {
7168 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7169 {
7170 if (json_paths)
7171 json_object_string_add(json_peer, "type", "confed-internal");
7172 else
7173 vty_out (vty, ", confed-internal");
7174 }
7175 else
7176 {
7177 if (json_paths)
7178 json_object_string_add(json_peer, "type", "internal");
7179 else
7180 vty_out (vty, ", internal");
7181 }
7182 }
7183 else
7184 {
7185 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
7186 {
7187 if (json_paths)
7188 json_object_string_add(json_peer, "type", "confed-external");
7189 else
7190 vty_out (vty, ", confed-external");
7191 }
7192 else
7193 {
7194 if (json_paths)
7195 json_object_string_add(json_peer, "type", "external");
7196 else
7197 vty_out (vty, ", external");
7198 }
7199 }
7200 }
7201 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
7202 {
7203 if (json_paths)
7204 {
7205 json_object_boolean_true_add(json_path, "aggregated");
7206 json_object_boolean_true_add(json_path, "local");
7207 }
7208 else
7209 {
7210 vty_out (vty, ", aggregated, local");
7211 }
7212 }
7213 else if (binfo->type != ZEBRA_ROUTE_BGP)
7214 {
7215 if (json_paths)
7216 json_object_boolean_true_add(json_path, "sourced");
7217 else
7218 vty_out (vty, ", sourced");
7219 }
7220 else
7221 {
7222 if (json_paths)
7223 {
7224 json_object_boolean_true_add(json_path, "sourced");
7225 json_object_boolean_true_add(json_path, "local");
7226 }
7227 else
7228 {
7229 vty_out (vty, ", sourced, local");
7230 }
7231 }
7232
7233 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
7234 {
7235 if (json_paths)
7236 json_object_boolean_true_add(json_path, "atomicAggregate");
7237 else
7238 vty_out (vty, ", atomic-aggregate");
7239 }
7240
7241 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7242 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7243 bgp_info_mpath_count (binfo)))
7244 {
7245 if (json_paths)
7246 json_object_boolean_true_add(json_path, "multipath");
7247 else
7248 vty_out (vty, ", multipath");
7249 }
7250
7251 // Mark the bestpath(s)
7252 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
7253 {
7254 first_as = aspath_get_first_as(attr->aspath);
7255
7256 if (json_paths)
7257 {
7258 if (!json_bestpath)
7259 json_bestpath = json_object_new_object();
7260 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
7261 }
7262 else
7263 {
7264 if (first_as)
7265 vty_out (vty, ", bestpath-from-AS %d", first_as);
7266 else
7267 vty_out (vty, ", bestpath-from-AS Local");
7268 }
7269 }
7270
7271 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
7272 {
7273 if (json_paths)
7274 {
7275 if (!json_bestpath)
7276 json_bestpath = json_object_new_object();
7277 json_object_boolean_true_add(json_bestpath, "overall");
7278 }
7279 else
7280 vty_out (vty, ", best");
7281 }
7282
7283 if (json_bestpath)
7284 json_object_object_add(json_path, "bestpath", json_bestpath);
7285
7286 if (!json_paths)
7287 vty_out (vty, "%s", VTY_NEWLINE);
7288
7289 /* Line 4 display Community */
7290 if (attr->community)
7291 {
7292 if (json_paths)
7293 {
7294 json_object_lock(attr->community->json);
7295 json_object_object_add(json_path, "community", attr->community->json);
7296 }
7297 else
7298 {
7299 vty_out (vty, " Community: %s%s", attr->community->str,
7300 VTY_NEWLINE);
7301 }
7302 }
7303
7304 /* Line 5 display Extended-community */
7305 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
7306 {
7307 if (json_paths)
7308 {
7309 json_ext_community = json_object_new_object();
7310 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
7311 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
7312 }
7313 else
7314 {
7315 vty_out (vty, " Extended Community: %s%s",
7316 attr->extra->ecommunity->str, VTY_NEWLINE);
7317 }
7318 }
7319
7320 /* Line 6 display Originator, Cluster-id */
7321 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7322 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7323 {
7324 assert (attr->extra);
7325 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7326 {
7327 if (json_paths)
7328 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
7329 else
7330 vty_out (vty, " Originator: %s",
7331 inet_ntoa (attr->extra->originator_id));
7332 }
7333
7334 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7335 {
7336 int i;
7337
7338 if (json_paths)
7339 {
7340 json_cluster_list = json_object_new_object();
7341 json_cluster_list_list = json_object_new_array();
7342
7343 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7344 {
7345 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
7346 json_object_array_add(json_cluster_list_list, json_string);
7347 }
7348
7349 /* struct cluster_list does not have "str" variable like
7350 * aspath and community do. Add this someday if someone
7351 * asks for it.
7352 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7353 */
7354 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
7355 json_object_object_add(json_path, "clusterList", json_cluster_list);
7356 }
7357 else
7358 {
7359 vty_out (vty, ", Cluster list: ");
7360
7361 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7362 {
7363 vty_out (vty, "%s ",
7364 inet_ntoa (attr->extra->cluster->list[i]));
7365 }
7366 }
7367 }
7368
7369 if (!json_paths)
7370 vty_out (vty, "%s", VTY_NEWLINE);
7371 }
7372
7373 if (binfo->extra && binfo->extra->damp_info)
7374 bgp_damp_info_vty (vty, binfo, json_path);
7375
7376 /* Line 7 display Addpath IDs */
7377 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
7378 {
7379 if (json_paths)
7380 {
7381 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7382 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
7383 }
7384 else
7385 {
7386 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7387 binfo->addpath_rx_id, binfo->addpath_tx_id,
7388 VTY_NEWLINE);
7389 }
7390 }
7391
7392 /* If we used addpath to TX a non-bestpath we need to display
7393 * "Advertised to" on a path-by-path basis */
7394 if (bgp->addpath_tx_used[afi][safi])
7395 {
7396 first = 1;
7397
7398 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7399 {
7400 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7401 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7402
7403 if ((addpath_capable && has_adj) ||
7404 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7405 {
7406 if (json_path && !json_adv_to)
7407 json_adv_to = json_object_new_object();
7408
7409 route_vty_out_advertised_to(vty, peer, &first,
7410 " Advertised to:",
7411 json_adv_to);
7412 }
7413 }
7414
7415 if (json_path)
7416 {
7417 if (json_adv_to)
7418 {
7419 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7420 }
7421 }
7422 else
7423 {
7424 if (!first)
7425 {
7426 vty_out (vty, "%s", VTY_NEWLINE);
7427 }
7428 }
7429 }
7430
7431 /* Line 8 display Uptime */
7432 #ifdef HAVE_CLOCK_MONOTONIC
7433 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
7434 if (json_paths)
7435 {
7436 json_last_update = json_object_new_object();
7437 json_object_int_add(json_last_update, "epoch", tbuf);
7438 json_object_string_add(json_last_update, "string", ctime(&tbuf));
7439 json_object_object_add(json_path, "lastUpdate", json_last_update);
7440 }
7441 else
7442 vty_out (vty, " Last update: %s", ctime(&tbuf));
7443 #else
7444 if (json_paths)
7445 {
7446 json_last_update = json_object_new_object();
7447 json_object_int_add(json_last_update, "epoch", tbuf);
7448 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
7449 json_object_object_add(json_path, "lastUpdate", json_last_update);
7450 }
7451 else
7452 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
7453 #endif /* HAVE_CLOCK_MONOTONIC */
7454 }
7455
7456 /* We've constructed the json object for this path, add it to the json
7457 * array of paths
7458 */
7459 if (json_paths)
7460 {
7461 if (json_nexthop_global || json_nexthop_ll)
7462 {
7463 json_nexthops = json_object_new_array();
7464
7465 if (json_nexthop_global)
7466 json_object_array_add(json_nexthops, json_nexthop_global);
7467
7468 if (json_nexthop_ll)
7469 json_object_array_add(json_nexthops, json_nexthop_ll);
7470
7471 json_object_object_add(json_path, "nexthops", json_nexthops);
7472 }
7473
7474 json_object_object_add(json_path, "peer", json_peer);
7475 json_object_array_add(json_paths, json_path);
7476 }
7477 else
7478 vty_out (vty, "%s", VTY_NEWLINE);
7479 }
7480
7481 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
7482 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7483 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7484
7485 enum bgp_show_type
7486 {
7487 bgp_show_type_normal,
7488 bgp_show_type_regexp,
7489 bgp_show_type_prefix_list,
7490 bgp_show_type_filter_list,
7491 bgp_show_type_route_map,
7492 bgp_show_type_neighbor,
7493 bgp_show_type_cidr_only,
7494 bgp_show_type_prefix_longer,
7495 bgp_show_type_community_all,
7496 bgp_show_type_community,
7497 bgp_show_type_community_exact,
7498 bgp_show_type_community_list,
7499 bgp_show_type_community_list_exact,
7500 bgp_show_type_flap_statistics,
7501 bgp_show_type_flap_address,
7502 bgp_show_type_flap_prefix,
7503 bgp_show_type_flap_cidr_only,
7504 bgp_show_type_flap_regexp,
7505 bgp_show_type_flap_filter_list,
7506 bgp_show_type_flap_prefix_list,
7507 bgp_show_type_flap_prefix_longer,
7508 bgp_show_type_flap_route_map,
7509 bgp_show_type_flap_neighbor,
7510 bgp_show_type_dampend_paths,
7511 bgp_show_type_damp_neighbor
7512 };
7513
7514 static int
7515 bgp_show_prefix_list (struct vty *vty, const char *name,
7516 const char *prefix_list_str, afi_t afi,
7517 safi_t safi, enum bgp_show_type type);
7518 static int
7519 bgp_show_filter_list (struct vty *vty, const char *name,
7520 const char *filter, afi_t afi,
7521 safi_t safi, enum bgp_show_type type);
7522 static int
7523 bgp_show_route_map (struct vty *vty, const char *name,
7524 const char *rmap_str, afi_t afi,
7525 safi_t safi, enum bgp_show_type type);
7526 static int
7527 bgp_show_community_list (struct vty *vty, const char *name,
7528 const char *com, int exact,
7529 afi_t afi, safi_t safi);
7530 static int
7531 bgp_show_prefix_longer (struct vty *vty, const char *name,
7532 const char *prefix, afi_t afi,
7533 safi_t safi, enum bgp_show_type type);
7534
7535 static int
7536 bgp_show_table (struct vty *vty, struct bgp *bgp, struct bgp_table *table,
7537 enum bgp_show_type type, void *output_arg, u_char use_json)
7538 {
7539 struct bgp_info *ri;
7540 struct bgp_node *rn;
7541 int header = 1;
7542 int display;
7543 unsigned long output_count;
7544 unsigned long total_count;
7545 struct prefix *p;
7546 char buf[BUFSIZ];
7547 char buf2[BUFSIZ];
7548 json_object *json_paths = NULL;
7549 int first = 1;
7550
7551 if (use_json)
7552 {
7553 vty_out (vty, "{ \"vrfId\": %d, \"vrfName\": \"%s\", \"tableVersion\": %" PRId64 ", \"routerId\": \"%s\", \"routes\": { ",
7554 bgp->vrf_id == VRF_UNKNOWN ? -1 : bgp->vrf_id,
7555 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ? "Default" : bgp->name,
7556 table->version, inet_ntoa (bgp->router_id));
7557 json_paths = json_object_new_object();
7558 }
7559
7560 /* This is first entry point, so reset total line. */
7561 output_count = 0;
7562 total_count = 0;
7563
7564 /* Start processing of routes. */
7565 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7566 if (rn->info != NULL)
7567 {
7568 display = 0;
7569 if (!first && use_json)
7570 {
7571 vty_out (vty, ",");
7572 }
7573 if (use_json)
7574 json_paths = json_object_new_array();
7575 else
7576 json_paths = NULL;
7577
7578 for (ri = rn->info; ri; ri = ri->next)
7579 {
7580 total_count++;
7581 if (type == bgp_show_type_flap_statistics
7582 || type == bgp_show_type_flap_address
7583 || type == bgp_show_type_flap_prefix
7584 || type == bgp_show_type_flap_cidr_only
7585 || type == bgp_show_type_flap_regexp
7586 || type == bgp_show_type_flap_filter_list
7587 || type == bgp_show_type_flap_prefix_list
7588 || type == bgp_show_type_flap_prefix_longer
7589 || type == bgp_show_type_flap_route_map
7590 || type == bgp_show_type_flap_neighbor
7591 || type == bgp_show_type_dampend_paths
7592 || type == bgp_show_type_damp_neighbor)
7593 {
7594 if (!(ri->extra && ri->extra->damp_info))
7595 continue;
7596 }
7597 if (type == bgp_show_type_regexp
7598 || type == bgp_show_type_flap_regexp)
7599 {
7600 regex_t *regex = output_arg;
7601
7602 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7603 continue;
7604 }
7605 if (type == bgp_show_type_prefix_list
7606 || type == bgp_show_type_flap_prefix_list)
7607 {
7608 struct prefix_list *plist = output_arg;
7609
7610 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7611 continue;
7612 }
7613 if (type == bgp_show_type_filter_list
7614 || type == bgp_show_type_flap_filter_list)
7615 {
7616 struct as_list *as_list = output_arg;
7617
7618 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7619 continue;
7620 }
7621 if (type == bgp_show_type_route_map
7622 || type == bgp_show_type_flap_route_map)
7623 {
7624 struct route_map *rmap = output_arg;
7625 struct bgp_info binfo;
7626 struct attr dummy_attr;
7627 struct attr_extra dummy_extra;
7628 int ret;
7629
7630 dummy_attr.extra = &dummy_extra;
7631 bgp_attr_dup (&dummy_attr, ri->attr);
7632
7633 binfo.peer = ri->peer;
7634 binfo.attr = &dummy_attr;
7635
7636 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7637 if (ret == RMAP_DENYMATCH)
7638 continue;
7639 }
7640 if (type == bgp_show_type_neighbor
7641 || type == bgp_show_type_flap_neighbor
7642 || type == bgp_show_type_damp_neighbor)
7643 {
7644 union sockunion *su = output_arg;
7645
7646 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7647 continue;
7648 }
7649 if (type == bgp_show_type_cidr_only
7650 || type == bgp_show_type_flap_cidr_only)
7651 {
7652 u_int32_t destination;
7653
7654 destination = ntohl (rn->p.u.prefix4.s_addr);
7655 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7656 continue;
7657 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7658 continue;
7659 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7660 continue;
7661 }
7662 if (type == bgp_show_type_prefix_longer
7663 || type == bgp_show_type_flap_prefix_longer)
7664 {
7665 struct prefix *p = output_arg;
7666
7667 if (! prefix_match (p, &rn->p))
7668 continue;
7669 }
7670 if (type == bgp_show_type_community_all)
7671 {
7672 if (! ri->attr->community)
7673 continue;
7674 }
7675 if (type == bgp_show_type_community)
7676 {
7677 struct community *com = output_arg;
7678
7679 if (! ri->attr->community ||
7680 ! community_match (ri->attr->community, com))
7681 continue;
7682 }
7683 if (type == bgp_show_type_community_exact)
7684 {
7685 struct community *com = output_arg;
7686
7687 if (! ri->attr->community ||
7688 ! community_cmp (ri->attr->community, com))
7689 continue;
7690 }
7691 if (type == bgp_show_type_community_list)
7692 {
7693 struct community_list *list = output_arg;
7694
7695 if (! community_list_match (ri->attr->community, list))
7696 continue;
7697 }
7698 if (type == bgp_show_type_community_list_exact)
7699 {
7700 struct community_list *list = output_arg;
7701
7702 if (! community_list_exact_match (ri->attr->community, list))
7703 continue;
7704 }
7705 if (type == bgp_show_type_flap_address
7706 || type == bgp_show_type_flap_prefix)
7707 {
7708 struct prefix *p = output_arg;
7709
7710 if (! prefix_match (&rn->p, p))
7711 continue;
7712
7713 if (type == bgp_show_type_flap_prefix)
7714 if (p->prefixlen != rn->p.prefixlen)
7715 continue;
7716 }
7717 if (type == bgp_show_type_dampend_paths
7718 || type == bgp_show_type_damp_neighbor)
7719 {
7720 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7721 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7722 continue;
7723 }
7724
7725 if (!use_json && header)
7726 {
7727 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
7728 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7729 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7730 if (type == bgp_show_type_dampend_paths
7731 || type == bgp_show_type_damp_neighbor)
7732 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7733 else if (type == bgp_show_type_flap_statistics
7734 || type == bgp_show_type_flap_address
7735 || type == bgp_show_type_flap_prefix
7736 || type == bgp_show_type_flap_cidr_only
7737 || type == bgp_show_type_flap_regexp
7738 || type == bgp_show_type_flap_filter_list
7739 || type == bgp_show_type_flap_prefix_list
7740 || type == bgp_show_type_flap_prefix_longer
7741 || type == bgp_show_type_flap_route_map
7742 || type == bgp_show_type_flap_neighbor)
7743 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7744 else
7745 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7746 header = 0;
7747 }
7748
7749 if (type == bgp_show_type_dampend_paths
7750 || type == bgp_show_type_damp_neighbor)
7751 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7752 else if (type == bgp_show_type_flap_statistics
7753 || type == bgp_show_type_flap_address
7754 || type == bgp_show_type_flap_prefix
7755 || type == bgp_show_type_flap_cidr_only
7756 || type == bgp_show_type_flap_regexp
7757 || type == bgp_show_type_flap_filter_list
7758 || type == bgp_show_type_flap_prefix_list
7759 || type == bgp_show_type_flap_prefix_longer
7760 || type == bgp_show_type_flap_route_map
7761 || type == bgp_show_type_flap_neighbor)
7762 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7763 else
7764 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7765 display++;
7766 }
7767
7768 if (display)
7769 {
7770 output_count++;
7771 if (use_json)
7772 {
7773 p = &rn->p;
7774 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7775 vty_out (vty, "\"%s\": ", buf2);
7776 vty_out (vty, "%s", json_object_to_json_string (json_paths));
7777 json_object_free (json_paths);
7778 first = 0;
7779
7780 }
7781 }
7782 }
7783
7784 if (use_json)
7785 {
7786 json_object_free (json_paths);
7787 vty_out (vty, " } }%s", VTY_NEWLINE);
7788 }
7789 else
7790 {
7791 /* No route is displayed */
7792 if (output_count == 0)
7793 {
7794 if (type == bgp_show_type_normal)
7795 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
7796 }
7797 else
7798 vty_out (vty, "%sDisplayed %ld routes and %ld total paths%s",
7799 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
7800 }
7801
7802 return CMD_SUCCESS;
7803 }
7804
7805 static int
7806 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
7807 enum bgp_show_type type, void *output_arg, u_char use_json)
7808 {
7809 struct bgp_table *table;
7810
7811 if (bgp == NULL)
7812 {
7813 bgp = bgp_get_default ();
7814 }
7815
7816 if (bgp == NULL)
7817 {
7818 if (!use_json)
7819 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7820 return CMD_WARNING;
7821 }
7822
7823 table = bgp->rib[afi][safi];
7824
7825 return bgp_show_table (vty, bgp, table, type, output_arg,
7826 use_json);
7827 }
7828
7829 static void
7830 bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7831 u_char use_json)
7832 {
7833 struct listnode *node, *nnode;
7834 struct bgp *bgp;
7835 struct bgp_table *table;
7836 int is_first = 1;
7837
7838 if (use_json)
7839 vty_out (vty, "{%s", VTY_NEWLINE);
7840
7841 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7842 {
7843 if (use_json)
7844 {
7845 if (! is_first)
7846 vty_out (vty, ",%s", VTY_NEWLINE);
7847 else
7848 is_first = 0;
7849
7850 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7851 ? "Default" : bgp->name);
7852 }
7853 else
7854 {
7855 vty_out (vty, "%sInstance %s:%s",
7856 VTY_NEWLINE,
7857 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7858 ? "Default" : bgp->name,
7859 VTY_NEWLINE);
7860 }
7861 table = bgp->rib[afi][safi];
7862 bgp_show_table (vty, bgp, table,
7863 bgp_show_type_normal, NULL, use_json);
7864
7865 }
7866
7867 if (use_json)
7868 vty_out (vty, "}%s", VTY_NEWLINE);
7869 }
7870
7871 /* Header of detailed BGP route information */
7872 static void
7873 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7874 struct bgp_node *rn,
7875 struct prefix_rd *prd, afi_t afi, safi_t safi,
7876 json_object *json)
7877 {
7878 struct bgp_info *ri;
7879 struct prefix *p;
7880 struct peer *peer;
7881 struct listnode *node, *nnode;
7882 char buf1[INET6_ADDRSTRLEN];
7883 char buf2[INET6_ADDRSTRLEN];
7884 int count = 0;
7885 int best = 0;
7886 int suppress = 0;
7887 int no_export = 0;
7888 int no_advertise = 0;
7889 int local_as = 0;
7890 int first = 1;
7891 json_object *json_adv_to = NULL;
7892
7893 p = &rn->p;
7894
7895 if (json)
7896 {
7897 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7898 json_object_int_add(json, "prefixlen", p->prefixlen);
7899 }
7900 else
7901 {
7902 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7903 ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ?
7904 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7905 safi == SAFI_MPLS_VPN ? ":" : "",
7906 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7907 p->prefixlen, VTY_NEWLINE);
7908 }
7909
7910 for (ri = rn->info; ri; ri = ri->next)
7911 {
7912 count++;
7913 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7914 {
7915 best = count;
7916 if (ri->extra && ri->extra->suppress)
7917 suppress = 1;
7918 if (ri->attr->community != NULL)
7919 {
7920 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7921 no_advertise = 1;
7922 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7923 no_export = 1;
7924 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7925 local_as = 1;
7926 }
7927 }
7928 }
7929
7930 if (!json)
7931 {
7932 vty_out (vty, "Paths: (%d available", count);
7933 if (best)
7934 {
7935 vty_out (vty, ", best #%d", best);
7936 if (safi == SAFI_UNICAST)
7937 vty_out (vty, ", table %s",
7938 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7939 ? "Default-IP-Routing-Table" : bgp->name);
7940 }
7941 else
7942 vty_out (vty, ", no best path");
7943
7944 if (no_advertise)
7945 vty_out (vty, ", not advertised to any peer");
7946 else if (no_export)
7947 vty_out (vty, ", not advertised to EBGP peer");
7948 else if (local_as)
7949 vty_out (vty, ", not advertised outside local AS");
7950
7951 if (suppress)
7952 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7953 vty_out (vty, ")%s", VTY_NEWLINE);
7954 }
7955
7956 /* If we are not using addpath then we can display Advertised to and that will
7957 * show what peers we advertised the bestpath to. If we are using addpath
7958 * though then we must display Advertised to on a path-by-path basis. */
7959 if (!bgp->addpath_tx_used[afi][safi])
7960 {
7961 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7962 {
7963 if (bgp_adj_out_lookup (peer, rn, 0))
7964 {
7965 if (json && !json_adv_to)
7966 json_adv_to = json_object_new_object();
7967
7968 route_vty_out_advertised_to(vty, peer, &first,
7969 " Advertised to non peer-group peers:\n ",
7970 json_adv_to);
7971 }
7972 }
7973
7974 if (json)
7975 {
7976 if (json_adv_to)
7977 {
7978 json_object_object_add(json, "advertisedTo", json_adv_to);
7979 }
7980 }
7981 else
7982 {
7983 if (first)
7984 vty_out (vty, " Not advertised to any peer");
7985 vty_out (vty, "%s", VTY_NEWLINE);
7986 }
7987 }
7988 }
7989
7990 /* Display specified route of BGP table. */
7991 static int
7992 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
7993 struct bgp_table *rib, const char *ip_str,
7994 afi_t afi, safi_t safi, struct prefix_rd *prd,
7995 int prefix_check, enum bgp_path_type pathtype,
7996 u_char use_json)
7997 {
7998 int ret;
7999 int header;
8000 int display = 0;
8001 struct prefix match;
8002 struct bgp_node *rn;
8003 struct bgp_node *rm;
8004 struct bgp_info *ri;
8005 struct bgp_table *table;
8006 json_object *json = NULL;
8007 json_object *json_paths = NULL;
8008
8009 /* Check IP address argument. */
8010 ret = str2prefix (ip_str, &match);
8011 if (! ret)
8012 {
8013 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
8014 return CMD_WARNING;
8015 }
8016
8017 match.family = afi2family (afi);
8018
8019 if (use_json)
8020 {
8021 json = json_object_new_object();
8022 json_paths = json_object_new_array();
8023 }
8024
8025 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
8026 {
8027 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
8028 {
8029 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8030 continue;
8031
8032 if ((table = rn->info) != NULL)
8033 {
8034 header = 1;
8035
8036 if ((rm = bgp_node_match (table, &match)) != NULL)
8037 {
8038 if (prefix_check && rm->p.prefixlen != match.prefixlen)
8039 {
8040 bgp_unlock_node (rm);
8041 continue;
8042 }
8043
8044 for (ri = rm->info; ri; ri = ri->next)
8045 {
8046 if (header)
8047 {
8048 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
8049 AFI_IP, safi, json);
8050 header = 0;
8051 }
8052 display++;
8053
8054 if (pathtype == BGP_PATH_ALL ||
8055 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8056 (pathtype == BGP_PATH_MULTIPATH &&
8057 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8058 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths);
8059 }
8060
8061 bgp_unlock_node (rm);
8062 }
8063 }
8064 }
8065 }
8066 else
8067 {
8068 header = 1;
8069
8070 if ((rn = bgp_node_match (rib, &match)) != NULL)
8071 {
8072 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8073 {
8074 for (ri = rn->info; ri; ri = ri->next)
8075 {
8076 if (header)
8077 {
8078 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
8079 header = 0;
8080 }
8081 display++;
8082
8083 if (pathtype == BGP_PATH_ALL ||
8084 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8085 (pathtype == BGP_PATH_MULTIPATH &&
8086 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8087 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
8088 }
8089 }
8090
8091 bgp_unlock_node (rn);
8092 }
8093 }
8094
8095 if (use_json)
8096 {
8097 if (display)
8098 json_object_object_add(json, "paths", json_paths);
8099
8100 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
8101 json_object_free(json);
8102 }
8103 else
8104 {
8105 if (!display)
8106 {
8107 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
8108 return CMD_WARNING;
8109 }
8110 }
8111
8112 return CMD_SUCCESS;
8113 }
8114
8115 /* Display specified route of Main RIB */
8116 static int
8117 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
8118 afi_t afi, safi_t safi, struct prefix_rd *prd,
8119 int prefix_check, enum bgp_path_type pathtype,
8120 u_char use_json)
8121 {
8122 struct bgp *bgp;
8123
8124 /* BGP structure lookup. */
8125 if (view_name)
8126 {
8127 bgp = bgp_lookup_by_name (view_name);
8128 if (bgp == NULL)
8129 {
8130 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
8131 return CMD_WARNING;
8132 }
8133 }
8134 else
8135 {
8136 bgp = bgp_get_default ();
8137 if (bgp == NULL)
8138 {
8139 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8140 return CMD_WARNING;
8141 }
8142 }
8143
8144 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
8145 afi, safi, prd, prefix_check, pathtype,
8146 use_json);
8147 }
8148
8149 /* BGP route print out function. */
8150 DEFUN (show_ip_bgp,
8151 show_ip_bgp_cmd,
8152 "show ip bgp {json}",
8153 SHOW_STR
8154 IP_STR
8155 BGP_STR
8156 "JavaScript Object Notation\n")
8157 {
8158 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8159 }
8160
8161 DEFUN (show_ip_bgp_ipv4,
8162 show_ip_bgp_ipv4_cmd,
8163 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" {json}",
8164 SHOW_STR
8165 IP_STR
8166 BGP_STR
8167 "Address family\n"
8168 BGP_SAFI_HELP_STR
8169 "JavaScript Object Notation\n")
8170 {
8171 u_char uj = use_json(argc, argv);
8172
8173 return bgp_show (vty, NULL, AFI_IP,
8174 bgp_vty_safi_from_arg(argv[0]),
8175 bgp_show_type_normal, NULL, uj);
8176 }
8177
8178 ALIAS (show_ip_bgp_ipv4,
8179 show_bgp_ipv4_safi_cmd,
8180 "show bgp ipv4 "BGP_SAFI_CMD_STR" {json}",
8181 SHOW_STR
8182 BGP_STR
8183 "Address family\n"
8184 BGP_SAFI_HELP_STR
8185 "JavaScript Object Notation\n")
8186
8187 DEFUN (show_ip_bgp_route,
8188 show_ip_bgp_route_cmd,
8189 "show ip bgp A.B.C.D {json}",
8190 SHOW_STR
8191 IP_STR
8192 BGP_STR
8193 "Network in the BGP routing table to display\n"
8194 "JavaScript Object Notation\n")
8195 {
8196 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8197 }
8198
8199 DEFUN (show_ip_bgp_route_pathtype,
8200 show_ip_bgp_route_pathtype_cmd,
8201 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
8202 SHOW_STR
8203 IP_STR
8204 BGP_STR
8205 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8206 "Display only the bestpath\n"
8207 "Display only multipaths\n"
8208 "JavaScript Object Notation\n")
8209 {
8210 u_char uj = use_json(argc, argv);
8211
8212 if (strncmp (argv[1], "b", 1) == 0)
8213 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8214 else
8215 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8216 }
8217
8218 DEFUN (show_bgp_ipv4_safi_route_pathtype,
8219 show_bgp_ipv4_safi_route_pathtype_cmd,
8220 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D (bestpath|multipath) {json}",
8221 SHOW_STR
8222 BGP_STR
8223 BGP_AFI_SAFI_HELP_STR
8224 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8225 "Display only the bestpath\n"
8226 "Display only multipaths\n"
8227 "JavaScript Object Notation\n")
8228 {
8229 u_char uj = use_json(argc, argv);
8230
8231 if (strncmp (argv[2], "b", 1) == 0)
8232 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8233 bgp_vty_safi_from_arg(argv[0]),
8234 NULL, 0, BGP_PATH_BESTPATH, uj);
8235 else
8236 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8237 bgp_vty_safi_from_arg(argv[0]),
8238 NULL, 0, BGP_PATH_MULTIPATH, uj);
8239 }
8240
8241 DEFUN (show_bgp_ipv4_prefix,
8242 show_bgp_ipv4_prefix_cmd,
8243 "show bgp ipv4 A.B.C.D/M {json}",
8244 SHOW_STR
8245 BGP_STR
8246 IP_STR
8247 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8248 JSON_STR)
8249 {
8250 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc, argv));
8251 }
8252
8253 DEFUN (show_bgp_ipv6_route,
8254 show_bgp_ipv6_route_cmd,
8255 "show bgp ipv6 X:X::X:X {json}",
8256 SHOW_STR
8257 BGP_STR
8258 "Address family\n"
8259 "Network in the BGP routing table to display\n"
8260 JSON_STR)
8261 {
8262 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
8263 }
8264
8265 DEFUN (show_bgp_ipv6_prefix,
8266 show_bgp_ipv6_prefix_cmd,
8267 "show bgp ipv6 X:X::X:X/M {json}",
8268 SHOW_STR
8269 BGP_STR
8270 IP_STR
8271 "IPv6 prefix <network>/<length>\n"
8272 JSON_STR)
8273 {
8274 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc,argv));
8275 }
8276
8277 DEFUN (show_ip_bgp_ipv4_route,
8278 show_ip_bgp_ipv4_route_cmd,
8279 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}",
8280 SHOW_STR
8281 IP_STR
8282 BGP_STR
8283 BGP_AFI_SAFI_HELP_STR
8284 "Network in the BGP routing table to display\n"
8285 "JavaScript Object Notation\n")
8286 {
8287 u_char uj = use_json(argc, argv);
8288
8289 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8290 bgp_vty_safi_from_arg(argv[0]),
8291 NULL, 0, BGP_PATH_ALL, uj);
8292 }
8293
8294 ALIAS (show_ip_bgp_ipv4_route,
8295 show_bgp_ipv4_safi_route_cmd,
8296 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}",
8297 SHOW_STR
8298 BGP_STR
8299 BGP_AFI_SAFI_HELP_STR
8300 "Network in the BGP routing table to display\n"
8301 "JavaScript Object Notation\n")
8302
8303 DEFUN (show_bgp_ipv4_safi_rd_route,
8304 show_bgp_ipv4_safi_rd_route_cmd,
8305 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
8306 SHOW_STR
8307 BGP_STR
8308 "Address Family\n"
8309 "Address Family Modifier\n"
8310 "Address Family Modifier\n"
8311 "Display information for a route distinguisher\n"
8312 "ENCAP Route Distinguisher\n"
8313 "Network in the BGP routing table to display\n")
8314 {
8315 int ret;
8316 struct prefix_rd prd;
8317 safi_t safi;
8318
8319 if (bgp_parse_safi(argv[0], &safi)) {
8320 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8321 return CMD_WARNING;
8322 }
8323 ret = str2prefix_rd (argv[1], &prd);
8324 if (! ret)
8325 {
8326 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8327 return CMD_WARNING;
8328 }
8329 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8330 }
8331
8332 DEFUN (show_bgp_ipv6_safi_rd_route,
8333 show_bgp_ipv6_safi_rd_route_cmd,
8334 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X {json}",
8335 SHOW_STR
8336 BGP_STR
8337 "Address Family\n"
8338 "Address Family Modifier\n"
8339 "Address Family Modifier\n"
8340 "Display information for a route distinguisher\n"
8341 "ENCAP Route Distinguisher\n"
8342 "Network in the BGP routing table to display\n")
8343 {
8344 int ret;
8345 struct prefix_rd prd;
8346 safi_t safi;
8347
8348 if (bgp_parse_safi(argv[0], &safi)) {
8349 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8350 return CMD_WARNING;
8351 }
8352 ret = str2prefix_rd (argv[1], &prd);
8353 if (! ret)
8354 {
8355 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8356 return CMD_WARNING;
8357 }
8358 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8359 }
8360
8361
8362 DEFUN (show_bgp_ipv4_safi_rd_prefix,
8363 show_bgp_ipv4_safi_rd_prefix_cmd,
8364 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
8365 SHOW_STR
8366 BGP_STR
8367 "Address Family\n"
8368 "Address Family Modifier\n"
8369 "Address Family Modifier\n"
8370 "Display information for a route distinguisher\n"
8371 "ENCAP Route Distinguisher\n"
8372 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8373 {
8374 int ret;
8375 struct prefix_rd prd;
8376 safi_t safi;
8377
8378 if (bgp_parse_safi(argv[0], &safi)) {
8379 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8380 return CMD_WARNING;
8381 }
8382
8383 ret = str2prefix_rd (argv[1], &prd);
8384 if (! ret)
8385 {
8386 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8387 return CMD_WARNING;
8388 }
8389 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv));
8390 }
8391
8392 DEFUN (show_bgp_ipv6_safi_rd_prefix,
8393 show_bgp_ipv6_safi_rd_prefix_cmd,
8394 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M {json}",
8395 SHOW_STR
8396 BGP_STR
8397 "Address Family\n"
8398 "Address Family Modifier\n"
8399 "Address Family Modifier\n"
8400 "Display information for a route distinguisher\n"
8401 "ENCAP Route Distinguisher\n"
8402 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8403 {
8404 int ret;
8405 struct prefix_rd prd;
8406 safi_t safi;
8407
8408 if (bgp_parse_safi(argv[0], &safi)) {
8409 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8410 return CMD_WARNING;
8411 }
8412
8413 ret = str2prefix_rd (argv[1], &prd);
8414 if (! ret)
8415 {
8416 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8417 return CMD_WARNING;
8418 }
8419 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv));
8420 }
8421
8422 DEFUN (show_ip_bgp_prefix,
8423 show_ip_bgp_prefix_cmd,
8424 "show ip bgp A.B.C.D/M {json}",
8425 SHOW_STR
8426 IP_STR
8427 BGP_STR
8428 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8429 "JavaScript Object Notation\n")
8430 {
8431 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8432 }
8433
8434 DEFUN (show_ip_bgp_prefix_pathtype,
8435 show_ip_bgp_prefix_pathtype_cmd,
8436 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
8437 SHOW_STR
8438 IP_STR
8439 BGP_STR
8440 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8441 "Display only the bestpath\n"
8442 "Display only multipaths\n"
8443 "JavaScript Object Notation\n")
8444 {
8445 u_char uj = use_json(argc, argv);
8446 if (strncmp (argv[1], "b", 1) == 0)
8447 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8448 else
8449 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8450 }
8451
8452 DEFUN (show_ip_bgp_ipv4_prefix,
8453 show_ip_bgp_ipv4_prefix_cmd,
8454 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}",
8455 SHOW_STR
8456 IP_STR
8457 BGP_STR
8458 BGP_AFI_SAFI_HELP_STR
8459 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8460 "JavaScript Object Notation\n")
8461 {
8462 u_char uj = use_json(argc, argv);
8463
8464 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8465 bgp_vty_safi_from_arg(argv[0]),
8466 NULL, 1, BGP_PATH_ALL, uj);
8467 }
8468
8469 ALIAS (show_ip_bgp_ipv4_prefix,
8470 show_bgp_ipv4_safi_prefix_cmd,
8471 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}",
8472 SHOW_STR
8473 BGP_STR
8474 BGP_AFI_SAFI_HELP_STR
8475 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8476 "JavaScript Object Notation\n")
8477
8478 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8479 show_ip_bgp_ipv4_prefix_pathtype_cmd,
8480 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}",
8481 SHOW_STR
8482 IP_STR
8483 BGP_STR
8484 BGP_AFI_SAFI_HELP_STR
8485 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8486 "Display only the bestpath\n"
8487 "Display only multipaths\n"
8488 "JavaScript Object Notation\n")
8489 {
8490 u_char uj = use_json(argc, argv);
8491
8492 if (strncmp (argv[2], "b", 1) == 0)
8493 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8494 bgp_vty_safi_from_arg(argv[0]),
8495 NULL, 1, BGP_PATH_BESTPATH, uj);
8496 else
8497 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8498 bgp_vty_safi_from_arg(argv[0]),
8499 NULL, 1, BGP_PATH_MULTIPATH, uj);
8500 }
8501
8502 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8503 show_bgp_ipv4_safi_prefix_pathtype_cmd,
8504 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}",
8505 SHOW_STR
8506 BGP_STR
8507 BGP_AFI_SAFI_HELP_STR
8508 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8509 "Display only the bestpath\n"
8510 "Display only multipaths\n"
8511 "JavaScript Object Notation\n")
8512
8513
8514 DEFUN (show_ip_bgp_view,
8515 show_ip_bgp_instance_cmd,
8516 "show ip bgp " BGP_INSTANCE_CMD " {json}",
8517 SHOW_STR
8518 IP_STR
8519 BGP_STR
8520 BGP_INSTANCE_HELP_STR
8521 "JavaScript Object Notation\n")
8522 {
8523 struct bgp *bgp;
8524
8525 /* BGP structure lookup. */
8526 bgp = bgp_lookup_by_name (argv[1]);
8527 if (bgp == NULL)
8528 {
8529 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8530 return CMD_WARNING;
8531 }
8532
8533 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8534 }
8535
8536 DEFUN (show_ip_bgp_instance_all,
8537 show_ip_bgp_instance_all_cmd,
8538 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
8539 SHOW_STR
8540 IP_STR
8541 BGP_STR
8542 BGP_INSTANCE_ALL_HELP_STR
8543 "JavaScript Object Notation\n")
8544 {
8545 u_char uj = use_json(argc, argv);
8546
8547 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8548 return CMD_SUCCESS;
8549 }
8550
8551 DEFUN (show_ip_bgp_instance_route,
8552 show_ip_bgp_instance_route_cmd,
8553 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
8554 SHOW_STR
8555 IP_STR
8556 BGP_STR
8557 BGP_INSTANCE_HELP_STR
8558 "Network in the BGP routing table to display\n"
8559 "JavaScript Object Notation\n")
8560 {
8561 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8562 }
8563
8564 DEFUN (show_ip_bgp_instance_route_pathtype,
8565 show_ip_bgp_instance_route_pathtype_cmd,
8566 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
8567 SHOW_STR
8568 IP_STR
8569 BGP_STR
8570 BGP_INSTANCE_HELP_STR
8571 "Network in the BGP routing table to display\n"
8572 "Display only the bestpath\n"
8573 "Display only multipaths\n"
8574 "JavaScript Object Notation\n")
8575 {
8576 u_char uj = use_json(argc, argv);
8577
8578 if (strncmp (argv[3], "b", 1) == 0)
8579 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8580 else
8581 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8582 }
8583
8584 DEFUN (show_ip_bgp_instance_prefix,
8585 show_ip_bgp_instance_prefix_cmd,
8586 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
8587 SHOW_STR
8588 IP_STR
8589 BGP_STR
8590 BGP_INSTANCE_HELP_STR
8591 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8592 "JavaScript Object Notation\n")
8593 {
8594 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8595 }
8596
8597 DEFUN (show_ip_bgp_instance_prefix_pathtype,
8598 show_ip_bgp_instance_prefix_pathtype_cmd,
8599 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
8600 SHOW_STR
8601 IP_STR
8602 BGP_STR
8603 BGP_INSTANCE_HELP_STR
8604 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8605 "Display only the bestpath\n"
8606 "Display only multipaths\n"
8607 "JavaScript Object Notation\n")
8608 {
8609 u_char uj = use_json(argc, argv);
8610 if (strncmp (argv[3], "b", 1) == 0)
8611 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8612 else
8613 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8614 }
8615
8616 #ifdef HAVE_IPV6
8617 DEFUN (show_bgp,
8618 show_bgp_cmd,
8619 "show bgp {json}",
8620 SHOW_STR
8621 BGP_STR
8622 "JavaScript Object Notation\n")
8623 {
8624 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8625 NULL, use_json(argc, argv));
8626 }
8627
8628 ALIAS (show_bgp,
8629 show_bgp_ipv6_cmd,
8630 "show bgp ipv6 {json}",
8631 SHOW_STR
8632 BGP_STR
8633 "Address family\n"
8634 "JavaScript Object Notation\n")
8635
8636 DEFUN (show_bgp_ipv6_safi,
8637 show_bgp_ipv6_safi_cmd,
8638 "show bgp ipv6 "BGP_SAFI_CMD_STR" {json}",
8639 SHOW_STR
8640 BGP_STR
8641 "Address family\n"
8642 BGP_SAFI_HELP_STR
8643 "JavaScript Object Notation\n")
8644 {
8645 u_char uj = use_json(argc, argv);
8646
8647 return bgp_show (vty, NULL, AFI_IP6,
8648 bgp_vty_safi_from_arg(argv[0]),
8649 bgp_show_type_normal, NULL, uj);
8650 }
8651
8652 static void
8653 bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8654 {
8655 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8656 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8657 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8658 }
8659
8660 /* old command */
8661 DEFUN (show_ipv6_bgp,
8662 show_ipv6_bgp_cmd,
8663 "show ipv6 bgp {json}",
8664 SHOW_STR
8665 IP_STR
8666 BGP_STR
8667 "JavaScript Object Notation\n")
8668 {
8669 bgp_show_ipv6_bgp_deprecate_warning(vty);
8670 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8671 NULL, use_json(argc, argv));
8672 }
8673
8674 DEFUN (show_bgp_route,
8675 show_bgp_route_cmd,
8676 "show bgp X:X::X:X {json}",
8677 SHOW_STR
8678 BGP_STR
8679 "Network in the BGP routing table to display\n"
8680 "JavaScript Object Notation\n")
8681 {
8682 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8683 }
8684
8685 DEFUN (show_bgp_ipv6_safi_route,
8686 show_bgp_ipv6_safi_route_cmd,
8687 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X {json}",
8688 SHOW_STR
8689 BGP_STR
8690 BGP_AFI_SAFI_HELP_STR
8691 "Network in the BGP routing table to display\n"
8692 "JavaScript Object Notation\n")
8693 {
8694 u_char uj = use_json(argc, argv);
8695
8696 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8697 bgp_vty_safi_from_arg(argv[0]),
8698 NULL, 0, BGP_PATH_ALL, uj);
8699 }
8700
8701 DEFUN (show_bgp_route_pathtype,
8702 show_bgp_route_pathtype_cmd,
8703 "show bgp X:X::X:X (bestpath|multipath) {json}",
8704 SHOW_STR
8705 BGP_STR
8706 "Network in the BGP routing table to display\n"
8707 "Display only the bestpath\n"
8708 "Display only multipaths\n"
8709 "JavaScript Object Notation\n")
8710 {
8711 u_char uj = use_json(argc, argv);
8712 if (strncmp (argv[1], "b", 1) == 0)
8713 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8714 else
8715 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8716 }
8717
8718 ALIAS (show_bgp_route_pathtype,
8719 show_bgp_ipv6_route_pathtype_cmd,
8720 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
8721 SHOW_STR
8722 BGP_STR
8723 "Address family\n"
8724 "Network in the BGP routing table to display\n"
8725 "Display only the bestpath\n"
8726 "Display only multipaths\n"
8727 "JavaScript Object Notation\n")
8728
8729 DEFUN (show_bgp_ipv6_safi_route_pathtype,
8730 show_bgp_ipv6_safi_route_pathtype_cmd,
8731 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X (bestpath|multipath) {json}",
8732 SHOW_STR
8733 BGP_STR
8734 BGP_AFI_SAFI_HELP_STR
8735 "Network in the BGP routing table to display\n"
8736 "Display only the bestpath\n"
8737 "Display only multipaths\n"
8738 "JavaScript Object Notation\n")
8739 {
8740 u_char uj = use_json(argc, argv);
8741 if (strncmp (argv[2], "b", 1) == 0)
8742 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8743 bgp_vty_safi_from_arg(argv[0]),
8744 NULL, 0, BGP_PATH_BESTPATH, uj);
8745 else
8746 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8747 bgp_vty_safi_from_arg(argv[0]),
8748 NULL, 0, BGP_PATH_MULTIPATH, uj);
8749 }
8750
8751 /* old command */
8752 DEFUN (show_ipv6_bgp_route,
8753 show_ipv6_bgp_route_cmd,
8754 "show ipv6 bgp X:X::X:X {json}",
8755 SHOW_STR
8756 IP_STR
8757 BGP_STR
8758 "Network in the BGP routing table to display\n"
8759 "JavaScript Object Notation\n")
8760 {
8761 bgp_show_ipv6_bgp_deprecate_warning(vty);
8762 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8763 }
8764
8765 DEFUN (show_bgp_prefix,
8766 show_bgp_prefix_cmd,
8767 "show bgp X:X::X:X/M {json}",
8768 SHOW_STR
8769 BGP_STR
8770 "IPv6 prefix <network>/<length>\n"
8771 "JavaScript Object Notation\n")
8772 {
8773 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8774 }
8775
8776 DEFUN (show_bgp_ipv6_safi_prefix,
8777 show_bgp_ipv6_safi_prefix_cmd,
8778 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M {json}",
8779 SHOW_STR
8780 BGP_STR
8781 BGP_AFI_SAFI_HELP_STR
8782 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8783 "JavaScript Object Notation\n")
8784 {
8785 u_char uj = use_json(argc, argv);
8786
8787 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8788 bgp_vty_safi_from_arg(argv[0]),
8789 NULL, 1, BGP_PATH_ALL, uj);
8790 }
8791
8792 DEFUN (show_bgp_prefix_pathtype,
8793 show_bgp_prefix_pathtype_cmd,
8794 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
8795 SHOW_STR
8796 BGP_STR
8797 "IPv6 prefix <network>/<length>\n"
8798 "Display only the bestpath\n"
8799 "Display only multipaths\n"
8800 "JavaScript Object Notation\n")
8801 {
8802 u_char uj = use_json(argc, argv);
8803 if (strncmp (argv[1], "b", 1) == 0)
8804 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8805 else
8806 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8807 }
8808
8809 ALIAS (show_bgp_prefix_pathtype,
8810 show_bgp_ipv6_prefix_pathtype_cmd,
8811 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8812 SHOW_STR
8813 BGP_STR
8814 "Address family\n"
8815 "IPv6 prefix <network>/<length>\n"
8816 "Display only the bestpath\n"
8817 "Display only multipaths\n"
8818 "JavaScript Object Notation\n")
8819
8820 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8821 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8822 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M (bestpath|multipath) {json}",
8823 SHOW_STR
8824 BGP_STR
8825 BGP_AFI_SAFI_HELP_STR
8826 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8827 "Display only the bestpath\n"
8828 "Display only multipaths\n"
8829 "JavaScript Object Notation\n")
8830 {
8831 u_char uj = use_json(argc, argv);
8832 if (strncmp (argv[2], "b", 1) == 0)
8833 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8834 bgp_vty_safi_from_arg(argv[0]),
8835 NULL, 1, BGP_PATH_BESTPATH, uj);
8836 else
8837 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8838 bgp_vty_safi_from_arg(argv[0]), NULL, 1, BGP_PATH_MULTIPATH, uj);
8839 }
8840
8841 /* old command */
8842 DEFUN (show_ipv6_bgp_prefix,
8843 show_ipv6_bgp_prefix_cmd,
8844 "show ipv6 bgp X:X::X:X/M {json}",
8845 SHOW_STR
8846 IP_STR
8847 BGP_STR
8848 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8849 "JavaScript Object Notation\n")
8850 {
8851 bgp_show_ipv6_bgp_deprecate_warning(vty);
8852 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8853 }
8854
8855 DEFUN (show_bgp_view,
8856 show_bgp_instance_cmd,
8857 "show bgp " BGP_INSTANCE_CMD " {json}",
8858 SHOW_STR
8859 BGP_STR
8860 BGP_INSTANCE_HELP_STR
8861 "JavaScript Object Notation\n")
8862 {
8863 struct bgp *bgp;
8864
8865 /* BGP structure lookup. */
8866 bgp = bgp_lookup_by_name (argv[1]);
8867 if (bgp == NULL)
8868 {
8869 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8870 return CMD_WARNING;
8871 }
8872
8873 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8874 }
8875
8876 DEFUN (show_bgp_instance_all,
8877 show_bgp_instance_all_cmd,
8878 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
8879 SHOW_STR
8880 BGP_STR
8881 BGP_INSTANCE_ALL_HELP_STR
8882 "JavaScript Object Notation\n")
8883 {
8884 u_char uj = use_json(argc, argv);
8885
8886 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
8887 return CMD_SUCCESS;
8888 }
8889
8890 ALIAS (show_bgp_view,
8891 show_bgp_instance_ipv6_cmd,
8892 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
8893 SHOW_STR
8894 BGP_STR
8895 BGP_INSTANCE_HELP_STR
8896 "Address family\n"
8897 "JavaScript Object Notation\n")
8898
8899 DEFUN (show_bgp_instance_route,
8900 show_bgp_instance_route_cmd,
8901 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
8902 SHOW_STR
8903 BGP_STR
8904 BGP_INSTANCE_HELP_STR
8905 "Network in the BGP routing table to display\n"
8906 "JavaScript Object Notation\n")
8907 {
8908 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8909 }
8910
8911 ALIAS (show_bgp_instance_route,
8912 show_bgp_instance_ipv6_route_cmd,
8913 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
8914 SHOW_STR
8915 BGP_STR
8916 BGP_INSTANCE_HELP_STR
8917 "Address family\n"
8918 "Network in the BGP routing table to display\n"
8919 "JavaScript Object Notation\n")
8920
8921 DEFUN (show_bgp_instance_route_pathtype,
8922 show_bgp_instance_route_pathtype_cmd,
8923 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
8924 SHOW_STR
8925 BGP_STR
8926 BGP_INSTANCE_HELP_STR
8927 "Network in the BGP routing table to display\n"
8928 "Display only the bestpath\n"
8929 "Display only multipaths\n"
8930 "JavaScript Object Notation\n")
8931 {
8932 u_char uj = use_json(argc, argv);
8933 if (strncmp (argv[3], "b", 1) == 0)
8934 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8935 else
8936 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8937 }
8938
8939 ALIAS (show_bgp_instance_route_pathtype,
8940 show_bgp_instance_ipv6_route_pathtype_cmd,
8941 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
8942 SHOW_STR
8943 BGP_STR
8944 BGP_INSTANCE_HELP_STR
8945 "Address family\n"
8946 "Network in the BGP routing table to display\n"
8947 "Display only the bestpath\n"
8948 "Display only multipaths\n"
8949 "JavaScript Object Notation\n")
8950
8951 DEFUN (show_bgp_instance_prefix,
8952 show_bgp_instance_prefix_cmd,
8953 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
8954 SHOW_STR
8955 BGP_STR
8956 BGP_INSTANCE_HELP_STR
8957 "IPv6 prefix <network>/<length>\n"
8958 "JavaScript Object Notation\n")
8959 {
8960 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8961 }
8962
8963 ALIAS (show_bgp_instance_prefix,
8964 show_bgp_instance_ipv6_prefix_cmd,
8965 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
8966 SHOW_STR
8967 BGP_STR
8968 BGP_INSTANCE_HELP_STR
8969 "Address family\n"
8970 "IPv6 prefix <network>/<length>\n"
8971 "JavaScript Object Notation\n")
8972
8973 DEFUN (show_bgp_instance_prefix_pathtype,
8974 show_bgp_instance_prefix_pathtype_cmd,
8975 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
8976 SHOW_STR
8977 BGP_STR
8978 BGP_INSTANCE_HELP_STR
8979 "IPv6 prefix <network>/<length>\n"
8980 "Display only the bestpath\n"
8981 "Display only multipaths\n"
8982 "JavaScript Object Notation\n")
8983 {
8984 u_char uj = use_json(argc, argv);
8985 if (strncmp (argv[3], "b", 1) == 0)
8986 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8987 else
8988 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8989 }
8990
8991 ALIAS (show_bgp_instance_prefix_pathtype,
8992 show_bgp_instance_ipv6_prefix_pathtype_cmd,
8993 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8994 SHOW_STR
8995 BGP_STR
8996 BGP_INSTANCE_HELP_STR
8997 "Address family\n"
8998 "IPv6 prefix <network>/<length>\n"
8999 "Display only the bestpath\n"
9000 "Display only multipaths\n"
9001 "JavaScript Object Notation\n")
9002
9003 DEFUN (show_bgp_instance_prefix_list,
9004 show_bgp_instance_prefix_list_cmd,
9005 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9006 SHOW_STR
9007 BGP_STR
9008 BGP_INSTANCE_HELP_STR
9009 "Display routes conforming to the prefix-list\n"
9010 "IPv6 prefix-list name\n")
9011 {
9012 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9013 bgp_show_type_prefix_list);
9014 }
9015
9016 ALIAS (show_bgp_instance_prefix_list,
9017 show_bgp_instance_ipv6_prefix_list_cmd,
9018 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
9019 SHOW_STR
9020 BGP_STR
9021 BGP_INSTANCE_HELP_STR
9022 "Address family\n"
9023 "Display routes conforming to the prefix-list\n"
9024 "IPv6 prefix-list name\n")
9025
9026 DEFUN (show_bgp_instance_filter_list,
9027 show_bgp_instance_filter_list_cmd,
9028 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
9029 SHOW_STR
9030 BGP_STR
9031 BGP_INSTANCE_HELP_STR
9032 "Display routes conforming to the filter-list\n"
9033 "Regular expression access list name\n")
9034 {
9035 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9036 bgp_show_type_filter_list);
9037 }
9038
9039 ALIAS (show_bgp_instance_filter_list,
9040 show_bgp_instance_ipv6_filter_list_cmd,
9041 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
9042 SHOW_STR
9043 BGP_STR
9044 BGP_INSTANCE_HELP_STR
9045 "Address family\n"
9046 "Display routes conforming to the filter-list\n"
9047 "Regular expression access list name\n")
9048
9049 DEFUN (show_bgp_instance_route_map,
9050 show_bgp_instance_route_map_cmd,
9051 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
9052 SHOW_STR
9053 BGP_STR
9054 BGP_INSTANCE_HELP_STR
9055 "Display routes matching the route-map\n"
9056 "A route-map to match on\n")
9057 {
9058 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9059 bgp_show_type_route_map);
9060 }
9061
9062 ALIAS (show_bgp_instance_route_map,
9063 show_bgp_instance_ipv6_route_map_cmd,
9064 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
9065 SHOW_STR
9066 BGP_STR
9067 BGP_INSTANCE_HELP_STR
9068 "Address family\n"
9069 "Display routes matching the route-map\n"
9070 "A route-map to match on\n")
9071
9072 DEFUN (show_bgp_instance_community_list,
9073 show_bgp_instance_community_list_cmd,
9074 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
9075 SHOW_STR
9076 BGP_STR
9077 BGP_INSTANCE_HELP_STR
9078 "Display routes matching the community-list\n"
9079 "community-list number\n"
9080 "community-list name\n")
9081 {
9082 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
9083 }
9084
9085 ALIAS (show_bgp_instance_community_list,
9086 show_bgp_instance_ipv6_community_list_cmd,
9087 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
9088 SHOW_STR
9089 BGP_STR
9090 BGP_INSTANCE_HELP_STR
9091 "Address family\n"
9092 "Display routes matching the community-list\n"
9093 "community-list number\n"
9094 "community-list name\n")
9095
9096 DEFUN (show_bgp_instance_prefix_longer,
9097 show_bgp_instance_prefix_longer_cmd,
9098 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
9099 SHOW_STR
9100 BGP_STR
9101 BGP_INSTANCE_HELP_STR
9102 "IPv6 prefix <network>/<length>\n"
9103 "Display route and more specific routes\n")
9104 {
9105 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9106 bgp_show_type_prefix_longer);
9107 }
9108
9109 ALIAS (show_bgp_instance_prefix_longer,
9110 show_bgp_instance_ipv6_prefix_longer_cmd,
9111 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
9112 SHOW_STR
9113 BGP_STR
9114 BGP_INSTANCE_HELP_STR
9115 "Address family\n"
9116 "IPv6 prefix <network>/<length>\n"
9117 "Display route and more specific routes\n")
9118
9119 /* old command */
9120 DEFUN (show_ipv6_mbgp,
9121 show_ipv6_mbgp_cmd,
9122 "show ipv6 mbgp {json}",
9123 SHOW_STR
9124 IP_STR
9125 MBGP_STR
9126 "JavaScript Object Notation\n")
9127 {
9128 bgp_show_ipv6_bgp_deprecate_warning(vty);
9129 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
9130 NULL, use_json(argc, argv));
9131 }
9132
9133 /* old command */
9134 DEFUN (show_ipv6_mbgp_route,
9135 show_ipv6_mbgp_route_cmd,
9136 "show ipv6 mbgp X:X::X:X {json}",
9137 SHOW_STR
9138 IP_STR
9139 MBGP_STR
9140 "Network in the MBGP routing table to display\n"
9141 "JavaScript Object Notation\n")
9142 {
9143 bgp_show_ipv6_bgp_deprecate_warning(vty);
9144 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
9145 }
9146
9147 /* old command */
9148 DEFUN (show_ipv6_mbgp_prefix,
9149 show_ipv6_mbgp_prefix_cmd,
9150 "show ipv6 mbgp X:X::X:X/M {json}",
9151 SHOW_STR
9152 IP_STR
9153 MBGP_STR
9154 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9155 "JavaScript Object Notation\n")
9156 {
9157 bgp_show_ipv6_bgp_deprecate_warning(vty);
9158 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
9159 }
9160 #endif
9161
9162
9163 static int
9164 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
9165 safi_t safi, enum bgp_show_type type)
9166 {
9167 int i;
9168 struct buffer *b;
9169 char *regstr;
9170 int first;
9171 regex_t *regex;
9172 int rc;
9173
9174 first = 0;
9175 b = buffer_new (1024);
9176 for (i = 0; i < argc; i++)
9177 {
9178 if (first)
9179 buffer_putc (b, ' ');
9180 else
9181 {
9182 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9183 continue;
9184 first = 1;
9185 }
9186
9187 buffer_putstr (b, argv[i]);
9188 }
9189 buffer_putc (b, '\0');
9190
9191 regstr = buffer_getstr (b);
9192 buffer_free (b);
9193
9194 regex = bgp_regcomp (regstr);
9195 XFREE(MTYPE_TMP, regstr);
9196 if (! regex)
9197 {
9198 vty_out (vty, "Can't compile regexp %s%s", argv[0],
9199 VTY_NEWLINE);
9200 return CMD_WARNING;
9201 }
9202
9203 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
9204 bgp_regex_free (regex);
9205 return rc;
9206 }
9207
9208 DEFUN (show_ip_bgp_regexp,
9209 show_ip_bgp_regexp_cmd,
9210 "show ip bgp regexp .LINE",
9211 SHOW_STR
9212 IP_STR
9213 BGP_STR
9214 "Display routes matching the AS path regular expression\n"
9215 "A regular-expression to match the BGP AS paths\n")
9216 {
9217 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9218 bgp_show_type_regexp);
9219 }
9220
9221 DEFUN (show_ip_bgp_flap_regexp,
9222 show_ip_bgp_flap_regexp_cmd,
9223 "show ip bgp flap-statistics regexp .LINE",
9224 SHOW_STR
9225 IP_STR
9226 BGP_STR
9227 "Display flap statistics of routes\n"
9228 "Display routes matching the AS path regular expression\n"
9229 "A regular-expression to match the BGP AS paths\n")
9230 {
9231 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9232 bgp_show_type_flap_regexp);
9233 }
9234
9235 ALIAS (show_ip_bgp_flap_regexp,
9236 show_ip_bgp_damp_flap_regexp_cmd,
9237 "show ip bgp dampening flap-statistics regexp .LINE",
9238 SHOW_STR
9239 IP_STR
9240 BGP_STR
9241 "Display detailed information about dampening\n"
9242 "Display flap statistics of routes\n"
9243 "Display routes matching the AS path regular expression\n"
9244 "A regular-expression to match the BGP AS paths\n")
9245
9246 DEFUN (show_ip_bgp_ipv4_regexp,
9247 show_ip_bgp_ipv4_regexp_cmd,
9248 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" regexp .LINE",
9249 SHOW_STR
9250 IP_STR
9251 BGP_STR
9252 "Address family\n"
9253 BGP_SAFI_HELP_STR
9254 "Display routes matching the AS path regular expression\n"
9255 "A regular-expression to match the BGP AS paths\n")
9256 {
9257 safi_t safi;
9258 safi = bgp_vty_safi_from_arg(argv[0]);
9259 return bgp_show_regexp (vty, argc, argv, AFI_IP, safi,
9260 bgp_show_type_regexp);
9261 }
9262
9263 #ifdef HAVE_IPV6
9264 DEFUN (show_bgp_regexp,
9265 show_bgp_regexp_cmd,
9266 "show bgp regexp .LINE",
9267 SHOW_STR
9268 BGP_STR
9269 "Display routes matching the AS path regular expression\n"
9270 "A regular-expression to match the BGP AS paths\n")
9271 {
9272 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9273 bgp_show_type_regexp);
9274 }
9275
9276 ALIAS (show_bgp_regexp,
9277 show_bgp_ipv6_regexp_cmd,
9278 "show bgp ipv6 regexp .LINE",
9279 SHOW_STR
9280 BGP_STR
9281 "Address family\n"
9282 "Display routes matching the AS path regular expression\n"
9283 "A regular-expression to match the BGP AS paths\n")
9284
9285 /* old command */
9286 DEFUN (show_ipv6_bgp_regexp,
9287 show_ipv6_bgp_regexp_cmd,
9288 "show ipv6 bgp regexp .LINE",
9289 SHOW_STR
9290 IP_STR
9291 BGP_STR
9292 "Display routes matching the AS path regular expression\n"
9293 "A regular-expression to match the BGP AS paths\n")
9294 {
9295 bgp_show_ipv6_bgp_deprecate_warning(vty);
9296 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9297 bgp_show_type_regexp);
9298 }
9299
9300 /* old command */
9301 DEFUN (show_ipv6_mbgp_regexp,
9302 show_ipv6_mbgp_regexp_cmd,
9303 "show ipv6 mbgp regexp .LINE",
9304 SHOW_STR
9305 IP_STR
9306 BGP_STR
9307 "Display routes matching the AS path regular expression\n"
9308 "A regular-expression to match the MBGP AS paths\n")
9309 {
9310 bgp_show_ipv6_bgp_deprecate_warning(vty);
9311 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9312 bgp_show_type_regexp);
9313 }
9314 #endif /* HAVE_IPV6 */
9315
9316 static int
9317 bgp_show_prefix_list (struct vty *vty, const char *name,
9318 const char *prefix_list_str, afi_t afi,
9319 safi_t safi, enum bgp_show_type type)
9320 {
9321 struct prefix_list *plist;
9322 struct bgp *bgp = NULL;
9323
9324 if (name && !(bgp = bgp_lookup_by_name(name)))
9325 {
9326 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9327 return CMD_WARNING;
9328 }
9329
9330 plist = prefix_list_lookup (afi, prefix_list_str);
9331 if (plist == NULL)
9332 {
9333 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9334 prefix_list_str, VTY_NEWLINE);
9335 return CMD_WARNING;
9336 }
9337
9338 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
9339 }
9340
9341 DEFUN (show_ip_bgp_prefix_list,
9342 show_ip_bgp_prefix_list_cmd,
9343 "show ip bgp prefix-list WORD",
9344 SHOW_STR
9345 IP_STR
9346 BGP_STR
9347 "Display routes conforming to the prefix-list\n"
9348 "IP prefix-list name\n")
9349 {
9350 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9351 bgp_show_type_prefix_list);
9352 }
9353
9354 DEFUN (show_ip_bgp_instance_prefix_list,
9355 show_ip_bgp_instance_prefix_list_cmd,
9356 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9357 SHOW_STR
9358 IP_STR
9359 BGP_STR
9360 BGP_INSTANCE_HELP_STR
9361 "Display routes conforming to the prefix-list\n"
9362 "IP prefix-list name\n")
9363 {
9364 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9365 bgp_show_type_prefix_list);
9366 }
9367
9368 DEFUN (show_ip_bgp_flap_prefix_list,
9369 show_ip_bgp_flap_prefix_list_cmd,
9370 "show ip bgp flap-statistics prefix-list WORD",
9371 SHOW_STR
9372 IP_STR
9373 BGP_STR
9374 "Display flap statistics of routes\n"
9375 "Display routes conforming to the prefix-list\n"
9376 "IP prefix-list name\n")
9377 {
9378 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9379 bgp_show_type_flap_prefix_list);
9380 }
9381
9382 ALIAS (show_ip_bgp_flap_prefix_list,
9383 show_ip_bgp_damp_flap_prefix_list_cmd,
9384 "show ip bgp dampening flap-statistics prefix-list WORD",
9385 SHOW_STR
9386 IP_STR
9387 BGP_STR
9388 "Display detailed information about dampening\n"
9389 "Display flap statistics of routes\n"
9390 "Display routes conforming to the prefix-list\n"
9391 "IP prefix-list name\n")
9392
9393 DEFUN (show_ip_bgp_ipv4_prefix_list,
9394 show_ip_bgp_ipv4_prefix_list_cmd,
9395 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" prefix-list WORD",
9396 SHOW_STR
9397 IP_STR
9398 BGP_STR
9399 "Address family\n"
9400 BGP_SAFI_HELP_STR
9401 "Display routes conforming to the prefix-list\n"
9402 "IP prefix-list name\n")
9403 {
9404 safi_t safi;
9405 safi = bgp_vty_safi_from_arg(argv[0]);
9406 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, safi,
9407 bgp_show_type_prefix_list);
9408 }
9409
9410 #ifdef HAVE_IPV6
9411 DEFUN (show_bgp_prefix_list,
9412 show_bgp_prefix_list_cmd,
9413 "show bgp prefix-list WORD",
9414 SHOW_STR
9415 BGP_STR
9416 "Display routes conforming to the prefix-list\n"
9417 "IPv6 prefix-list name\n")
9418 {
9419 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9420 bgp_show_type_prefix_list);
9421 }
9422
9423 ALIAS (show_bgp_prefix_list,
9424 show_bgp_ipv6_prefix_list_cmd,
9425 "show bgp ipv6 prefix-list WORD",
9426 SHOW_STR
9427 BGP_STR
9428 "Address family\n"
9429 "Display routes conforming to the prefix-list\n"
9430 "IPv6 prefix-list name\n")
9431
9432 /* old command */
9433 DEFUN (show_ipv6_bgp_prefix_list,
9434 show_ipv6_bgp_prefix_list_cmd,
9435 "show ipv6 bgp prefix-list WORD",
9436 SHOW_STR
9437 IPV6_STR
9438 BGP_STR
9439 "Display routes matching the prefix-list\n"
9440 "IPv6 prefix-list name\n")
9441 {
9442 bgp_show_ipv6_bgp_deprecate_warning(vty);
9443 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9444 bgp_show_type_prefix_list);
9445 }
9446
9447 /* old command */
9448 DEFUN (show_ipv6_mbgp_prefix_list,
9449 show_ipv6_mbgp_prefix_list_cmd,
9450 "show ipv6 mbgp prefix-list WORD",
9451 SHOW_STR
9452 IPV6_STR
9453 MBGP_STR
9454 "Display routes matching the prefix-list\n"
9455 "IPv6 prefix-list name\n")
9456 {
9457 bgp_show_ipv6_bgp_deprecate_warning(vty);
9458 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9459 bgp_show_type_prefix_list);
9460 }
9461 #endif /* HAVE_IPV6 */
9462
9463 static int
9464 bgp_show_filter_list (struct vty *vty, const char *name,
9465 const char *filter, afi_t afi,
9466 safi_t safi, enum bgp_show_type type)
9467 {
9468 struct as_list *as_list;
9469 struct bgp *bgp = NULL;
9470
9471 if (name && !(bgp = bgp_lookup_by_name(name)))
9472 {
9473 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9474 return CMD_WARNING;
9475 }
9476
9477 as_list = as_list_lookup (filter);
9478 if (as_list == NULL)
9479 {
9480 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9481 return CMD_WARNING;
9482 }
9483
9484 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
9485 }
9486
9487 DEFUN (show_ip_bgp_filter_list,
9488 show_ip_bgp_filter_list_cmd,
9489 "show ip bgp filter-list WORD",
9490 SHOW_STR
9491 IP_STR
9492 BGP_STR
9493 "Display routes conforming to the filter-list\n"
9494 "Regular expression access list name\n")
9495 {
9496 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9497 bgp_show_type_filter_list);
9498 }
9499
9500 DEFUN (show_ip_bgp_instance_filter_list,
9501 show_ip_bgp_instance_filter_list_cmd,
9502 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
9503 SHOW_STR
9504 IP_STR
9505 BGP_STR
9506 BGP_INSTANCE_HELP_STR
9507 "Display routes conforming to the filter-list\n"
9508 "Regular expression access list name\n")
9509 {
9510 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9511 bgp_show_type_filter_list);
9512 }
9513
9514 DEFUN (show_ip_bgp_flap_filter_list,
9515 show_ip_bgp_flap_filter_list_cmd,
9516 "show ip bgp flap-statistics filter-list WORD",
9517 SHOW_STR
9518 IP_STR
9519 BGP_STR
9520 "Display flap statistics of routes\n"
9521 "Display routes conforming to the filter-list\n"
9522 "Regular expression access list name\n")
9523 {
9524 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9525 bgp_show_type_flap_filter_list);
9526 }
9527
9528 ALIAS (show_ip_bgp_flap_filter_list,
9529 show_ip_bgp_damp_flap_filter_list_cmd,
9530 "show ip bgp dampening flap-statistics filter-list WORD",
9531 SHOW_STR
9532 IP_STR
9533 BGP_STR
9534 "Display detailed information about dampening\n"
9535 "Display flap statistics of routes\n"
9536 "Display routes conforming to the filter-list\n"
9537 "Regular expression access list name\n")
9538
9539 DEFUN (show_ip_bgp_ipv4_filter_list,
9540 show_ip_bgp_ipv4_filter_list_cmd,
9541 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" filter-list WORD",
9542 SHOW_STR
9543 IP_STR
9544 BGP_STR
9545 "Address family\n"
9546 BGP_SAFI_HELP_STR
9547 "Display routes conforming to the filter-list\n"
9548 "Regular expression access list name\n")
9549 {
9550 safi_t safi;
9551 safi = bgp_vty_safi_from_arg(argv[0]);
9552 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, safi,
9553 bgp_show_type_filter_list);
9554 }
9555
9556 #ifdef HAVE_IPV6
9557 DEFUN (show_bgp_filter_list,
9558 show_bgp_filter_list_cmd,
9559 "show bgp filter-list WORD",
9560 SHOW_STR
9561 BGP_STR
9562 "Display routes conforming to the filter-list\n"
9563 "Regular expression access list name\n")
9564 {
9565 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9566 bgp_show_type_filter_list);
9567 }
9568
9569 ALIAS (show_bgp_filter_list,
9570 show_bgp_ipv6_filter_list_cmd,
9571 "show bgp ipv6 filter-list WORD",
9572 SHOW_STR
9573 BGP_STR
9574 "Address family\n"
9575 "Display routes conforming to the filter-list\n"
9576 "Regular expression access list name\n")
9577
9578 /* old command */
9579 DEFUN (show_ipv6_bgp_filter_list,
9580 show_ipv6_bgp_filter_list_cmd,
9581 "show ipv6 bgp filter-list WORD",
9582 SHOW_STR
9583 IPV6_STR
9584 BGP_STR
9585 "Display routes conforming to the filter-list\n"
9586 "Regular expression access list name\n")
9587 {
9588 bgp_show_ipv6_bgp_deprecate_warning(vty);
9589 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9590 bgp_show_type_filter_list);
9591 }
9592
9593 /* old command */
9594 DEFUN (show_ipv6_mbgp_filter_list,
9595 show_ipv6_mbgp_filter_list_cmd,
9596 "show ipv6 mbgp filter-list WORD",
9597 SHOW_STR
9598 IPV6_STR
9599 MBGP_STR
9600 "Display routes conforming to the filter-list\n"
9601 "Regular expression access list name\n")
9602 {
9603 bgp_show_ipv6_bgp_deprecate_warning(vty);
9604 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9605 bgp_show_type_filter_list);
9606 }
9607 #endif /* HAVE_IPV6 */
9608
9609 DEFUN (show_ip_bgp_dampening_info,
9610 show_ip_bgp_dampening_params_cmd,
9611 "show ip bgp dampening parameters",
9612 SHOW_STR
9613 IP_STR
9614 BGP_STR
9615 "Display detailed information about dampening\n"
9616 "Display detail of configured dampening parameters\n")
9617 {
9618 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9619 }
9620
9621
9622 DEFUN (show_ip_bgp_ipv4_dampening_parameters,
9623 show_ip_bgp_ipv4_dampening_parameters_cmd,
9624 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening parameters",
9625 SHOW_STR
9626 IP_STR
9627 BGP_STR
9628 "Address family\n"
9629 BGP_SAFI_HELP_STR
9630 "Display detailed information about dampening\n"
9631 "Display detail of configured dampening parameters\n")
9632 {
9633 safi_t safi;
9634 safi = bgp_vty_safi_from_arg(argv[0]);
9635 return bgp_show_dampening_parameters (vty, AFI_IP, safi);
9636 }
9637
9638
9639 DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
9640 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
9641 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening flap-statistics",
9642 SHOW_STR
9643 IP_STR
9644 BGP_STR
9645 "Address family\n"
9646 BGP_SAFI_HELP_STR
9647 "Display detailed information about dampening\n"
9648 "Display flap statistics of routes\n")
9649 {
9650 safi_t safi;
9651 safi = bgp_vty_safi_from_arg(argv[0]);
9652 return bgp_show (vty, NULL, AFI_IP, safi,
9653 bgp_show_type_flap_statistics, NULL, 0);
9654 }
9655
9656 DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
9657 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
9658 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening dampened-paths",
9659 SHOW_STR
9660 IP_STR
9661 BGP_STR
9662 "Address family\n"
9663 BGP_SAFI_HELP_STR
9664 "Display detailed information about dampening\n"
9665 "Display paths suppressed due to dampening\n")
9666 {
9667 safi_t safi;
9668 safi = bgp_vty_safi_from_arg(argv[0]);
9669 return bgp_show (vty, NULL, AFI_IP, safi,
9670 bgp_show_type_dampend_paths, NULL, 0);
9671 }
9672
9673 static int
9674 bgp_show_route_map (struct vty *vty, const char *name,
9675 const char *rmap_str, afi_t afi,
9676 safi_t safi, enum bgp_show_type type)
9677 {
9678 struct route_map *rmap;
9679 struct bgp *bgp = NULL;
9680
9681 if (name && !(bgp = bgp_lookup_by_name(name)))
9682 {
9683 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9684 return CMD_WARNING;
9685 }
9686
9687 rmap = route_map_lookup_by_name (rmap_str);
9688 if (! rmap)
9689 {
9690 vty_out (vty, "%% %s is not a valid route-map name%s",
9691 rmap_str, VTY_NEWLINE);
9692 return CMD_WARNING;
9693 }
9694
9695 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
9696 }
9697
9698 DEFUN (show_ip_bgp_route_map,
9699 show_ip_bgp_route_map_cmd,
9700 "show ip bgp route-map WORD",
9701 SHOW_STR
9702 IP_STR
9703 BGP_STR
9704 "Display routes matching the route-map\n"
9705 "A route-map to match on\n")
9706 {
9707 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9708 bgp_show_type_route_map);
9709 }
9710
9711 DEFUN (show_ip_bgp_instance_route_map,
9712 show_ip_bgp_instance_route_map_cmd,
9713 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
9714 SHOW_STR
9715 IP_STR
9716 BGP_STR
9717 BGP_INSTANCE_HELP_STR
9718 "Display routes matching the route-map\n"
9719 "A route-map to match on\n")
9720 {
9721 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9722 bgp_show_type_route_map);
9723 }
9724
9725 DEFUN (show_ip_bgp_flap_route_map,
9726 show_ip_bgp_flap_route_map_cmd,
9727 "show ip bgp flap-statistics route-map WORD",
9728 SHOW_STR
9729 IP_STR
9730 BGP_STR
9731 "Display flap statistics of routes\n"
9732 "Display routes matching the route-map\n"
9733 "A route-map to match on\n")
9734 {
9735 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9736 bgp_show_type_flap_route_map);
9737 }
9738
9739 ALIAS (show_ip_bgp_flap_route_map,
9740 show_ip_bgp_damp_flap_route_map_cmd,
9741 "show ip bgp dampening flap-statistics route-map WORD",
9742 SHOW_STR
9743 IP_STR
9744 BGP_STR
9745 "Display detailed information about dampening\n"
9746 "Display flap statistics of routes\n"
9747 "Display routes matching the route-map\n"
9748 "A route-map to match on\n")
9749
9750 DEFUN (show_ip_bgp_ipv4_route_map,
9751 show_ip_bgp_ipv4_route_map_cmd,
9752 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" route-map WORD",
9753 SHOW_STR
9754 IP_STR
9755 BGP_STR
9756 "Address family\n"
9757 BGP_SAFI_HELP_STR
9758 "Display routes matching the route-map\n"
9759 "A route-map to match on\n")
9760 {
9761 safi_t safi;
9762 safi = bgp_vty_safi_from_arg(argv[0]);
9763 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, safi,
9764 bgp_show_type_route_map);
9765 }
9766
9767 DEFUN (show_bgp_route_map,
9768 show_bgp_route_map_cmd,
9769 "show bgp route-map WORD",
9770 SHOW_STR
9771 BGP_STR
9772 "Display routes matching the route-map\n"
9773 "A route-map to match on\n")
9774 {
9775 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9776 bgp_show_type_route_map);
9777 }
9778
9779 ALIAS (show_bgp_route_map,
9780 show_bgp_ipv6_route_map_cmd,
9781 "show bgp ipv6 route-map WORD",
9782 SHOW_STR
9783 BGP_STR
9784 "Address family\n"
9785 "Display routes matching the route-map\n"
9786 "A route-map to match on\n")
9787
9788 DEFUN (show_ip_bgp_cidr_only,
9789 show_ip_bgp_cidr_only_cmd,
9790 "show ip bgp cidr-only",
9791 SHOW_STR
9792 IP_STR
9793 BGP_STR
9794 "Display only routes with non-natural netmasks\n")
9795 {
9796 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9797 bgp_show_type_cidr_only, NULL, 0);
9798 }
9799
9800 DEFUN (show_ip_bgp_flap_cidr_only,
9801 show_ip_bgp_flap_cidr_only_cmd,
9802 "show ip bgp flap-statistics cidr-only",
9803 SHOW_STR
9804 IP_STR
9805 BGP_STR
9806 "Display flap statistics of routes\n"
9807 "Display only routes with non-natural netmasks\n")
9808 {
9809 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9810 bgp_show_type_flap_cidr_only, NULL, 0);
9811 }
9812
9813 ALIAS (show_ip_bgp_flap_cidr_only,
9814 show_ip_bgp_damp_flap_cidr_only_cmd,
9815 "show ip bgp dampening flap-statistics cidr-only",
9816 SHOW_STR
9817 IP_STR
9818 BGP_STR
9819 "Display detailed information about dampening\n"
9820 "Display flap statistics of routes\n"
9821 "Display only routes with non-natural netmasks\n")
9822
9823 DEFUN (show_ip_bgp_ipv4_cidr_only,
9824 show_ip_bgp_ipv4_cidr_only_cmd,
9825 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" cidr-only",
9826 SHOW_STR
9827 IP_STR
9828 BGP_STR
9829 "Address family\n"
9830 BGP_SAFI_HELP_STR
9831 "Display only routes with non-natural netmasks\n")
9832 {
9833 safi_t safi;
9834 safi = bgp_vty_safi_from_arg(argv[0]);
9835 return bgp_show (vty, NULL, AFI_IP, safi,
9836 bgp_show_type_cidr_only, NULL, 0);
9837 }
9838
9839 DEFUN (show_ip_bgp_community_all,
9840 show_ip_bgp_community_all_cmd,
9841 "show ip bgp community",
9842 SHOW_STR
9843 IP_STR
9844 BGP_STR
9845 "Display routes matching the communities\n")
9846 {
9847 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9848 bgp_show_type_community_all, NULL, 0);
9849 }
9850
9851 DEFUN (show_ip_bgp_ipv4_community_all,
9852 show_ip_bgp_ipv4_community_all_cmd,
9853 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community",
9854 SHOW_STR
9855 IP_STR
9856 BGP_STR
9857 "Address family\n"
9858 BGP_SAFI_HELP_STR
9859 "Display routes matching the communities\n")
9860 {
9861 safi_t safi;
9862 safi = bgp_vty_safi_from_arg(argv[0]);
9863 return bgp_show (vty, NULL, AFI_IP, safi,
9864 bgp_show_type_community_all, NULL, 0);
9865 }
9866
9867 #ifdef HAVE_IPV6
9868 DEFUN (show_bgp_community_all,
9869 show_bgp_community_all_cmd,
9870 "show bgp community",
9871 SHOW_STR
9872 BGP_STR
9873 "Display routes matching the communities\n")
9874 {
9875 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9876 bgp_show_type_community_all, NULL, 0);
9877 }
9878
9879 ALIAS (show_bgp_community_all,
9880 show_bgp_ipv6_community_all_cmd,
9881 "show bgp ipv6 community",
9882 SHOW_STR
9883 BGP_STR
9884 "Address family\n"
9885 "Display routes matching the communities\n")
9886
9887 /* old command */
9888 DEFUN (show_ipv6_bgp_community_all,
9889 show_ipv6_bgp_community_all_cmd,
9890 "show ipv6 bgp community",
9891 SHOW_STR
9892 IPV6_STR
9893 BGP_STR
9894 "Display routes matching the communities\n")
9895 {
9896 bgp_show_ipv6_bgp_deprecate_warning(vty);
9897 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9898 bgp_show_type_community_all, NULL, 0);
9899 }
9900
9901 /* old command */
9902 DEFUN (show_ipv6_mbgp_community_all,
9903 show_ipv6_mbgp_community_all_cmd,
9904 "show ipv6 mbgp community",
9905 SHOW_STR
9906 IPV6_STR
9907 MBGP_STR
9908 "Display routes matching the communities\n")
9909 {
9910 bgp_show_ipv6_bgp_deprecate_warning(vty);
9911 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9912 bgp_show_type_community_all, NULL, 0);
9913 }
9914 #endif /* HAVE_IPV6 */
9915
9916 static int
9917 bgp_show_community (struct vty *vty, const char *view_name, int argc,
9918 const char **argv, int exact, afi_t afi, safi_t safi)
9919 {
9920 struct community *com;
9921 struct buffer *b;
9922 struct bgp *bgp;
9923 int i;
9924 char *str;
9925 int first = 0;
9926
9927 /* BGP structure lookup */
9928 if (view_name)
9929 {
9930 bgp = bgp_lookup_by_name (view_name);
9931 if (bgp == NULL)
9932 {
9933 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
9934 return CMD_WARNING;
9935 }
9936 }
9937 else
9938 {
9939 bgp = bgp_get_default ();
9940 if (bgp == NULL)
9941 {
9942 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9943 return CMD_WARNING;
9944 }
9945 }
9946
9947 b = buffer_new (1024);
9948 for (i = 0; i < argc; i++)
9949 {
9950 if (first)
9951 buffer_putc (b, ' ');
9952 else
9953 {
9954 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9955 continue;
9956 first = 1;
9957 }
9958
9959 buffer_putstr (b, argv[i]);
9960 }
9961 buffer_putc (b, '\0');
9962
9963 str = buffer_getstr (b);
9964 buffer_free (b);
9965
9966 com = community_str2com (str);
9967 XFREE (MTYPE_TMP, str);
9968 if (! com)
9969 {
9970 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9971 return CMD_WARNING;
9972 }
9973
9974 return bgp_show (vty, bgp, afi, safi,
9975 (exact ? bgp_show_type_community_exact :
9976 bgp_show_type_community), com, 0);
9977 }
9978
9979 DEFUN (show_ip_bgp_community,
9980 show_ip_bgp_community_cmd,
9981 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9982 SHOW_STR
9983 IP_STR
9984 BGP_STR
9985 "Display routes matching the communities\n"
9986 COMMUNITY_AANN_STR
9987 "Do not send outside local AS (well-known community)\n"
9988 "Do not advertise to any peer (well-known community)\n"
9989 "Do not export to next AS (well-known community)\n")
9990 {
9991 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9992 }
9993
9994 ALIAS (show_ip_bgp_community,
9995 show_ip_bgp_community2_cmd,
9996 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9997 SHOW_STR
9998 IP_STR
9999 BGP_STR
10000 "Display routes matching the communities\n"
10001 COMMUNITY_AANN_STR
10002 "Do not send outside local AS (well-known community)\n"
10003 "Do not advertise to any peer (well-known community)\n"
10004 "Do not export to next AS (well-known community)\n"
10005 COMMUNITY_AANN_STR
10006 "Do not send outside local AS (well-known community)\n"
10007 "Do not advertise to any peer (well-known community)\n"
10008 "Do not export to next AS (well-known community)\n")
10009
10010 ALIAS (show_ip_bgp_community,
10011 show_ip_bgp_community3_cmd,
10012 "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)",
10013 SHOW_STR
10014 IP_STR
10015 BGP_STR
10016 "Display routes matching the communities\n"
10017 COMMUNITY_AANN_STR
10018 "Do not send outside local AS (well-known community)\n"
10019 "Do not advertise to any peer (well-known community)\n"
10020 "Do not export to next AS (well-known community)\n"
10021 COMMUNITY_AANN_STR
10022 "Do not send outside local AS (well-known community)\n"
10023 "Do not advertise to any peer (well-known community)\n"
10024 "Do not export to next AS (well-known community)\n"
10025 COMMUNITY_AANN_STR
10026 "Do not send outside local AS (well-known community)\n"
10027 "Do not advertise to any peer (well-known community)\n"
10028 "Do not export to next AS (well-known community)\n")
10029
10030 ALIAS (show_ip_bgp_community,
10031 show_ip_bgp_community4_cmd,
10032 "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)",
10033 SHOW_STR
10034 IP_STR
10035 BGP_STR
10036 "Display routes matching the communities\n"
10037 COMMUNITY_AANN_STR
10038 "Do not send outside local AS (well-known community)\n"
10039 "Do not advertise to any peer (well-known community)\n"
10040 "Do not export to next AS (well-known community)\n"
10041 COMMUNITY_AANN_STR
10042 "Do not send outside local AS (well-known community)\n"
10043 "Do not advertise to any peer (well-known community)\n"
10044 "Do not export to next AS (well-known community)\n"
10045 COMMUNITY_AANN_STR
10046 "Do not send outside local AS (well-known community)\n"
10047 "Do not advertise to any peer (well-known community)\n"
10048 "Do not export to next AS (well-known community)\n"
10049 COMMUNITY_AANN_STR
10050 "Do not send outside local AS (well-known community)\n"
10051 "Do not advertise to any peer (well-known community)\n"
10052 "Do not export to next AS (well-known community)\n")
10053
10054 DEFUN (show_ip_bgp_ipv4_community,
10055 show_ip_bgp_ipv4_community_cmd,
10056 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export)",
10057 SHOW_STR
10058 IP_STR
10059 BGP_STR
10060 "Address family\n"
10061 BGP_SAFI_HELP_STR
10062 "Display routes matching the communities\n"
10063 COMMUNITY_AANN_STR
10064 "Do not send outside local AS (well-known community)\n"
10065 "Do not advertise to any peer (well-known community)\n"
10066 "Do not export to next AS (well-known community)\n")
10067 {
10068 safi_t safi;
10069 safi = bgp_vty_safi_from_arg(argv[0]);
10070 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, safi);
10071 }
10072
10073 ALIAS (show_ip_bgp_ipv4_community,
10074 show_ip_bgp_ipv4_community2_cmd,
10075 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10076 SHOW_STR
10077 IP_STR
10078 BGP_STR
10079 "Address family\n"
10080 BGP_SAFI_HELP_STR
10081 "Display routes matching the communities\n"
10082 COMMUNITY_AANN_STR
10083 "Do not send outside local AS (well-known community)\n"
10084 "Do not advertise to any peer (well-known community)\n"
10085 "Do not export to next AS (well-known community)\n"
10086 COMMUNITY_AANN_STR
10087 "Do not send outside local AS (well-known community)\n"
10088 "Do not advertise to any peer (well-known community)\n"
10089 "Do not export to next AS (well-known community)\n")
10090
10091 ALIAS (show_ip_bgp_ipv4_community,
10092 show_ip_bgp_ipv4_community3_cmd,
10093 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" 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)",
10094 SHOW_STR
10095 IP_STR
10096 BGP_STR
10097 "Address family\n"
10098 BGP_SAFI_HELP_STR
10099 "Display routes matching the communities\n"
10100 COMMUNITY_AANN_STR
10101 "Do not send outside local AS (well-known community)\n"
10102 "Do not advertise to any peer (well-known community)\n"
10103 "Do not export to next AS (well-known community)\n"
10104 COMMUNITY_AANN_STR
10105 "Do not send outside local AS (well-known community)\n"
10106 "Do not advertise to any peer (well-known community)\n"
10107 "Do not export to next AS (well-known community)\n"
10108 COMMUNITY_AANN_STR
10109 "Do not send outside local AS (well-known community)\n"
10110 "Do not advertise to any peer (well-known community)\n"
10111 "Do not export to next AS (well-known community)\n")
10112
10113 ALIAS (show_ip_bgp_ipv4_community,
10114 show_ip_bgp_ipv4_community4_cmd,
10115 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" 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)",
10116 SHOW_STR
10117 IP_STR
10118 BGP_STR
10119 "Address family\n"
10120 BGP_SAFI_HELP_STR
10121 "Display routes matching the communities\n"
10122 COMMUNITY_AANN_STR
10123 "Do not send outside local AS (well-known community)\n"
10124 "Do not advertise to any peer (well-known community)\n"
10125 "Do not export to next AS (well-known community)\n"
10126 COMMUNITY_AANN_STR
10127 "Do not send outside local AS (well-known community)\n"
10128 "Do not advertise to any peer (well-known community)\n"
10129 "Do not export to next AS (well-known community)\n"
10130 COMMUNITY_AANN_STR
10131 "Do not send outside local AS (well-known community)\n"
10132 "Do not advertise to any peer (well-known community)\n"
10133 "Do not export to next AS (well-known community)\n"
10134 COMMUNITY_AANN_STR
10135 "Do not send outside local AS (well-known community)\n"
10136 "Do not advertise to any peer (well-known community)\n"
10137 "Do not export to next AS (well-known community)\n")
10138
10139 DEFUN (show_bgp_instance_afi_safi_community_all,
10140 show_bgp_instance_afi_safi_community_all_cmd,
10141 "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community",
10142 SHOW_STR
10143 BGP_STR
10144 BGP_INSTANCE_HELP_STR
10145 BGP_AFI_SAFI_HELP_STR
10146 "Display routes matching the communities\n")
10147 {
10148 int afi;
10149 int safi;
10150 struct bgp *bgp;
10151
10152 /* BGP structure lookup. */
10153 bgp = bgp_lookup_by_name (argv[1]);
10154 if (bgp == NULL)
10155 {
10156 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
10157 return CMD_WARNING;
10158 }
10159
10160 afi = bgp_vty_safi_from_arg(argv[2]);
10161 safi = bgp_vty_safi_from_arg(argv[3]);
10162 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
10163 }
10164
10165 DEFUN (show_bgp_instance_afi_safi_community,
10166 show_bgp_instance_afi_safi_community_cmd,
10167 "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export)",
10168 SHOW_STR
10169 BGP_STR
10170 BGP_INSTANCE_HELP_STR
10171 "Address family\n"
10172 "Address family\n"
10173 "Address family modifier\n"
10174 "Address family modifier\n"
10175 "Display routes matching the communities\n"
10176 COMMUNITY_AANN_STR
10177 "Do not send outside local AS (well-known community)\n"
10178 "Do not advertise to any peer (well-known community)\n"
10179 "Do not export to next AS (well-known community)\n")
10180 {
10181 int afi;
10182 int safi;
10183
10184 afi = bgp_vty_safi_from_arg(argv[2]);
10185 safi = bgp_vty_safi_from_arg(argv[3]);
10186 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
10187 }
10188
10189 ALIAS (show_bgp_instance_afi_safi_community,
10190 show_bgp_instance_afi_safi_community2_cmd,
10191 "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10192 SHOW_STR
10193 BGP_STR
10194 BGP_INSTANCE_HELP_STR
10195 "Address family\n"
10196 "Address family\n"
10197 "Address family modifier\n"
10198 "Address family modifier\n"
10199 "Display routes matching the communities\n"
10200 COMMUNITY_AANN_STR
10201 "Do not send outside local AS (well-known community)\n"
10202 "Do not advertise to any peer (well-known community)\n"
10203 "Do not export to next AS (well-known community)\n"
10204 COMMUNITY_AANN_STR
10205 "Do not send outside local AS (well-known community)\n"
10206 "Do not advertise to any peer (well-known community)\n"
10207 "Do not export to next AS (well-known community)\n")
10208
10209 ALIAS (show_bgp_instance_afi_safi_community,
10210 show_bgp_instance_afi_safi_community3_cmd,
10211 "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" 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)",
10212 SHOW_STR
10213 BGP_STR
10214 BGP_INSTANCE_HELP_STR
10215 "Address family\n"
10216 "Address family\n"
10217 "Address family modifier\n"
10218 "Address family modifier\n"
10219 "Display routes matching the communities\n"
10220 COMMUNITY_AANN_STR
10221 "Do not send outside local AS (well-known community)\n"
10222 "Do not advertise to any peer (well-known community)\n"
10223 "Do not export to next AS (well-known community)\n"
10224 COMMUNITY_AANN_STR
10225 "Do not send outside local AS (well-known community)\n"
10226 "Do not advertise to any peer (well-known community)\n"
10227 "Do not export to next AS (well-known community)\n"
10228 COMMUNITY_AANN_STR
10229 "Do not send outside local AS (well-known community)\n"
10230 "Do not advertise to any peer (well-known community)\n"
10231 "Do not export to next AS (well-known community)\n")
10232
10233 ALIAS (show_bgp_instance_afi_safi_community,
10234 show_bgp_instance_afi_safi_community4_cmd,
10235 "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" 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)",
10236 SHOW_STR
10237 BGP_STR
10238 BGP_INSTANCE_HELP_STR
10239 "Address family\n"
10240 "Address family\n"
10241 "Address family modifier\n"
10242 "Address family modifier\n"
10243 "Display routes matching the communities\n"
10244 COMMUNITY_AANN_STR
10245 "Do not send outside local AS (well-known community)\n"
10246 "Do not advertise to any peer (well-known community)\n"
10247 "Do not export to next AS (well-known community)\n"
10248 COMMUNITY_AANN_STR
10249 "Do not send outside local AS (well-known community)\n"
10250 "Do not advertise to any peer (well-known community)\n"
10251 "Do not export to next AS (well-known community)\n"
10252 COMMUNITY_AANN_STR
10253 "Do not send outside local AS (well-known community)\n"
10254 "Do not advertise to any peer (well-known community)\n"
10255 "Do not export to next AS (well-known community)\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
10261 DEFUN (show_ip_bgp_community_exact,
10262 show_ip_bgp_community_exact_cmd,
10263 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10264 SHOW_STR
10265 IP_STR
10266 BGP_STR
10267 "Display routes matching the communities\n"
10268 COMMUNITY_AANN_STR
10269 "Do not send outside local AS (well-known community)\n"
10270 "Do not advertise to any peer (well-known community)\n"
10271 "Do not export to next AS (well-known community)\n"
10272 "Exact match of the communities")
10273 {
10274 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10275 }
10276
10277 ALIAS (show_ip_bgp_community_exact,
10278 show_ip_bgp_community2_exact_cmd,
10279 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10280 SHOW_STR
10281 IP_STR
10282 BGP_STR
10283 "Display routes matching the communities\n"
10284 COMMUNITY_AANN_STR
10285 "Do not send outside local AS (well-known community)\n"
10286 "Do not advertise to any peer (well-known community)\n"
10287 "Do not export to next AS (well-known community)\n"
10288 COMMUNITY_AANN_STR
10289 "Do not send outside local AS (well-known community)\n"
10290 "Do not advertise to any peer (well-known community)\n"
10291 "Do not export to next AS (well-known community)\n"
10292 "Exact match of the communities")
10293
10294 ALIAS (show_ip_bgp_community_exact,
10295 show_ip_bgp_community3_exact_cmd,
10296 "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",
10297 SHOW_STR
10298 IP_STR
10299 BGP_STR
10300 "Display routes matching the communities\n"
10301 COMMUNITY_AANN_STR
10302 "Do not send outside local AS (well-known community)\n"
10303 "Do not advertise to any peer (well-known community)\n"
10304 "Do not export to next AS (well-known community)\n"
10305 COMMUNITY_AANN_STR
10306 "Do not send outside local AS (well-known community)\n"
10307 "Do not advertise to any peer (well-known community)\n"
10308 "Do not export to next AS (well-known community)\n"
10309 COMMUNITY_AANN_STR
10310 "Do not send outside local AS (well-known community)\n"
10311 "Do not advertise to any peer (well-known community)\n"
10312 "Do not export to next AS (well-known community)\n"
10313 "Exact match of the communities")
10314
10315 ALIAS (show_ip_bgp_community_exact,
10316 show_ip_bgp_community4_exact_cmd,
10317 "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",
10318 SHOW_STR
10319 IP_STR
10320 BGP_STR
10321 "Display routes matching the communities\n"
10322 COMMUNITY_AANN_STR
10323 "Do not send outside local AS (well-known community)\n"
10324 "Do not advertise to any peer (well-known community)\n"
10325 "Do not export to next AS (well-known community)\n"
10326 COMMUNITY_AANN_STR
10327 "Do not send outside local AS (well-known community)\n"
10328 "Do not advertise to any peer (well-known community)\n"
10329 "Do not export to next AS (well-known community)\n"
10330 COMMUNITY_AANN_STR
10331 "Do not send outside local AS (well-known community)\n"
10332 "Do not advertise to any peer (well-known community)\n"
10333 "Do not export to next AS (well-known community)\n"
10334 COMMUNITY_AANN_STR
10335 "Do not send outside local AS (well-known community)\n"
10336 "Do not advertise to any peer (well-known community)\n"
10337 "Do not export to next AS (well-known community)\n"
10338 "Exact match of the communities")
10339
10340 DEFUN (show_ip_bgp_ipv4_community_exact,
10341 show_ip_bgp_ipv4_community_exact_cmd,
10342 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10343 SHOW_STR
10344 IP_STR
10345 BGP_STR
10346 "Address family\n"
10347 BGP_SAFI_HELP_STR
10348 "Display routes matching the communities\n"
10349 COMMUNITY_AANN_STR
10350 "Do not send outside local AS (well-known community)\n"
10351 "Do not advertise to any peer (well-known community)\n"
10352 "Do not export to next AS (well-known community)\n"
10353 "Exact match of the communities")
10354 {
10355 safi_t safi;
10356 safi = bgp_vty_safi_from_arg(argv[0]);
10357 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, safi);
10358 }
10359
10360 ALIAS (show_ip_bgp_ipv4_community_exact,
10361 show_ip_bgp_ipv4_community2_exact_cmd,
10362 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10363 SHOW_STR
10364 IP_STR
10365 BGP_STR
10366 "Address family\n"
10367 BGP_SAFI_HELP_STR
10368 "Display routes matching the communities\n"
10369 COMMUNITY_AANN_STR
10370 "Do not send outside local AS (well-known community)\n"
10371 "Do not advertise to any peer (well-known community)\n"
10372 "Do not export to next AS (well-known community)\n"
10373 COMMUNITY_AANN_STR
10374 "Do not send outside local AS (well-known community)\n"
10375 "Do not advertise to any peer (well-known community)\n"
10376 "Do not export to next AS (well-known community)\n"
10377 "Exact match of the communities")
10378
10379 ALIAS (show_ip_bgp_ipv4_community_exact,
10380 show_ip_bgp_ipv4_community3_exact_cmd,
10381 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" 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",
10382 SHOW_STR
10383 IP_STR
10384 BGP_STR
10385 "Address family\n"
10386 BGP_SAFI_HELP_STR
10387 "Display routes matching the communities\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 COMMUNITY_AANN_STR
10393 "Do not send outside local AS (well-known community)\n"
10394 "Do not advertise to any peer (well-known community)\n"
10395 "Do not export to next AS (well-known community)\n"
10396 COMMUNITY_AANN_STR
10397 "Do not send outside local AS (well-known community)\n"
10398 "Do not advertise to any peer (well-known community)\n"
10399 "Do not export to next AS (well-known community)\n"
10400 "Exact match of the communities")
10401
10402 ALIAS (show_ip_bgp_ipv4_community_exact,
10403 show_ip_bgp_ipv4_community4_exact_cmd,
10404 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" 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",
10405 SHOW_STR
10406 IP_STR
10407 BGP_STR
10408 "Address family\n"
10409 BGP_SAFI_HELP_STR
10410 "Display routes matching the communities\n"
10411 COMMUNITY_AANN_STR
10412 "Do not send outside local AS (well-known community)\n"
10413 "Do not advertise to any peer (well-known community)\n"
10414 "Do not export to next AS (well-known community)\n"
10415 COMMUNITY_AANN_STR
10416 "Do not send outside local AS (well-known community)\n"
10417 "Do not advertise to any peer (well-known community)\n"
10418 "Do not export to next AS (well-known community)\n"
10419 COMMUNITY_AANN_STR
10420 "Do not send outside local AS (well-known community)\n"
10421 "Do not advertise to any peer (well-known community)\n"
10422 "Do not export to next AS (well-known community)\n"
10423 COMMUNITY_AANN_STR
10424 "Do not send outside local AS (well-known community)\n"
10425 "Do not advertise to any peer (well-known community)\n"
10426 "Do not export to next AS (well-known community)\n"
10427 "Exact match of the communities")
10428
10429 #ifdef HAVE_IPV6
10430 DEFUN (show_bgp_community,
10431 show_bgp_community_cmd,
10432 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10433 SHOW_STR
10434 BGP_STR
10435 "Display routes matching the communities\n"
10436 COMMUNITY_AANN_STR
10437 "Do not send outside local AS (well-known community)\n"
10438 "Do not advertise to any peer (well-known community)\n"
10439 "Do not export to next AS (well-known community)\n")
10440 {
10441 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10442 }
10443
10444 ALIAS (show_bgp_community,
10445 show_bgp_ipv6_community_cmd,
10446 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10447 SHOW_STR
10448 BGP_STR
10449 "Address family\n"
10450 "Display routes matching the communities\n"
10451 COMMUNITY_AANN_STR
10452 "Do not send outside local AS (well-known community)\n"
10453 "Do not advertise to any peer (well-known community)\n"
10454 "Do not export to next AS (well-known community)\n")
10455
10456 ALIAS (show_bgp_community,
10457 show_bgp_community2_cmd,
10458 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10459 SHOW_STR
10460 BGP_STR
10461 "Display routes matching the communities\n"
10462 COMMUNITY_AANN_STR
10463 "Do not send outside local AS (well-known community)\n"
10464 "Do not advertise to any peer (well-known community)\n"
10465 "Do not export to next AS (well-known community)\n"
10466 COMMUNITY_AANN_STR
10467 "Do not send outside local AS (well-known community)\n"
10468 "Do not advertise to any peer (well-known community)\n"
10469 "Do not export to next AS (well-known community)\n")
10470
10471 ALIAS (show_bgp_community,
10472 show_bgp_ipv6_community2_cmd,
10473 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10474 SHOW_STR
10475 BGP_STR
10476 "Address family\n"
10477 "Display routes matching the communities\n"
10478 COMMUNITY_AANN_STR
10479 "Do not send outside local AS (well-known community)\n"
10480 "Do not advertise to any peer (well-known community)\n"
10481 "Do not export to next AS (well-known community)\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
10487 ALIAS (show_bgp_community,
10488 show_bgp_community3_cmd,
10489 "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)",
10490 SHOW_STR
10491 BGP_STR
10492 "Display routes matching the communities\n"
10493 COMMUNITY_AANN_STR
10494 "Do not send outside local AS (well-known community)\n"
10495 "Do not advertise to any peer (well-known community)\n"
10496 "Do not export to next AS (well-known community)\n"
10497 COMMUNITY_AANN_STR
10498 "Do not send outside local AS (well-known community)\n"
10499 "Do not advertise to any peer (well-known community)\n"
10500 "Do not export to next AS (well-known community)\n"
10501 COMMUNITY_AANN_STR
10502 "Do not send outside local AS (well-known community)\n"
10503 "Do not advertise to any peer (well-known community)\n"
10504 "Do not export to next AS (well-known community)\n")
10505
10506 ALIAS (show_bgp_community,
10507 show_bgp_ipv6_community3_cmd,
10508 "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)",
10509 SHOW_STR
10510 BGP_STR
10511 "Address family\n"
10512 "Display routes matching the communities\n"
10513 COMMUNITY_AANN_STR
10514 "Do not send outside local AS (well-known community)\n"
10515 "Do not advertise to any peer (well-known community)\n"
10516 "Do not export to next AS (well-known community)\n"
10517 COMMUNITY_AANN_STR
10518 "Do not send outside local AS (well-known community)\n"
10519 "Do not advertise to any peer (well-known community)\n"
10520 "Do not export to next AS (well-known community)\n"
10521 COMMUNITY_AANN_STR
10522 "Do not send outside local AS (well-known community)\n"
10523 "Do not advertise to any peer (well-known community)\n"
10524 "Do not export to next AS (well-known community)\n")
10525
10526 ALIAS (show_bgp_community,
10527 show_bgp_community4_cmd,
10528 "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)",
10529 SHOW_STR
10530 BGP_STR
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 COMMUNITY_AANN_STR
10541 "Do not send outside local AS (well-known community)\n"
10542 "Do not advertise to any peer (well-known community)\n"
10543 "Do not export to next AS (well-known community)\n"
10544 COMMUNITY_AANN_STR
10545 "Do not send outside local AS (well-known community)\n"
10546 "Do not advertise to any peer (well-known community)\n"
10547 "Do not export to next AS (well-known community)\n")
10548
10549 ALIAS (show_bgp_community,
10550 show_bgp_ipv6_community4_cmd,
10551 "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)",
10552 SHOW_STR
10553 BGP_STR
10554 "Address family\n"
10555 "Display routes matching the communities\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 COMMUNITY_AANN_STR
10565 "Do not send outside local AS (well-known community)\n"
10566 "Do not advertise to any peer (well-known community)\n"
10567 "Do not export to next AS (well-known community)\n"
10568 COMMUNITY_AANN_STR
10569 "Do not send outside local AS (well-known community)\n"
10570 "Do not advertise to any peer (well-known community)\n"
10571 "Do not export to next AS (well-known community)\n")
10572
10573 /* old command */
10574 DEFUN (show_ipv6_bgp_community,
10575 show_ipv6_bgp_community_cmd,
10576 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10577 SHOW_STR
10578 IPV6_STR
10579 BGP_STR
10580 "Display routes matching the communities\n"
10581 COMMUNITY_AANN_STR
10582 "Do not send outside local AS (well-known community)\n"
10583 "Do not advertise to any peer (well-known community)\n"
10584 "Do not export to next AS (well-known community)\n")
10585 {
10586 bgp_show_ipv6_bgp_deprecate_warning(vty);
10587 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10588 }
10589
10590 /* old command */
10591 ALIAS (show_ipv6_bgp_community,
10592 show_ipv6_bgp_community2_cmd,
10593 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10594 SHOW_STR
10595 IPV6_STR
10596 BGP_STR
10597 "Display routes matching the communities\n"
10598 COMMUNITY_AANN_STR
10599 "Do not send outside local AS (well-known community)\n"
10600 "Do not advertise to any peer (well-known community)\n"
10601 "Do not export to next AS (well-known community)\n"
10602 COMMUNITY_AANN_STR
10603 "Do not send outside local AS (well-known community)\n"
10604 "Do not advertise to any peer (well-known community)\n"
10605 "Do not export to next AS (well-known community)\n")
10606
10607 /* old command */
10608 ALIAS (show_ipv6_bgp_community,
10609 show_ipv6_bgp_community3_cmd,
10610 "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)",
10611 SHOW_STR
10612 IPV6_STR
10613 BGP_STR
10614 "Display routes matching the communities\n"
10615 COMMUNITY_AANN_STR
10616 "Do not send outside local AS (well-known community)\n"
10617 "Do not advertise to any peer (well-known community)\n"
10618 "Do not export to next AS (well-known community)\n"
10619 COMMUNITY_AANN_STR
10620 "Do not send outside local AS (well-known community)\n"
10621 "Do not advertise to any peer (well-known community)\n"
10622 "Do not export to next AS (well-known community)\n"
10623 COMMUNITY_AANN_STR
10624 "Do not send outside local AS (well-known community)\n"
10625 "Do not advertise to any peer (well-known community)\n"
10626 "Do not export to next AS (well-known community)\n")
10627
10628 /* old command */
10629 ALIAS (show_ipv6_bgp_community,
10630 show_ipv6_bgp_community4_cmd,
10631 "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)",
10632 SHOW_STR
10633 IPV6_STR
10634 BGP_STR
10635 "Display routes matching the communities\n"
10636 COMMUNITY_AANN_STR
10637 "Do not send outside local AS (well-known community)\n"
10638 "Do not advertise to any peer (well-known community)\n"
10639 "Do not export to next AS (well-known community)\n"
10640 COMMUNITY_AANN_STR
10641 "Do not send outside local AS (well-known community)\n"
10642 "Do not advertise to any peer (well-known community)\n"
10643 "Do not export to next AS (well-known community)\n"
10644 COMMUNITY_AANN_STR
10645 "Do not send outside local AS (well-known community)\n"
10646 "Do not advertise to any peer (well-known community)\n"
10647 "Do not export to next AS (well-known community)\n"
10648 COMMUNITY_AANN_STR
10649 "Do not send outside local AS (well-known community)\n"
10650 "Do not advertise to any peer (well-known community)\n"
10651 "Do not export to next AS (well-known community)\n")
10652
10653 DEFUN (show_bgp_community_exact,
10654 show_bgp_community_exact_cmd,
10655 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10656 SHOW_STR
10657 BGP_STR
10658 "Display routes matching the communities\n"
10659 COMMUNITY_AANN_STR
10660 "Do not send outside local AS (well-known community)\n"
10661 "Do not advertise to any peer (well-known community)\n"
10662 "Do not export to next AS (well-known community)\n"
10663 "Exact match of the communities")
10664 {
10665 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10666 }
10667
10668 ALIAS (show_bgp_community_exact,
10669 show_bgp_ipv6_community_exact_cmd,
10670 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10671 SHOW_STR
10672 BGP_STR
10673 "Address family\n"
10674 "Display routes matching the communities\n"
10675 COMMUNITY_AANN_STR
10676 "Do not send outside local AS (well-known community)\n"
10677 "Do not advertise to any peer (well-known community)\n"
10678 "Do not export to next AS (well-known community)\n"
10679 "Exact match of the communities")
10680
10681 ALIAS (show_bgp_community_exact,
10682 show_bgp_community2_exact_cmd,
10683 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10684 SHOW_STR
10685 BGP_STR
10686 "Display routes matching the communities\n"
10687 COMMUNITY_AANN_STR
10688 "Do not send outside local AS (well-known community)\n"
10689 "Do not advertise to any peer (well-known community)\n"
10690 "Do not export to next AS (well-known community)\n"
10691 COMMUNITY_AANN_STR
10692 "Do not send outside local AS (well-known community)\n"
10693 "Do not advertise to any peer (well-known community)\n"
10694 "Do not export to next AS (well-known community)\n"
10695 "Exact match of the communities")
10696
10697 ALIAS (show_bgp_community_exact,
10698 show_bgp_ipv6_community2_exact_cmd,
10699 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10700 SHOW_STR
10701 BGP_STR
10702 "Address family\n"
10703 "Display routes matching the communities\n"
10704 COMMUNITY_AANN_STR
10705 "Do not send outside local AS (well-known community)\n"
10706 "Do not advertise to any peer (well-known community)\n"
10707 "Do not export to next AS (well-known community)\n"
10708 COMMUNITY_AANN_STR
10709 "Do not send outside local AS (well-known community)\n"
10710 "Do not advertise to any peer (well-known community)\n"
10711 "Do not export to next AS (well-known community)\n"
10712 "Exact match of the communities")
10713
10714 ALIAS (show_bgp_community_exact,
10715 show_bgp_community3_exact_cmd,
10716 "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",
10717 SHOW_STR
10718 BGP_STR
10719 "Display routes matching the communities\n"
10720 COMMUNITY_AANN_STR
10721 "Do not send outside local AS (well-known community)\n"
10722 "Do not advertise to any peer (well-known community)\n"
10723 "Do not export to next AS (well-known community)\n"
10724 COMMUNITY_AANN_STR
10725 "Do not send outside local AS (well-known community)\n"
10726 "Do not advertise to any peer (well-known community)\n"
10727 "Do not export to next AS (well-known community)\n"
10728 COMMUNITY_AANN_STR
10729 "Do not send outside local AS (well-known community)\n"
10730 "Do not advertise to any peer (well-known community)\n"
10731 "Do not export to next AS (well-known community)\n"
10732 "Exact match of the communities")
10733
10734 ALIAS (show_bgp_community_exact,
10735 show_bgp_ipv6_community3_exact_cmd,
10736 "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",
10737 SHOW_STR
10738 BGP_STR
10739 "Address family\n"
10740 "Display routes matching the communities\n"
10741 COMMUNITY_AANN_STR
10742 "Do not send outside local AS (well-known community)\n"
10743 "Do not advertise to any peer (well-known community)\n"
10744 "Do not export to next AS (well-known community)\n"
10745 COMMUNITY_AANN_STR
10746 "Do not send outside local AS (well-known community)\n"
10747 "Do not advertise to any peer (well-known community)\n"
10748 "Do not export to next AS (well-known community)\n"
10749 COMMUNITY_AANN_STR
10750 "Do not send outside local AS (well-known community)\n"
10751 "Do not advertise to any peer (well-known community)\n"
10752 "Do not export to next AS (well-known community)\n"
10753 "Exact match of the communities")
10754
10755 ALIAS (show_bgp_community_exact,
10756 show_bgp_community4_exact_cmd,
10757 "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",
10758 SHOW_STR
10759 BGP_STR
10760 "Display routes matching the communities\n"
10761 COMMUNITY_AANN_STR
10762 "Do not send outside local AS (well-known community)\n"
10763 "Do not advertise to any peer (well-known community)\n"
10764 "Do not export to next AS (well-known community)\n"
10765 COMMUNITY_AANN_STR
10766 "Do not send outside local AS (well-known community)\n"
10767 "Do not advertise to any peer (well-known community)\n"
10768 "Do not export to next AS (well-known community)\n"
10769 COMMUNITY_AANN_STR
10770 "Do not send outside local AS (well-known community)\n"
10771 "Do not advertise to any peer (well-known community)\n"
10772 "Do not export to next AS (well-known community)\n"
10773 COMMUNITY_AANN_STR
10774 "Do not send outside local AS (well-known community)\n"
10775 "Do not advertise to any peer (well-known community)\n"
10776 "Do not export to next AS (well-known community)\n"
10777 "Exact match of the communities")
10778
10779 ALIAS (show_bgp_community_exact,
10780 show_bgp_ipv6_community4_exact_cmd,
10781 "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",
10782 SHOW_STR
10783 BGP_STR
10784 "Address family\n"
10785 "Display routes matching the communities\n"
10786 COMMUNITY_AANN_STR
10787 "Do not send outside local AS (well-known community)\n"
10788 "Do not advertise to any peer (well-known community)\n"
10789 "Do not export to next AS (well-known community)\n"
10790 COMMUNITY_AANN_STR
10791 "Do not send outside local AS (well-known community)\n"
10792 "Do not advertise to any peer (well-known community)\n"
10793 "Do not export to next AS (well-known community)\n"
10794 COMMUNITY_AANN_STR
10795 "Do not send outside local AS (well-known community)\n"
10796 "Do not advertise to any peer (well-known community)\n"
10797 "Do not export to next AS (well-known community)\n"
10798 COMMUNITY_AANN_STR
10799 "Do not send outside local AS (well-known community)\n"
10800 "Do not advertise to any peer (well-known community)\n"
10801 "Do not export to next AS (well-known community)\n"
10802 "Exact match of the communities")
10803
10804 /* old command */
10805 DEFUN (show_ipv6_bgp_community_exact,
10806 show_ipv6_bgp_community_exact_cmd,
10807 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10808 SHOW_STR
10809 IPV6_STR
10810 BGP_STR
10811 "Display routes matching the communities\n"
10812 COMMUNITY_AANN_STR
10813 "Do not send outside local AS (well-known community)\n"
10814 "Do not advertise to any peer (well-known community)\n"
10815 "Do not export to next AS (well-known community)\n"
10816 "Exact match of the communities")
10817 {
10818 bgp_show_ipv6_bgp_deprecate_warning(vty);
10819 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10820 }
10821
10822 /* old command */
10823 ALIAS (show_ipv6_bgp_community_exact,
10824 show_ipv6_bgp_community2_exact_cmd,
10825 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10826 SHOW_STR
10827 IPV6_STR
10828 BGP_STR
10829 "Display routes matching the communities\n"
10830 COMMUNITY_AANN_STR
10831 "Do not send outside local AS (well-known community)\n"
10832 "Do not advertise to any peer (well-known community)\n"
10833 "Do not export to next AS (well-known community)\n"
10834 COMMUNITY_AANN_STR
10835 "Do not send outside local AS (well-known community)\n"
10836 "Do not advertise to any peer (well-known community)\n"
10837 "Do not export to next AS (well-known community)\n"
10838 "Exact match of the communities")
10839
10840 /* old command */
10841 ALIAS (show_ipv6_bgp_community_exact,
10842 show_ipv6_bgp_community3_exact_cmd,
10843 "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",
10844 SHOW_STR
10845 IPV6_STR
10846 BGP_STR
10847 "Display routes matching the communities\n"
10848 COMMUNITY_AANN_STR
10849 "Do not send outside local AS (well-known community)\n"
10850 "Do not advertise to any peer (well-known community)\n"
10851 "Do not export to next AS (well-known community)\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 /* old command */
10863 ALIAS (show_ipv6_bgp_community_exact,
10864 show_ipv6_bgp_community4_exact_cmd,
10865 "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",
10866 SHOW_STR
10867 IPV6_STR
10868 BGP_STR
10869 "Display routes matching the communities\n"
10870 COMMUNITY_AANN_STR
10871 "Do not send outside local AS (well-known community)\n"
10872 "Do not advertise to any peer (well-known community)\n"
10873 "Do not export to next AS (well-known community)\n"
10874 COMMUNITY_AANN_STR
10875 "Do not send outside local AS (well-known community)\n"
10876 "Do not advertise to any peer (well-known community)\n"
10877 "Do not export to next AS (well-known community)\n"
10878 COMMUNITY_AANN_STR
10879 "Do not send outside local AS (well-known community)\n"
10880 "Do not advertise to any peer (well-known community)\n"
10881 "Do not export to next AS (well-known community)\n"
10882 COMMUNITY_AANN_STR
10883 "Do not send outside local AS (well-known community)\n"
10884 "Do not advertise to any peer (well-known community)\n"
10885 "Do not export to next AS (well-known community)\n"
10886 "Exact match of the communities")
10887
10888 /* old command */
10889 DEFUN (show_ipv6_mbgp_community,
10890 show_ipv6_mbgp_community_cmd,
10891 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10892 SHOW_STR
10893 IPV6_STR
10894 MBGP_STR
10895 "Display routes matching the communities\n"
10896 COMMUNITY_AANN_STR
10897 "Do not send outside local AS (well-known community)\n"
10898 "Do not advertise to any peer (well-known community)\n"
10899 "Do not export to next AS (well-known community)\n")
10900 {
10901 bgp_show_ipv6_bgp_deprecate_warning(vty);
10902 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10903 }
10904
10905 /* old command */
10906 ALIAS (show_ipv6_mbgp_community,
10907 show_ipv6_mbgp_community2_cmd,
10908 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10909 SHOW_STR
10910 IPV6_STR
10911 MBGP_STR
10912 "Display routes matching the communities\n"
10913 COMMUNITY_AANN_STR
10914 "Do not send outside local AS (well-known community)\n"
10915 "Do not advertise to any peer (well-known community)\n"
10916 "Do not export to next AS (well-known community)\n"
10917 COMMUNITY_AANN_STR
10918 "Do not send outside local AS (well-known community)\n"
10919 "Do not advertise to any peer (well-known community)\n"
10920 "Do not export to next AS (well-known community)\n")
10921
10922 /* old command */
10923 ALIAS (show_ipv6_mbgp_community,
10924 show_ipv6_mbgp_community3_cmd,
10925 "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)",
10926 SHOW_STR
10927 IPV6_STR
10928 MBGP_STR
10929 "Display routes matching the communities\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
10943 /* old command */
10944 ALIAS (show_ipv6_mbgp_community,
10945 show_ipv6_mbgp_community4_cmd,
10946 "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)",
10947 SHOW_STR
10948 IPV6_STR
10949 MBGP_STR
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
10968 /* old command */
10969 DEFUN (show_ipv6_mbgp_community_exact,
10970 show_ipv6_mbgp_community_exact_cmd,
10971 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10972 SHOW_STR
10973 IPV6_STR
10974 MBGP_STR
10975 "Display routes matching the communities\n"
10976 COMMUNITY_AANN_STR
10977 "Do not send outside local AS (well-known community)\n"
10978 "Do not advertise to any peer (well-known community)\n"
10979 "Do not export to next AS (well-known community)\n"
10980 "Exact match of the communities")
10981 {
10982 bgp_show_ipv6_bgp_deprecate_warning(vty);
10983 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10984 }
10985
10986 /* old command */
10987 ALIAS (show_ipv6_mbgp_community_exact,
10988 show_ipv6_mbgp_community2_exact_cmd,
10989 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10990 SHOW_STR
10991 IPV6_STR
10992 MBGP_STR
10993 "Display routes matching the communities\n"
10994 COMMUNITY_AANN_STR
10995 "Do not send outside local AS (well-known community)\n"
10996 "Do not advertise to any peer (well-known community)\n"
10997 "Do not export to next AS (well-known community)\n"
10998 COMMUNITY_AANN_STR
10999 "Do not send outside local AS (well-known community)\n"
11000 "Do not advertise to any peer (well-known community)\n"
11001 "Do not export to next AS (well-known community)\n"
11002 "Exact match of the communities")
11003
11004 /* old command */
11005 ALIAS (show_ipv6_mbgp_community_exact,
11006 show_ipv6_mbgp_community3_exact_cmd,
11007 "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",
11008 SHOW_STR
11009 IPV6_STR
11010 MBGP_STR
11011 "Display routes matching the communities\n"
11012 COMMUNITY_AANN_STR
11013 "Do not send outside local AS (well-known community)\n"
11014 "Do not advertise to any peer (well-known community)\n"
11015 "Do not export to next AS (well-known community)\n"
11016 COMMUNITY_AANN_STR
11017 "Do not send outside local AS (well-known community)\n"
11018 "Do not advertise to any peer (well-known community)\n"
11019 "Do not export to next AS (well-known community)\n"
11020 COMMUNITY_AANN_STR
11021 "Do not send outside local AS (well-known community)\n"
11022 "Do not advertise to any peer (well-known community)\n"
11023 "Do not export to next AS (well-known community)\n"
11024 "Exact match of the communities")
11025
11026 /* old command */
11027 ALIAS (show_ipv6_mbgp_community_exact,
11028 show_ipv6_mbgp_community4_exact_cmd,
11029 "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",
11030 SHOW_STR
11031 IPV6_STR
11032 MBGP_STR
11033 "Display routes matching the communities\n"
11034 COMMUNITY_AANN_STR
11035 "Do not send outside local AS (well-known community)\n"
11036 "Do not advertise to any peer (well-known community)\n"
11037 "Do not export to next AS (well-known community)\n"
11038 COMMUNITY_AANN_STR
11039 "Do not send outside local AS (well-known community)\n"
11040 "Do not advertise to any peer (well-known community)\n"
11041 "Do not export to next AS (well-known community)\n"
11042 COMMUNITY_AANN_STR
11043 "Do not send outside local AS (well-known community)\n"
11044 "Do not advertise to any peer (well-known community)\n"
11045 "Do not export to next AS (well-known community)\n"
11046 COMMUNITY_AANN_STR
11047 "Do not send outside local AS (well-known community)\n"
11048 "Do not advertise to any peer (well-known community)\n"
11049 "Do not export to next AS (well-known community)\n"
11050 "Exact match of the communities")
11051 #endif /* HAVE_IPV6 */
11052
11053 static int
11054 bgp_show_community_list (struct vty *vty, const char *name,
11055 const char *com, int exact,
11056 afi_t afi, safi_t safi)
11057 {
11058 struct community_list *list;
11059 struct bgp *bgp = NULL;
11060
11061 if (name && !(bgp = bgp_lookup_by_name(name)))
11062 {
11063 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11064 return CMD_WARNING;
11065 }
11066
11067 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
11068 if (list == NULL)
11069 {
11070 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11071 VTY_NEWLINE);
11072 return CMD_WARNING;
11073 }
11074
11075 return bgp_show (vty, bgp, afi, safi,
11076 (exact ? bgp_show_type_community_list_exact :
11077 bgp_show_type_community_list), list, 0);
11078 }
11079
11080 DEFUN (show_ip_bgp_community_list,
11081 show_ip_bgp_community_list_cmd,
11082 "show ip bgp community-list (<1-500>|WORD)",
11083 SHOW_STR
11084 IP_STR
11085 BGP_STR
11086 "Display routes matching the community-list\n"
11087 "community-list number\n"
11088 "community-list name\n")
11089 {
11090 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
11091 }
11092
11093 DEFUN (show_ip_bgp_instance_community_list,
11094 show_ip_bgp_instance_community_list_cmd,
11095 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
11096 SHOW_STR
11097 IP_STR
11098 BGP_STR
11099 BGP_INSTANCE_HELP_STR
11100 "Display routes matching the community-list\n"
11101 "community-list number\n"
11102 "community-list name\n")
11103 {
11104 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
11105 }
11106
11107 DEFUN (show_ip_bgp_ipv4_community_list,
11108 show_ip_bgp_ipv4_community_list_cmd,
11109 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community-list (<1-500>|WORD)",
11110 SHOW_STR
11111 IP_STR
11112 BGP_STR
11113 "Address family\n"
11114 BGP_SAFI_HELP_STR
11115 "Display routes matching the community-list\n"
11116 "community-list number\n"
11117 "community-list name\n")
11118 {
11119 safi_t safi;
11120 safi = bgp_vty_safi_from_arg(argv[0]);
11121 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, safi);
11122 }
11123
11124 DEFUN (show_ip_bgp_community_list_exact,
11125 show_ip_bgp_community_list_exact_cmd,
11126 "show ip bgp community-list (<1-500>|WORD) exact-match",
11127 SHOW_STR
11128 IP_STR
11129 BGP_STR
11130 "Display routes matching the community-list\n"
11131 "community-list number\n"
11132 "community-list name\n"
11133 "Exact match of the communities\n")
11134 {
11135 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
11136 }
11137
11138 DEFUN (show_ip_bgp_ipv4_community_list_exact,
11139 show_ip_bgp_ipv4_community_list_exact_cmd,
11140 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community-list (<1-500>|WORD) exact-match",
11141 SHOW_STR
11142 IP_STR
11143 BGP_STR
11144 "Address family\n"
11145 BGP_SAFI_HELP_STR
11146 "Display routes matching the community-list\n"
11147 "community-list number\n"
11148 "community-list name\n"
11149 "Exact match of the communities\n")
11150 {
11151 safi_t safi;
11152 safi = bgp_vty_safi_from_arg(argv[0]);
11153 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, safi);
11154 }
11155
11156 #ifdef HAVE_IPV6
11157 DEFUN (show_bgp_community_list,
11158 show_bgp_community_list_cmd,
11159 "show bgp community-list (<1-500>|WORD)",
11160 SHOW_STR
11161 BGP_STR
11162 "Display routes matching the community-list\n"
11163 "community-list number\n"
11164 "community-list name\n")
11165 {
11166 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11167 }
11168
11169 ALIAS (show_bgp_community_list,
11170 show_bgp_ipv6_community_list_cmd,
11171 "show bgp ipv6 community-list (<1-500>|WORD)",
11172 SHOW_STR
11173 BGP_STR
11174 "Address family\n"
11175 "Display routes matching the community-list\n"
11176 "community-list number\n"
11177 "community-list name\n")
11178
11179 /* old command */
11180 DEFUN (show_ipv6_bgp_community_list,
11181 show_ipv6_bgp_community_list_cmd,
11182 "show ipv6 bgp community-list WORD",
11183 SHOW_STR
11184 IPV6_STR
11185 BGP_STR
11186 "Display routes matching the community-list\n"
11187 "community-list name\n")
11188 {
11189 bgp_show_ipv6_bgp_deprecate_warning(vty);
11190 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11191 }
11192
11193 /* old command */
11194 DEFUN (show_ipv6_mbgp_community_list,
11195 show_ipv6_mbgp_community_list_cmd,
11196 "show ipv6 mbgp community-list WORD",
11197 SHOW_STR
11198 IPV6_STR
11199 MBGP_STR
11200 "Display routes matching the community-list\n"
11201 "community-list name\n")
11202 {
11203 bgp_show_ipv6_bgp_deprecate_warning(vty);
11204 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11205 }
11206
11207 DEFUN (show_bgp_community_list_exact,
11208 show_bgp_community_list_exact_cmd,
11209 "show bgp community-list (<1-500>|WORD) exact-match",
11210 SHOW_STR
11211 BGP_STR
11212 "Display routes matching the community-list\n"
11213 "community-list number\n"
11214 "community-list name\n"
11215 "Exact match of the communities\n")
11216 {
11217 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11218 }
11219
11220 ALIAS (show_bgp_community_list_exact,
11221 show_bgp_ipv6_community_list_exact_cmd,
11222 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11223 SHOW_STR
11224 BGP_STR
11225 "Address family\n"
11226 "Display routes matching the community-list\n"
11227 "community-list number\n"
11228 "community-list name\n"
11229 "Exact match of the communities\n")
11230
11231 /* old command */
11232 DEFUN (show_ipv6_bgp_community_list_exact,
11233 show_ipv6_bgp_community_list_exact_cmd,
11234 "show ipv6 bgp community-list WORD exact-match",
11235 SHOW_STR
11236 IPV6_STR
11237 BGP_STR
11238 "Display routes matching the community-list\n"
11239 "community-list name\n"
11240 "Exact match of the communities\n")
11241 {
11242 bgp_show_ipv6_bgp_deprecate_warning(vty);
11243 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11244 }
11245
11246 /* old command */
11247 DEFUN (show_ipv6_mbgp_community_list_exact,
11248 show_ipv6_mbgp_community_list_exact_cmd,
11249 "show ipv6 mbgp community-list WORD exact-match",
11250 SHOW_STR
11251 IPV6_STR
11252 MBGP_STR
11253 "Display routes matching the community-list\n"
11254 "community-list name\n"
11255 "Exact match of the communities\n")
11256 {
11257 bgp_show_ipv6_bgp_deprecate_warning(vty);
11258 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11259 }
11260 #endif /* HAVE_IPV6 */
11261
11262 static int
11263 bgp_show_prefix_longer (struct vty *vty, const char *name,
11264 const char *prefix, afi_t afi,
11265 safi_t safi, enum bgp_show_type type)
11266 {
11267 int ret;
11268 struct prefix *p;
11269 struct bgp *bgp = NULL;
11270
11271 if (name && !(bgp = bgp_lookup_by_name(name)))
11272 {
11273 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11274 return CMD_WARNING;
11275 }
11276
11277 p = prefix_new();
11278
11279 ret = str2prefix (prefix, p);
11280 if (! ret)
11281 {
11282 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11283 return CMD_WARNING;
11284 }
11285
11286 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
11287 prefix_free(p);
11288 return ret;
11289 }
11290
11291 DEFUN (show_ip_bgp_prefix_longer,
11292 show_ip_bgp_prefix_longer_cmd,
11293 "show ip bgp A.B.C.D/M longer-prefixes",
11294 SHOW_STR
11295 IP_STR
11296 BGP_STR
11297 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11298 "Display route and more specific routes\n")
11299 {
11300 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11301 bgp_show_type_prefix_longer);
11302 }
11303
11304 DEFUN (show_ip_bgp_instance_prefix_longer,
11305 show_ip_bgp_instance_prefix_longer_cmd,
11306 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
11307 SHOW_STR
11308 IP_STR
11309 BGP_STR
11310 BGP_INSTANCE_HELP_STR
11311 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11312 "Display route and more specific routes\n")
11313 {
11314 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
11315 bgp_show_type_prefix_longer);
11316 }
11317
11318 DEFUN (show_ip_bgp_flap_prefix_longer,
11319 show_ip_bgp_flap_prefix_longer_cmd,
11320 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11321 SHOW_STR
11322 IP_STR
11323 BGP_STR
11324 "Display flap statistics of routes\n"
11325 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11326 "Display route and more specific routes\n")
11327 {
11328 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11329 bgp_show_type_flap_prefix_longer);
11330 }
11331
11332 ALIAS (show_ip_bgp_flap_prefix_longer,
11333 show_ip_bgp_damp_flap_prefix_longer_cmd,
11334 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11335 SHOW_STR
11336 IP_STR
11337 BGP_STR
11338 "Display detailed information about dampening\n"
11339 "Display flap statistics of routes\n"
11340 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11341 "Display route and more specific routes\n")
11342
11343 DEFUN (show_ip_bgp_ipv4_prefix_longer,
11344 show_ip_bgp_ipv4_prefix_longer_cmd,
11345 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M longer-prefixes",
11346 SHOW_STR
11347 IP_STR
11348 BGP_STR
11349 "Address family\n"
11350 BGP_SAFI_HELP_STR
11351 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11352 "Display route and more specific routes\n")
11353 {
11354 safi_t safi;
11355 safi = bgp_vty_safi_from_arg(argv[0]);
11356 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, safi,
11357 bgp_show_type_prefix_longer);
11358 }
11359
11360 DEFUN (show_ip_bgp_flap_address,
11361 show_ip_bgp_flap_address_cmd,
11362 "show ip bgp flap-statistics A.B.C.D",
11363 SHOW_STR
11364 IP_STR
11365 BGP_STR
11366 "Display flap statistics of routes\n"
11367 "Network in the BGP routing table to display\n")
11368 {
11369 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11370 bgp_show_type_flap_address);
11371 }
11372
11373 ALIAS (show_ip_bgp_flap_address,
11374 show_ip_bgp_damp_flap_address_cmd,
11375 "show ip bgp dampening flap-statistics A.B.C.D",
11376 SHOW_STR
11377 IP_STR
11378 BGP_STR
11379 "Display detailed information about dampening\n"
11380 "Display flap statistics of routes\n"
11381 "Network in the BGP routing table to display\n")
11382
11383 DEFUN (show_ip_bgp_flap_prefix,
11384 show_ip_bgp_flap_prefix_cmd,
11385 "show ip bgp flap-statistics A.B.C.D/M",
11386 SHOW_STR
11387 IP_STR
11388 BGP_STR
11389 "Display flap statistics of routes\n"
11390 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11391 {
11392 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11393 bgp_show_type_flap_prefix);
11394 }
11395
11396 ALIAS (show_ip_bgp_flap_prefix,
11397 show_ip_bgp_damp_flap_prefix_cmd,
11398 "show ip bgp dampening flap-statistics A.B.C.D/M",
11399 SHOW_STR
11400 IP_STR
11401 BGP_STR
11402 "Display detailed information about dampening\n"
11403 "Display flap statistics of routes\n"
11404 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11405
11406 #ifdef HAVE_IPV6
11407 DEFUN (show_bgp_prefix_longer,
11408 show_bgp_prefix_longer_cmd,
11409 "show bgp X:X::X:X/M longer-prefixes",
11410 SHOW_STR
11411 BGP_STR
11412 "IPv6 prefix <network>/<length>\n"
11413 "Display route and more specific routes\n")
11414 {
11415 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11416 bgp_show_type_prefix_longer);
11417 }
11418
11419 ALIAS (show_bgp_prefix_longer,
11420 show_bgp_ipv6_prefix_longer_cmd,
11421 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11422 SHOW_STR
11423 BGP_STR
11424 "Address family\n"
11425 "IPv6 prefix <network>/<length>\n"
11426 "Display route and more specific routes\n")
11427
11428 /* old command */
11429 DEFUN (show_ipv6_bgp_prefix_longer,
11430 show_ipv6_bgp_prefix_longer_cmd,
11431 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11432 SHOW_STR
11433 IPV6_STR
11434 BGP_STR
11435 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11436 "Display route and more specific routes\n")
11437 {
11438 bgp_show_ipv6_bgp_deprecate_warning(vty);
11439 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11440 bgp_show_type_prefix_longer);
11441 }
11442
11443 /* old command */
11444 DEFUN (show_ipv6_mbgp_prefix_longer,
11445 show_ipv6_mbgp_prefix_longer_cmd,
11446 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11447 SHOW_STR
11448 IPV6_STR
11449 MBGP_STR
11450 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11451 "Display route and more specific routes\n")
11452 {
11453 bgp_show_ipv6_bgp_deprecate_warning(vty);
11454 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
11455 bgp_show_type_prefix_longer);
11456 }
11457 #endif /* HAVE_IPV6 */
11458
11459 static struct peer *
11460 peer_lookup_in_view (struct vty *vty, const char *view_name,
11461 const char *ip_str, u_char use_json)
11462 {
11463 int ret;
11464 struct bgp *bgp;
11465 struct peer *peer;
11466 union sockunion su;
11467
11468 /* BGP structure lookup. */
11469 if (view_name)
11470 {
11471 bgp = bgp_lookup_by_name (view_name);
11472 if (! bgp)
11473 {
11474 if (use_json)
11475 {
11476 json_object *json_no = NULL;
11477 json_no = json_object_new_object();
11478 json_object_string_add(json_no, "warning", "Can't find BGP view");
11479 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11480 json_object_free(json_no);
11481 }
11482 else
11483 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
11484 return NULL;
11485 }
11486 }
11487 else
11488 {
11489 bgp = bgp_get_default ();
11490 if (! bgp)
11491 {
11492 if (use_json)
11493 {
11494 json_object *json_no = NULL;
11495 json_no = json_object_new_object();
11496 json_object_string_add(json_no, "warning", "No BGP process configured");
11497 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11498 json_object_free(json_no);
11499 }
11500 else
11501 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11502 return NULL;
11503 }
11504 }
11505
11506 /* Get peer sockunion. */
11507 ret = str2sockunion (ip_str, &su);
11508 if (ret < 0)
11509 {
11510 peer = peer_lookup_by_conf_if (bgp, ip_str);
11511 if (!peer)
11512 {
11513 peer = peer_lookup_by_hostname(bgp, ip_str);
11514
11515 if (!peer)
11516 {
11517 if (use_json)
11518 {
11519 json_object *json_no = NULL;
11520 json_no = json_object_new_object();
11521 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11522 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11523 json_object_free(json_no);
11524 }
11525 else
11526 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11527 return NULL;
11528 }
11529 }
11530 return peer;
11531 }
11532
11533 /* Peer structure lookup. */
11534 peer = peer_lookup (bgp, &su);
11535 if (! peer)
11536 {
11537 if (use_json)
11538 {
11539 json_object *json_no = NULL;
11540 json_no = json_object_new_object();
11541 json_object_string_add(json_no, "warning","No such neighbor");
11542 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11543 json_object_free(json_no);
11544 }
11545 else
11546 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11547 return NULL;
11548 }
11549
11550 return peer;
11551 }
11552
11553 enum bgp_stats
11554 {
11555 BGP_STATS_MAXBITLEN = 0,
11556 BGP_STATS_RIB,
11557 BGP_STATS_PREFIXES,
11558 BGP_STATS_TOTPLEN,
11559 BGP_STATS_UNAGGREGATEABLE,
11560 BGP_STATS_MAX_AGGREGATEABLE,
11561 BGP_STATS_AGGREGATES,
11562 BGP_STATS_SPACE,
11563 BGP_STATS_ASPATH_COUNT,
11564 BGP_STATS_ASPATH_MAXHOPS,
11565 BGP_STATS_ASPATH_TOTHOPS,
11566 BGP_STATS_ASPATH_MAXSIZE,
11567 BGP_STATS_ASPATH_TOTSIZE,
11568 BGP_STATS_ASN_HIGHEST,
11569 BGP_STATS_MAX,
11570 };
11571
11572 static const char *table_stats_strs[] =
11573 {
11574 [BGP_STATS_PREFIXES] = "Total Prefixes",
11575 [BGP_STATS_TOTPLEN] = "Average prefix length",
11576 [BGP_STATS_RIB] = "Total Advertisements",
11577 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11578 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11579 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11580 [BGP_STATS_SPACE] = "Address space advertised",
11581 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11582 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11583 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11584 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11585 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11586 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11587 [BGP_STATS_MAX] = NULL,
11588 };
11589
11590 struct bgp_table_stats
11591 {
11592 struct bgp_table *table;
11593 unsigned long long counts[BGP_STATS_MAX];
11594 };
11595
11596 #if 0
11597 #define TALLY_SIGFIG 100000
11598 static unsigned long
11599 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11600 {
11601 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11602 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11603 unsigned long ret = newtot / count;
11604
11605 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11606 return ret + 1;
11607 else
11608 return ret;
11609 }
11610 #endif
11611
11612 static int
11613 bgp_table_stats_walker (struct thread *t)
11614 {
11615 struct bgp_node *rn;
11616 struct bgp_node *top;
11617 struct bgp_table_stats *ts = THREAD_ARG (t);
11618 unsigned int space = 0;
11619
11620 if (!(top = bgp_table_top (ts->table)))
11621 return 0;
11622
11623 switch (top->p.family)
11624 {
11625 case AF_INET:
11626 space = IPV4_MAX_BITLEN;
11627 break;
11628 case AF_INET6:
11629 space = IPV6_MAX_BITLEN;
11630 break;
11631 }
11632
11633 ts->counts[BGP_STATS_MAXBITLEN] = space;
11634
11635 for (rn = top; rn; rn = bgp_route_next (rn))
11636 {
11637 struct bgp_info *ri;
11638 struct bgp_node *prn = bgp_node_parent_nolock (rn);
11639 unsigned int rinum = 0;
11640
11641 if (rn == top)
11642 continue;
11643
11644 if (!rn->info)
11645 continue;
11646
11647 ts->counts[BGP_STATS_PREFIXES]++;
11648 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11649
11650 #if 0
11651 ts->counts[BGP_STATS_AVGPLEN]
11652 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11653 ts->counts[BGP_STATS_AVGPLEN],
11654 rn->p.prefixlen);
11655 #endif
11656
11657 /* check if the prefix is included by any other announcements */
11658 while (prn && !prn->info)
11659 prn = bgp_node_parent_nolock (prn);
11660
11661 if (prn == NULL || prn == top)
11662 {
11663 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11664 /* announced address space */
11665 if (space)
11666 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11667 }
11668 else if (prn->info)
11669 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11670
11671 for (ri = rn->info; ri; ri = ri->next)
11672 {
11673 rinum++;
11674 ts->counts[BGP_STATS_RIB]++;
11675
11676 if (ri->attr &&
11677 (CHECK_FLAG (ri->attr->flag,
11678 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11679 ts->counts[BGP_STATS_AGGREGATES]++;
11680
11681 /* as-path stats */
11682 if (ri->attr && ri->attr->aspath)
11683 {
11684 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11685 unsigned int size = aspath_size (ri->attr->aspath);
11686 as_t highest = aspath_highest (ri->attr->aspath);
11687
11688 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11689
11690 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11691 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11692
11693 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11694 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11695
11696 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11697 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11698 #if 0
11699 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11700 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11701 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11702 hops);
11703 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11704 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11705 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11706 size);
11707 #endif
11708 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11709 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11710 }
11711 }
11712 }
11713 return 0;
11714 }
11715
11716 static int
11717 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11718 {
11719 struct bgp_table_stats ts;
11720 unsigned int i;
11721
11722 if (!bgp->rib[afi][safi])
11723 {
11724 vty_out (vty, "%% No RIB exists for the AFI(%d)/SAFI(%d)%s",
11725 afi, safi, VTY_NEWLINE);
11726 return CMD_WARNING;
11727 }
11728
11729 memset (&ts, 0, sizeof (ts));
11730 ts.table = bgp->rib[afi][safi];
11731 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11732
11733 vty_out (vty, "BGP %s RIB statistics%s%s",
11734 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11735
11736 for (i = 0; i < BGP_STATS_MAX; i++)
11737 {
11738 if (!table_stats_strs[i])
11739 continue;
11740
11741 switch (i)
11742 {
11743 #if 0
11744 case BGP_STATS_ASPATH_AVGHOPS:
11745 case BGP_STATS_ASPATH_AVGSIZE:
11746 case BGP_STATS_AVGPLEN:
11747 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11748 vty_out (vty, "%12.2f",
11749 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11750 break;
11751 #endif
11752 case BGP_STATS_ASPATH_TOTHOPS:
11753 case BGP_STATS_ASPATH_TOTSIZE:
11754 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11755 vty_out (vty, "%12.2f",
11756 ts.counts[i] ?
11757 (float)ts.counts[i] /
11758 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11759 : 0);
11760 break;
11761 case BGP_STATS_TOTPLEN:
11762 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11763 vty_out (vty, "%12.2f",
11764 ts.counts[i] ?
11765 (float)ts.counts[i] /
11766 (float)ts.counts[BGP_STATS_PREFIXES]
11767 : 0);
11768 break;
11769 case BGP_STATS_SPACE:
11770 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11771 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11772 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11773 break;
11774 vty_out (vty, "%30s: ", "%% announced ");
11775 vty_out (vty, "%12.2f%s",
11776 100 * (float)ts.counts[BGP_STATS_SPACE] /
11777 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
11778 VTY_NEWLINE);
11779 vty_out (vty, "%30s: ", "/8 equivalent ");
11780 vty_out (vty, "%12.2f%s",
11781 (float)ts.counts[BGP_STATS_SPACE] /
11782 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11783 VTY_NEWLINE);
11784 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11785 break;
11786 vty_out (vty, "%30s: ", "/24 equivalent ");
11787 vty_out (vty, "%12.2f",
11788 (float)ts.counts[BGP_STATS_SPACE] /
11789 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11790 break;
11791 default:
11792 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11793 vty_out (vty, "%12llu", ts.counts[i]);
11794 }
11795
11796 vty_out (vty, "%s", VTY_NEWLINE);
11797 }
11798 return CMD_SUCCESS;
11799 }
11800
11801 static int
11802 bgp_table_stats_vty (struct vty *vty, const char *name,
11803 const char *afi_str, const char *safi_str)
11804 {
11805 struct bgp *bgp;
11806 afi_t afi;
11807 safi_t safi;
11808
11809 if (name)
11810 bgp = bgp_lookup_by_name (name);
11811 else
11812 bgp = bgp_get_default ();
11813
11814 if (!bgp)
11815 {
11816 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11817 return CMD_WARNING;
11818 }
11819 afi = bgp_vty_afi_from_arg(afi_str);
11820 if (afi == AFI_MAX)
11821 {
11822 vty_out (vty, "%% Invalid address family \"%s\"%s",
11823 afi_str, VTY_NEWLINE);
11824 return CMD_WARNING;
11825 }
11826 safi = bgp_vty_safi_from_arg(safi_str);
11827 if (safi == SAFI_MAX)
11828 {
11829 vty_out (vty, "%% Invalid subsequent address family %s%s",
11830 safi_str, VTY_NEWLINE);
11831 return CMD_WARNING;
11832 }
11833
11834 return bgp_table_stats (vty, bgp, afi, safi);
11835 }
11836
11837 DEFUN (show_bgp_statistics,
11838 show_bgp_statistics_cmd,
11839 "show bgp "BGP_AFI_SAFI_CMD_STR" statistics",
11840 SHOW_STR
11841 BGP_STR
11842 BGP_INSTANCE_HELP_STR
11843 "BGP RIB advertisement statistics\n")
11844 {
11845 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11846 }
11847
11848 DEFUN (show_bgp_statistics_view,
11849 show_bgp_statistics_view_cmd,
11850 "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" statistics",
11851 SHOW_STR
11852 BGP_STR
11853 BGP_INSTANCE_HELP_STR
11854 BGP_AFI_SAFI_HELP_STR
11855 "BGP RIB advertisement statistics\n")
11856 {
11857 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
11858 }
11859
11860 enum bgp_pcounts
11861 {
11862 PCOUNT_ADJ_IN = 0,
11863 PCOUNT_DAMPED,
11864 PCOUNT_REMOVED,
11865 PCOUNT_HISTORY,
11866 PCOUNT_STALE,
11867 PCOUNT_VALID,
11868 PCOUNT_ALL,
11869 PCOUNT_COUNTED,
11870 PCOUNT_PFCNT, /* the figure we display to users */
11871 PCOUNT_MAX,
11872 };
11873
11874 static const char *pcount_strs[] =
11875 {
11876 [PCOUNT_ADJ_IN] = "Adj-in",
11877 [PCOUNT_DAMPED] = "Damped",
11878 [PCOUNT_REMOVED] = "Removed",
11879 [PCOUNT_HISTORY] = "History",
11880 [PCOUNT_STALE] = "Stale",
11881 [PCOUNT_VALID] = "Valid",
11882 [PCOUNT_ALL] = "All RIB",
11883 [PCOUNT_COUNTED] = "PfxCt counted",
11884 [PCOUNT_PFCNT] = "Useable",
11885 [PCOUNT_MAX] = NULL,
11886 };
11887
11888 struct peer_pcounts
11889 {
11890 unsigned int count[PCOUNT_MAX];
11891 const struct peer *peer;
11892 const struct bgp_table *table;
11893 };
11894
11895 static int
11896 bgp_peer_count_walker (struct thread *t)
11897 {
11898 struct bgp_node *rn;
11899 struct peer_pcounts *pc = THREAD_ARG (t);
11900 const struct peer *peer = pc->peer;
11901
11902 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
11903 {
11904 struct bgp_adj_in *ain;
11905 struct bgp_info *ri;
11906
11907 for (ain = rn->adj_in; ain; ain = ain->next)
11908 if (ain->peer == peer)
11909 pc->count[PCOUNT_ADJ_IN]++;
11910
11911 for (ri = rn->info; ri; ri = ri->next)
11912 {
11913 char buf[SU_ADDRSTRLEN];
11914
11915 if (ri->peer != peer)
11916 continue;
11917
11918 pc->count[PCOUNT_ALL]++;
11919
11920 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
11921 pc->count[PCOUNT_DAMPED]++;
11922 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
11923 pc->count[PCOUNT_HISTORY]++;
11924 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
11925 pc->count[PCOUNT_REMOVED]++;
11926 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
11927 pc->count[PCOUNT_STALE]++;
11928 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
11929 pc->count[PCOUNT_VALID]++;
11930 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11931 pc->count[PCOUNT_PFCNT]++;
11932
11933 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11934 {
11935 pc->count[PCOUNT_COUNTED]++;
11936 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11937 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
11938 peer->host,
11939 inet_ntop(rn->p.family, &rn->p.u.prefix,
11940 buf, SU_ADDRSTRLEN),
11941 rn->p.prefixlen,
11942 ri->flags);
11943 }
11944 else
11945 {
11946 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11947 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
11948 peer->host,
11949 inet_ntop(rn->p.family, &rn->p.u.prefix,
11950 buf, SU_ADDRSTRLEN),
11951 rn->p.prefixlen,
11952 ri->flags);
11953 }
11954 }
11955 }
11956 return 0;
11957 }
11958
11959 static int
11960 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
11961 {
11962 struct peer_pcounts pcounts = { .peer = peer };
11963 unsigned int i;
11964 json_object *json = NULL;
11965 json_object *json_loop = NULL;
11966
11967 if (use_json)
11968 {
11969 json = json_object_new_object();
11970 json_loop = json_object_new_object();
11971 }
11972
11973 if (!peer || !peer->bgp || !peer->afc[afi][safi]
11974 || !peer->bgp->rib[afi][safi])
11975 {
11976 if (use_json)
11977 {
11978 json_object_string_add(json, "warning", "No such neighbor or address family");
11979 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
11980 json_object_free(json);
11981 }
11982 else
11983 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
11984
11985 return CMD_WARNING;
11986 }
11987
11988 memset (&pcounts, 0, sizeof(pcounts));
11989 pcounts.peer = peer;
11990 pcounts.table = peer->bgp->rib[afi][safi];
11991
11992 /* in-place call via thread subsystem so as to record execution time
11993 * * stats for the thread-walk (i.e. ensure this can't be blamed on
11994 * * on just vty_read()).
11995 * */
11996 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
11997
11998 if (use_json)
11999 {
12000 json_object_string_add(json, "prefixCountsFor", peer->host);
12001 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
12002 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
12003
12004 for (i = 0; i < PCOUNT_MAX; i++)
12005 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
12006
12007 json_object_object_add(json, "ribTableWalkCounters", json_loop);
12008
12009 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12010 {
12011 json_object_string_add(json, "pfxctDriftFor", peer->host);
12012 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
12013 }
12014 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12015 json_object_free(json);
12016 }
12017 else
12018 {
12019
12020 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
12021 {
12022 vty_out (vty, "Prefix counts for %s/%s, %s%s",
12023 peer->hostname, peer->host, afi_safi_print (afi, safi),
12024 VTY_NEWLINE);
12025 }
12026 else
12027 {
12028 vty_out (vty, "Prefix counts for %s, %s%s",
12029 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12030 }
12031
12032 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12033 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12034 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12035
12036 for (i = 0; i < PCOUNT_MAX; i++)
12037 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
12038
12039 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12040 {
12041 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12042 peer->host, VTY_NEWLINE);
12043 vty_out (vty, "Please report this bug, with the above command output%s",
12044 VTY_NEWLINE);
12045 }
12046 }
12047
12048 return CMD_SUCCESS;
12049 }
12050
12051 DEFUN (show_ip_bgp_neighbor_prefix_counts,
12052 show_ip_bgp_neighbor_prefix_counts_cmd,
12053 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12054 SHOW_STR
12055 IP_STR
12056 BGP_STR
12057 "Detailed information on TCP and BGP neighbor connections\n"
12058 "Neighbor to display information about\n"
12059 "Neighbor to display information about\n"
12060 "Neighbor on bgp configured interface\n"
12061 "Display detailed prefix count information\n"
12062 "JavaScript Object Notation\n")
12063 {
12064 struct peer *peer;
12065 u_char uj = use_json(argc, argv);
12066
12067 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12068 if (! peer)
12069 return CMD_WARNING;
12070
12071 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12072 }
12073
12074 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
12075 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
12076 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12077 SHOW_STR
12078 IP_STR
12079 BGP_STR
12080 BGP_INSTANCE_HELP_STR
12081 "Detailed information on TCP and BGP neighbor connections\n"
12082 "Neighbor to display information about\n"
12083 "Neighbor to display information about\n"
12084 "Neighbor on bgp configured interface\n"
12085 "Display detailed prefix count information\n"
12086 "JavaScript Object Notation\n")
12087 {
12088 struct peer *peer;
12089 u_char uj = use_json(argc, argv);
12090
12091 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12092 if (! peer)
12093 return CMD_WARNING;
12094
12095 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12096 }
12097
12098 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12099 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12100 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12101 SHOW_STR
12102 BGP_STR
12103 "Address family\n"
12104 "Detailed information on TCP and BGP neighbor connections\n"
12105 "Neighbor to display information about\n"
12106 "Neighbor to display information about\n"
12107 "Neighbor on bgp configured interface\n"
12108 "Display detailed prefix count information\n"
12109 "JavaScript Object Notation\n")
12110 {
12111 struct peer *peer;
12112 u_char uj = use_json(argc, argv);
12113
12114 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12115 if (! peer)
12116 return CMD_WARNING;
12117
12118 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12119 }
12120
12121 DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
12122 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
12123 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12124 SHOW_STR
12125 BGP_STR
12126 BGP_INSTANCE_HELP_STR
12127 "Address family\n"
12128 "Detailed information on TCP and BGP neighbor connections\n"
12129 "Neighbor to display information about\n"
12130 "Neighbor to display information about\n"
12131 "Neighbor on bgp configured interface\n"
12132 "Display detailed prefix count information\n"
12133 "JavaScript Object Notation\n")
12134 {
12135 struct peer *peer;
12136 u_char uj = use_json(argc, argv);
12137
12138 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12139 if (! peer)
12140 return CMD_WARNING;
12141
12142 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12143 }
12144
12145 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12146 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12147 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12148 SHOW_STR
12149 IP_STR
12150 BGP_STR
12151 "Address family\n"
12152 BGP_SAFI_HELP_STR
12153 "Detailed information on TCP and BGP neighbor connections\n"
12154 "Neighbor to display information about\n"
12155 "Neighbor to display information about\n"
12156 "Neighbor on bgp configured interface\n"
12157 "Display detailed prefix count information\n"
12158 "JavaScript Object Notation\n")
12159 {
12160 struct peer *peer;
12161 u_char uj = use_json(argc, argv);
12162
12163 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12164 if (! peer)
12165 return CMD_WARNING;
12166
12167 safi_t safi;
12168 safi = bgp_vty_safi_from_arg(argv[0]);
12169 return bgp_peer_counts (vty, peer, AFI_IP, safi, uj);
12170 }
12171
12172 static void
12173 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12174 int in, const char *rmap_name, u_char use_json, json_object *json)
12175 {
12176 struct bgp_table *table;
12177 struct bgp_adj_in *ain;
12178 struct bgp_adj_out *adj;
12179 unsigned long output_count;
12180 unsigned long filtered_count;
12181 struct bgp_node *rn;
12182 int header1 = 1;
12183 struct bgp *bgp;
12184 int header2 = 1;
12185 struct attr attr;
12186 struct attr_extra extra;
12187 int ret;
12188 struct update_subgroup *subgrp;
12189 json_object *json_scode = NULL;
12190 json_object *json_ocode = NULL;
12191 json_object *json_ar = NULL;
12192 struct peer_af *paf;
12193
12194 if (use_json)
12195 {
12196 json_scode = json_object_new_object();
12197 json_ocode = json_object_new_object();
12198 json_ar = json_object_new_object();
12199
12200 json_object_string_add(json_scode, "suppressed", "s");
12201 json_object_string_add(json_scode, "damped", "d");
12202 json_object_string_add(json_scode, "history", "h");
12203 json_object_string_add(json_scode, "valid", "*");
12204 json_object_string_add(json_scode, "best", ">");
12205 json_object_string_add(json_scode, "multipath", "=");
12206 json_object_string_add(json_scode, "internal", "i");
12207 json_object_string_add(json_scode, "ribFailure", "r");
12208 json_object_string_add(json_scode, "stale", "S");
12209 json_object_string_add(json_scode, "removed", "R");
12210
12211 json_object_string_add(json_ocode, "igp", "i");
12212 json_object_string_add(json_ocode, "egp", "e");
12213 json_object_string_add(json_ocode, "incomplete", "?");
12214 }
12215
12216 bgp = peer->bgp;
12217
12218 if (! bgp)
12219 {
12220 if (use_json)
12221 {
12222 json_object_string_add(json, "alert", "no BGP");
12223 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12224 json_object_free(json);
12225 }
12226 else
12227 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
12228 return;
12229 }
12230
12231 table = bgp->rib[afi][safi];
12232
12233 output_count = filtered_count = 0;
12234 subgrp = peer_subgroup(peer, afi, safi);
12235
12236 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
12237 {
12238 if (use_json)
12239 {
12240 json_object_int_add(json, "bgpTableVersion", table->version);
12241 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12242 json_object_object_add(json, "bgpStatusCodes", json_scode);
12243 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12244 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
12245 }
12246 else
12247 {
12248 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
12249 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12250 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12251
12252 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12253 VTY_NEWLINE, VTY_NEWLINE);
12254 }
12255 header1 = 0;
12256 }
12257
12258 attr.extra = &extra;
12259 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12260 {
12261 if (in)
12262 {
12263 for (ain = rn->adj_in; ain; ain = ain->next)
12264 {
12265 if (ain->peer == peer)
12266 {
12267 if (header1)
12268 {
12269 if (use_json)
12270 {
12271 json_object_int_add(json, "bgpTableVersion", 0);
12272 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12273 json_object_object_add(json, "bgpStatusCodes", json_scode);
12274 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12275 }
12276 else
12277 {
12278 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12279 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12280 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12281 }
12282 header1 = 0;
12283 }
12284 if (header2)
12285 {
12286 if (!use_json)
12287 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12288 header2 = 0;
12289 }
12290 if (ain->attr)
12291 {
12292 bgp_attr_dup(&attr, ain->attr);
12293 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12294 {
12295 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12296 output_count++;
12297 }
12298 else
12299 filtered_count++;
12300 }
12301 }
12302 }
12303 }
12304 else
12305 {
12306 for (adj = rn->adj_out; adj; adj = adj->next)
12307 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12308 if (paf->peer == peer)
12309 {
12310 if (header1)
12311 {
12312 if (use_json)
12313 {
12314 json_object_int_add(json, "bgpTableVersion", table->version);
12315 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12316 json_object_object_add(json, "bgpStatusCodes", json_scode);
12317 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12318 }
12319 else
12320 {
12321 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12322 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12323 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12324 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12325 }
12326 header1 = 0;
12327 }
12328
12329 if (header2)
12330 {
12331 if (!use_json)
12332 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12333 header2 = 0;
12334 }
12335
12336 if (adj->attr)
12337 {
12338 bgp_attr_dup(&attr, adj->attr);
12339 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12340 if (ret != RMAP_DENY)
12341 {
12342 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12343 output_count++;
12344 }
12345 else
12346 filtered_count++;
12347 }
12348 }
12349 }
12350 }
12351 if (use_json)
12352 json_object_object_add(json, "advertisedRoutes", json_ar);
12353
12354 if (output_count != 0)
12355 {
12356 if (use_json)
12357 json_object_int_add(json, "totalPrefixCounter", output_count);
12358 else
12359 vty_out (vty, "%sTotal number of prefixes %ld%s",
12360 VTY_NEWLINE, output_count, VTY_NEWLINE);
12361 }
12362 if (use_json)
12363 {
12364 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12365 json_object_free(json);
12366 }
12367
12368 }
12369
12370 static int
12371 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12372 int in, const char *rmap_name, u_char use_json)
12373 {
12374 json_object *json = NULL;
12375
12376 if (use_json)
12377 json = json_object_new_object();
12378
12379 if (!peer || !peer->afc[afi][safi])
12380 {
12381 if (use_json)
12382 {
12383 json_object_string_add(json, "warning", "No such neighbor or address family");
12384 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12385 json_object_free(json);
12386 }
12387 else
12388 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12389
12390 return CMD_WARNING;
12391 }
12392
12393 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12394 {
12395 if (use_json)
12396 {
12397 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12398 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12399 json_object_free(json);
12400 }
12401 else
12402 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12403
12404 return CMD_WARNING;
12405 }
12406
12407 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
12408
12409 return CMD_SUCCESS;
12410 }
12411
12412 DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12413 show_ip_bgp_instance_neighbor_advertised_route_cmd,
12414 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12415 SHOW_STR
12416 IP_STR
12417 BGP_STR
12418 BGP_INSTANCE_HELP_STR
12419 "Detailed information on TCP and BGP neighbor connections\n"
12420 "Neighbor to display information about\n"
12421 "Neighbor to display information about\n"
12422 "Display the routes advertised to a BGP neighbor\n"
12423 "JavaScript Object Notation\n")
12424 {
12425 struct peer *peer;
12426 u_char uj = use_json(argc, argv);
12427
12428 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12429 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12430 else
12431 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12432
12433 if (! peer)
12434 return CMD_WARNING;
12435
12436 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
12437 }
12438
12439 DEFUN (show_ip_bgp_neighbor_advertised_route,
12440 show_ip_bgp_neighbor_advertised_route_cmd,
12441 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12442 SHOW_STR
12443 IP_STR
12444 BGP_STR
12445 "Detailed information on TCP and BGP neighbor connections\n"
12446 "Neighbor to display information about\n"
12447 "Neighbor to display information about\n"
12448 "Neighbor on bgp configured interface\n"
12449 "Display the routes advertised to a BGP neighbor\n"
12450 "JavaScript Object Notation\n")
12451
12452 {
12453 struct peer *peer;
12454 const char *rmap_name = NULL;
12455 u_char uj = use_json(argc, argv);
12456
12457 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12458
12459 if (! peer)
12460 return CMD_WARNING;
12461
12462 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12463 || (argc == 3))
12464 rmap_name = argv[1];
12465
12466 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12467 }
12468
12469 ALIAS (show_ip_bgp_neighbor_advertised_route,
12470 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
12471 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12472 SHOW_STR
12473 IP_STR
12474 BGP_STR
12475 "Detailed information on TCP and BGP neighbor connections\n"
12476 "Neighbor to display information about\n"
12477 "Neighbor to display information about\n"
12478 "Neighbor on bgp configured interface\n"
12479 "Display the routes advertised to a BGP neighbor\n"
12480 "JavaScript Object Notation\n")
12481
12482 ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12483 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12484 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12485 SHOW_STR
12486 IP_STR
12487 BGP_STR
12488 BGP_INSTANCE_HELP_STR
12489 "Detailed information on TCP and BGP neighbor connections\n"
12490 "Neighbor to display information about\n"
12491 "Neighbor to display information about\n"
12492 "Neighbor on bgp configured interface\n"
12493 "Display the routes advertised to a BGP neighbor\n"
12494 "JavaScript Object Notation\n")
12495 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12496 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12497 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12498 SHOW_STR
12499 IP_STR
12500 BGP_STR
12501 "Address family\n"
12502 BGP_SAFI_HELP_STR
12503 "Detailed information on TCP and BGP neighbor connections\n"
12504 "Neighbor to display information about\n"
12505 "Neighbor to display information about\n"
12506 "Neighbor on bgp configured interface\n"
12507 "Display the routes advertised to a BGP neighbor\n"
12508 "JavaScript Object Notation\n")
12509 {
12510 struct peer *peer;
12511 const char *rmap_name = NULL;
12512 safi_t safi;
12513
12514 u_char uj = use_json(argc, argv);
12515
12516 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12517 if (! peer)
12518 return CMD_WARNING;
12519
12520 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12521 rmap_name = argv[2];
12522
12523 safi = bgp_vty_safi_from_arg(argv[0]);
12524 return peer_adj_routes (vty, peer, AFI_IP, safi, 0, rmap_name, uj);
12525 }
12526
12527 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12528 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
12529 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12530 SHOW_STR
12531 IP_STR
12532 BGP_STR
12533 "Address family\n"
12534 BGP_SAFI_HELP_STR
12535 "Detailed information on TCP and BGP neighbor connections\n"
12536 "Neighbor to display information about\n"
12537 "Neighbor to display information about\n"
12538 "Neighbor on bgp configured interface\n"
12539 "Display the routes advertised to a BGP neighbor\n"
12540 "Route-map to control what is displayed\n"
12541 "JavaScript Object Notation\n")
12542
12543 #ifdef HAVE_IPV6
12544 DEFUN (show_bgp_instance_neighbor_advertised_route,
12545 show_bgp_instance_neighbor_advertised_route_cmd,
12546 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12547 SHOW_STR
12548 BGP_STR
12549 BGP_INSTANCE_HELP_STR
12550 "Detailed information on TCP and BGP neighbor connections\n"
12551 "Neighbor to display information about\n"
12552 "Neighbor to display information about\n"
12553 "Neighbor on bgp configured interface\n"
12554 "Display the routes advertised to a BGP neighbor\n"
12555 "JavaScript Object Notation\n")
12556 {
12557 struct peer *peer;
12558 u_char uj = use_json(argc, argv);
12559
12560 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12561 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12562 else
12563 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12564
12565 if (! peer)
12566 return CMD_WARNING;
12567
12568 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
12569 }
12570
12571 ALIAS (show_bgp_instance_neighbor_advertised_route,
12572 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12573 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12574 SHOW_STR
12575 BGP_STR
12576 BGP_INSTANCE_HELP_STR
12577 "Address family\n"
12578 "Detailed information on TCP and BGP neighbor connections\n"
12579 "Neighbor to display information about\n"
12580 "Neighbor to display information about\n"
12581 "Neighbor on bgp configured interface\n"
12582 "Display the routes advertised to a BGP neighbor\n"
12583 "JavaScript Object Notation\n")
12584
12585 DEFUN (show_bgp_neighbor_advertised_route,
12586 show_bgp_neighbor_advertised_route_cmd,
12587 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12588 SHOW_STR
12589 BGP_STR
12590 "Detailed information on TCP and BGP neighbor connections\n"
12591 "Neighbor to display information about\n"
12592 "Neighbor to display information about\n"
12593 "Neighbor on bgp configured interface\n"
12594 "Display the routes advertised to a BGP neighbor\n"
12595 "JavaScript Object Notation\n")
12596
12597 {
12598 struct peer *peer;
12599 const char *rmap_name = NULL;
12600 u_char uj = use_json(argc, argv);
12601
12602 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12603
12604 if (!peer)
12605 return CMD_WARNING;
12606
12607 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12608 rmap_name = argv[1];
12609
12610 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
12611 }
12612
12613 ALIAS (show_bgp_neighbor_advertised_route,
12614 show_bgp_ipv6_neighbor_advertised_route_cmd,
12615 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12616 SHOW_STR
12617 BGP_STR
12618 "Address family\n"
12619 "Detailed information on TCP and BGP neighbor connections\n"
12620 "Neighbor to display information about\n"
12621 "Neighbor to display information about\n"
12622 "Neighbor on bgp configured interface\n"
12623 "Display the routes advertised to a BGP neighbor\n"
12624 "JavaScript Object Notation\n")
12625
12626 /* old command */
12627 ALIAS (show_bgp_neighbor_advertised_route,
12628 ipv6_bgp_neighbor_advertised_route_cmd,
12629 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12630 SHOW_STR
12631 IPV6_STR
12632 BGP_STR
12633 "Detailed information on TCP and BGP neighbor connections\n"
12634 "Neighbor to display information about\n"
12635 "Neighbor to display information about\n"
12636 "Neighbor on bgp configured interface\n"
12637 "Display the routes advertised to a BGP neighbor\n"
12638 "JavaScript Object Notation\n")
12639
12640 /* old command */
12641 DEFUN (ipv6_mbgp_neighbor_advertised_route,
12642 ipv6_mbgp_neighbor_advertised_route_cmd,
12643 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12644 SHOW_STR
12645 IPV6_STR
12646 MBGP_STR
12647 "Detailed information on TCP and BGP neighbor connections\n"
12648 "Neighbor to display information about\n"
12649 "Neighbor to display information about\n"
12650 "Neighbor on bgp configured interface\n"
12651 "Neighbor on bgp configured interface\n"
12652 "Display the routes advertised to a BGP neighbor\n"
12653 "JavaScript Object Notation\n")
12654 {
12655 struct peer *peer;
12656 u_char uj = use_json(argc, argv);
12657
12658 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12659 if (! peer)
12660 return CMD_WARNING;
12661
12662 bgp_show_ipv6_bgp_deprecate_warning(vty);
12663 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
12664 }
12665 #endif /* HAVE_IPV6 */
12666
12667 DEFUN (show_bgp_instance_neighbor_received_routes,
12668 show_bgp_instance_neighbor_received_routes_cmd,
12669 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12670 SHOW_STR
12671 BGP_STR
12672 BGP_INSTANCE_HELP_STR
12673 "Detailed information on TCP and BGP neighbor connections\n"
12674 "Neighbor to display information about\n"
12675 "Neighbor to display information about\n"
12676 "Neighbor on bgp configured interface\n"
12677 "Display the received routes from neighbor\n"
12678 "JavaScript Object Notation\n")
12679 {
12680 struct peer *peer;
12681 u_char uj = use_json(argc, argv);
12682
12683 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12684 if (! peer)
12685 return CMD_WARNING;
12686
12687 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
12688 }
12689
12690 DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12691 show_ip_bgp_instance_neighbor_received_routes_cmd,
12692 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12693 SHOW_STR
12694 IP_STR
12695 BGP_STR
12696 BGP_INSTANCE_HELP_STR
12697 "Detailed information on TCP and BGP neighbor connections\n"
12698 "Neighbor to display information about\n"
12699 "Neighbor to display information about\n"
12700 "Neighbor on bgp configured interface\n"
12701 "Display the received routes from neighbor\n"
12702 "JavaScript Object Notation\n")
12703 {
12704 struct peer *peer;
12705 u_char uj = use_json(argc, argv);
12706
12707 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12708 if (! peer)
12709 return CMD_WARNING;
12710
12711 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
12712 }
12713
12714 ALIAS (show_bgp_instance_neighbor_received_routes,
12715 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12716 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12717 SHOW_STR
12718 BGP_STR
12719 BGP_INSTANCE_HELP_STR
12720 "Address family\n"
12721 "Detailed information on TCP and BGP neighbor connections\n"
12722 "Neighbor to display information about\n"
12723 "Neighbor to display information about\n"
12724 "Neighbor on bgp configured interface\n"
12725 "Display the received routes from neighbor\n"
12726 "JavaScript Object Notation\n")
12727
12728 DEFUN (show_ip_bgp_neighbor_received_routes,
12729 show_ip_bgp_neighbor_received_routes_cmd,
12730 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12731 SHOW_STR
12732 IP_STR
12733 BGP_STR
12734 "Detailed information on TCP and BGP neighbor connections\n"
12735 "Neighbor to display information about\n"
12736 "Neighbor to display information about\n"
12737 "Neighbor on bgp configured interface\n"
12738 "Display the received routes from neighbor\n"
12739 "JavaScript Object Notation\n")
12740
12741 {
12742 struct peer *peer;
12743 const char *rmap_name = NULL;
12744 u_char uj = use_json(argc, argv);
12745
12746 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12747
12748 if (! peer)
12749 return CMD_WARNING;
12750
12751 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12752 rmap_name = argv[1];
12753
12754 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12755 }
12756
12757 ALIAS (show_ip_bgp_neighbor_received_routes,
12758 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12759 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12760 SHOW_STR
12761 IP_STR
12762 BGP_STR
12763 "Detailed information on TCP and BGP neighbor connections\n"
12764 "Neighbor to display information about\n"
12765 "Neighbor to display information about\n"
12766 "Neighbor on bgp configured interface\n"
12767 "Display the received routes from neighbor\n"
12768 "JavaScript Object Notation\n")
12769
12770 ALIAS (show_ip_bgp_instance_neighbor_received_routes,
12771 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
12772 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12773 SHOW_STR
12774 IP_STR
12775 BGP_STR
12776 BGP_INSTANCE_HELP_STR
12777 "Detailed information on TCP and BGP neighbor connections\n"
12778 "Neighbor to display information about\n"
12779 "Neighbor to display information about\n"
12780 "Neighbor on bgp configured interface\n"
12781 "Display the received routes from neighbor\n"
12782 "JavaScript Object Notation\n")
12783
12784 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12785 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12786 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12787 SHOW_STR
12788 IP_STR
12789 BGP_STR
12790 "Address family\n"
12791 BGP_SAFI_HELP_STR
12792 "Detailed information on TCP and BGP neighbor connections\n"
12793 "Neighbor to display information about\n"
12794 "Neighbor to display information about\n"
12795 "Neighbor on bgp configured interface\n"
12796 "Display the received routes from neighbor\n"
12797 "JavaScript Object Notation\n")
12798 {
12799 struct peer *peer;
12800 const char *rmap_name = NULL;
12801 safi_t safi;
12802 u_char uj = use_json(argc, argv);
12803
12804 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12805 if (! peer)
12806 return CMD_WARNING;
12807
12808 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12809 rmap_name = argv[2];
12810
12811 safi = bgp_vty_safi_from_arg(argv[0]);
12812 return peer_adj_routes (vty, peer, AFI_IP, safi, 1, rmap_name, uj);
12813 }
12814
12815 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12816 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
12817 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12818 SHOW_STR
12819 IP_STR
12820 BGP_STR
12821 "Address family\n"
12822 BGP_SAFI_HELP_STR
12823 "Detailed information on TCP and BGP neighbor connections\n"
12824 "Neighbor to display information about\n"
12825 "Neighbor to display information about\n"
12826 "Neighbor on bgp configured interface\n"
12827 "Display the received routes from neighbor\n"
12828 "JavaScript Object Notation\n")
12829
12830 DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12831 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
12832 "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
12833 SHOW_STR
12834 BGP_STR
12835 BGP_INSTANCE_HELP_STR
12836 BGP_AFI_SAFI_HELP_STR
12837 "Detailed information on TCP and BGP neighbor connections\n"
12838 "Neighbor to display information about\n"
12839 "Neighbor to display information about\n"
12840 "Neighbor on bgp configured interface\n"
12841 "Display the advertised routes to neighbor\n"
12842 "Display the received routes from neighbor\n"
12843 "JavaScript Object Notation\n")
12844 {
12845 int afi;
12846 int safi;
12847 int in;
12848 struct peer *peer;
12849 u_char uj = use_json(argc, argv);
12850
12851 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
12852
12853 if (! peer)
12854 return CMD_WARNING;
12855
12856 afi = bgp_vty_safi_from_arg(argv[2]);
12857 safi = bgp_vty_safi_from_arg(argv[3]);
12858 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
12859
12860 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
12861 }
12862
12863 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12864 show_ip_bgp_neighbor_received_prefix_filter_cmd,
12865 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12866 SHOW_STR
12867 IP_STR
12868 BGP_STR
12869 "Detailed information on TCP and BGP neighbor connections\n"
12870 "Neighbor to display information about\n"
12871 "Neighbor to display information about\n"
12872 "Neighbor on bgp configured interface\n"
12873 "Display information received from a BGP neighbor\n"
12874 "Display the prefixlist filter\n"
12875 "JavaScript Object Notation\n")
12876 {
12877 char name[BUFSIZ];
12878 union sockunion su;
12879 struct peer *peer;
12880 int count, ret;
12881 u_char uj = use_json(argc, argv);
12882
12883 ret = str2sockunion (argv[0], &su);
12884 if (ret < 0)
12885 {
12886 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12887 if (! peer)
12888 {
12889 if (uj)
12890 {
12891 json_object *json_no = NULL;
12892 json_object *json_sub = NULL;
12893 json_no = json_object_new_object();
12894 json_sub = json_object_new_object();
12895 json_object_string_add(json_no, "warning", "Malformed address or name");
12896 json_object_string_add(json_sub, "warningCause", argv[0]);
12897 json_object_object_add(json_no, "detail", json_sub);
12898 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12899 json_object_free(json_no);
12900 }
12901 else
12902 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12903 return CMD_WARNING;
12904 }
12905 }
12906 else
12907 {
12908 peer = peer_lookup (NULL, &su);
12909 if (! peer)
12910 {
12911 if (uj)
12912 {
12913 json_object *json_no = NULL;
12914 json_no = json_object_new_object();
12915 json_object_string_add(json_no, "warning", "Peer not found");
12916 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12917 json_object_free(json_no);
12918 }
12919 else
12920 vty_out (vty, "No peer%s", VTY_NEWLINE);
12921 return CMD_WARNING;
12922 }
12923 }
12924
12925 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12926 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
12927 if (count)
12928 {
12929 if (!uj)
12930 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12931 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
12932 }
12933 else
12934 {
12935 if (uj)
12936 {
12937 json_object *json_no = NULL;
12938 json_no = json_object_new_object();
12939 json_object_boolean_true_add(json_no, "noFuntionalOutput");
12940 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12941 json_object_free(json_no);
12942 }
12943 else
12944 vty_out (vty, "No functional output%s", VTY_NEWLINE);
12945 }
12946
12947 return CMD_SUCCESS;
12948 }
12949
12950 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
12951 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
12952 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12953 SHOW_STR
12954 IP_STR
12955 BGP_STR
12956 "Address family\n"
12957 BGP_SAFI_HELP_STR
12958 "Detailed information on TCP and BGP neighbor connections\n"
12959 "Neighbor to display information about\n"
12960 "Neighbor to display information about\n"
12961 "Neighbor on bgp configured interface\n"
12962 "Display information received from a BGP neighbor\n"
12963 "Display the prefixlist filter\n"
12964 "JavaScript Object Notation\n")
12965 {
12966 char name[BUFSIZ];
12967 union sockunion su;
12968 struct peer *peer;
12969 int count, ret;
12970 u_char uj = use_json(argc, argv);
12971
12972 ret = str2sockunion (argv[1], &su);
12973 if (ret < 0)
12974 {
12975 peer = peer_lookup_by_conf_if (NULL, argv[1]);
12976 if (! peer)
12977 {
12978 if (uj)
12979 {
12980 json_object *json_no = NULL;
12981 json_object *json_sub = NULL;
12982 json_no = json_object_new_object();
12983 json_sub = json_object_new_object();
12984 json_object_string_add(json_no, "warning", "Malformed address or name");
12985 json_object_string_add(json_sub, "warningCause", argv[1]);
12986 json_object_object_add(json_no, "detail", json_sub);
12987 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12988 json_object_free(json_no);
12989 }
12990 else
12991 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
12992 return CMD_WARNING;
12993 }
12994 }
12995 else
12996 {
12997 peer = peer_lookup (NULL, &su);
12998 if (! peer)
12999 {
13000 if (uj)
13001 {
13002 json_object *json_no = NULL;
13003 json_no = json_object_new_object();
13004 json_object_string_add(json_no, "warning", "Peer not found");
13005 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13006 json_object_free(json_no);
13007 }
13008 else
13009 vty_out (vty, "No peer%s", VTY_NEWLINE);
13010 return CMD_WARNING;
13011 }
13012 }
13013
13014 {
13015 safi_t safi;
13016 safi = bgp_vty_safi_from_arg(argv[0]);
13017 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13018 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13019 if (count)
13020 {
13021 if (!uj)
13022 vty_out (vty, "Address family: %s%s",
13023 afi_safi_print (AFI_IP, safi), VTY_NEWLINE);
13024 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13025 }
13026 else
13027 {
13028 if (uj)
13029 {
13030 json_object *json_no = NULL;
13031 json_no = json_object_new_object();
13032 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13033 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13034 json_object_free(json_no);
13035 }
13036 else
13037 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13038 }
13039 }
13040
13041 return CMD_SUCCESS;
13042 }
13043 #ifdef HAVE_IPV6
13044 DEFUN (show_bgp_neighbor_received_routes,
13045 show_bgp_neighbor_received_routes_cmd,
13046 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13047 SHOW_STR
13048 BGP_STR
13049 "Detailed information on TCP and BGP neighbor connections\n"
13050 "Neighbor to display information about\n"
13051 "Neighbor to display information about\n"
13052 "Neighbor on bgp configured interface\n"
13053 "Display the received routes from neighbor\n"
13054 "JavaScript Object Notation\n")
13055 {
13056 struct peer *peer;
13057 const char *rmap_name = NULL;
13058 u_char uj = use_json(argc, argv);
13059
13060 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13061
13062 if (! peer)
13063 return CMD_WARNING;
13064
13065 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
13066 rmap_name = argv[1];
13067
13068 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
13069 }
13070
13071 ALIAS (show_bgp_neighbor_received_routes,
13072 show_bgp_ipv6_neighbor_received_routes_cmd,
13073 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13074 SHOW_STR
13075 BGP_STR
13076 "Address family\n"
13077 "Detailed information on TCP and BGP neighbor connections\n"
13078 "Neighbor to display information about\n"
13079 "Neighbor to display information about\n"
13080 "Neighbor on bgp configured interface\n"
13081 "Display the received routes from neighbor\n"
13082 "JavaScript Object Notation\n")
13083
13084 DEFUN (show_bgp_neighbor_received_prefix_filter,
13085 show_bgp_neighbor_received_prefix_filter_cmd,
13086 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13087 SHOW_STR
13088 BGP_STR
13089 "Detailed information on TCP and BGP neighbor connections\n"
13090 "Neighbor to display information about\n"
13091 "Neighbor to display information about\n"
13092 "Neighbor on bgp configured interface\n"
13093 "Display information received from a BGP neighbor\n"
13094 "Display the prefixlist filter\n"
13095 "JavaScript Object Notation\n")
13096 {
13097 char name[BUFSIZ];
13098 union sockunion su;
13099 struct peer *peer;
13100 int count, ret;
13101 u_char uj = use_json(argc, argv);
13102
13103 ret = str2sockunion (argv[0], &su);
13104 if (ret < 0)
13105 {
13106 peer = peer_lookup_by_conf_if (NULL, argv[0]);
13107 if (! peer)
13108 {
13109 if (uj)
13110 {
13111 json_object *json_no = NULL;
13112 json_object *json_sub = NULL;
13113 json_no = json_object_new_object();
13114 json_sub = json_object_new_object();
13115 json_object_string_add(json_no, "warning", "Malformed address or name");
13116 json_object_string_add(json_sub, "warningCause", argv[0]);
13117 json_object_object_add(json_no, "detail", json_sub);
13118 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13119 json_object_free(json_no);
13120 }
13121 else
13122 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
13123 return CMD_WARNING;
13124 }
13125 }
13126 else
13127 {
13128 peer = peer_lookup (NULL, &su);
13129 if (! peer)
13130 {
13131 if (uj)
13132 {
13133 json_object *json_no = NULL;
13134 json_no = json_object_new_object();
13135 json_object_string_add(json_no, "warning", "No Peer");
13136 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13137 json_object_free(json_no);
13138 }
13139 else
13140 vty_out (vty, "No peer%s", VTY_NEWLINE);
13141 return CMD_WARNING;
13142 }
13143 }
13144
13145 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13146 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13147 if (count)
13148 {
13149 if (!uj)
13150 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13151 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13152 }
13153 else
13154 {
13155 if (uj)
13156 {
13157 json_object *json_no = NULL;
13158 json_no = json_object_new_object();
13159 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13160 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13161 json_object_free(json_no);
13162 }
13163 else
13164 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13165 }
13166
13167 return CMD_SUCCESS;
13168 }
13169
13170 ALIAS (show_bgp_neighbor_received_prefix_filter,
13171 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13172 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13173 SHOW_STR
13174 BGP_STR
13175 "Address family\n"
13176 "Detailed information on TCP and BGP neighbor connections\n"
13177 "Neighbor to display information about\n"
13178 "Neighbor to display information about\n"
13179 "Neighbor on bgp configured interface\n"
13180 "Display information received from a BGP neighbor\n"
13181 "Display the prefixlist filter\n"
13182 "JavaScript Object Notation\n")
13183
13184 /* old command */
13185 ALIAS (show_bgp_neighbor_received_routes,
13186 ipv6_bgp_neighbor_received_routes_cmd,
13187 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13188 SHOW_STR
13189 IPV6_STR
13190 BGP_STR
13191 "Detailed information on TCP and BGP neighbor connections\n"
13192 "Neighbor to display information about\n"
13193 "Neighbor to display information about\n"
13194 "Neighbor on bgp configured interface\n"
13195 "Display the received routes from neighbor\n"
13196 "JavaScript Object Notation\n")
13197
13198 /* old command */
13199 DEFUN (ipv6_mbgp_neighbor_received_routes,
13200 ipv6_mbgp_neighbor_received_routes_cmd,
13201 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13202 SHOW_STR
13203 IPV6_STR
13204 MBGP_STR
13205 "Detailed information on TCP and BGP neighbor connections\n"
13206 "Neighbor to display information about\n"
13207 "Neighbor to display information about\n"
13208 "Neighbor on bgp configured interface\n"
13209 "Display the received routes from neighbor\n"
13210 "JavaScript Object Notation\n")
13211 {
13212 struct peer *peer;
13213 u_char uj = use_json(argc, argv);
13214
13215 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13216 if (! peer)
13217 return CMD_WARNING;
13218
13219 bgp_show_ipv6_bgp_deprecate_warning(vty);
13220 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
13221 }
13222
13223 DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
13224 show_bgp_instance_neighbor_received_prefix_filter_cmd,
13225 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13226 SHOW_STR
13227 BGP_STR
13228 BGP_INSTANCE_HELP_STR
13229 "Detailed information on TCP and BGP neighbor connections\n"
13230 "Neighbor to display information about\n"
13231 "Neighbor to display information about\n"
13232 "Neighbor on bgp configured interface\n"
13233 "Display information received from a BGP neighbor\n"
13234 "Display the prefixlist filter\n"
13235 "JavaScript Object Notation\n")
13236 {
13237 char name[BUFSIZ];
13238 union sockunion su;
13239 struct peer *peer;
13240 struct bgp *bgp;
13241 int count, ret;
13242 u_char uj = use_json(argc, argv);
13243
13244 /* BGP structure lookup. */
13245 bgp = bgp_lookup_by_name (argv[1]);
13246 if (bgp == NULL)
13247 {
13248 if (uj)
13249 {
13250 json_object *json_no = NULL;
13251 json_no = json_object_new_object();
13252 json_object_string_add(json_no, "warning", "Can't find BGP view");
13253 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13254 json_object_free(json_no);
13255 }
13256 else
13257 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
13258 return CMD_WARNING;
13259 }
13260
13261 ret = str2sockunion (argv[2], &su);
13262 if (ret < 0)
13263 {
13264 peer = peer_lookup_by_conf_if (bgp, argv[2]);
13265 if (! peer)
13266 {
13267 if (uj)
13268 {
13269 json_object *json_no = NULL;
13270 json_object *json_sub = NULL;
13271 json_no = json_object_new_object();
13272 json_sub = json_object_new_object();
13273 json_object_string_add(json_no, "warning", "Malformed address or name");
13274 json_object_string_add(json_sub, "warningCause", argv[2]);
13275 json_object_object_add(json_no, "detail", json_sub);
13276 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13277 json_object_free(json_no);
13278 }
13279 else
13280 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
13281 return CMD_WARNING;
13282 }
13283 }
13284 else
13285 {
13286 peer = peer_lookup (bgp, &su);
13287 if (! peer)
13288 {
13289 if (uj)
13290 {
13291 json_object *json_no = NULL;
13292 json_no = json_object_new_object();
13293 json_object_boolean_true_add(json_no, "noPeer");
13294 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13295 json_object_free(json_no);
13296 }
13297 else
13298 vty_out (vty, "No peer%s", VTY_NEWLINE);
13299 return CMD_WARNING;
13300 }
13301
13302 }
13303
13304 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13305 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13306 if (count)
13307 {
13308 if (!uj)
13309 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13310 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13311 }
13312
13313 return CMD_SUCCESS;
13314 }
13315 ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
13316 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
13317 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13318 SHOW_STR
13319 BGP_STR
13320 BGP_INSTANCE_HELP_STR
13321 "Address family\n"
13322 "Detailed information on TCP and BGP neighbor connections\n"
13323 "Neighbor to display information about\n"
13324 "Neighbor to display information about\n"
13325 "Neighbor on bgp configured interface\n"
13326 "Display information received from a BGP neighbor\n"
13327 "Display the prefixlist filter\n"
13328 "JavaScript Object NOtation\n")
13329 #endif /* HAVE_IPV6 */
13330
13331 static int
13332 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
13333 safi_t safi, enum bgp_show_type type, u_char use_json)
13334 {
13335 if (! peer || ! peer->afc[afi][safi])
13336 {
13337 if (use_json)
13338 {
13339 json_object *json_no = NULL;
13340 json_no = json_object_new_object();
13341 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13342 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13343 json_object_free(json_no);
13344 }
13345 else
13346 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
13347 return CMD_WARNING;
13348 }
13349
13350 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
13351 }
13352
13353 DEFUN (show_ip_bgp_neighbor_routes,
13354 show_ip_bgp_neighbor_routes_cmd,
13355 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13356 SHOW_STR
13357 IP_STR
13358 BGP_STR
13359 "Detailed information on TCP and BGP neighbor connections\n"
13360 "Neighbor to display information about\n"
13361 "Neighbor to display information about\n"
13362 "Neighbor on bgp configured interface\n"
13363 "Display routes learned from neighbor\n"
13364 "JavaScript Object Notation\n")
13365 {
13366 struct peer *peer;
13367 u_char uj = use_json(argc, argv);
13368
13369 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13370 if (! peer)
13371 return CMD_WARNING;
13372
13373 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13374 bgp_show_type_neighbor, uj);
13375 }
13376
13377 DEFUN (show_ip_bgp_instance_neighbor_routes,
13378 show_ip_bgp_instance_neighbor_routes_cmd,
13379 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13380 SHOW_STR
13381 IP_STR
13382 BGP_STR
13383 BGP_INSTANCE_HELP_STR
13384 "Detailed information on TCP and BGP neighbor connections\n"
13385 "Neighbor to display information about\n"
13386 "Neighbor to display information about\n"
13387 "Neighbor on bgp configured interface\n"
13388 "Display routes learned from neighbor\n"
13389 "JavaScript Object Notation\n")
13390 {
13391 struct peer *peer;
13392 u_char uj = use_json(argc, argv);
13393
13394 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13395 if (! peer)
13396 return CMD_WARNING;
13397
13398 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13399 bgp_show_type_neighbor, uj);
13400 }
13401
13402 DEFUN (show_ip_bgp_neighbor_flap,
13403 show_ip_bgp_neighbor_flap_cmd,
13404 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13405 SHOW_STR
13406 IP_STR
13407 BGP_STR
13408 "Detailed information on TCP and BGP neighbor connections\n"
13409 "Neighbor to display information about\n"
13410 "Neighbor to display information about\n"
13411 "Neighbor on bgp configured interface\n"
13412 "Display flap statistics of the routes learned from neighbor\n"
13413 "JavaScript Object Notation\n")
13414 {
13415 struct peer *peer;
13416 u_char uj = use_json(argc, argv);
13417
13418 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13419 if (! peer)
13420 return CMD_WARNING;
13421
13422 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13423 bgp_show_type_flap_neighbor, uj);
13424 }
13425
13426 DEFUN (show_ip_bgp_neighbor_damp,
13427 show_ip_bgp_neighbor_damp_cmd,
13428 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13429 SHOW_STR
13430 IP_STR
13431 BGP_STR
13432 "Detailed information on TCP and BGP neighbor connections\n"
13433 "Neighbor to display information about\n"
13434 "Neighbor to display information about\n"
13435 "Neighbor on bgp configured interface\n"
13436 "Display the dampened routes received from neighbor\n"
13437 "JavaScript Object Notation\n")
13438 {
13439 struct peer *peer;
13440 u_char uj = use_json(argc, argv);
13441
13442 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13443 if (! peer)
13444 return CMD_WARNING;
13445
13446 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13447 bgp_show_type_damp_neighbor, uj);
13448 }
13449
13450 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13451 show_ip_bgp_ipv4_neighbor_routes_cmd,
13452 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13453 SHOW_STR
13454 IP_STR
13455 BGP_STR
13456 "Address family\n"
13457 BGP_SAFI_HELP_STR
13458 "Detailed information on TCP and BGP neighbor connections\n"
13459 "Neighbor to display information about\n"
13460 "Neighbor to display information about\n"
13461 "Neighbor on bgp configured interface\n"
13462 "Display routes learned from neighbor\n"
13463 "JavaScript Object Notation\n")
13464 {
13465 struct peer *peer;
13466 safi_t safi;
13467 u_char uj = use_json(argc, argv);
13468
13469 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13470 if (! peer)
13471 return CMD_WARNING;
13472
13473 safi = bgp_vty_safi_from_arg(argv[0]);
13474 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
13475 bgp_show_type_neighbor, uj);
13476 }
13477
13478 #ifdef HAVE_IPV6
13479 DEFUN (show_bgp_instance_neighbor_routes,
13480 show_bgp_instance_neighbor_routes_cmd,
13481 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13482 SHOW_STR
13483 BGP_STR
13484 BGP_INSTANCE_HELP_STR
13485 "Detailed information on TCP and BGP neighbor connections\n"
13486 "Neighbor to display information about\n"
13487 "Neighbor to display information about\n"
13488 "Neighbor on bgp configured interface\n"
13489 "Display routes learned from neighbor\n"
13490 "JavaScript Object Notation\n")
13491 {
13492 struct peer *peer;
13493 u_char uj = use_json(argc, argv);
13494
13495 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13496 if (! peer)
13497 return CMD_WARNING;
13498
13499 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13500 bgp_show_type_neighbor, uj);
13501 }
13502
13503 ALIAS (show_bgp_instance_neighbor_routes,
13504 show_bgp_instance_ipv6_neighbor_routes_cmd,
13505 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13506 SHOW_STR
13507 BGP_STR
13508 BGP_INSTANCE_HELP_STR
13509 "Address family\n"
13510 "Detailed information on TCP and BGP neighbor connections\n"
13511 "Neighbor to display information about\n"
13512 "Neighbor to display information about\n"
13513 "Neighbor on bgp configured interface\n"
13514 "Display routes learned from neighbor\n"
13515 "JavaScript Object Notation\n")
13516
13517 DEFUN (show_bgp_instance_neighbor_damp,
13518 show_bgp_instance_neighbor_damp_cmd,
13519 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13520 SHOW_STR
13521 BGP_STR
13522 BGP_INSTANCE_HELP_STR
13523 "Detailed information on TCP and BGP neighbor connections\n"
13524 "Neighbor to display information about\n"
13525 "Neighbor to display information about\n"
13526 "Neighbor on bgp configured interface\n"
13527 "Display the dampened routes received from neighbor\n"
13528 "JavaScript Object Notation\n")
13529 {
13530 struct peer *peer;
13531 u_char uj = use_json(argc, argv);
13532
13533 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13534 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13535 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13536 else
13537 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13538
13539 if (! peer)
13540 return CMD_WARNING;
13541
13542 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13543 bgp_show_type_damp_neighbor, uj);
13544 }
13545
13546 ALIAS (show_bgp_instance_neighbor_damp,
13547 show_bgp_instance_ipv6_neighbor_damp_cmd,
13548 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13549 SHOW_STR
13550 BGP_STR
13551 BGP_INSTANCE_HELP_STR
13552 "Address family\n"
13553 "Detailed information on TCP and BGP neighbor connections\n"
13554 "Neighbor to display information about\n"
13555 "Neighbor to display information about\n"
13556 "Neighbor on bgp configured interface\n"
13557 "Display the dampened routes received from neighbor\n"
13558 "JavaScript Object Notation\n")
13559
13560 DEFUN (show_bgp_instance_neighbor_flap,
13561 show_bgp_instance_neighbor_flap_cmd,
13562 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13563 SHOW_STR
13564 BGP_STR
13565 BGP_INSTANCE_HELP_STR
13566 "Detailed information on TCP and BGP neighbor connections\n"
13567 "Neighbor to display information about\n"
13568 "Neighbor to display information about\n"
13569 "Neighbor on bgp configured interface\n"
13570 "Display flap statistics of the routes learned from neighbor\n"
13571 "JavaScript Object Notation\n")
13572 {
13573 struct peer *peer;
13574 u_char uj = use_json(argc, argv);
13575
13576 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13577 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13578 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13579 else
13580 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13581
13582 if (! peer)
13583 return CMD_WARNING;
13584
13585 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13586 bgp_show_type_flap_neighbor, uj);
13587 }
13588
13589 ALIAS (show_bgp_instance_neighbor_flap,
13590 show_bgp_instance_ipv6_neighbor_flap_cmd,
13591 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13592 SHOW_STR
13593 BGP_STR
13594 BGP_INSTANCE_HELP_STR
13595 "Address family\n"
13596 "Detailed information on TCP and BGP neighbor connections\n"
13597 "Neighbor to display information about\n"
13598 "Neighbor to display information about\n"
13599 "Neighbor on bgp configured interface\n"
13600 "Display flap statistics of the routes learned from neighbor\n"
13601 "JavaScript Object Notation\n")
13602
13603 DEFUN (show_bgp_neighbor_routes,
13604 show_bgp_neighbor_routes_cmd,
13605 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13606 SHOW_STR
13607 BGP_STR
13608 "Detailed information on TCP and BGP neighbor connections\n"
13609 "Neighbor to display information about\n"
13610 "Neighbor to display information about\n"
13611 "Neighbor on bgp configured interface\n"
13612 "Display routes learned from neighbor\n"
13613 "JavaScript Object Notation\n")
13614 {
13615 struct peer *peer;
13616 u_char uj = use_json(argc, argv);
13617
13618 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13619 if (! peer)
13620 return CMD_WARNING;
13621
13622 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13623 bgp_show_type_neighbor, uj);
13624 }
13625
13626
13627 ALIAS (show_bgp_neighbor_routes,
13628 show_bgp_ipv6_neighbor_routes_cmd,
13629 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13630 SHOW_STR
13631 BGP_STR
13632 "Address family\n"
13633 "Detailed information on TCP and BGP neighbor connections\n"
13634 "Neighbor to display information about\n"
13635 "Neighbor to display information about\n"
13636 "Neighbor on bgp configured interface\n"
13637 "Display routes learned from neighbor\n"
13638 "JavaScript Object Notation\n")
13639
13640 /* old command */
13641 ALIAS (show_bgp_neighbor_routes,
13642 ipv6_bgp_neighbor_routes_cmd,
13643 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13644 SHOW_STR
13645 IPV6_STR
13646 BGP_STR
13647 "Detailed information on TCP and BGP neighbor connections\n"
13648 "Neighbor to display information about\n"
13649 "Neighbor to display information about\n"
13650 "Neighbor on bgp configured interface\n"
13651 "Display routes learned from neighbor\n"
13652 "JavaScript Object Notation\n")
13653
13654 /* old command */
13655 DEFUN (ipv6_mbgp_neighbor_routes,
13656 ipv6_mbgp_neighbor_routes_cmd,
13657 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13658 SHOW_STR
13659 IPV6_STR
13660 MBGP_STR
13661 "Detailed information on TCP and BGP neighbor connections\n"
13662 "Neighbor to display information about\n"
13663 "Neighbor to display information about\n"
13664 "Neighbor on bgp configured interface\n"
13665 "Display routes learned from neighbor\n"
13666 "JavaScript Object Notation\n")
13667 {
13668 struct peer *peer;
13669 u_char uj = use_json(argc, argv);
13670
13671 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13672 if (! peer)
13673 return CMD_WARNING;
13674
13675 bgp_show_ipv6_bgp_deprecate_warning(vty);
13676 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
13677 bgp_show_type_neighbor, uj);
13678 }
13679
13680 ALIAS (show_bgp_instance_neighbor_flap,
13681 show_bgp_neighbor_flap_cmd,
13682 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13683 SHOW_STR
13684 BGP_STR
13685 "Detailed information on TCP and BGP neighbor connections\n"
13686 "Neighbor to display information about\n"
13687 "Neighbor to display information about\n"
13688 "Neighbor on bgp configured interface\n"
13689 "Display flap statistics of the routes learned from neighbor\n"
13690 "JavaScript Object Notation\n")
13691
13692 ALIAS (show_bgp_instance_neighbor_flap,
13693 show_bgp_ipv6_neighbor_flap_cmd,
13694 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13695 SHOW_STR
13696 BGP_STR
13697 "Address family\n"
13698 "Detailed information on TCP and BGP neighbor connections\n"
13699 "Neighbor to display information about\n"
13700 "Neighbor to display information about\n"
13701 "Neighbor on bgp configured interface\n"
13702 "Display flap statistics of the routes learned from neighbor\n"
13703 "JavaScript Object Notation\n")
13704
13705 ALIAS (show_bgp_instance_neighbor_damp,
13706 show_bgp_neighbor_damp_cmd,
13707 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13708 SHOW_STR
13709 BGP_STR
13710 "Detailed information on TCP and BGP neighbor connections\n"
13711 "Neighbor to display information about\n"
13712 "Neighbor to display information about\n"
13713 "Neighbor on bgp configured interface\n"
13714 "Display the dampened routes received from neighbor\n"
13715 "JavaScript Object Notation\n")
13716
13717 ALIAS (show_bgp_instance_neighbor_damp,
13718 show_bgp_ipv6_neighbor_damp_cmd,
13719 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13720 SHOW_STR
13721 BGP_STR
13722 "Address family\n"
13723 "Detailed information on TCP and BGP neighbor connections\n"
13724 "Neighbor to display information about\n"
13725 "Neighbor to display information about\n"
13726 "Neighbor on bgp configured interface\n"
13727 "Display the dampened routes received from neighbor\n"
13728 "JavaScript Object Notation\n")
13729
13730 #endif /* HAVE_IPV6 */
13731
13732 struct bgp_table *bgp_distance_table[AFI_MAX][SAFI_MAX];
13733
13734 struct bgp_distance
13735 {
13736 /* Distance value for the IP source prefix. */
13737 u_char distance;
13738
13739 /* Name of the access-list to be matched. */
13740 char *access_list;
13741 };
13742
13743 static struct bgp_distance *
13744 bgp_distance_new (void)
13745 {
13746 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
13747 }
13748
13749 static void
13750 bgp_distance_free (struct bgp_distance *bdistance)
13751 {
13752 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13753 }
13754
13755 static int
13756 bgp_distance_set (struct vty *vty, const char *distance_str,
13757 const char *ip_str, const char *access_list_str)
13758 {
13759 int ret;
13760 afi_t afi;
13761 safi_t safi;
13762 struct prefix p;
13763 u_char distance;
13764 struct bgp_node *rn;
13765 struct bgp_distance *bdistance;
13766
13767 afi = bgp_node_afi (vty);
13768 safi = bgp_node_safi (vty);
13769
13770 ret = str2prefix (ip_str, &p);
13771 if (ret == 0)
13772 {
13773 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13774 return CMD_WARNING;
13775 }
13776
13777 distance = atoi (distance_str);
13778
13779 /* Get BGP distance node. */
13780 rn = bgp_node_get (bgp_distance_table[afi][safi], (struct prefix *) &p);
13781 if (rn->info)
13782 {
13783 bdistance = rn->info;
13784 bgp_unlock_node (rn);
13785 }
13786 else
13787 {
13788 bdistance = bgp_distance_new ();
13789 rn->info = bdistance;
13790 }
13791
13792 /* Set distance value. */
13793 bdistance->distance = distance;
13794
13795 /* Reset access-list configuration. */
13796 if (bdistance->access_list)
13797 {
13798 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13799 bdistance->access_list = NULL;
13800 }
13801 if (access_list_str)
13802 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
13803
13804 return CMD_SUCCESS;
13805 }
13806
13807 static int
13808 bgp_distance_unset (struct vty *vty, const char *distance_str,
13809 const char *ip_str, const char *access_list_str)
13810 {
13811 int ret;
13812 afi_t afi;
13813 safi_t safi;
13814 struct prefix p;
13815 int distance;
13816 struct bgp_node *rn;
13817 struct bgp_distance *bdistance;
13818
13819 afi = bgp_node_afi (vty);
13820 safi = bgp_node_safi (vty);
13821
13822 ret = str2prefix (ip_str, &p);
13823 if (ret == 0)
13824 {
13825 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13826 return CMD_WARNING;
13827 }
13828
13829 rn = bgp_node_lookup (bgp_distance_table[afi][safi], (struct prefix *)&p);
13830 if (! rn)
13831 {
13832 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13833 return CMD_WARNING;
13834 }
13835
13836 bdistance = rn->info;
13837 distance = atoi(distance_str);
13838
13839 if (bdistance->distance != distance)
13840 {
13841 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
13842 return CMD_WARNING;
13843 }
13844
13845 if (bdistance->access_list)
13846 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13847 bgp_distance_free (bdistance);
13848
13849 rn->info = NULL;
13850 bgp_unlock_node (rn);
13851 bgp_unlock_node (rn);
13852
13853 return CMD_SUCCESS;
13854 }
13855
13856 /* Apply BGP information to distance method. */
13857 u_char
13858 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, afi_t afi,
13859 safi_t safi, struct bgp *bgp)
13860 {
13861 struct bgp_node *rn;
13862 struct prefix q;
13863 struct peer *peer;
13864 struct bgp_distance *bdistance;
13865 struct access_list *alist;
13866 struct bgp_static *bgp_static;
13867
13868 if (! bgp)
13869 return 0;
13870
13871 peer = rinfo->peer;
13872
13873 /* Check source address. */
13874 sockunion2hostprefix (&peer->su, &q);
13875 rn = bgp_node_match (bgp_distance_table[afi][safi], &q);
13876 if (rn)
13877 {
13878 bdistance = rn->info;
13879 bgp_unlock_node (rn);
13880
13881 if (bdistance->access_list)
13882 {
13883 alist = access_list_lookup (afi, bdistance->access_list);
13884 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13885 return bdistance->distance;
13886 }
13887 else
13888 return bdistance->distance;
13889 }
13890
13891 /* Backdoor check. */
13892 rn = bgp_node_lookup (bgp->route[afi][safi], p);
13893 if (rn)
13894 {
13895 bgp_static = rn->info;
13896 bgp_unlock_node (rn);
13897
13898 if (bgp_static->backdoor)
13899 {
13900 if (bgp->distance_local[afi][safi])
13901 return bgp->distance_local[afi][safi];
13902 else
13903 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13904 }
13905 }
13906
13907 if (peer->sort == BGP_PEER_EBGP)
13908 {
13909 if (bgp->distance_ebgp[afi][safi])
13910 return bgp->distance_ebgp[afi][safi];
13911 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13912 }
13913 else
13914 {
13915 if (bgp->distance_ibgp[afi][safi])
13916 return bgp->distance_ibgp[afi][safi];
13917 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13918 }
13919 }
13920
13921 DEFUN (bgp_distance,
13922 bgp_distance_cmd,
13923 "distance bgp <1-255> <1-255> <1-255>",
13924 "Define an administrative distance\n"
13925 "BGP distance\n"
13926 "Distance for routes external to the AS\n"
13927 "Distance for routes internal to the AS\n"
13928 "Distance for local routes\n")
13929 {
13930 struct bgp *bgp;
13931 afi_t afi;
13932 safi_t safi;
13933
13934 bgp = vty->index;
13935 afi = bgp_node_afi (vty);
13936 safi = bgp_node_safi (vty);
13937
13938 bgp->distance_ebgp[afi][safi] = atoi (argv[0]);
13939 bgp->distance_ibgp[afi][safi] = atoi (argv[1]);
13940 bgp->distance_local[afi][safi] = atoi (argv[2]);
13941 return CMD_SUCCESS;
13942 }
13943
13944 DEFUN (no_bgp_distance,
13945 no_bgp_distance_cmd,
13946 "no distance bgp <1-255> <1-255> <1-255>",
13947 NO_STR
13948 "Define an administrative distance\n"
13949 "BGP distance\n"
13950 "Distance for routes external to the AS\n"
13951 "Distance for routes internal to the AS\n"
13952 "Distance for local routes\n")
13953 {
13954 struct bgp *bgp;
13955 afi_t afi;
13956 safi_t safi;
13957
13958 bgp = vty->index;
13959 afi = bgp_node_afi (vty);
13960 safi = bgp_node_safi (vty);
13961
13962 bgp->distance_ebgp[afi][safi] = 0;
13963 bgp->distance_ibgp[afi][safi] = 0;
13964 bgp->distance_local[afi][safi] = 0;
13965 return CMD_SUCCESS;
13966 }
13967
13968 ALIAS (no_bgp_distance,
13969 no_bgp_distance2_cmd,
13970 "no distance bgp",
13971 NO_STR
13972 "Define an administrative distance\n"
13973 "BGP distance\n")
13974
13975 DEFUN (bgp_distance_source,
13976 bgp_distance_source_cmd,
13977 "distance <1-255> A.B.C.D/M",
13978 "Define an administrative distance\n"
13979 "Administrative distance\n"
13980 "IP source prefix\n")
13981 {
13982 bgp_distance_set (vty, argv[0], argv[1], NULL);
13983 return CMD_SUCCESS;
13984 }
13985
13986 DEFUN (no_bgp_distance_source,
13987 no_bgp_distance_source_cmd,
13988 "no distance <1-255> A.B.C.D/M",
13989 NO_STR
13990 "Define an administrative distance\n"
13991 "Administrative distance\n"
13992 "IP source prefix\n")
13993 {
13994 bgp_distance_unset (vty, argv[0], argv[1], NULL);
13995 return CMD_SUCCESS;
13996 }
13997
13998 DEFUN (bgp_distance_source_access_list,
13999 bgp_distance_source_access_list_cmd,
14000 "distance <1-255> A.B.C.D/M WORD",
14001 "Define an administrative distance\n"
14002 "Administrative distance\n"
14003 "IP source prefix\n"
14004 "Access list name\n")
14005 {
14006 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14007 return CMD_SUCCESS;
14008 }
14009
14010 DEFUN (no_bgp_distance_source_access_list,
14011 no_bgp_distance_source_access_list_cmd,
14012 "no distance <1-255> A.B.C.D/M WORD",
14013 NO_STR
14014 "Define an administrative distance\n"
14015 "Administrative distance\n"
14016 "IP source prefix\n"
14017 "Access list name\n")
14018 {
14019 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14020 return CMD_SUCCESS;
14021 }
14022
14023 DEFUN (ipv6_bgp_distance_source,
14024 ipv6_bgp_distance_source_cmd,
14025 "distance <1-255> X:X::X:X/M",
14026 "Define an administrative distance\n"
14027 "Administrative distance\n"
14028 "IP source prefix\n")
14029 {
14030 bgp_distance_set (vty, argv[0], argv[1], NULL);
14031 return CMD_SUCCESS;
14032 }
14033
14034 DEFUN (no_ipv6_bgp_distance_source,
14035 no_ipv6_bgp_distance_source_cmd,
14036 "no distance <1-255> X:X::X:X/M",
14037 NO_STR
14038 "Define an administrative distance\n"
14039 "Administrative distance\n"
14040 "IP source prefix\n")
14041 {
14042 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14043 return CMD_SUCCESS;
14044 }
14045
14046 DEFUN (ipv6_bgp_distance_source_access_list,
14047 ipv6_bgp_distance_source_access_list_cmd,
14048 "distance <1-255> X:X::X:X/M WORD",
14049 "Define an administrative distance\n"
14050 "Administrative distance\n"
14051 "IP source prefix\n"
14052 "Access list name\n")
14053 {
14054 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14055 return CMD_SUCCESS;
14056 }
14057
14058 DEFUN (no_ipv6_bgp_distance_source_access_list,
14059 no_ipv6_bgp_distance_source_access_list_cmd,
14060 "no distance <1-255> X:X::X:X/M WORD",
14061 NO_STR
14062 "Define an administrative distance\n"
14063 "Administrative distance\n"
14064 "IP source prefix\n"
14065 "Access list name\n")
14066 {
14067 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14068 return CMD_SUCCESS;
14069 }
14070
14071 DEFUN (bgp_damp_set,
14072 bgp_damp_set_cmd,
14073 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14074 "BGP Specific commands\n"
14075 "Enable route-flap dampening\n"
14076 "Half-life time for the penalty\n"
14077 "Value to start reusing a route\n"
14078 "Value to start suppressing a route\n"
14079 "Maximum duration to suppress a stable route\n")
14080 {
14081 struct bgp *bgp;
14082 int half = DEFAULT_HALF_LIFE * 60;
14083 int reuse = DEFAULT_REUSE;
14084 int suppress = DEFAULT_SUPPRESS;
14085 int max = 4 * half;
14086
14087 if (argc == 4)
14088 {
14089 half = atoi (argv[0]) * 60;
14090 reuse = atoi (argv[1]);
14091 suppress = atoi (argv[2]);
14092 max = atoi (argv[3]) * 60;
14093 }
14094 else if (argc == 1)
14095 {
14096 half = atoi (argv[0]) * 60;
14097 max = 4 * half;
14098 }
14099
14100 bgp = vty->index;
14101
14102 if (suppress < reuse)
14103 {
14104 vty_out (vty, "Suppress value cannot be less than reuse value %s",
14105 VTY_NEWLINE);
14106 return 0;
14107 }
14108
14109 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14110 half, reuse, suppress, max);
14111 }
14112
14113 ALIAS (bgp_damp_set,
14114 bgp_damp_set2_cmd,
14115 "bgp dampening <1-45>",
14116 "BGP Specific commands\n"
14117 "Enable route-flap dampening\n"
14118 "Half-life time for the penalty\n")
14119
14120 ALIAS (bgp_damp_set,
14121 bgp_damp_set3_cmd,
14122 "bgp dampening",
14123 "BGP Specific commands\n"
14124 "Enable route-flap dampening\n")
14125
14126 DEFUN (bgp_damp_unset,
14127 bgp_damp_unset_cmd,
14128 "no bgp dampening",
14129 NO_STR
14130 "BGP Specific commands\n"
14131 "Enable route-flap dampening\n")
14132 {
14133 struct bgp *bgp;
14134
14135 bgp = vty->index;
14136 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14137 }
14138
14139 ALIAS (bgp_damp_unset,
14140 bgp_damp_unset2_cmd,
14141 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14142 NO_STR
14143 "BGP Specific commands\n"
14144 "Enable route-flap dampening\n"
14145 "Half-life time for the penalty\n"
14146 "Value to start reusing a route\n"
14147 "Value to start suppressing a route\n"
14148 "Maximum duration to suppress a stable route\n")
14149
14150 ALIAS (bgp_damp_unset,
14151 bgp_damp_unset3_cmd,
14152 "no bgp dampening <1-45>",
14153 NO_STR
14154 "BGP Specific commands\n"
14155 "Enable route-flap dampening\n"
14156 "Half-life time for the penalty\n")
14157
14158 DEFUN (show_ip_bgp_dampened_paths,
14159 show_ip_bgp_dampened_paths_cmd,
14160 "show ip bgp dampened-paths",
14161 SHOW_STR
14162 IP_STR
14163 BGP_STR
14164 "Display paths suppressed due to dampening\n")
14165 {
14166 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
14167 NULL, 0);
14168 }
14169
14170 ALIAS (show_ip_bgp_dampened_paths,
14171 show_ip_bgp_damp_dampened_paths_cmd,
14172 "show ip bgp dampening dampened-paths",
14173 SHOW_STR
14174 IP_STR
14175 BGP_STR
14176 "Display detailed information about dampening\n"
14177 "Display paths suppressed due to dampening\n")
14178
14179 DEFUN (show_ip_bgp_flap_statistics,
14180 show_ip_bgp_flap_statistics_cmd,
14181 "show ip bgp flap-statistics",
14182 SHOW_STR
14183 IP_STR
14184 BGP_STR
14185 "Display flap statistics of routes\n")
14186 {
14187 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
14188 bgp_show_type_flap_statistics, NULL, 0);
14189 }
14190
14191 ALIAS (show_ip_bgp_flap_statistics,
14192 show_ip_bgp_damp_flap_statistics_cmd,
14193 "show ip bgp dampening flap-statistics",
14194 SHOW_STR
14195 IP_STR
14196 BGP_STR
14197 "Display detailed information about dampening\n"
14198 "Display flap statistics of routes\n")
14199
14200 /* Display specified route of BGP table. */
14201 static int
14202 bgp_clear_damp_route (struct vty *vty, const char *view_name,
14203 const char *ip_str, afi_t afi, safi_t safi,
14204 struct prefix_rd *prd, int prefix_check)
14205 {
14206 int ret;
14207 struct prefix match;
14208 struct bgp_node *rn;
14209 struct bgp_node *rm;
14210 struct bgp_info *ri;
14211 struct bgp_info *ri_temp;
14212 struct bgp *bgp;
14213 struct bgp_table *table;
14214
14215 /* BGP structure lookup. */
14216 if (view_name)
14217 {
14218 bgp = bgp_lookup_by_name (view_name);
14219 if (bgp == NULL)
14220 {
14221 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
14222 return CMD_WARNING;
14223 }
14224 }
14225 else
14226 {
14227 bgp = bgp_get_default ();
14228 if (bgp == NULL)
14229 {
14230 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14231 return CMD_WARNING;
14232 }
14233 }
14234
14235 /* Check IP address argument. */
14236 ret = str2prefix (ip_str, &match);
14237 if (! ret)
14238 {
14239 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14240 return CMD_WARNING;
14241 }
14242
14243 match.family = afi2family (afi);
14244
14245 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
14246 {
14247 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
14248 {
14249 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14250 continue;
14251
14252 if ((table = rn->info) != NULL)
14253 if ((rm = bgp_node_match (table, &match)) != NULL)
14254 {
14255 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14256 {
14257 ri = rm->info;
14258 while (ri)
14259 {
14260 if (ri->extra && ri->extra->damp_info)
14261 {
14262 ri_temp = ri->next;
14263 bgp_damp_info_free (ri->extra->damp_info, 1);
14264 ri = ri_temp;
14265 }
14266 else
14267 ri = ri->next;
14268 }
14269 }
14270
14271 bgp_unlock_node (rm);
14272 }
14273 }
14274 }
14275 else
14276 {
14277 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
14278 {
14279 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14280 {
14281 ri = rn->info;
14282 while (ri)
14283 {
14284 if (ri->extra && ri->extra->damp_info)
14285 {
14286 ri_temp = ri->next;
14287 bgp_damp_info_free (ri->extra->damp_info, 1);
14288 ri = ri_temp;
14289 }
14290 else
14291 ri = ri->next;
14292 }
14293 }
14294
14295 bgp_unlock_node (rn);
14296 }
14297 }
14298
14299 return CMD_SUCCESS;
14300 }
14301
14302 DEFUN (clear_ip_bgp_dampening,
14303 clear_ip_bgp_dampening_cmd,
14304 "clear ip bgp dampening",
14305 CLEAR_STR
14306 IP_STR
14307 BGP_STR
14308 "Clear route flap dampening information\n")
14309 {
14310 bgp_damp_info_clean ();
14311 return CMD_SUCCESS;
14312 }
14313
14314 DEFUN (clear_ip_bgp_dampening_prefix,
14315 clear_ip_bgp_dampening_prefix_cmd,
14316 "clear ip bgp dampening A.B.C.D/M",
14317 CLEAR_STR
14318 IP_STR
14319 BGP_STR
14320 "Clear route flap dampening information\n"
14321 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14322 {
14323 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14324 SAFI_UNICAST, NULL, 1);
14325 }
14326
14327 DEFUN (clear_ip_bgp_dampening_address,
14328 clear_ip_bgp_dampening_address_cmd,
14329 "clear ip bgp dampening A.B.C.D",
14330 CLEAR_STR
14331 IP_STR
14332 BGP_STR
14333 "Clear route flap dampening information\n"
14334 "Network to clear damping information\n")
14335 {
14336 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14337 SAFI_UNICAST, NULL, 0);
14338 }
14339
14340 DEFUN (clear_ip_bgp_dampening_address_mask,
14341 clear_ip_bgp_dampening_address_mask_cmd,
14342 "clear ip bgp dampening A.B.C.D A.B.C.D",
14343 CLEAR_STR
14344 IP_STR
14345 BGP_STR
14346 "Clear route flap dampening information\n"
14347 "Network to clear damping information\n"
14348 "Network mask\n")
14349 {
14350 int ret;
14351 char prefix_str[BUFSIZ];
14352
14353 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14354 if (! ret)
14355 {
14356 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14357 return CMD_WARNING;
14358 }
14359
14360 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14361 SAFI_UNICAST, NULL, 0);
14362 }
14363
14364 /* also used for encap safi */
14365 static int
14366 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14367 afi_t afi, safi_t safi, int *write)
14368 {
14369 struct bgp_node *prn;
14370 struct bgp_node *rn;
14371 struct bgp_table *table;
14372 struct prefix *p;
14373 struct prefix_rd *prd;
14374 struct bgp_static *bgp_static;
14375 u_int32_t label;
14376 char buf[SU_ADDRSTRLEN];
14377 char rdbuf[RD_ADDRSTRLEN];
14378
14379 /* Network configuration. */
14380 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14381 if ((table = prn->info) != NULL)
14382 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14383 if ((bgp_static = rn->info) != NULL)
14384 {
14385 p = &rn->p;
14386 prd = (struct prefix_rd *) &prn->p;
14387
14388 /* "address-family" display. */
14389 bgp_config_write_family_header (vty, afi, safi, write);
14390
14391 /* "network" configuration display. */
14392 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14393 label = decode_label (bgp_static->tag);
14394
14395 vty_out (vty, " network %s/%d rd %s tag %d",
14396 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14397 p->prefixlen,
14398 rdbuf, label);
14399 vty_out (vty, "%s", VTY_NEWLINE);
14400 }
14401 return 0;
14402 }
14403
14404 /* Configuration of static route announcement and aggregate
14405 information. */
14406 int
14407 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14408 afi_t afi, safi_t safi, int *write)
14409 {
14410 struct bgp_node *rn;
14411 struct prefix *p;
14412 struct bgp_static *bgp_static;
14413 struct bgp_aggregate *bgp_aggregate;
14414 char buf[SU_ADDRSTRLEN];
14415
14416 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
14417 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14418
14419 /* Network configuration. */
14420 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14421 if ((bgp_static = rn->info) != NULL)
14422 {
14423 p = &rn->p;
14424
14425 /* "address-family" display. */
14426 bgp_config_write_family_header (vty, afi, safi, write);
14427
14428 /* "network" configuration display. */
14429 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14430 {
14431 u_int32_t destination;
14432 struct in_addr netmask;
14433
14434 destination = ntohl (p->u.prefix4.s_addr);
14435 masklen2ip (p->prefixlen, &netmask);
14436 vty_out (vty, " network %s",
14437 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14438
14439 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14440 || (IN_CLASSB (destination) && p->prefixlen == 16)
14441 || (IN_CLASSA (destination) && p->prefixlen == 8)
14442 || p->u.prefix4.s_addr == 0)
14443 {
14444 /* Natural mask is not display. */
14445 }
14446 else
14447 vty_out (vty, " mask %s", inet_ntoa (netmask));
14448 }
14449 else
14450 {
14451 vty_out (vty, " network %s/%d",
14452 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14453 p->prefixlen);
14454 }
14455
14456 if (bgp_static->rmap.name)
14457 vty_out (vty, " route-map %s", bgp_static->rmap.name);
14458 else
14459 {
14460 if (bgp_static->backdoor)
14461 vty_out (vty, " backdoor");
14462 }
14463
14464 vty_out (vty, "%s", VTY_NEWLINE);
14465 }
14466
14467 /* Aggregate-address configuration. */
14468 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14469 if ((bgp_aggregate = rn->info) != NULL)
14470 {
14471 p = &rn->p;
14472
14473 /* "address-family" display. */
14474 bgp_config_write_family_header (vty, afi, safi, write);
14475
14476 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14477 {
14478 struct in_addr netmask;
14479
14480 masklen2ip (p->prefixlen, &netmask);
14481 vty_out (vty, " aggregate-address %s %s",
14482 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14483 inet_ntoa (netmask));
14484 }
14485 else
14486 {
14487 vty_out (vty, " aggregate-address %s/%d",
14488 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14489 p->prefixlen);
14490 }
14491
14492 if (bgp_aggregate->as_set)
14493 vty_out (vty, " as-set");
14494
14495 if (bgp_aggregate->summary_only)
14496 vty_out (vty, " summary-only");
14497
14498 vty_out (vty, "%s", VTY_NEWLINE);
14499 }
14500
14501 return 0;
14502 }
14503
14504 int
14505 bgp_config_write_distance (struct vty *vty, struct bgp *bgp, afi_t afi,
14506 safi_t safi, int *write)
14507 {
14508 struct bgp_node *rn;
14509 struct bgp_distance *bdistance;
14510
14511 /* Distance configuration. */
14512 if (bgp->distance_ebgp[afi][safi]
14513 && bgp->distance_ibgp[afi][safi]
14514 && bgp->distance_local[afi][safi]
14515 && (bgp->distance_ebgp[afi][safi] != ZEBRA_EBGP_DISTANCE_DEFAULT
14516 || bgp->distance_ibgp[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT
14517 || bgp->distance_local[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT))
14518 {
14519 bgp_config_write_family_header (vty, afi, safi, write);
14520 vty_out (vty, " distance bgp %d %d %d%s",
14521 bgp->distance_ebgp[afi][safi], bgp->distance_ibgp[afi][safi],
14522 bgp->distance_local[afi][safi], VTY_NEWLINE);
14523 }
14524
14525 for (rn = bgp_table_top (bgp_distance_table[afi][safi]); rn;
14526 rn = bgp_route_next (rn))
14527 if ((bdistance = rn->info) != NULL)
14528 {
14529 char buf[PREFIX_STRLEN];
14530
14531 bgp_config_write_family_header (vty, afi, safi, write);
14532 vty_out (vty, " distance %d %s %s%s", bdistance->distance,
14533 prefix2str (&rn->p, buf, sizeof (buf)),
14534 bdistance->access_list ? bdistance->access_list : "",
14535 VTY_NEWLINE);
14536 }
14537
14538 return *write;
14539 }
14540
14541 /* Allocate routing table structure and install commands. */
14542 void
14543 bgp_route_init (void)
14544 {
14545 afi_t afi;
14546 safi_t safi;
14547
14548 /* Init BGP distance table. */
14549 for (afi = AFI_IP; afi < AFI_MAX; afi++)
14550 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
14551 bgp_distance_table[afi][safi] = bgp_table_init (afi, safi);
14552
14553 /* IPv4 BGP commands. */
14554 install_element (BGP_NODE, &bgp_table_map_cmd);
14555 install_element (BGP_NODE, &bgp_network_cmd);
14556 install_element (BGP_NODE, &bgp_network_mask_cmd);
14557 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14558 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14559 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14560 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14561 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14562 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14563 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
14564 install_element (BGP_NODE, &no_bgp_table_map_cmd);
14565 install_element (BGP_NODE, &no_bgp_network_cmd);
14566 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14567 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14568 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14569 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14570 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14571 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14572 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14573 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14574
14575 install_element (BGP_NODE, &aggregate_address_cmd);
14576 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14577 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14578 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14579 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14580 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14581 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14582 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14583 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14584 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14585 install_element (BGP_NODE, &no_aggregate_address_cmd);
14586 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14587 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14588 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14589 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14590 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14591 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14592 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14593 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14594 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14595
14596 /* IPv4 unicast configuration. */
14597 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
14598 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14599 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14600 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14601 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14602 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14603 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
14604 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
14605 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
14606 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14607 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14608 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14609 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14610 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14611
14612 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14613 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14614 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14615 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14616 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14617 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14618 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14619 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14620 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14621 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14622 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14623 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14624 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14625 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14626 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14627 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14628 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14629 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14630 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14631 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14632
14633 /* IPv4 multicast configuration. */
14634 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
14635 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14636 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14637 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14638 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14639 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14640 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
14641 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
14642 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14643 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14644 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14645 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14646 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14647 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14648 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14649 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14650 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14651 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14652 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14653 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14654 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14655 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14656 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14657 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14658 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14659 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14660 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14661 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14662 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14663 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14664 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14665 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14666 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14667 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14668
14669 install_element (VIEW_NODE, &show_ip_bgp_cmd);
14670 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
14671 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
14672 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
14673 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
14674 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
14675 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
14676 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14677 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14678 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14679 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
14680 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
14681 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14682 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
14683 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14684 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14685 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14686 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14687 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14688 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14689
14690 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14691 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14692 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14693 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14694 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14695 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14696 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
14697 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14698 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14699 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
14700 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14701 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14702 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14703 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14704 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14705 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14706 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14707 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14708 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14709 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14710 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14711 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14712 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
14713 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14714 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14715 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14716 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14717 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14718 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14719 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14720 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14721 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14722 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14723 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14724 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14725 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14726 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14727 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
14728 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14729 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14730 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14731 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14732 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14733 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14734 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14735 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14736 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14737 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14738 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14739 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14740 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14741 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14742 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14743 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14744 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14745 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14746 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14747 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
14748 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14749 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14750 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14751 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14752 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
14753 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
14754 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14755 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
14756 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
14757 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
14758 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14759 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
14760 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14761 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
14762 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14763 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14764 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
14765 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14766 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14767 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
14768 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14769 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14770 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14771 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
14772 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14773 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
14774 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14775 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
14776
14777 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
14778 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
14779 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
14780 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
14781 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
14782
14783 /* BGP dampening clear commands */
14784 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14785 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14786 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14787 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14788
14789 /* prefix count */
14790 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14791 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
14792 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14793 #ifdef HAVE_IPV6
14794 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14795 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
14796
14797 /* New config IPv6 BGP commands. */
14798 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
14799 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14800 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
14801 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
14802 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14803 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14804
14805 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14806 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14807 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14808 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
14809
14810 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14811 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
14812
14813 /* Old config IPv6 BGP commands. */
14814 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14815 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14816
14817 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14818 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14819 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14820 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14821
14822 install_element (VIEW_NODE, &show_bgp_cmd);
14823 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
14824 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
14825 install_element (VIEW_NODE, &show_bgp_route_cmd);
14826 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
14827 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
14828 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14829 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14830 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14831 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14832 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
14833 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14834 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14835 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14836 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14837 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14838 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14839 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14840 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14841 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14842 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14843 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14844 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14845 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14846 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14847 install_element (VIEW_NODE, &show_bgp_community_cmd);
14848 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14849 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14850 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14851 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14852 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14853 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14854 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14855 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14856 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14857 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14858 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14859 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14860 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14861 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14862 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14863 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14864 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14865 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14866 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14867 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14868 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14869 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14870 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14871 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14872 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14873 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14874 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14875 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14876 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14877 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14878 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14879 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14880 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14881 install_element (VIEW_NODE, &show_bgp_instance_cmd);
14882 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
14883 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
14884 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
14885 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
14886 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
14887 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14888 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
14889 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14890 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14891 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14892 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
14893 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14894 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
14895 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14896 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
14897 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14898 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
14899 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14900 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
14901 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14902 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14903 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14904 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14905 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14906 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
14907 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14908 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14909 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14910 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
14911 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14912 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
14913 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
14914
14915 /* Statistics */
14916 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
14917 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
14918 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
14919 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
14920
14921 /* old command */
14922 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14923 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14924 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
14925 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
14926 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
14927 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
14928 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
14929 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
14930 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
14931 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
14932 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
14933 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
14934 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
14935 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
14936 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
14937 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
14938 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
14939 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
14940 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
14941 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
14942 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
14943 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
14944 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
14945 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
14946 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
14947 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
14948 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
14949 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
14950 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
14951 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
14952 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
14953 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
14954 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
14955 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
14956 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
14957 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
14958
14959 /* old command */
14960 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
14961 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
14962
14963 /* old command */
14964 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
14965 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
14966
14967 /* old command */
14968 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
14969 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
14970 #endif /* HAVE_IPV6 */
14971
14972 install_element (BGP_NODE, &bgp_distance_cmd);
14973 install_element (BGP_NODE, &no_bgp_distance_cmd);
14974 install_element (BGP_NODE, &no_bgp_distance2_cmd);
14975 install_element (BGP_NODE, &bgp_distance_source_cmd);
14976 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
14977 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
14978 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
14979 install_element (BGP_IPV4_NODE, &bgp_distance_cmd);
14980 install_element (BGP_IPV4_NODE, &no_bgp_distance_cmd);
14981 install_element (BGP_IPV4_NODE, &no_bgp_distance2_cmd);
14982 install_element (BGP_IPV4_NODE, &bgp_distance_source_cmd);
14983 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_cmd);
14984 install_element (BGP_IPV4_NODE, &bgp_distance_source_access_list_cmd);
14985 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_access_list_cmd);
14986 install_element (BGP_IPV4M_NODE, &bgp_distance_cmd);
14987 install_element (BGP_IPV4M_NODE, &no_bgp_distance_cmd);
14988 install_element (BGP_IPV4M_NODE, &no_bgp_distance2_cmd);
14989 install_element (BGP_IPV4M_NODE, &bgp_distance_source_cmd);
14990 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_cmd);
14991 install_element (BGP_IPV4M_NODE, &bgp_distance_source_access_list_cmd);
14992 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_access_list_cmd);
14993 install_element (BGP_IPV6_NODE, &bgp_distance_cmd);
14994 install_element (BGP_IPV6_NODE, &no_bgp_distance_cmd);
14995 install_element (BGP_IPV6_NODE, &no_bgp_distance2_cmd);
14996 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
14997 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
14998 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
14999 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
15000 install_element (BGP_IPV6M_NODE, &bgp_distance_cmd);
15001 install_element (BGP_IPV6M_NODE, &no_bgp_distance_cmd);
15002 install_element (BGP_IPV6M_NODE, &no_bgp_distance2_cmd);
15003 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_cmd);
15004 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_cmd);
15005 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_access_list_cmd);
15006 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
15007
15008 install_element (BGP_NODE, &bgp_damp_set_cmd);
15009 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15010 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15011 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15012 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
15013 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
15014 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15015 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15016 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15017 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15018 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
15019 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
15020
15021 /* IPv4 Multicast Mode */
15022 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
15023 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
15024 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
15025 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
15026 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
15027 }
15028
15029 void
15030 bgp_route_finish (void)
15031 {
15032 afi_t afi;
15033 safi_t safi;
15034
15035 for (afi = AFI_IP; afi < AFI_MAX; afi++)
15036 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
15037 {
15038 bgp_table_unlock (bgp_distance_table[afi][safi]);
15039 bgp_distance_table[afi][safi] = NULL;
15040 }
15041 }