]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
bgpd rfapi: Shift rfapi receive hooks for vpn and encap safis into
[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 && safi != SAFI_MPLS_VPN &&\
1439 (p->family == AF_INET6 || peer_cap_enhe(peer))) || \
1440 ((safi == SAFI_ENCAP || safi == SAFI_MPLS_VPN) &&\
1441 attr->extra->mp_nexthop_len >= IPV6_MAX_BYTELEN))
1442
1443 /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if
1444 * the peer (group) is configured to receive link-local nexthop unchanged
1445 * and it is available in the prefix OR we're not reflecting the route and
1446 * the peer (group) to whom we're going to announce is on a shared network
1447 * and this is either a self-originated route or the peer is EBGP.
1448 */
1449 if (NEXTHOP_IS_V6)
1450 {
1451 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
1452 if ((CHECK_FLAG (peer->af_flags[afi][safi],
1453 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) &&
1454 IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) ||
1455 (!reflect && peer->shared_network &&
1456 (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP)))
1457 {
1458 attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
1459 }
1460
1461 /* Clear off link-local nexthop in source, whenever it is not needed to
1462 * ensure more prefixes share the same attribute for announcement.
1463 */
1464 if (!(CHECK_FLAG (peer->af_flags[afi][safi],
1465 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
1466 memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
1467 }
1468 #endif /* HAVE_IPV6 */
1469
1470 bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
1471 bgp_peer_as_override(bgp, afi, safi, peer, attr);
1472
1473 /* Route map & unsuppress-map apply. */
1474 if (ROUTE_MAP_OUT_NAME (filter)
1475 || (ri->extra && ri->extra->suppress) )
1476 {
1477 struct bgp_info info;
1478 struct attr dummy_attr;
1479 struct attr_extra dummy_extra;
1480
1481 dummy_attr.extra = &dummy_extra;
1482
1483 info.peer = peer;
1484 info.attr = attr;
1485 /* don't confuse inbound and outbound setting */
1486 RESET_FLAG(attr->rmap_change_flags);
1487
1488 /*
1489 * The route reflector is not allowed to modify the attributes
1490 * of the reflected IBGP routes unless explicitly allowed.
1491 */
1492 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
1493 && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
1494 {
1495 bgp_attr_dup (&dummy_attr, attr);
1496 info.attr = &dummy_attr;
1497 }
1498
1499 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1500
1501 if (ri->extra && ri->extra->suppress)
1502 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1503 else
1504 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1505
1506 peer->rmap_type = 0;
1507
1508 if (ret == RMAP_DENYMATCH)
1509 {
1510 bgp_attr_flush (attr);
1511 return 0;
1512 }
1513 }
1514
1515 /* After route-map has been applied, we check to see if the nexthop to
1516 * be carried in the attribute (that is used for the announcement) can
1517 * be cleared off or not. We do this in all cases where we would be
1518 * setting the nexthop to "ourselves". For IPv6, we only need to consider
1519 * the global nexthop here; the link-local nexthop would have been cleared
1520 * already, and if not, it is required by the update formation code.
1521 * Also see earlier comments in this function.
1522 */
1523 /*
1524 * If route-map has performed some operation on the nexthop or the peer
1525 * configuration says to pass it unchanged, we cannot reset the nexthop
1526 * here, so only attempt to do it if these aren't true. Note that the
1527 * route-map handler itself might have cleared the nexthop, if for example,
1528 * it is configured as 'peer-address'.
1529 */
1530 if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
1531 riattr->rmap_change_flags) &&
1532 !transparent &&
1533 !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
1534 {
1535 /* We can reset the nexthop, if setting (or forcing) it to 'self' */
1536 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
1537 CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
1538 {
1539 if (!reflect ||
1540 CHECK_FLAG (peer->af_flags[afi][safi],
1541 PEER_FLAG_FORCE_NEXTHOP_SELF))
1542 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
1543 AF_INET6 : p->family), attr);
1544 }
1545 else if (peer->sort == BGP_PEER_EBGP)
1546 {
1547 /* Can also reset the nexthop if announcing to EBGP, but only if
1548 * no peer in the subgroup is on a shared subnet.
1549 * Note: 3rd party nexthop currently implemented for IPv4 only.
1550 */
1551 SUBGRP_FOREACH_PEER (subgrp, paf)
1552 {
1553 if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer))
1554 break;
1555 }
1556 if (!paf)
1557 subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
1558 }
1559 /* If IPv6/MP and nexthop does not have any override and happens to
1560 * be a link-local address, reset it so that we don't pass along the
1561 * source's link-local IPv6 address to recipients who may not be on
1562 * the same interface.
1563 */
1564 if (p->family == AF_INET6 || peer_cap_enhe(peer))
1565 {
1566 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
1567 subgroup_announce_reset_nhop (AF_INET6, attr);
1568 }
1569 }
1570
1571 return 1;
1572 }
1573
1574 struct bgp_info_pair
1575 {
1576 struct bgp_info *old;
1577 struct bgp_info *new;
1578 };
1579
1580 static void
1581 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1582 struct bgp_maxpaths_cfg *mpath_cfg,
1583 struct bgp_info_pair *result)
1584 {
1585 struct bgp_info *new_select;
1586 struct bgp_info *old_select;
1587 struct bgp_info *ri;
1588 struct bgp_info *ri1;
1589 struct bgp_info *ri2;
1590 struct bgp_info *nextri = NULL;
1591 int paths_eq, do_mpath, debug;
1592 struct list mp_list;
1593 char pfx_buf[PREFIX2STR_BUFFER];
1594 char path_buf[PATH_ADDPATH_STR_BUFFER];
1595
1596 bgp_mp_list_init (&mp_list);
1597 do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
1598
1599 debug = bgp_debug_bestpath(&rn->p);
1600
1601 if (debug)
1602 prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf));
1603
1604 /* bgp deterministic-med */
1605 new_select = NULL;
1606 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1607 {
1608
1609 /* Clear BGP_INFO_DMED_SELECTED for all paths */
1610 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1611 bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED);
1612
1613 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1614 {
1615 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1616 continue;
1617 if (BGP_INFO_HOLDDOWN (ri1))
1618 continue;
1619 if (ri1->peer && ri1->peer != bgp->peer_self)
1620 if (ri1->peer->status != Established)
1621 continue;
1622
1623 new_select = ri1;
1624 if (ri1->next)
1625 {
1626 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1627 {
1628 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1629 continue;
1630 if (BGP_INFO_HOLDDOWN (ri2))
1631 continue;
1632 if (ri2->peer &&
1633 ri2->peer != bgp->peer_self &&
1634 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1635 if (ri2->peer->status != Established)
1636 continue;
1637
1638 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1639 || aspath_cmp_left_confed (ri1->attr->aspath,
1640 ri2->attr->aspath))
1641 {
1642 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
1643 mpath_cfg, debug, pfx_buf))
1644 {
1645 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1646 new_select = ri2;
1647 }
1648
1649 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1650 }
1651 }
1652 }
1653 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1654 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1655
1656 if (debug)
1657 {
1658 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1659 zlog_debug("%s: %s is the bestpath from AS %d",
1660 pfx_buf, path_buf, aspath_get_first_as(new_select->attr->aspath));
1661 }
1662 }
1663 }
1664
1665 /* Check old selected route and new selected route. */
1666 old_select = NULL;
1667 new_select = NULL;
1668 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1669 {
1670 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1671 old_select = ri;
1672
1673 if (BGP_INFO_HOLDDOWN (ri))
1674 {
1675 /* reap REMOVED routes, if needs be
1676 * selected route must stay for a while longer though
1677 */
1678 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1679 && (ri != old_select))
1680 bgp_info_reap (rn, ri);
1681
1682 continue;
1683 }
1684
1685 if (ri->peer &&
1686 ri->peer != bgp->peer_self &&
1687 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1688 if (ri->peer->status != Established)
1689 continue;
1690
1691 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1692 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1693 {
1694 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1695 continue;
1696 }
1697
1698 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1699
1700 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
1701 {
1702 new_select = ri;
1703 }
1704 }
1705
1706 /* Now that we know which path is the bestpath see if any of the other paths
1707 * qualify as multipaths
1708 */
1709 if (debug)
1710 {
1711 if (new_select)
1712 bgp_info_path_with_addpath_rx_str (new_select, path_buf);
1713 else
1714 sprintf (path_buf, "NONE");
1715 zlog_debug("%s: After path selection, newbest is %s oldbest was %s",
1716 pfx_buf, path_buf,
1717 old_select ? old_select->peer->host : "NONE");
1718 }
1719
1720 if (do_mpath && new_select)
1721 {
1722 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1723 {
1724
1725 if (debug)
1726 bgp_info_path_with_addpath_rx_str (ri, path_buf);
1727
1728 if (ri == new_select)
1729 {
1730 if (debug)
1731 zlog_debug("%s: %s is the bestpath, add to the multipath list",
1732 pfx_buf, path_buf);
1733 bgp_mp_list_add (&mp_list, ri);
1734 continue;
1735 }
1736
1737 if (BGP_INFO_HOLDDOWN (ri))
1738 continue;
1739
1740 if (ri->peer &&
1741 ri->peer != bgp->peer_self &&
1742 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1743 if (ri->peer->status != Established)
1744 continue;
1745
1746 if (!bgp_info_nexthop_cmp (ri, new_select))
1747 {
1748 if (debug)
1749 zlog_debug("%s: %s has the same nexthop as the bestpath, skip it",
1750 pfx_buf, path_buf);
1751 continue;
1752 }
1753
1754 bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
1755
1756 if (paths_eq)
1757 {
1758 if (debug)
1759 zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list",
1760 pfx_buf, path_buf);
1761 bgp_mp_list_add (&mp_list, ri);
1762 }
1763 }
1764 }
1765
1766 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1767 bgp_info_mpath_aggregate_update (new_select, old_select);
1768 bgp_mp_list_clear (&mp_list);
1769
1770 result->old = old_select;
1771 result->new = new_select;
1772
1773 return;
1774 }
1775
1776 /*
1777 * A new route/change in bestpath of an existing route. Evaluate the path
1778 * for advertisement to the subgroup.
1779 */
1780 int
1781 subgroup_process_announce_selected (struct update_subgroup *subgrp,
1782 struct bgp_info *selected,
1783 struct bgp_node *rn,
1784 u_int32_t addpath_tx_id)
1785 {
1786 struct prefix *p;
1787 struct peer *onlypeer;
1788 struct attr attr;
1789 struct attr_extra extra;
1790 afi_t afi;
1791 safi_t safi;
1792
1793 p = &rn->p;
1794 afi = SUBGRP_AFI(subgrp);
1795 safi = SUBGRP_SAFI(subgrp);
1796 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ?
1797 (SUBGRP_PFIRST(subgrp))->peer : NULL);
1798
1799 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1800 if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi],
1801 PEER_STATUS_ORF_WAIT_REFRESH))
1802 return 0;
1803
1804 memset(&extra, 0, sizeof(struct attr_extra));
1805 /* It's initialized in bgp_announce_check() */
1806 attr.extra = &extra;
1807
1808 /* Announcement to the subgroup. If the route is filtered withdraw it. */
1809 if (selected)
1810 {
1811 if (subgroup_announce_check(selected, subgrp, p, &attr))
1812 bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected);
1813 else
1814 bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id);
1815 }
1816
1817 /* If selected is NULL we must withdraw the path using addpath_tx_id */
1818 else
1819 {
1820 bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id);
1821 }
1822
1823 return 0;
1824 }
1825
1826 /*
1827 * Clear IGP changed flag and attribute changed flag for a route (all paths).
1828 * This is called at the end of route processing.
1829 */
1830 static void
1831 bgp_zebra_clear_route_change_flags (struct bgp_node *rn)
1832 {
1833 struct bgp_info *ri;
1834
1835 for (ri = rn->info; ri; ri = ri->next)
1836 {
1837 if (BGP_INFO_HOLDDOWN (ri))
1838 continue;
1839 UNSET_FLAG (ri->flags, BGP_INFO_IGP_CHANGED);
1840 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1841 }
1842 }
1843
1844 /*
1845 * Has the route changed from the RIB's perspective? This is invoked only
1846 * if the route selection returns the same best route as earlier - to
1847 * determine if we need to update zebra or not.
1848 */
1849 static int
1850 bgp_zebra_has_route_changed (struct bgp_node *rn, struct bgp_info *selected)
1851 {
1852 struct bgp_info *mpinfo;
1853
1854 /* If this is multipath, check all selected paths for any nexthop change or
1855 * attribute change. Some attribute changes (e.g., community) aren't of
1856 * relevance to the RIB, but we'll update zebra to ensure we handle the
1857 * case of BGP nexthop change. This is the behavior when the best path has
1858 * an attribute change anyway.
1859 */
1860 if (CHECK_FLAG (selected->flags, BGP_INFO_IGP_CHANGED) ||
1861 CHECK_FLAG (selected->flags, BGP_INFO_MULTIPATH_CHG))
1862 return 1;
1863
1864 /* If this is multipath, check all selected paths for any nexthop change */
1865 for (mpinfo = bgp_info_mpath_first (selected); mpinfo;
1866 mpinfo = bgp_info_mpath_next (mpinfo))
1867 {
1868 if (CHECK_FLAG (mpinfo->flags, BGP_INFO_IGP_CHANGED)
1869 || CHECK_FLAG (mpinfo->flags, BGP_INFO_ATTR_CHANGED))
1870 return 1;
1871 }
1872
1873 /* Nothing has changed from the RIB's perspective. */
1874 return 0;
1875 }
1876
1877 struct bgp_process_queue
1878 {
1879 struct bgp *bgp;
1880 struct bgp_node *rn;
1881 afi_t afi;
1882 safi_t safi;
1883 };
1884
1885 static wq_item_status
1886 bgp_process_main (struct work_queue *wq, void *data)
1887 {
1888 struct bgp_process_queue *pq = data;
1889 struct bgp *bgp = pq->bgp;
1890 struct bgp_node *rn = pq->rn;
1891 afi_t afi = pq->afi;
1892 safi_t safi = pq->safi;
1893 struct prefix *p = &rn->p;
1894 struct bgp_info *new_select;
1895 struct bgp_info *old_select;
1896 struct bgp_info_pair old_and_new;
1897
1898 /* Is it end of initial update? (after startup) */
1899 if (!rn)
1900 {
1901 quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
1902 sizeof(bgp->update_delay_zebra_resume_time));
1903
1904 bgp->main_zebra_update_hold = 0;
1905 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1906 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1907 {
1908 bgp_zebra_announce_table(bgp, afi, safi);
1909 }
1910 bgp->main_peers_update_hold = 0;
1911
1912 bgp_start_routeadv(bgp);
1913 return WQ_SUCCESS;
1914 }
1915
1916 /* Best path selection. */
1917 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1918 old_select = old_and_new.old;
1919 new_select = old_and_new.new;
1920
1921 /* Nothing to do. */
1922 if (old_select && old_select == new_select &&
1923 !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) &&
1924 !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) &&
1925 !bgp->addpath_tx_used[afi][safi])
1926 {
1927 if (bgp_zebra_has_route_changed (rn, old_select))
1928 {
1929 #if ENABLE_BGP_VNC
1930 vnc_import_bgp_add_route(bgp, p, old_select);
1931 vnc_import_bgp_exterior_add_route(bgp, p, old_select);
1932 #endif
1933 bgp_zebra_announce (p, old_select, bgp, afi, safi);
1934 }
1935 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1936 bgp_zebra_clear_route_change_flags (rn);
1937 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1938 return WQ_SUCCESS;
1939 }
1940
1941 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1942 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1943
1944 /* bestpath has changed; bump version */
1945 if (old_select || new_select)
1946 {
1947 bgp_bump_version(rn);
1948
1949 if (!bgp->t_rmap_def_originate_eval)
1950 {
1951 bgp_lock (bgp);
1952 THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
1953 update_group_refresh_default_originate_route_map,
1954 bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
1955 }
1956 }
1957
1958 if (old_select)
1959 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1960 if (new_select)
1961 {
1962 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1963 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1964 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1965 }
1966
1967 #if ENABLE_BGP_VNC
1968 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
1969 if (old_select != new_select) {
1970 if (old_select) {
1971 vnc_import_bgp_exterior_del_route(bgp, p, old_select);
1972 vnc_import_bgp_del_route(bgp, p, old_select);
1973 }
1974 if (new_select) {
1975 vnc_import_bgp_exterior_add_route(bgp, p, new_select);
1976 vnc_import_bgp_add_route(bgp, p, new_select);
1977 }
1978 }
1979 }
1980 #endif
1981
1982 group_announce_route(bgp, afi, safi, rn, new_select);
1983
1984 /* FIB update. */
1985 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) &&
1986 (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) &&
1987 !bgp_option_check (BGP_OPT_NO_FIB))
1988 {
1989 if (new_select
1990 && new_select->type == ZEBRA_ROUTE_BGP
1991 && (new_select->sub_type == BGP_ROUTE_NORMAL ||
1992 new_select->sub_type == BGP_ROUTE_AGGREGATE))
1993 bgp_zebra_announce (p, new_select, bgp, afi, safi);
1994 else
1995 {
1996 /* Withdraw the route from the kernel. */
1997 if (old_select
1998 && old_select->type == ZEBRA_ROUTE_BGP
1999 && (old_select->sub_type == BGP_ROUTE_NORMAL ||
2000 old_select->sub_type == BGP_ROUTE_AGGREGATE))
2001 bgp_zebra_withdraw (p, old_select, safi);
2002 }
2003 }
2004
2005 /* Clear any route change flags. */
2006 bgp_zebra_clear_route_change_flags (rn);
2007
2008 /* Reap old select bgp_info, if it has been removed */
2009 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
2010 bgp_info_reap (rn, old_select);
2011
2012 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2013 return WQ_SUCCESS;
2014 }
2015
2016 static void
2017 bgp_processq_del (struct work_queue *wq, void *data)
2018 {
2019 struct bgp_process_queue *pq = data;
2020 struct bgp_table *table;
2021
2022 bgp_unlock (pq->bgp);
2023 if (pq->rn)
2024 {
2025 table = bgp_node_table (pq->rn);
2026 bgp_unlock_node (pq->rn);
2027 bgp_table_unlock (table);
2028 }
2029 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
2030 }
2031
2032 void
2033 bgp_process_queue_init (void)
2034 {
2035 if (!bm->process_main_queue)
2036 {
2037 bm->process_main_queue
2038 = work_queue_new (bm->master, "process_main_queue");
2039
2040 if ( !bm->process_main_queue)
2041 {
2042 zlog_err ("%s: Failed to allocate work queue", __func__);
2043 exit (1);
2044 }
2045 }
2046
2047 bm->process_main_queue->spec.workfunc = &bgp_process_main;
2048 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
2049 bm->process_main_queue->spec.max_retries = 0;
2050 bm->process_main_queue->spec.hold = 50;
2051 /* Use a higher yield value of 50ms for main queue processing */
2052 bm->process_main_queue->spec.yield = 50 * 1000L;
2053 }
2054
2055 void
2056 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
2057 {
2058 struct bgp_process_queue *pqnode;
2059
2060 /* already scheduled for processing? */
2061 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
2062 return;
2063
2064 if (bm->process_main_queue == NULL)
2065 bgp_process_queue_init ();
2066
2067 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2068 sizeof (struct bgp_process_queue));
2069 if (!pqnode)
2070 return;
2071
2072 /* all unlocked in bgp_processq_del */
2073 bgp_table_lock (bgp_node_table (rn));
2074 pqnode->rn = bgp_lock_node (rn);
2075 pqnode->bgp = bgp;
2076 bgp_lock (bgp);
2077 pqnode->afi = afi;
2078 pqnode->safi = safi;
2079 work_queue_add (bm->process_main_queue, pqnode);
2080 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
2081 return;
2082 }
2083
2084 void
2085 bgp_add_eoiu_mark (struct bgp *bgp)
2086 {
2087 struct bgp_process_queue *pqnode;
2088
2089 if (bm->process_main_queue == NULL)
2090 bgp_process_queue_init ();
2091
2092 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
2093 sizeof (struct bgp_process_queue));
2094 if (!pqnode)
2095 return;
2096
2097 pqnode->rn = NULL;
2098 pqnode->bgp = bgp;
2099 bgp_lock (bgp);
2100 work_queue_add (bm->process_main_queue, pqnode);
2101 }
2102
2103 static int
2104 bgp_maximum_prefix_restart_timer (struct thread *thread)
2105 {
2106 struct peer *peer;
2107
2108 peer = THREAD_ARG (thread);
2109 peer->t_pmax_restart = NULL;
2110
2111 if (bgp_debug_neighbor_events(peer))
2112 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
2113 peer->host);
2114
2115 peer_clear (peer, NULL);
2116
2117 return 0;
2118 }
2119
2120 int
2121 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
2122 safi_t safi, int always)
2123 {
2124 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
2125 return 0;
2126
2127 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
2128 {
2129 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
2130 && ! always)
2131 return 0;
2132
2133 zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
2134 "limit %ld", afi_safi_print (afi, safi), peer->host,
2135 peer->pcount[afi][safi], peer->pmax[afi][safi]);
2136 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2137
2138 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
2139 return 0;
2140
2141 {
2142 u_int8_t ndata[7];
2143
2144 if (safi == SAFI_MPLS_VPN)
2145 safi = SAFI_MPLS_LABELED_VPN;
2146
2147 ndata[0] = (afi >> 8);
2148 ndata[1] = afi;
2149 ndata[2] = safi;
2150 ndata[3] = (peer->pmax[afi][safi] >> 24);
2151 ndata[4] = (peer->pmax[afi][safi] >> 16);
2152 ndata[5] = (peer->pmax[afi][safi] >> 8);
2153 ndata[6] = (peer->pmax[afi][safi]);
2154
2155 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
2156 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
2157 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
2158 }
2159
2160 /* Dynamic peers will just close their connection. */
2161 if (peer_dynamic_neighbor (peer))
2162 return 1;
2163
2164 /* restart timer start */
2165 if (peer->pmax_restart[afi][safi])
2166 {
2167 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
2168
2169 if (bgp_debug_neighbor_events(peer))
2170 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
2171 peer->host, peer->v_pmax_restart);
2172
2173 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
2174 peer->v_pmax_restart);
2175 }
2176
2177 return 1;
2178 }
2179 else
2180 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
2181
2182 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
2183 {
2184 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
2185 && ! always)
2186 return 0;
2187
2188 zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
2189 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
2190 peer->pmax[afi][safi]);
2191 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2192 }
2193 else
2194 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
2195 return 0;
2196 }
2197
2198 /* Unconditionally remove the route from the RIB, without taking
2199 * damping into consideration (eg, because the session went down)
2200 */
2201 static void
2202 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2203 afi_t afi, safi_t safi)
2204 {
2205 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2206
2207 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2208 bgp_info_delete (rn, ri); /* keep historical info */
2209
2210 bgp_process (peer->bgp, rn, afi, safi);
2211 }
2212
2213 static void
2214 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
2215 afi_t afi, safi_t safi, struct prefix_rd *prd)
2216 {
2217 int status = BGP_DAMP_NONE;
2218
2219 /* apply dampening, if result is suppressed, we'll be retaining
2220 * the bgp_info in the RIB for historical reference.
2221 */
2222 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2223 && peer->sort == BGP_PEER_EBGP)
2224 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
2225 == BGP_DAMP_SUPPRESSED)
2226 {
2227 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
2228 return;
2229 }
2230
2231 #if ENABLE_BGP_VNC
2232 if (safi == SAFI_MPLS_VPN) {
2233 struct bgp_node *prn = NULL;
2234 struct bgp_table *table = NULL;
2235
2236 prn = bgp_node_get(peer->bgp->rib[afi][safi], (struct prefix *) prd);
2237 if (prn->info) {
2238 table = (struct bgp_table *)(prn->info);
2239
2240 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2241 peer->bgp,
2242 prd,
2243 table,
2244 &rn->p,
2245 ri);
2246 }
2247 bgp_unlock_node(prn);
2248 }
2249 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2250 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2251
2252 vnc_import_bgp_del_route(peer->bgp, &rn->p, ri);
2253 vnc_import_bgp_exterior_del_route(peer->bgp, &rn->p, ri);
2254 }
2255 }
2256 #endif
2257 bgp_rib_remove (rn, ri, peer, afi, safi);
2258 }
2259
2260 static struct bgp_info *
2261 info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
2262 struct bgp_node *rn)
2263 {
2264 struct bgp_info *new;
2265
2266 /* Make new BGP info. */
2267 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
2268 new->type = type;
2269 new->instance = instance;
2270 new->sub_type = sub_type;
2271 new->peer = peer;
2272 new->attr = attr;
2273 new->uptime = bgp_clock ();
2274 new->net = rn;
2275 new->addpath_tx_id = ++peer->bgp->addpath_tx_id;
2276 return new;
2277 }
2278
2279 static void
2280 bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
2281 {
2282 if (addpath_id)
2283 sprintf(buf, " with addpath ID %d", addpath_id);
2284 }
2285
2286
2287 /* Check if received nexthop is valid or not. */
2288 static int
2289 bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
2290 {
2291 struct attr_extra *attre = attr->extra;
2292 int ret = 0;
2293
2294 /* Only validated for unicast and multicast currently. */
2295 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2296 return 0;
2297
2298 /* If NEXT_HOP is present, validate it. */
2299 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2300 {
2301 if (attr->nexthop.s_addr == 0 ||
2302 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2303 bgp_nexthop_self (bgp, attr))
2304 ret = 1;
2305 }
2306
2307 /* If MP_NEXTHOP is present, validate it. */
2308 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2309 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2310 * it is not an IPv6 link-local address.
2311 */
2312 if (attre && attre->mp_nexthop_len)
2313 {
2314 switch (attre->mp_nexthop_len)
2315 {
2316 case BGP_ATTR_NHLEN_IPV4:
2317 case BGP_ATTR_NHLEN_VPNV4:
2318 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2319 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2320 break;
2321
2322 #ifdef HAVE_IPV6
2323 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2324 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2325 case BGP_ATTR_NHLEN_VPNV6_GLOBAL:
2326 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2327 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2328 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2329 break;
2330 #endif /* HAVE_IPV6 */
2331
2332 default:
2333 ret = 1;
2334 break;
2335 }
2336 }
2337
2338 return ret;
2339 }
2340
2341 int
2342 bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2343 struct attr *attr, afi_t afi, safi_t safi, int type,
2344 int sub_type, struct prefix_rd *prd, u_char *tag,
2345 int soft_reconfig)
2346 {
2347 int ret;
2348 int aspath_loop_count = 0;
2349 struct bgp_node *rn;
2350 struct bgp *bgp;
2351 struct attr new_attr;
2352 struct attr_extra new_extra;
2353 struct attr *attr_new;
2354 struct bgp_info *ri;
2355 struct bgp_info *new;
2356 const char *reason;
2357 char buf[SU_ADDRSTRLEN];
2358 char buf2[30];
2359 int connected = 0;
2360 int do_loop_check = 1;
2361 #if ENABLE_BGP_VNC
2362 int vnc_implicit_withdraw = 0;
2363 #endif
2364
2365 memset (&new_attr, 0, sizeof(struct attr));
2366 memset (&new_extra, 0, sizeof(struct attr_extra));
2367
2368 bgp = peer->bgp;
2369 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2370
2371 /* When peer's soft reconfiguration enabled. Record input packet in
2372 Adj-RIBs-In. */
2373 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2374 && peer != bgp->peer_self)
2375 bgp_adj_in_set (rn, peer, attr, addpath_id);
2376
2377 /* Check previously received route. */
2378 for (ri = rn->info; ri; ri = ri->next)
2379 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2380 ri->addpath_rx_id == addpath_id)
2381 break;
2382
2383 /* AS path local-as loop check. */
2384 if (peer->change_local_as)
2385 {
2386 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2387 aspath_loop_count = 1;
2388
2389 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2390 {
2391 reason = "as-path contains our own AS;";
2392 goto filtered;
2393 }
2394 }
2395
2396 /* If the peer is configured for "allowas-in origin" and the last ASN in the
2397 * as-path is our ASN then we do not need to call aspath_loop_check
2398 */
2399 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN_ORIGIN))
2400 if (aspath_get_last_as(attr->aspath) == bgp->as)
2401 do_loop_check = 0;
2402
2403 /* AS path loop check. */
2404 if (do_loop_check)
2405 {
2406 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2407 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2408 && aspath_loop_check(attr->aspath, bgp->confed_id) > peer->allowas_in[afi][safi]))
2409 {
2410 reason = "as-path contains our own AS;";
2411 goto filtered;
2412 }
2413 }
2414
2415 /* Route reflector originator ID check. */
2416 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2417 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2418 {
2419 reason = "originator is us;";
2420 goto filtered;
2421 }
2422
2423 /* Route reflector cluster ID check. */
2424 if (bgp_cluster_filter (peer, attr))
2425 {
2426 reason = "reflected from the same cluster;";
2427 goto filtered;
2428 }
2429
2430 /* Apply incoming filter. */
2431 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2432 {
2433 reason = "filter;";
2434 goto filtered;
2435 }
2436
2437 new_attr.extra = &new_extra;
2438 bgp_attr_dup (&new_attr, attr);
2439
2440 /* Apply incoming route-map.
2441 * NB: new_attr may now contain newly allocated values from route-map "set"
2442 * commands, so we need bgp_attr_flush in the error paths, until we intern
2443 * the attr (which takes over the memory references) */
2444 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2445 {
2446 reason = "route-map;";
2447 bgp_attr_flush (&new_attr);
2448 goto filtered;
2449 }
2450
2451 /* next hop check. */
2452 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
2453 {
2454 reason = "martian or self next-hop;";
2455 bgp_attr_flush (&new_attr);
2456 goto filtered;
2457 }
2458
2459 attr_new = bgp_attr_intern (&new_attr);
2460
2461 /* If the update is implicit withdraw. */
2462 if (ri)
2463 {
2464 ri->uptime = bgp_clock ();
2465
2466 /* Same attribute comes in. */
2467 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2468 && attrhash_cmp (ri->attr, attr_new))
2469 {
2470 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2471 && peer->sort == BGP_PEER_EBGP
2472 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2473 {
2474 if (bgp_debug_update(peer, p, NULL, 1))
2475 {
2476 bgp_info_addpath_rx_str(addpath_id, buf2);
2477 zlog_debug ("%s rcvd %s/%d%s",
2478 peer->host,
2479 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2480 p->prefixlen, buf2);
2481 }
2482
2483 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2484 {
2485 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2486 bgp_process (bgp, rn, afi, safi);
2487 }
2488 }
2489 else /* Duplicate - odd */
2490 {
2491 if (bgp_debug_update(peer, p, NULL, 1))
2492 {
2493 if (!peer->rcvd_attr_printed)
2494 {
2495 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2496 peer->rcvd_attr_printed = 1;
2497 }
2498
2499 bgp_info_addpath_rx_str(addpath_id, buf2);
2500 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
2501 peer->host,
2502 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2503 p->prefixlen, buf2);
2504 }
2505
2506 /* graceful restart STALE flag unset. */
2507 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2508 {
2509 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2510 bgp_process (bgp, rn, afi, safi);
2511 }
2512 }
2513
2514 bgp_unlock_node (rn);
2515 bgp_attr_unintern (&attr_new);
2516
2517 return 0;
2518 }
2519
2520 /* Withdraw/Announce before we fully processed the withdraw */
2521 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2522 {
2523 if (bgp_debug_update(peer, p, NULL, 1))
2524 {
2525 bgp_info_addpath_rx_str(addpath_id, buf2);
2526 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2527 peer->host,
2528 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2529 p->prefixlen, buf2);
2530 }
2531 bgp_info_restore (rn, ri);
2532 }
2533
2534 /* Received Logging. */
2535 if (bgp_debug_update(peer, p, NULL, 1))
2536 {
2537 bgp_info_addpath_rx_str(addpath_id, buf2);
2538 zlog_debug ("%s rcvd %s/%d%s",
2539 peer->host,
2540 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2541 p->prefixlen, buf2);
2542 }
2543
2544 /* graceful restart STALE flag unset. */
2545 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2546 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2547
2548 /* The attribute is changed. */
2549 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2550
2551 /* implicit withdraw, decrement aggregate and pcount here.
2552 * only if update is accepted, they'll increment below.
2553 */
2554 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2555
2556 /* Update bgp route dampening information. */
2557 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2558 && peer->sort == BGP_PEER_EBGP)
2559 {
2560 /* This is implicit withdraw so we should update dampening
2561 information. */
2562 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2563 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2564 }
2565 #if ENABLE_BGP_VNC
2566 if (safi == SAFI_MPLS_VPN) {
2567 struct bgp_node *prn = NULL;
2568 struct bgp_table *table = NULL;
2569
2570 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2571 if (prn->info) {
2572 table = (struct bgp_table *)(prn->info);
2573
2574 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2575 bgp,
2576 prd,
2577 table,
2578 p,
2579 ri);
2580 }
2581 bgp_unlock_node(prn);
2582 }
2583 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2584 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2585 /*
2586 * Implicit withdraw case.
2587 */
2588 ++vnc_implicit_withdraw;
2589 vnc_import_bgp_del_route(bgp, p, ri);
2590 vnc_import_bgp_exterior_del_route(bgp, p, ri);
2591 }
2592 }
2593 #endif
2594
2595 /* Update to new attribute. */
2596 bgp_attr_unintern (&ri->attr);
2597 ri->attr = attr_new;
2598
2599 /* Update MPLS tag. */
2600 if (safi == SAFI_MPLS_VPN)
2601 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2602
2603 #if ENABLE_BGP_VNC
2604 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
2605 {
2606 if (vnc_implicit_withdraw)
2607 {
2608 /*
2609 * Add back the route with its new attributes (e.g., nexthop).
2610 * The route is still selected, until the route selection
2611 * queued by bgp_process actually runs. We have to make this
2612 * update to the VNC side immediately to avoid racing against
2613 * configuration changes (e.g., route-map changes) which
2614 * trigger re-importation of the entire RIB.
2615 */
2616 vnc_import_bgp_add_route(bgp, p, ri);
2617 vnc_import_bgp_exterior_add_route(bgp, p, ri);
2618 }
2619 }
2620 #endif
2621
2622 /* Update bgp route dampening information. */
2623 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2624 && peer->sort == BGP_PEER_EBGP)
2625 {
2626 /* Now we do normal update dampening. */
2627 ret = bgp_damp_update (ri, rn, afi, safi);
2628 if (ret == BGP_DAMP_SUPPRESSED)
2629 {
2630 bgp_unlock_node (rn);
2631 return 0;
2632 }
2633 }
2634
2635 /* Nexthop reachability check. */
2636 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2637 {
2638 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2639 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2640 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2641 connected = 1;
2642 else
2643 connected = 0;
2644
2645 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
2646 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2647 else
2648 {
2649 if (BGP_DEBUG(nht, NHT))
2650 {
2651 char buf1[INET6_ADDRSTRLEN];
2652 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2653 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2654 }
2655 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2656 }
2657 }
2658 else
2659 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2660
2661 #if ENABLE_BGP_VNC
2662 if (safi == SAFI_MPLS_VPN)
2663 {
2664 struct bgp_node *prn = NULL;
2665 struct bgp_table *table = NULL;
2666
2667 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2668 if (prn->info)
2669 {
2670 table = (struct bgp_table *)(prn->info);
2671
2672 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2673 bgp,
2674 prd,
2675 table,
2676 p,
2677 ri);
2678 }
2679 bgp_unlock_node(prn);
2680 }
2681 #endif
2682
2683 /* Process change. */
2684 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2685
2686 bgp_process (bgp, rn, afi, safi);
2687 bgp_unlock_node (rn);
2688
2689 #if ENABLE_BGP_VNC
2690 if (SAFI_MPLS_VPN == safi)
2691 {
2692 uint32_t label = decode_label(tag);
2693
2694 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2695 &label);
2696 }
2697 if (SAFI_ENCAP == safi)
2698 {
2699 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2700 NULL);
2701 }
2702 #endif
2703
2704 return 0;
2705 } // End of implicit withdraw
2706
2707 /* Received Logging. */
2708 if (bgp_debug_update(peer, p, NULL, 1))
2709 {
2710 if (!peer->rcvd_attr_printed)
2711 {
2712 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2713 peer->rcvd_attr_printed = 1;
2714 }
2715
2716 bgp_info_addpath_rx_str(addpath_id, buf2);
2717 zlog_debug ("%s rcvd %s/%d%s",
2718 peer->host,
2719 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2720 p->prefixlen, buf2);
2721 }
2722
2723 /* Make new BGP info. */
2724 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2725
2726 /* Update MPLS tag. */
2727 if (safi == SAFI_MPLS_VPN)
2728 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2729
2730 /* Nexthop reachability check. */
2731 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2732 {
2733 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2734 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2735 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2736 connected = 1;
2737 else
2738 connected = 0;
2739
2740 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
2741 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2742 else
2743 {
2744 if (BGP_DEBUG(nht, NHT))
2745 {
2746 char buf1[INET6_ADDRSTRLEN];
2747 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2748 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2749 }
2750 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2751 }
2752 }
2753 else
2754 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2755
2756 /* Addpath ID */
2757 new->addpath_rx_id = addpath_id;
2758
2759 /* Increment prefix */
2760 bgp_aggregate_increment (bgp, p, new, afi, safi);
2761
2762 /* Register new BGP information. */
2763 bgp_info_add (rn, new);
2764
2765 /* route_node_get lock */
2766 bgp_unlock_node (rn);
2767
2768 #if ENABLE_BGP_VNC
2769 if (safi == SAFI_MPLS_VPN)
2770 {
2771 struct bgp_node *prn = NULL;
2772 struct bgp_table *table = NULL;
2773
2774 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2775 if (prn->info)
2776 {
2777 table = (struct bgp_table *)(prn->info);
2778
2779 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2780 bgp,
2781 prd,
2782 table,
2783 p,
2784 new);
2785 }
2786 bgp_unlock_node(prn);
2787 }
2788 #endif
2789
2790 /* If maximum prefix count is configured and current prefix
2791 count exeed it. */
2792 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2793 return -1;
2794
2795 /* Process change. */
2796 bgp_process (bgp, rn, afi, safi);
2797
2798 #if ENABLE_BGP_VNC
2799 if (SAFI_MPLS_VPN == safi)
2800 {
2801 uint32_t label = decode_label(tag);
2802
2803 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2804 &label);
2805 }
2806 if (SAFI_ENCAP == safi)
2807 {
2808 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2809 NULL);
2810 }
2811 #endif
2812
2813 return 0;
2814
2815 /* This BGP update is filtered. Log the reason then update BGP
2816 entry. */
2817 filtered:
2818 if (bgp_debug_update(peer, p, NULL, 1))
2819 {
2820 if (!peer->rcvd_attr_printed)
2821 {
2822 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2823 peer->rcvd_attr_printed = 1;
2824 }
2825
2826 bgp_info_addpath_rx_str(addpath_id, buf2);
2827 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
2828 peer->host,
2829 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2830 p->prefixlen, buf2, reason);
2831 }
2832
2833 if (ri)
2834 bgp_rib_remove (rn, ri, peer, afi, safi);
2835
2836 bgp_unlock_node (rn);
2837
2838 return 0;
2839 }
2840
2841 int
2842 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2843 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2844 struct prefix_rd *prd, u_char *tag)
2845 {
2846 struct bgp *bgp;
2847 char buf[SU_ADDRSTRLEN];
2848 char buf2[30];
2849 struct bgp_node *rn;
2850 struct bgp_info *ri;
2851
2852 #if ENABLE_BGP_VNC
2853 if ((SAFI_MPLS_VPN == safi) || (SAFI_ENCAP == safi))
2854 {
2855 rfapiProcessWithdraw(peer, NULL, p, prd, NULL, afi, safi, type, 0);
2856 }
2857 #endif
2858
2859 bgp = peer->bgp;
2860
2861 /* Lookup node. */
2862 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2863
2864 /* If peer is soft reconfiguration enabled. Record input packet for
2865 * further calculation.
2866 *
2867 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2868 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2869 * the iteration over all RS clients.
2870 * Since we need to remove the entry from adj_in anyway, do that first and
2871 * if there was no entry, we don't need to do anything more.
2872 */
2873 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2874 && peer != bgp->peer_self)
2875 if (!bgp_adj_in_unset (rn, peer, addpath_id))
2876 {
2877 if (bgp_debug_update (peer, p, NULL, 1))
2878 zlog_debug ("%s withdrawing route %s/%d "
2879 "not in adj-in", peer->host,
2880 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2881 p->prefixlen);
2882 bgp_unlock_node (rn);
2883 return 0;
2884 }
2885
2886 /* Lookup withdrawn route. */
2887 for (ri = rn->info; ri; ri = ri->next)
2888 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2889 ri->addpath_rx_id == addpath_id)
2890 break;
2891
2892 /* Logging. */
2893 if (bgp_debug_update(peer, p, NULL, 1))
2894 {
2895 bgp_info_addpath_rx_str(addpath_id, buf2);
2896 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2897 peer->host,
2898 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2899 p->prefixlen, buf2);
2900 }
2901
2902 /* Withdraw specified route from routing table. */
2903 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2904 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
2905 else if (bgp_debug_update(peer, p, NULL, 1))
2906 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2907 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2908 p->prefixlen);
2909
2910 /* Unlock bgp_node_get() lock. */
2911 bgp_unlock_node (rn);
2912
2913 return 0;
2914 }
2915
2916 void
2917 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2918 {
2919 struct update_subgroup *subgrp;
2920 subgrp = peer_subgroup(peer, afi, safi);
2921 subgroup_default_originate(subgrp, withdraw);
2922 }
2923
2924
2925 /*
2926 * bgp_stop_announce_route_timer
2927 */
2928 void
2929 bgp_stop_announce_route_timer (struct peer_af *paf)
2930 {
2931 if (!paf->t_announce_route)
2932 return;
2933
2934 THREAD_TIMER_OFF (paf->t_announce_route);
2935 }
2936
2937 /*
2938 * bgp_announce_route_timer_expired
2939 *
2940 * Callback that is invoked when the route announcement timer for a
2941 * peer_af expires.
2942 */
2943 static int
2944 bgp_announce_route_timer_expired (struct thread *t)
2945 {
2946 struct peer_af *paf;
2947 struct peer *peer;
2948
2949 paf = THREAD_ARG (t);
2950 peer = paf->peer;
2951
2952 assert (paf->t_announce_route);
2953 paf->t_announce_route = NULL;
2954
2955 if (peer->status != Established)
2956 return 0;
2957
2958 if (!peer->afc_nego[paf->afi][paf->safi])
2959 return 0;
2960
2961 peer_af_announce_route (paf, 1);
2962 return 0;
2963 }
2964
2965 /*
2966 * bgp_announce_route
2967 *
2968 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2969 */
2970 void
2971 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2972 {
2973 struct peer_af *paf;
2974 struct update_subgroup *subgrp;
2975
2976 paf = peer_af_find (peer, afi, safi);
2977 if (!paf)
2978 return;
2979 subgrp = PAF_SUBGRP(paf);
2980
2981 /*
2982 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2983 * or a refresh has already been triggered.
2984 */
2985 if (!subgrp || paf->t_announce_route)
2986 return;
2987
2988 /*
2989 * Start a timer to stagger/delay the announce. This serves
2990 * two purposes - announcement can potentially be combined for
2991 * multiple peers and the announcement doesn't happen in the
2992 * vty context.
2993 */
2994 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
2995 bgp_announce_route_timer_expired, paf,
2996 (subgrp->peer_count == 1) ?
2997 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
2998 BGP_ANNOUNCE_ROUTE_DELAY_MS);
2999 }
3000
3001 /*
3002 * Announce routes from all AF tables to a peer.
3003 *
3004 * This should ONLY be called when there is a need to refresh the
3005 * routes to the peer based on a policy change for this peer alone
3006 * or a route refresh request received from the peer.
3007 * The operation will result in splitting the peer from its existing
3008 * subgroups and putting it in new subgroups.
3009 */
3010 void
3011 bgp_announce_route_all (struct peer *peer)
3012 {
3013 afi_t afi;
3014 safi_t safi;
3015
3016 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3017 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3018 bgp_announce_route (peer, afi, safi);
3019 }
3020
3021 static void
3022 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
3023 struct bgp_table *table, struct prefix_rd *prd)
3024 {
3025 int ret;
3026 struct bgp_node *rn;
3027 struct bgp_adj_in *ain;
3028
3029 if (! table)
3030 table = peer->bgp->rib[afi][safi];
3031
3032 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3033 for (ain = rn->adj_in; ain; ain = ain->next)
3034 {
3035 if (ain->peer == peer)
3036 {
3037 struct bgp_info *ri = rn->info;
3038 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
3039
3040 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
3041 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
3042 prd, tag, 1);
3043
3044 if (ret < 0)
3045 {
3046 bgp_unlock_node (rn);
3047 return;
3048 }
3049 }
3050 }
3051 }
3052
3053 void
3054 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3055 {
3056 struct bgp_node *rn;
3057 struct bgp_table *table;
3058
3059 if (peer->status != Established)
3060 return;
3061
3062 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
3063 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
3064 else
3065 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3066 rn = bgp_route_next (rn))
3067 if ((table = rn->info) != NULL)
3068 {
3069 struct prefix_rd prd;
3070 prd.family = AF_UNSPEC;
3071 prd.prefixlen = 64;
3072 memcpy(&prd.val, rn->p.u.val, 8);
3073
3074 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3075 }
3076 }
3077
3078
3079 struct bgp_clear_node_queue
3080 {
3081 struct bgp_node *rn;
3082 };
3083
3084 static wq_item_status
3085 bgp_clear_route_node (struct work_queue *wq, void *data)
3086 {
3087 struct bgp_clear_node_queue *cnq = data;
3088 struct bgp_node *rn = cnq->rn;
3089 struct peer *peer = wq->spec.data;
3090 struct bgp_info *ri;
3091 afi_t afi = bgp_node_table (rn)->afi;
3092 safi_t safi = bgp_node_table (rn)->safi;
3093
3094 assert (rn && peer);
3095
3096 /* It is possible that we have multiple paths for a prefix from a peer
3097 * if that peer is using AddPath.
3098 */
3099 for (ri = rn->info; ri; ri = ri->next)
3100 if (ri->peer == peer)
3101 {
3102 /* graceful restart STALE flag set. */
3103 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3104 && peer->nsf[afi][safi]
3105 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
3106 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3107 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
3108 else
3109 bgp_rib_remove (rn, ri, peer, afi, safi);
3110 }
3111 return WQ_SUCCESS;
3112 }
3113
3114 static void
3115 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
3116 {
3117 struct bgp_clear_node_queue *cnq = data;
3118 struct bgp_node *rn = cnq->rn;
3119 struct bgp_table *table = bgp_node_table (rn);
3120
3121 bgp_unlock_node (rn);
3122 bgp_table_unlock (table);
3123 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
3124 }
3125
3126 static void
3127 bgp_clear_node_complete (struct work_queue *wq)
3128 {
3129 struct peer *peer = wq->spec.data;
3130
3131 /* Tickle FSM to start moving again */
3132 BGP_EVENT_ADD (peer, Clearing_Completed);
3133
3134 peer_unlock (peer); /* bgp_clear_route */
3135 }
3136
3137 static void
3138 bgp_clear_node_queue_init (struct peer *peer)
3139 {
3140 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
3141
3142 snprintf (wname, sizeof(wname), "clear %s", peer->host);
3143 #undef CLEAR_QUEUE_NAME_LEN
3144
3145 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
3146 {
3147 zlog_err ("%s: Failed to allocate work queue", __func__);
3148 exit (1);
3149 }
3150 peer->clear_node_queue->spec.hold = 10;
3151 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3152 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3153 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3154 peer->clear_node_queue->spec.max_retries = 0;
3155
3156 /* we only 'lock' this peer reference when the queue is actually active */
3157 peer->clear_node_queue->spec.data = peer;
3158 }
3159
3160 static void
3161 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
3162 struct bgp_table *table)
3163 {
3164 struct bgp_node *rn;
3165 int force = bm->process_main_queue ? 0 : 1;
3166
3167 if (! table)
3168 table = peer->bgp->rib[afi][safi];
3169
3170 /* If still no table => afi/safi isn't configured at all or smth. */
3171 if (! table)
3172 return;
3173
3174 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3175 {
3176 struct bgp_info *ri, *next;
3177 struct bgp_adj_in *ain;
3178 struct bgp_adj_in *ain_next;
3179
3180 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3181 * queued for every clearing peer, regardless of whether it is
3182 * relevant to the peer at hand.
3183 *
3184 * Overview: There are 3 different indices which need to be
3185 * scrubbed, potentially, when a peer is removed:
3186 *
3187 * 1 peer's routes visible via the RIB (ie accepted routes)
3188 * 2 peer's routes visible by the (optional) peer's adj-in index
3189 * 3 other routes visible by the peer's adj-out index
3190 *
3191 * 3 there is no hurry in scrubbing, once the struct peer is
3192 * removed from bgp->peer, we could just GC such deleted peer's
3193 * adj-outs at our leisure.
3194 *
3195 * 1 and 2 must be 'scrubbed' in some way, at least made
3196 * invisible via RIB index before peer session is allowed to be
3197 * brought back up. So one needs to know when such a 'search' is
3198 * complete.
3199 *
3200 * Ideally:
3201 *
3202 * - there'd be a single global queue or a single RIB walker
3203 * - rather than tracking which route_nodes still need to be
3204 * examined on a peer basis, we'd track which peers still
3205 * aren't cleared
3206 *
3207 * Given that our per-peer prefix-counts now should be reliable,
3208 * this may actually be achievable. It doesn't seem to be a huge
3209 * problem at this time,
3210 *
3211 * It is possible that we have multiple paths for a prefix from a peer
3212 * if that peer is using AddPath.
3213 */
3214 ain = rn->adj_in;
3215 while (ain)
3216 {
3217 ain_next = ain->next;
3218
3219 if (ain->peer == peer)
3220 {
3221 bgp_adj_in_remove (rn, ain);
3222 bgp_unlock_node (rn);
3223 }
3224
3225 ain = ain_next;
3226 }
3227
3228 for (ri = rn->info; ri; ri = next)
3229 {
3230 next = ri->next;
3231 if (ri->peer != peer)
3232 continue;
3233
3234 if (force)
3235 bgp_info_reap (rn, ri);
3236 else
3237 {
3238 struct bgp_clear_node_queue *cnq;
3239
3240 /* both unlocked in bgp_clear_node_queue_del */
3241 bgp_table_lock (bgp_node_table (rn));
3242 bgp_lock_node (rn);
3243 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3244 sizeof (struct bgp_clear_node_queue));
3245 cnq->rn = rn;
3246 work_queue_add (peer->clear_node_queue, cnq);
3247 break;
3248 }
3249 }
3250 }
3251 return;
3252 }
3253
3254 void
3255 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
3256 {
3257 struct bgp_node *rn;
3258 struct bgp_table *table;
3259
3260 if (peer->clear_node_queue == NULL)
3261 bgp_clear_node_queue_init (peer);
3262
3263 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3264 * Idle until it receives a Clearing_Completed event. This protects
3265 * against peers which flap faster than we can we clear, which could
3266 * lead to:
3267 *
3268 * a) race with routes from the new session being installed before
3269 * clear_route_node visits the node (to delete the route of that
3270 * peer)
3271 * b) resource exhaustion, clear_route_node likely leads to an entry
3272 * on the process_main queue. Fast-flapping could cause that queue
3273 * to grow and grow.
3274 */
3275
3276 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3277 * the unlock will happen upon work-queue completion; other wise, the
3278 * unlock happens at the end of this function.
3279 */
3280 if (!peer->clear_node_queue->thread)
3281 peer_lock (peer);
3282
3283 if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP)
3284 bgp_clear_route_table (peer, afi, safi, NULL);
3285 else
3286 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3287 rn = bgp_route_next (rn))
3288 if ((table = rn->info) != NULL)
3289 bgp_clear_route_table (peer, afi, safi, table);
3290
3291 /* unlock if no nodes got added to the clear-node-queue. */
3292 if (!peer->clear_node_queue->thread)
3293 peer_unlock (peer);
3294
3295 }
3296
3297 void
3298 bgp_clear_route_all (struct peer *peer)
3299 {
3300 afi_t afi;
3301 safi_t safi;
3302
3303 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3304 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3305 bgp_clear_route (peer, afi, safi);
3306
3307 #if ENABLE_BGP_VNC
3308 rfapiProcessPeerDown(peer);
3309 #endif
3310 }
3311
3312 void
3313 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3314 {
3315 struct bgp_table *table;
3316 struct bgp_node *rn;
3317 struct bgp_adj_in *ain;
3318 struct bgp_adj_in *ain_next;
3319
3320 table = peer->bgp->rib[afi][safi];
3321
3322 /* It is possible that we have multiple paths for a prefix from a peer
3323 * if that peer is using AddPath.
3324 */
3325 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3326 {
3327 ain = rn->adj_in;
3328
3329 while (ain)
3330 {
3331 ain_next = ain->next;
3332
3333 if (ain->peer == peer)
3334 {
3335 bgp_adj_in_remove (rn, ain);
3336 bgp_unlock_node (rn);
3337 }
3338
3339 ain = ain_next;
3340 }
3341 }
3342 }
3343
3344 void
3345 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3346 {
3347 struct bgp_node *rn;
3348 struct bgp_info *ri;
3349 struct bgp_table *table;
3350
3351 table = peer->bgp->rib[afi][safi];
3352
3353 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3354 {
3355 for (ri = rn->info; ri; ri = ri->next)
3356 if (ri->peer == peer)
3357 {
3358 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3359 bgp_rib_remove (rn, ri, peer, afi, safi);
3360 break;
3361 }
3362 }
3363 }
3364
3365 static void
3366 bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3367 {
3368 struct bgp_node *rn;
3369 struct bgp_info *ri;
3370 struct bgp_info *next;
3371
3372 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3373 for (ri = rn->info; ri; ri = next)
3374 {
3375 next = ri->next;
3376 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3377 && ri->type == ZEBRA_ROUTE_BGP
3378 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3379 ri->sub_type == BGP_ROUTE_AGGREGATE))
3380 {
3381 #if ENABLE_BGP_VNC
3382 if (table->owner && table->owner->bgp)
3383 vnc_import_bgp_del_route(table->owner->bgp, &rn->p, ri);
3384 #endif
3385 bgp_zebra_withdraw (&rn->p, ri, safi);
3386 bgp_info_reap (rn, ri);
3387 }
3388 }
3389 }
3390
3391 /* Delete all kernel routes. */
3392 void
3393 bgp_cleanup_routes (struct bgp *bgp)
3394 {
3395 afi_t afi;
3396
3397 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3398 {
3399 struct bgp_node *rn;
3400
3401 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
3402
3403 /*
3404 * VPN and ENCAP tables are two-level (RD is top level)
3405 */
3406 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3407 rn = bgp_route_next (rn))
3408 {
3409 if (rn->info)
3410 {
3411 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3412 bgp_table_finish ((struct bgp_table **)&(rn->info));
3413 rn->info = NULL;
3414 bgp_unlock_node(rn);
3415 }
3416 }
3417
3418 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3419 rn = bgp_route_next (rn))
3420 {
3421 if (rn->info)
3422 {
3423 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3424 bgp_table_finish ((struct bgp_table **)&(rn->info));
3425 rn->info = NULL;
3426 bgp_unlock_node(rn);
3427 }
3428 }
3429 }
3430 }
3431
3432 void
3433 bgp_reset (void)
3434 {
3435 vty_reset ();
3436 bgp_zclient_reset ();
3437 access_list_reset ();
3438 prefix_list_reset ();
3439 }
3440
3441 static int
3442 bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3443 {
3444 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3445 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3446 }
3447
3448 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3449 value. */
3450 int
3451 bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3452 struct bgp_nlri *packet)
3453 {
3454 u_char *pnt;
3455 u_char *lim;
3456 struct prefix p;
3457 int psize;
3458 int ret;
3459 afi_t afi;
3460 safi_t safi;
3461 int addpath_encoded;
3462 u_int32_t addpath_id;
3463
3464 /* Check peer status. */
3465 if (peer->status != Established)
3466 return 0;
3467
3468 pnt = packet->nlri;
3469 lim = pnt + packet->length;
3470 afi = packet->afi;
3471 safi = packet->safi;
3472 addpath_id = 0;
3473 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3474
3475 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3476 syntactic validity. If the field is syntactically incorrect,
3477 then the Error Subcode is set to Invalid Network Field. */
3478 for (; pnt < lim; pnt += psize)
3479 {
3480 /* Clear prefix structure. */
3481 memset (&p, 0, sizeof (struct prefix));
3482
3483 if (addpath_encoded)
3484 {
3485
3486 /* When packet overflow occurs return immediately. */
3487 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3488 return -1;
3489
3490 addpath_id = ntohl(*((uint32_t*) pnt));
3491 pnt += BGP_ADDPATH_ID_LEN;
3492 }
3493
3494 /* Fetch prefix length. */
3495 p.prefixlen = *pnt++;
3496 /* afi/safi validity already verified by caller, bgp_update_receive */
3497 p.family = afi2family (afi);
3498
3499 /* Prefix length check. */
3500 if (p.prefixlen > prefix_blen (&p) * 8)
3501 {
3502 zlog_err("%s [Error] Update packet error (wrong perfix length %d for afi %u)",
3503 peer->host, p.prefixlen, packet->afi);
3504 return -1;
3505 }
3506
3507 /* Packet size overflow check. */
3508 psize = PSIZE (p.prefixlen);
3509
3510 /* When packet overflow occur return immediately. */
3511 if (pnt + psize > lim)
3512 {
3513 zlog_err("%s [Error] Update packet error (prefix length %d overflows packet)",
3514 peer->host, p.prefixlen);
3515 return -1;
3516 }
3517
3518 /* Defensive coding, double-check the psize fits in a struct prefix */
3519 if (psize > (ssize_t) sizeof(p.u))
3520 {
3521 zlog_err("%s [Error] Update packet error (prefix length %d too large for prefix storage %zu)",
3522 peer->host, p.prefixlen, sizeof(p.u));
3523 return -1;
3524 }
3525
3526 /* Fetch prefix from NLRI packet. */
3527 memcpy (&p.u.prefix, pnt, psize);
3528
3529 /* Check address. */
3530 if (afi == AFI_IP && safi == SAFI_UNICAST)
3531 {
3532 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3533 {
3534 /* From RFC4271 Section 6.3:
3535 *
3536 * If a prefix in the NLRI field is semantically incorrect
3537 * (e.g., an unexpected multicast IP address), an error SHOULD
3538 * be logged locally, and the prefix SHOULD be ignored.
3539 */
3540 zlog_err ("%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3541 peer->host, inet_ntoa (p.u.prefix4));
3542 continue;
3543 }
3544 }
3545
3546 #ifdef HAVE_IPV6
3547 /* Check address. */
3548 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3549 {
3550 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3551 {
3552 char buf[BUFSIZ];
3553
3554 zlog_err ("%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3555 peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3556
3557 continue;
3558 }
3559 if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3560 {
3561 char buf[BUFSIZ];
3562
3563 zlog_err ("%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3564 peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3565
3566 continue;
3567 }
3568 }
3569 #endif /* HAVE_IPV6 */
3570
3571 /* Normal process. */
3572 if (attr)
3573 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3574 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3575 else
3576 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3577 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3578
3579 /* Address family configuration mismatch or maximum-prefix count
3580 overflow. */
3581 if (ret < 0)
3582 return -1;
3583 }
3584
3585 /* Packet length consistency check. */
3586 if (pnt != lim)
3587 {
3588 zlog_err ("%s [Error] Update packet error (prefix length mismatch with total length)",
3589 peer->host);
3590 return -1;
3591 }
3592
3593 return 0;
3594 }
3595
3596 static struct bgp_static *
3597 bgp_static_new (void)
3598 {
3599 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3600 }
3601
3602 static void
3603 bgp_static_free (struct bgp_static *bgp_static)
3604 {
3605 if (bgp_static->rmap.name)
3606 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3607 XFREE (MTYPE_BGP_STATIC, bgp_static);
3608 }
3609
3610 static void
3611 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3612 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3613 {
3614 struct bgp_node *rn;
3615 struct bgp_info *ri;
3616 struct bgp_info *new;
3617 struct bgp_info info;
3618 struct attr attr;
3619 struct attr *attr_new;
3620 int ret;
3621 #if ENABLE_BGP_VNC
3622 int vnc_implicit_withdraw = 0;
3623 #endif
3624
3625 assert (bgp_static);
3626 if (!bgp_static)
3627 return;
3628
3629 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3630
3631 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3632
3633 attr.nexthop = bgp_static->igpnexthop;
3634 attr.med = bgp_static->igpmetric;
3635 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3636
3637 if (bgp_static->atomic)
3638 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3639
3640 /* Apply route-map. */
3641 if (bgp_static->rmap.name)
3642 {
3643 struct attr attr_tmp = attr;
3644 info.peer = bgp->peer_self;
3645 info.attr = &attr_tmp;
3646
3647 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3648
3649 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3650
3651 bgp->peer_self->rmap_type = 0;
3652
3653 if (ret == RMAP_DENYMATCH)
3654 {
3655 /* Free uninterned attribute. */
3656 bgp_attr_flush (&attr_tmp);
3657
3658 /* Unintern original. */
3659 aspath_unintern (&attr.aspath);
3660 bgp_attr_extra_free (&attr);
3661 bgp_static_withdraw (bgp, p, afi, safi);
3662 return;
3663 }
3664 attr_new = bgp_attr_intern (&attr_tmp);
3665 }
3666 else
3667 attr_new = bgp_attr_intern (&attr);
3668
3669 for (ri = rn->info; ri; ri = ri->next)
3670 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3671 && ri->sub_type == BGP_ROUTE_STATIC)
3672 break;
3673
3674 if (ri)
3675 {
3676 if (attrhash_cmp (ri->attr, attr_new) &&
3677 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3678 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
3679 {
3680 bgp_unlock_node (rn);
3681 bgp_attr_unintern (&attr_new);
3682 aspath_unintern (&attr.aspath);
3683 bgp_attr_extra_free (&attr);
3684 return;
3685 }
3686 else
3687 {
3688 /* The attribute is changed. */
3689 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3690
3691 /* Rewrite BGP route information. */
3692 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3693 bgp_info_restore(rn, ri);
3694 else
3695 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3696 #if ENABLE_BGP_VNC
3697 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3698 {
3699 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
3700 {
3701 /*
3702 * Implicit withdraw case.
3703 * We have to do this before ri is changed
3704 */
3705 ++vnc_implicit_withdraw;
3706 vnc_import_bgp_del_route(bgp, p, ri);
3707 vnc_import_bgp_exterior_del_route(bgp, p, ri);
3708 }
3709 }
3710 #endif
3711 bgp_attr_unintern (&ri->attr);
3712 ri->attr = attr_new;
3713 ri->uptime = bgp_clock ();
3714 #if ENABLE_BGP_VNC
3715 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3716 {
3717 if (vnc_implicit_withdraw)
3718 {
3719 vnc_import_bgp_add_route(bgp, p, ri);
3720 vnc_import_bgp_exterior_add_route(bgp, p, ri);
3721 }
3722 }
3723 #endif
3724
3725 /* Nexthop reachability check. */
3726 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3727 {
3728 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
3729 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3730 else
3731 {
3732 if (BGP_DEBUG(nht, NHT))
3733 {
3734 char buf1[INET6_ADDRSTRLEN];
3735 inet_ntop(p->family, &p->u.prefix, buf1,
3736 INET6_ADDRSTRLEN);
3737 zlog_debug("%s(%s): Route not in table, not advertising",
3738 __FUNCTION__, buf1);
3739 }
3740 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3741 }
3742 }
3743 else
3744 {
3745 /* Delete the NHT structure if any, if we're toggling between
3746 * enabling/disabling import check. We deregister the route
3747 * from NHT to avoid overloading NHT and the process interaction
3748 */
3749 bgp_unlink_nexthop(ri);
3750 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3751 }
3752 /* Process change. */
3753 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3754 bgp_process (bgp, rn, afi, safi);
3755 bgp_unlock_node (rn);
3756 aspath_unintern (&attr.aspath);
3757 bgp_attr_extra_free (&attr);
3758 return;
3759 }
3760 }
3761
3762 /* Make new BGP info. */
3763 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3764 rn);
3765 /* Nexthop reachability check. */
3766 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3767 {
3768 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
3769 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3770 else
3771 {
3772 if (BGP_DEBUG(nht, NHT))
3773 {
3774 char buf1[INET6_ADDRSTRLEN];
3775 inet_ntop(p->family, &p->u.prefix, buf1,
3776 INET6_ADDRSTRLEN);
3777 zlog_debug("%s(%s): Route not in table, not advertising",
3778 __FUNCTION__, buf1);
3779 }
3780 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3781 }
3782 }
3783 else
3784 {
3785 /* Delete the NHT structure if any, if we're toggling between
3786 * enabling/disabling import check. We deregister the route
3787 * from NHT to avoid overloading NHT and the process interaction
3788 */
3789 bgp_unlink_nexthop(new);
3790
3791 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3792 }
3793
3794 /* Aggregate address increment. */
3795 bgp_aggregate_increment (bgp, p, new, afi, safi);
3796
3797 /* Register new BGP information. */
3798 bgp_info_add (rn, new);
3799
3800 /* route_node_get lock */
3801 bgp_unlock_node (rn);
3802
3803 /* Process change. */
3804 bgp_process (bgp, rn, afi, safi);
3805
3806 /* Unintern original. */
3807 aspath_unintern (&attr.aspath);
3808 bgp_attr_extra_free (&attr);
3809 }
3810
3811 void
3812 bgp_static_update (struct bgp *bgp, struct prefix *p,
3813 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3814 {
3815 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3816 }
3817
3818 void
3819 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3820 safi_t safi)
3821 {
3822 struct bgp_node *rn;
3823 struct bgp_info *ri;
3824
3825 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3826
3827 /* Check selected route and self inserted route. */
3828 for (ri = rn->info; ri; ri = ri->next)
3829 if (ri->peer == bgp->peer_self
3830 && ri->type == ZEBRA_ROUTE_BGP
3831 && ri->sub_type == BGP_ROUTE_STATIC)
3832 break;
3833
3834 /* Withdraw static BGP route from routing table. */
3835 if (ri)
3836 {
3837 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3838 bgp_unlink_nexthop(ri);
3839 bgp_info_delete (rn, ri);
3840 bgp_process (bgp, rn, afi, safi);
3841 }
3842
3843 /* Unlock bgp_node_lookup. */
3844 bgp_unlock_node (rn);
3845 }
3846
3847 /*
3848 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3849 */
3850 static void
3851 bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3852 safi_t safi, struct prefix_rd *prd, u_char *tag)
3853 {
3854 struct bgp_node *rn;
3855 struct bgp_info *ri;
3856
3857 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3858
3859 /* Check selected route and self inserted route. */
3860 for (ri = rn->info; ri; ri = ri->next)
3861 if (ri->peer == bgp->peer_self
3862 && ri->type == ZEBRA_ROUTE_BGP
3863 && ri->sub_type == BGP_ROUTE_STATIC)
3864 break;
3865
3866 /* Withdraw static BGP route from routing table. */
3867 if (ri)
3868 {
3869 #if ENABLE_BGP_VNC
3870 rfapiProcessWithdraw(
3871 ri->peer,
3872 NULL,
3873 p,
3874 prd,
3875 ri->attr,
3876 afi,
3877 safi,
3878 ri->type,
3879 1); /* Kill, since it is an administrative change */
3880 #endif
3881 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3882 bgp_info_delete (rn, ri);
3883 bgp_process (bgp, rn, afi, safi);
3884 }
3885
3886 /* Unlock bgp_node_lookup. */
3887 bgp_unlock_node (rn);
3888 }
3889
3890 static void
3891 bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3892 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3893 {
3894 struct bgp_node *rn;
3895 struct bgp_info *new;
3896 struct attr *attr_new;
3897 struct attr attr = { 0 };
3898 struct bgp_info *ri;
3899 #if ENABLE_BGP_VNC
3900 u_int32_t label = 0;
3901 #endif
3902
3903 assert (bgp_static);
3904
3905 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3906
3907 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3908
3909 attr.nexthop = bgp_static->igpnexthop;
3910 attr.med = bgp_static->igpmetric;
3911 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3912
3913 /* Apply route-map. */
3914 if (bgp_static->rmap.name)
3915 {
3916 struct attr attr_tmp = attr;
3917 struct bgp_info info;
3918 int ret;
3919
3920 info.peer = bgp->peer_self;
3921 info.attr = &attr_tmp;
3922
3923 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3924
3925 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3926
3927 bgp->peer_self->rmap_type = 0;
3928
3929 if (ret == RMAP_DENYMATCH)
3930 {
3931 /* Free uninterned attribute. */
3932 bgp_attr_flush (&attr_tmp);
3933
3934 /* Unintern original. */
3935 aspath_unintern (&attr.aspath);
3936 bgp_attr_extra_free (&attr);
3937 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3938 bgp_static->tag);
3939 return;
3940 }
3941
3942 attr_new = bgp_attr_intern (&attr_tmp);
3943 }
3944 else
3945 {
3946 attr_new = bgp_attr_intern (&attr);
3947 }
3948
3949 for (ri = rn->info; ri; ri = ri->next)
3950 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3951 && ri->sub_type == BGP_ROUTE_STATIC)
3952 break;
3953
3954 if (ri)
3955 {
3956 if (attrhash_cmp (ri->attr, attr_new) &&
3957 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3958 {
3959 bgp_unlock_node (rn);
3960 bgp_attr_unintern (&attr_new);
3961 aspath_unintern (&attr.aspath);
3962 bgp_attr_extra_free (&attr);
3963 return;
3964 }
3965 else
3966 {
3967 /* The attribute is changed. */
3968 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3969
3970 /* Rewrite BGP route information. */
3971 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3972 bgp_info_restore(rn, ri);
3973 else
3974 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3975 bgp_attr_unintern (&ri->attr);
3976 ri->attr = attr_new;
3977 ri->uptime = bgp_clock ();
3978 #if ENABLE_BGP_VNC
3979 if (ri->extra)
3980 label = decode_label (ri->extra->tag);
3981 #endif
3982
3983 /* Process change. */
3984 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3985 bgp_process (bgp, rn, afi, safi);
3986 #if ENABLE_BGP_VNC
3987 rfapiProcessUpdate(ri->peer, NULL, p, &bgp_static->prd,
3988 ri->attr, afi, safi,
3989 ri->type, ri->sub_type, &label);
3990 #endif
3991 bgp_unlock_node (rn);
3992 aspath_unintern (&attr.aspath);
3993 bgp_attr_extra_free (&attr);
3994 return;
3995 }
3996 }
3997
3998
3999 /* Make new BGP info. */
4000 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
4001 rn);
4002 SET_FLAG (new->flags, BGP_INFO_VALID);
4003 new->extra = bgp_info_extra_new();
4004 memcpy (new->extra->tag, bgp_static->tag, 3);
4005 #if ENABLE_BGP_VNC
4006 label = decode_label (bgp_static->tag);
4007 #endif
4008
4009 /* Aggregate address increment. */
4010 bgp_aggregate_increment (bgp, p, new, afi, safi);
4011
4012 /* Register new BGP information. */
4013 bgp_info_add (rn, new);
4014
4015 /* route_node_get lock */
4016 bgp_unlock_node (rn);
4017
4018 /* Process change. */
4019 bgp_process (bgp, rn, afi, safi);
4020
4021 #if ENABLE_BGP_VNC
4022 rfapiProcessUpdate(new->peer, NULL, p, &bgp_static->prd,
4023 new->attr, afi, safi,
4024 new->type, new->sub_type, &label);
4025 #endif
4026
4027 /* Unintern original. */
4028 aspath_unintern (&attr.aspath);
4029 bgp_attr_extra_free (&attr);
4030 }
4031
4032 /* Configure static BGP network. When user don't run zebra, static
4033 route should be installed as valid. */
4034 static int
4035 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
4036 afi_t afi, safi_t safi, const char *rmap, int backdoor)
4037 {
4038 int ret;
4039 struct prefix p;
4040 struct bgp_static *bgp_static;
4041 struct bgp_node *rn;
4042 u_char need_update = 0;
4043
4044 /* Convert IP prefix string to struct prefix. */
4045 ret = str2prefix (ip_str, &p);
4046 if (! ret)
4047 {
4048 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4049 return CMD_WARNING;
4050 }
4051 #ifdef HAVE_IPV6
4052 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4053 {
4054 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4055 VTY_NEWLINE);
4056 return CMD_WARNING;
4057 }
4058 #endif /* HAVE_IPV6 */
4059
4060 apply_mask (&p);
4061
4062 /* Set BGP static route configuration. */
4063 rn = bgp_node_get (bgp->route[afi][safi], &p);
4064
4065 if (rn->info)
4066 {
4067 /* Configuration change. */
4068 bgp_static = rn->info;
4069
4070 /* Check previous routes are installed into BGP. */
4071 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4072 need_update = 1;
4073
4074 bgp_static->backdoor = backdoor;
4075
4076 if (rmap)
4077 {
4078 if (bgp_static->rmap.name)
4079 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4080 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4081 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4082 }
4083 else
4084 {
4085 if (bgp_static->rmap.name)
4086 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4087 bgp_static->rmap.name = NULL;
4088 bgp_static->rmap.map = NULL;
4089 bgp_static->valid = 0;
4090 }
4091 bgp_unlock_node (rn);
4092 }
4093 else
4094 {
4095 /* New configuration. */
4096 bgp_static = bgp_static_new ();
4097 bgp_static->backdoor = backdoor;
4098 bgp_static->valid = 0;
4099 bgp_static->igpmetric = 0;
4100 bgp_static->igpnexthop.s_addr = 0;
4101
4102 if (rmap)
4103 {
4104 if (bgp_static->rmap.name)
4105 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4106 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4107 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4108 }
4109 rn->info = bgp_static;
4110 }
4111
4112 bgp_static->valid = 1;
4113 if (need_update)
4114 bgp_static_withdraw (bgp, &p, afi, safi);
4115
4116 if (! bgp_static->backdoor)
4117 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4118
4119 return CMD_SUCCESS;
4120 }
4121
4122 /* Configure static BGP network. */
4123 static int
4124 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4125 afi_t afi, safi_t safi)
4126 {
4127 int ret;
4128 struct prefix p;
4129 struct bgp_static *bgp_static;
4130 struct bgp_node *rn;
4131
4132 /* Convert IP prefix string to struct prefix. */
4133 ret = str2prefix (ip_str, &p);
4134 if (! ret)
4135 {
4136 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4137 return CMD_WARNING;
4138 }
4139 #ifdef HAVE_IPV6
4140 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4141 {
4142 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4143 VTY_NEWLINE);
4144 return CMD_WARNING;
4145 }
4146 #endif /* HAVE_IPV6 */
4147
4148 apply_mask (&p);
4149
4150 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4151 if (! rn)
4152 {
4153 vty_out (vty, "%% Can't find specified static route configuration.%s",
4154 VTY_NEWLINE);
4155 return CMD_WARNING;
4156 }
4157
4158 bgp_static = rn->info;
4159
4160 /* Update BGP RIB. */
4161 if (! bgp_static->backdoor)
4162 bgp_static_withdraw (bgp, &p, afi, safi);
4163
4164 /* Clear configuration. */
4165 bgp_static_free (bgp_static);
4166 rn->info = NULL;
4167 bgp_unlock_node (rn);
4168 bgp_unlock_node (rn);
4169
4170 return CMD_SUCCESS;
4171 }
4172
4173 void
4174 bgp_static_add (struct bgp *bgp)
4175 {
4176 afi_t afi;
4177 safi_t safi;
4178 struct bgp_node *rn;
4179 struct bgp_node *rm;
4180 struct bgp_table *table;
4181 struct bgp_static *bgp_static;
4182
4183 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4184 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4185 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4186 if (rn->info != NULL)
4187 {
4188 if (safi == SAFI_MPLS_VPN)
4189 {
4190 table = rn->info;
4191
4192 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4193 {
4194 bgp_static = rn->info;
4195 bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
4196 }
4197 }
4198 else
4199 {
4200 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
4201 }
4202 }
4203 }
4204
4205 /* Called from bgp_delete(). Delete all static routes from the BGP
4206 instance. */
4207 void
4208 bgp_static_delete (struct bgp *bgp)
4209 {
4210 afi_t afi;
4211 safi_t safi;
4212 struct bgp_node *rn;
4213 struct bgp_node *rm;
4214 struct bgp_table *table;
4215 struct bgp_static *bgp_static;
4216
4217 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4218 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4219 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4220 if (rn->info != NULL)
4221 {
4222 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
4223 {
4224 table = rn->info;
4225
4226 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4227 {
4228 bgp_static = rn->info;
4229 bgp_static_withdraw_safi (bgp, &rm->p,
4230 AFI_IP, safi,
4231 (struct prefix_rd *)&rn->p,
4232 bgp_static->tag);
4233 bgp_static_free (bgp_static);
4234 rn->info = NULL;
4235 bgp_unlock_node (rn);
4236 }
4237 }
4238 else
4239 {
4240 bgp_static = rn->info;
4241 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4242 bgp_static_free (bgp_static);
4243 rn->info = NULL;
4244 bgp_unlock_node (rn);
4245 }
4246 }
4247 }
4248
4249 void
4250 bgp_static_redo_import_check (struct bgp *bgp)
4251 {
4252 afi_t afi;
4253 safi_t safi;
4254 struct bgp_node *rn;
4255 struct bgp_static *bgp_static;
4256
4257 /* Use this flag to force reprocessing of the route */
4258 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4259 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4260 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4261 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4262 if (rn->info != NULL)
4263 {
4264 bgp_static = rn->info;
4265 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
4266 }
4267 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4268 }
4269
4270 static void
4271 bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
4272 {
4273 struct bgp_table *table;
4274 struct bgp_node *rn;
4275 struct bgp_info *ri;
4276
4277 table = bgp->rib[afi][safi];
4278 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4279 {
4280 for (ri = rn->info; ri; ri = ri->next)
4281 {
4282 if (ri->peer == bgp->peer_self &&
4283 ((ri->type == ZEBRA_ROUTE_BGP &&
4284 ri->sub_type == BGP_ROUTE_STATIC) ||
4285 (ri->type != ZEBRA_ROUTE_BGP &&
4286 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
4287 {
4288 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
4289 bgp_unlink_nexthop(ri);
4290 bgp_info_delete (rn, ri);
4291 bgp_process (bgp, rn, afi, safi);
4292 }
4293 }
4294 }
4295 }
4296
4297 /*
4298 * Purge all networks and redistributed routes from routing table.
4299 * Invoked upon the instance going down.
4300 */
4301 void
4302 bgp_purge_static_redist_routes (struct bgp *bgp)
4303 {
4304 afi_t afi;
4305 safi_t safi;
4306
4307 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4308 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4309 bgp_purge_af_static_redist_routes (bgp, afi, safi);
4310 }
4311
4312 /*
4313 * gpz 110624
4314 * Currently this is used to set static routes for VPN and ENCAP.
4315 * I think it can probably be factored with bgp_static_set.
4316 */
4317 int
4318 bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4319 const char *rd_str, const char *tag_str,
4320 const char *rmap_str)
4321 {
4322 int ret;
4323 struct prefix p;
4324 struct prefix_rd prd;
4325 struct bgp *bgp;
4326 struct bgp_node *prn;
4327 struct bgp_node *rn;
4328 struct bgp_table *table;
4329 struct bgp_static *bgp_static;
4330 u_char tag[3];
4331
4332 bgp = vty->index;
4333
4334 ret = str2prefix (ip_str, &p);
4335 if (! ret)
4336 {
4337 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4338 return CMD_WARNING;
4339 }
4340 apply_mask (&p);
4341
4342 ret = str2prefix_rd (rd_str, &prd);
4343 if (! ret)
4344 {
4345 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4346 return CMD_WARNING;
4347 }
4348
4349 ret = str2tag (tag_str, tag);
4350 if (! ret)
4351 {
4352 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4353 return CMD_WARNING;
4354 }
4355
4356 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4357 (struct prefix *)&prd);
4358 if (prn->info == NULL)
4359 prn->info = bgp_table_init (AFI_IP, safi);
4360 else
4361 bgp_unlock_node (prn);
4362 table = prn->info;
4363
4364 rn = bgp_node_get (table, &p);
4365
4366 if (rn->info)
4367 {
4368 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4369 bgp_unlock_node (rn);
4370 }
4371 else
4372 {
4373 /* New configuration. */
4374 bgp_static = bgp_static_new ();
4375 bgp_static->backdoor = 0;
4376 bgp_static->valid = 0;
4377 bgp_static->igpmetric = 0;
4378 bgp_static->igpnexthop.s_addr = 0;
4379 memcpy(bgp_static->tag, tag, 3);
4380 bgp_static->prd = prd;
4381
4382 if (rmap_str)
4383 {
4384 if (bgp_static->rmap.name)
4385 free (bgp_static->rmap.name);
4386 bgp_static->rmap.name = strdup (rmap_str);
4387 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4388 }
4389 rn->info = bgp_static;
4390
4391 bgp_static->valid = 1;
4392 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
4393 }
4394
4395 return CMD_SUCCESS;
4396 }
4397
4398 /* Configure static BGP network. */
4399 int
4400 bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4401 const char *rd_str, const char *tag_str)
4402 {
4403 int ret;
4404 struct bgp *bgp;
4405 struct prefix p;
4406 struct prefix_rd prd;
4407 struct bgp_node *prn;
4408 struct bgp_node *rn;
4409 struct bgp_table *table;
4410 struct bgp_static *bgp_static;
4411 u_char tag[3];
4412
4413 bgp = vty->index;
4414
4415 /* Convert IP prefix string to struct prefix. */
4416 ret = str2prefix (ip_str, &p);
4417 if (! ret)
4418 {
4419 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4420 return CMD_WARNING;
4421 }
4422 apply_mask (&p);
4423
4424 ret = str2prefix_rd (rd_str, &prd);
4425 if (! ret)
4426 {
4427 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4428 return CMD_WARNING;
4429 }
4430
4431 ret = str2tag (tag_str, tag);
4432 if (! ret)
4433 {
4434 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4435 return CMD_WARNING;
4436 }
4437
4438 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4439 (struct prefix *)&prd);
4440 if (prn->info == NULL)
4441 prn->info = bgp_table_init (AFI_IP, safi);
4442 else
4443 bgp_unlock_node (prn);
4444 table = prn->info;
4445
4446 rn = bgp_node_lookup (table, &p);
4447
4448 if (rn)
4449 {
4450 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
4451
4452 bgp_static = rn->info;
4453 bgp_static_free (bgp_static);
4454 rn->info = NULL;
4455 bgp_unlock_node (rn);
4456 bgp_unlock_node (rn);
4457 }
4458 else
4459 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4460
4461 return CMD_SUCCESS;
4462 }
4463
4464 static int
4465 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4466 const char *rmap_name)
4467 {
4468 struct bgp_rmap *rmap;
4469
4470 rmap = &bgp->table_map[afi][safi];
4471 if (rmap_name)
4472 {
4473 if (rmap->name)
4474 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4475 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
4476 rmap->map = route_map_lookup_by_name (rmap_name);
4477 }
4478 else
4479 {
4480 if (rmap->name)
4481 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4482 rmap->name = NULL;
4483 rmap->map = NULL;
4484 }
4485
4486 bgp_zebra_announce_table(bgp, afi, safi);
4487
4488 return CMD_SUCCESS;
4489 }
4490
4491 static int
4492 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4493 const char *rmap_name)
4494 {
4495 struct bgp_rmap *rmap;
4496
4497 rmap = &bgp->table_map[afi][safi];
4498 if (rmap->name)
4499 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4500 rmap->name = NULL;
4501 rmap->map = NULL;
4502
4503 bgp_zebra_announce_table(bgp, afi, safi);
4504
4505 return CMD_SUCCESS;
4506 }
4507
4508 int
4509 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4510 safi_t safi, int *write)
4511 {
4512 if (bgp->table_map[afi][safi].name)
4513 {
4514 bgp_config_write_family_header (vty, afi, safi, write);
4515 vty_out (vty, " table-map %s%s",
4516 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4517 }
4518
4519 return 0;
4520 }
4521
4522 DEFUN (bgp_table_map,
4523 bgp_table_map_cmd,
4524 "table-map WORD",
4525 "BGP table to RIB route download filter\n"
4526 "Name of the route map\n")
4527 {
4528 return bgp_table_map_set (vty, vty->index,
4529 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4530 }
4531 DEFUN (no_bgp_table_map,
4532 no_bgp_table_map_cmd,
4533 "no table-map WORD",
4534 "BGP table to RIB route download filter\n"
4535 "Name of the route map\n")
4536 {
4537 return bgp_table_map_unset (vty, vty->index,
4538 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4539 }
4540
4541 DEFUN (bgp_network,
4542 bgp_network_cmd,
4543 "network A.B.C.D/M",
4544 "Specify a network to announce via BGP\n"
4545 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4546 {
4547 return bgp_static_set (vty, vty->index, argv[0],
4548 AFI_IP, bgp_node_safi (vty), NULL, 0);
4549 }
4550
4551 DEFUN (bgp_network_route_map,
4552 bgp_network_route_map_cmd,
4553 "network A.B.C.D/M route-map WORD",
4554 "Specify a network to announce via BGP\n"
4555 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4556 "Route-map to modify the attributes\n"
4557 "Name of the route map\n")
4558 {
4559 return bgp_static_set (vty, vty->index, argv[0],
4560 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4561 }
4562
4563 DEFUN (bgp_network_backdoor,
4564 bgp_network_backdoor_cmd,
4565 "network A.B.C.D/M backdoor",
4566 "Specify a network to announce via BGP\n"
4567 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4568 "Specify a BGP backdoor route\n")
4569 {
4570 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4571 NULL, 1);
4572 }
4573
4574 DEFUN (bgp_network_mask,
4575 bgp_network_mask_cmd,
4576 "network A.B.C.D mask A.B.C.D",
4577 "Specify a network to announce via BGP\n"
4578 "Network number\n"
4579 "Network mask\n"
4580 "Network mask\n")
4581 {
4582 int ret;
4583 char prefix_str[BUFSIZ];
4584
4585 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4586 if (! ret)
4587 {
4588 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4589 return CMD_WARNING;
4590 }
4591
4592 return bgp_static_set (vty, vty->index, prefix_str,
4593 AFI_IP, bgp_node_safi (vty), NULL, 0);
4594 }
4595
4596 DEFUN (bgp_network_mask_route_map,
4597 bgp_network_mask_route_map_cmd,
4598 "network A.B.C.D mask A.B.C.D route-map WORD",
4599 "Specify a network to announce via BGP\n"
4600 "Network number\n"
4601 "Network mask\n"
4602 "Network mask\n"
4603 "Route-map to modify the attributes\n"
4604 "Name of the route map\n")
4605 {
4606 int ret;
4607 char prefix_str[BUFSIZ];
4608
4609 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4610 if (! ret)
4611 {
4612 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4613 return CMD_WARNING;
4614 }
4615
4616 return bgp_static_set (vty, vty->index, prefix_str,
4617 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4618 }
4619
4620 DEFUN (bgp_network_mask_backdoor,
4621 bgp_network_mask_backdoor_cmd,
4622 "network A.B.C.D mask A.B.C.D backdoor",
4623 "Specify a network to announce via BGP\n"
4624 "Network number\n"
4625 "Network mask\n"
4626 "Network mask\n"
4627 "Specify a BGP backdoor route\n")
4628 {
4629 int ret;
4630 char prefix_str[BUFSIZ];
4631
4632 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4633 if (! ret)
4634 {
4635 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4636 return CMD_WARNING;
4637 }
4638
4639 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4640 NULL, 1);
4641 }
4642
4643 DEFUN (bgp_network_mask_natural,
4644 bgp_network_mask_natural_cmd,
4645 "network A.B.C.D",
4646 "Specify a network to announce via BGP\n"
4647 "Network number\n")
4648 {
4649 int ret;
4650 char prefix_str[BUFSIZ];
4651
4652 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4653 if (! ret)
4654 {
4655 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4656 return CMD_WARNING;
4657 }
4658
4659 return bgp_static_set (vty, vty->index, prefix_str,
4660 AFI_IP, bgp_node_safi (vty), NULL, 0);
4661 }
4662
4663 DEFUN (bgp_network_mask_natural_route_map,
4664 bgp_network_mask_natural_route_map_cmd,
4665 "network A.B.C.D route-map WORD",
4666 "Specify a network to announce via BGP\n"
4667 "Network number\n"
4668 "Route-map to modify the attributes\n"
4669 "Name of the route map\n")
4670 {
4671 int ret;
4672 char prefix_str[BUFSIZ];
4673
4674 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4675 if (! ret)
4676 {
4677 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4678 return CMD_WARNING;
4679 }
4680
4681 return bgp_static_set (vty, vty->index, prefix_str,
4682 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4683 }
4684
4685 DEFUN (bgp_network_mask_natural_backdoor,
4686 bgp_network_mask_natural_backdoor_cmd,
4687 "network A.B.C.D backdoor",
4688 "Specify a network to announce via BGP\n"
4689 "Network number\n"
4690 "Specify a BGP backdoor route\n")
4691 {
4692 int ret;
4693 char prefix_str[BUFSIZ];
4694
4695 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4696 if (! ret)
4697 {
4698 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4699 return CMD_WARNING;
4700 }
4701
4702 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4703 NULL, 1);
4704 }
4705
4706 DEFUN (no_bgp_network,
4707 no_bgp_network_cmd,
4708 "no network A.B.C.D/M",
4709 NO_STR
4710 "Specify a network to announce via BGP\n"
4711 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4712 {
4713 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4714 bgp_node_safi (vty));
4715 }
4716
4717 ALIAS (no_bgp_network,
4718 no_bgp_network_route_map_cmd,
4719 "no network A.B.C.D/M route-map WORD",
4720 NO_STR
4721 "Specify a network to announce via BGP\n"
4722 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4723 "Route-map to modify the attributes\n"
4724 "Name of the route map\n")
4725
4726 ALIAS (no_bgp_network,
4727 no_bgp_network_backdoor_cmd,
4728 "no network A.B.C.D/M backdoor",
4729 NO_STR
4730 "Specify a network to announce via BGP\n"
4731 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4732 "Specify a BGP backdoor route\n")
4733
4734 DEFUN (no_bgp_network_mask,
4735 no_bgp_network_mask_cmd,
4736 "no network A.B.C.D mask A.B.C.D",
4737 NO_STR
4738 "Specify a network to announce via BGP\n"
4739 "Network number\n"
4740 "Network mask\n"
4741 "Network mask\n")
4742 {
4743 int ret;
4744 char prefix_str[BUFSIZ];
4745
4746 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4747 if (! ret)
4748 {
4749 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4750 return CMD_WARNING;
4751 }
4752
4753 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4754 bgp_node_safi (vty));
4755 }
4756
4757 ALIAS (no_bgp_network_mask,
4758 no_bgp_network_mask_route_map_cmd,
4759 "no network A.B.C.D mask A.B.C.D route-map WORD",
4760 NO_STR
4761 "Specify a network to announce via BGP\n"
4762 "Network number\n"
4763 "Network mask\n"
4764 "Network mask\n"
4765 "Route-map to modify the attributes\n"
4766 "Name of the route map\n")
4767
4768 ALIAS (no_bgp_network_mask,
4769 no_bgp_network_mask_backdoor_cmd,
4770 "no network A.B.C.D mask A.B.C.D backdoor",
4771 NO_STR
4772 "Specify a network to announce via BGP\n"
4773 "Network number\n"
4774 "Network mask\n"
4775 "Network mask\n"
4776 "Specify a BGP backdoor route\n")
4777
4778 DEFUN (no_bgp_network_mask_natural,
4779 no_bgp_network_mask_natural_cmd,
4780 "no network A.B.C.D",
4781 NO_STR
4782 "Specify a network to announce via BGP\n"
4783 "Network number\n")
4784 {
4785 int ret;
4786 char prefix_str[BUFSIZ];
4787
4788 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4789 if (! ret)
4790 {
4791 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4792 return CMD_WARNING;
4793 }
4794
4795 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4796 bgp_node_safi (vty));
4797 }
4798
4799 ALIAS (no_bgp_network_mask_natural,
4800 no_bgp_network_mask_natural_route_map_cmd,
4801 "no network A.B.C.D route-map WORD",
4802 NO_STR
4803 "Specify a network to announce via BGP\n"
4804 "Network number\n"
4805 "Route-map to modify the attributes\n"
4806 "Name of the route map\n")
4807
4808 ALIAS (no_bgp_network_mask_natural,
4809 no_bgp_network_mask_natural_backdoor_cmd,
4810 "no network A.B.C.D backdoor",
4811 NO_STR
4812 "Specify a network to announce via BGP\n"
4813 "Network number\n"
4814 "Specify a BGP backdoor route\n")
4815
4816 #ifdef HAVE_IPV6
4817 DEFUN (ipv6_bgp_network,
4818 ipv6_bgp_network_cmd,
4819 "network X:X::X:X/M",
4820 "Specify a network to announce via BGP\n"
4821 "IPv6 prefix <network>/<length>\n")
4822 {
4823 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4824 NULL, 0);
4825 }
4826
4827 DEFUN (ipv6_bgp_network_route_map,
4828 ipv6_bgp_network_route_map_cmd,
4829 "network X:X::X:X/M route-map WORD",
4830 "Specify a network to announce via BGP\n"
4831 "IPv6 prefix <network>/<length>\n"
4832 "Route-map to modify the attributes\n"
4833 "Name of the route map\n")
4834 {
4835 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4836 bgp_node_safi (vty), argv[1], 0);
4837 }
4838
4839 DEFUN (no_ipv6_bgp_network,
4840 no_ipv6_bgp_network_cmd,
4841 "no network X:X::X:X/M",
4842 NO_STR
4843 "Specify a network to announce via BGP\n"
4844 "IPv6 prefix <network>/<length>\n")
4845 {
4846 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4847 }
4848
4849 ALIAS (no_ipv6_bgp_network,
4850 no_ipv6_bgp_network_route_map_cmd,
4851 "no network X:X::X:X/M route-map WORD",
4852 NO_STR
4853 "Specify a network to announce via BGP\n"
4854 "IPv6 prefix <network>/<length>\n"
4855 "Route-map to modify the attributes\n"
4856 "Name of the route map\n")
4857
4858 ALIAS (ipv6_bgp_network,
4859 old_ipv6_bgp_network_cmd,
4860 "ipv6 bgp network X:X::X:X/M",
4861 IPV6_STR
4862 BGP_STR
4863 "Specify a network to announce via BGP\n"
4864 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4865
4866 ALIAS (no_ipv6_bgp_network,
4867 old_no_ipv6_bgp_network_cmd,
4868 "no ipv6 bgp network X:X::X:X/M",
4869 NO_STR
4870 IPV6_STR
4871 BGP_STR
4872 "Specify a network to announce via BGP\n"
4873 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4874 #endif /* HAVE_IPV6 */
4875
4876 /* Aggreagete address:
4877
4878 advertise-map Set condition to advertise attribute
4879 as-set Generate AS set path information
4880 attribute-map Set attributes of aggregate
4881 route-map Set parameters of aggregate
4882 summary-only Filter more specific routes from updates
4883 suppress-map Conditionally filter more specific routes from updates
4884 <cr>
4885 */
4886 struct bgp_aggregate
4887 {
4888 /* Summary-only flag. */
4889 u_char summary_only;
4890
4891 /* AS set generation. */
4892 u_char as_set;
4893
4894 /* Route-map for aggregated route. */
4895 struct route_map *map;
4896
4897 /* Suppress-count. */
4898 unsigned long count;
4899
4900 /* SAFI configuration. */
4901 safi_t safi;
4902 };
4903
4904 static struct bgp_aggregate *
4905 bgp_aggregate_new (void)
4906 {
4907 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4908 }
4909
4910 static void
4911 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4912 {
4913 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4914 }
4915
4916 /* Update an aggregate as routes are added/removed from the BGP table */
4917 static void
4918 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4919 afi_t afi, safi_t safi, struct bgp_info *del,
4920 struct bgp_aggregate *aggregate)
4921 {
4922 struct bgp_table *table;
4923 struct bgp_node *top;
4924 struct bgp_node *rn;
4925 u_char origin;
4926 struct aspath *aspath = NULL;
4927 struct aspath *asmerge = NULL;
4928 struct community *community = NULL;
4929 struct community *commerge = NULL;
4930 #if defined(AGGREGATE_NEXTHOP_CHECK)
4931 struct in_addr nexthop;
4932 u_int32_t med = 0;
4933 #endif
4934 struct bgp_info *ri;
4935 struct bgp_info *new;
4936 int first = 1;
4937 unsigned long match = 0;
4938 u_char atomic_aggregate = 0;
4939
4940 /* Record adding route's nexthop and med. */
4941 if (rinew)
4942 {
4943 #if defined(AGGREGATE_NEXTHOP_CHECK)
4944 nexthop = rinew->attr->nexthop;
4945 med = rinew->attr->med;
4946 #endif
4947 }
4948
4949 /* ORIGIN attribute: If at least one route among routes that are
4950 aggregated has ORIGIN with the value INCOMPLETE, then the
4951 aggregated route must have the ORIGIN attribute with the value
4952 INCOMPLETE. Otherwise, if at least one route among routes that
4953 are aggregated has ORIGIN with the value EGP, then the aggregated
4954 route must have the origin attribute with the value EGP. In all
4955 other case the value of the ORIGIN attribute of the aggregated
4956 route is INTERNAL. */
4957 origin = BGP_ORIGIN_IGP;
4958
4959 table = bgp->rib[afi][safi];
4960
4961 top = bgp_node_get (table, p);
4962 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4963 if (rn->p.prefixlen > p->prefixlen)
4964 {
4965 match = 0;
4966
4967 for (ri = rn->info; ri; ri = ri->next)
4968 {
4969 if (BGP_INFO_HOLDDOWN (ri))
4970 continue;
4971
4972 if (del && ri == del)
4973 continue;
4974
4975 if (! rinew && first)
4976 {
4977 #if defined(AGGREGATE_NEXTHOP_CHECK)
4978 nexthop = ri->attr->nexthop;
4979 med = ri->attr->med;
4980 #endif
4981 first = 0;
4982 }
4983
4984 #ifdef AGGREGATE_NEXTHOP_CHECK
4985 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4986 || ri->attr->med != med)
4987 {
4988 if (aspath)
4989 aspath_free (aspath);
4990 if (community)
4991 community_free (community);
4992 bgp_unlock_node (rn);
4993 bgp_unlock_node (top);
4994 return;
4995 }
4996 #endif /* AGGREGATE_NEXTHOP_CHECK */
4997
4998 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4999 atomic_aggregate = 1;
5000
5001 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5002 {
5003 if (aggregate->summary_only)
5004 {
5005 (bgp_info_extra_get (ri))->suppress++;
5006 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5007 match++;
5008 }
5009
5010 aggregate->count++;
5011
5012 if (origin < ri->attr->origin)
5013 origin = ri->attr->origin;
5014
5015 if (aggregate->as_set)
5016 {
5017 if (aspath)
5018 {
5019 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5020 aspath_free (aspath);
5021 aspath = asmerge;
5022 }
5023 else
5024 aspath = aspath_dup (ri->attr->aspath);
5025
5026 if (ri->attr->community)
5027 {
5028 if (community)
5029 {
5030 commerge = community_merge (community,
5031 ri->attr->community);
5032 community = community_uniq_sort (commerge);
5033 community_free (commerge);
5034 }
5035 else
5036 community = community_dup (ri->attr->community);
5037 }
5038 }
5039 }
5040 }
5041 if (match)
5042 bgp_process (bgp, rn, afi, safi);
5043 }
5044 bgp_unlock_node (top);
5045
5046 if (rinew)
5047 {
5048 aggregate->count++;
5049
5050 if (aggregate->summary_only)
5051 (bgp_info_extra_get (rinew))->suppress++;
5052
5053 if (origin < rinew->attr->origin)
5054 origin = rinew->attr->origin;
5055
5056 if (aggregate->as_set)
5057 {
5058 if (aspath)
5059 {
5060 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5061 aspath_free (aspath);
5062 aspath = asmerge;
5063 }
5064 else
5065 aspath = aspath_dup (rinew->attr->aspath);
5066
5067 if (rinew->attr->community)
5068 {
5069 if (community)
5070 {
5071 commerge = community_merge (community,
5072 rinew->attr->community);
5073 community = community_uniq_sort (commerge);
5074 community_free (commerge);
5075 }
5076 else
5077 community = community_dup (rinew->attr->community);
5078 }
5079 }
5080 }
5081
5082 if (aggregate->count > 0)
5083 {
5084 rn = bgp_node_get (table, p);
5085 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5086 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5087 aggregate->as_set,
5088 atomic_aggregate), rn);
5089 SET_FLAG (new->flags, BGP_INFO_VALID);
5090
5091 bgp_info_add (rn, new);
5092 bgp_unlock_node (rn);
5093 bgp_process (bgp, rn, afi, safi);
5094 }
5095 else
5096 {
5097 if (aspath)
5098 aspath_free (aspath);
5099 if (community)
5100 community_free (community);
5101 }
5102 }
5103
5104 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5105 struct bgp_aggregate *);
5106
5107 void
5108 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5109 struct bgp_info *ri, afi_t afi, safi_t safi)
5110 {
5111 struct bgp_node *child;
5112 struct bgp_node *rn;
5113 struct bgp_aggregate *aggregate;
5114 struct bgp_table *table;
5115
5116 /* MPLS-VPN aggregation is not yet supported. */
5117 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5118 return;
5119
5120 table = bgp->aggregate[afi][safi];
5121
5122 /* No aggregates configured. */
5123 if (bgp_table_top_nolock (table) == NULL)
5124 return;
5125
5126 if (p->prefixlen == 0)
5127 return;
5128
5129 if (BGP_INFO_HOLDDOWN (ri))
5130 return;
5131
5132 child = bgp_node_get (table, p);
5133
5134 /* Aggregate address configuration check. */
5135 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5136 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5137 {
5138 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5139 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
5140 }
5141 bgp_unlock_node (child);
5142 }
5143
5144 void
5145 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5146 struct bgp_info *del, afi_t afi, safi_t safi)
5147 {
5148 struct bgp_node *child;
5149 struct bgp_node *rn;
5150 struct bgp_aggregate *aggregate;
5151 struct bgp_table *table;
5152
5153 /* MPLS-VPN aggregation is not yet supported. */
5154 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5155 return;
5156
5157 table = bgp->aggregate[afi][safi];
5158
5159 /* No aggregates configured. */
5160 if (bgp_table_top_nolock (table) == NULL)
5161 return;
5162
5163 if (p->prefixlen == 0)
5164 return;
5165
5166 child = bgp_node_get (table, p);
5167
5168 /* Aggregate address configuration check. */
5169 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5170 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5171 {
5172 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5173 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
5174 }
5175 bgp_unlock_node (child);
5176 }
5177
5178 /* Called via bgp_aggregate_set when the user configures aggregate-address */
5179 static void
5180 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5181 struct bgp_aggregate *aggregate)
5182 {
5183 struct bgp_table *table;
5184 struct bgp_node *top;
5185 struct bgp_node *rn;
5186 struct bgp_info *new;
5187 struct bgp_info *ri;
5188 unsigned long match;
5189 u_char origin = BGP_ORIGIN_IGP;
5190 struct aspath *aspath = NULL;
5191 struct aspath *asmerge = NULL;
5192 struct community *community = NULL;
5193 struct community *commerge = NULL;
5194 u_char atomic_aggregate = 0;
5195
5196 table = bgp->rib[afi][safi];
5197
5198 /* Sanity check. */
5199 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5200 return;
5201 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5202 return;
5203
5204 /* If routes exists below this node, generate aggregate routes. */
5205 top = bgp_node_get (table, p);
5206 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5207 if (rn->p.prefixlen > p->prefixlen)
5208 {
5209 match = 0;
5210
5211 for (ri = rn->info; ri; ri = ri->next)
5212 {
5213 if (BGP_INFO_HOLDDOWN (ri))
5214 continue;
5215
5216 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5217 atomic_aggregate = 1;
5218
5219 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5220 {
5221 /* summary-only aggregate route suppress aggregated
5222 route announcement. */
5223 if (aggregate->summary_only)
5224 {
5225 (bgp_info_extra_get (ri))->suppress++;
5226 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5227 match++;
5228 }
5229
5230 /* If at least one route among routes that are aggregated has
5231 * ORIGIN with the value INCOMPLETE, then the aggregated route
5232 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5233 * Otherwise, if at least one route among routes that are
5234 * aggregated has ORIGIN with the value EGP, then the aggregated
5235 * route MUST have the ORIGIN attribute with the value EGP.
5236 */
5237 if (origin < ri->attr->origin)
5238 origin = ri->attr->origin;
5239
5240 /* as-set aggregate route generate origin, as path,
5241 community aggregation. */
5242 if (aggregate->as_set)
5243 {
5244 if (aspath)
5245 {
5246 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5247 aspath_free (aspath);
5248 aspath = asmerge;
5249 }
5250 else
5251 aspath = aspath_dup (ri->attr->aspath);
5252
5253 if (ri->attr->community)
5254 {
5255 if (community)
5256 {
5257 commerge = community_merge (community,
5258 ri->attr->community);
5259 community = community_uniq_sort (commerge);
5260 community_free (commerge);
5261 }
5262 else
5263 community = community_dup (ri->attr->community);
5264 }
5265 }
5266 aggregate->count++;
5267 }
5268 }
5269
5270 /* If this node is suppressed, process the change. */
5271 if (match)
5272 bgp_process (bgp, rn, afi, safi);
5273 }
5274 bgp_unlock_node (top);
5275
5276 /* Add aggregate route to BGP table. */
5277 if (aggregate->count)
5278 {
5279 rn = bgp_node_get (table, p);
5280 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5281 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5282 aggregate->as_set,
5283 atomic_aggregate), rn);
5284 SET_FLAG (new->flags, BGP_INFO_VALID);
5285
5286 bgp_info_add (rn, new);
5287 bgp_unlock_node (rn);
5288
5289 /* Process change. */
5290 bgp_process (bgp, rn, afi, safi);
5291 }
5292 else
5293 {
5294 if (aspath)
5295 aspath_free (aspath);
5296 if (community)
5297 community_free (community);
5298 }
5299 }
5300
5301 void
5302 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5303 safi_t safi, struct bgp_aggregate *aggregate)
5304 {
5305 struct bgp_table *table;
5306 struct bgp_node *top;
5307 struct bgp_node *rn;
5308 struct bgp_info *ri;
5309 unsigned long match;
5310
5311 table = bgp->rib[afi][safi];
5312
5313 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5314 return;
5315 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5316 return;
5317
5318 /* If routes exists below this node, generate aggregate routes. */
5319 top = bgp_node_get (table, p);
5320 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5321 if (rn->p.prefixlen > p->prefixlen)
5322 {
5323 match = 0;
5324
5325 for (ri = rn->info; ri; ri = ri->next)
5326 {
5327 if (BGP_INFO_HOLDDOWN (ri))
5328 continue;
5329
5330 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5331 {
5332 if (aggregate->summary_only && ri->extra)
5333 {
5334 ri->extra->suppress--;
5335
5336 if (ri->extra->suppress == 0)
5337 {
5338 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5339 match++;
5340 }
5341 }
5342 aggregate->count--;
5343 }
5344 }
5345
5346 /* If this node was suppressed, process the change. */
5347 if (match)
5348 bgp_process (bgp, rn, afi, safi);
5349 }
5350 bgp_unlock_node (top);
5351
5352 /* Delete aggregate route from BGP table. */
5353 rn = bgp_node_get (table, p);
5354
5355 for (ri = rn->info; ri; ri = ri->next)
5356 if (ri->peer == bgp->peer_self
5357 && ri->type == ZEBRA_ROUTE_BGP
5358 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5359 break;
5360
5361 /* Withdraw static BGP route from routing table. */
5362 if (ri)
5363 {
5364 bgp_info_delete (rn, ri);
5365 bgp_process (bgp, rn, afi, safi);
5366 }
5367
5368 /* Unlock bgp_node_lookup. */
5369 bgp_unlock_node (rn);
5370 }
5371
5372 /* Aggregate route attribute. */
5373 #define AGGREGATE_SUMMARY_ONLY 1
5374 #define AGGREGATE_AS_SET 1
5375
5376 static int
5377 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5378 afi_t afi, safi_t safi)
5379 {
5380 int ret;
5381 struct prefix p;
5382 struct bgp_node *rn;
5383 struct bgp *bgp;
5384 struct bgp_aggregate *aggregate;
5385
5386 /* Convert string to prefix structure. */
5387 ret = str2prefix (prefix_str, &p);
5388 if (!ret)
5389 {
5390 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5391 return CMD_WARNING;
5392 }
5393 apply_mask (&p);
5394
5395 /* Get BGP structure. */
5396 bgp = vty->index;
5397
5398 /* Old configuration check. */
5399 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5400 if (! rn)
5401 {
5402 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5403 VTY_NEWLINE);
5404 return CMD_WARNING;
5405 }
5406
5407 aggregate = rn->info;
5408 if (aggregate->safi & SAFI_UNICAST)
5409 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5410 if (aggregate->safi & SAFI_MULTICAST)
5411 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5412
5413 /* Unlock aggregate address configuration. */
5414 rn->info = NULL;
5415 bgp_aggregate_free (aggregate);
5416 bgp_unlock_node (rn);
5417 bgp_unlock_node (rn);
5418
5419 return CMD_SUCCESS;
5420 }
5421
5422 static int
5423 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5424 afi_t afi, safi_t safi,
5425 u_char summary_only, u_char as_set)
5426 {
5427 int ret;
5428 struct prefix p;
5429 struct bgp_node *rn;
5430 struct bgp *bgp;
5431 struct bgp_aggregate *aggregate;
5432
5433 /* Convert string to prefix structure. */
5434 ret = str2prefix (prefix_str, &p);
5435 if (!ret)
5436 {
5437 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5438 return CMD_WARNING;
5439 }
5440 apply_mask (&p);
5441
5442 /* Get BGP structure. */
5443 bgp = vty->index;
5444
5445 /* Old configuration check. */
5446 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5447
5448 if (rn->info)
5449 {
5450 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5451 /* try to remove the old entry */
5452 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5453 if (ret)
5454 {
5455 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5456 bgp_unlock_node (rn);
5457 return CMD_WARNING;
5458 }
5459 }
5460
5461 /* Make aggregate address structure. */
5462 aggregate = bgp_aggregate_new ();
5463 aggregate->summary_only = summary_only;
5464 aggregate->as_set = as_set;
5465 aggregate->safi = safi;
5466 rn->info = aggregate;
5467
5468 /* Aggregate address insert into BGP routing table. */
5469 if (safi & SAFI_UNICAST)
5470 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5471 if (safi & SAFI_MULTICAST)
5472 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5473
5474 return CMD_SUCCESS;
5475 }
5476
5477 DEFUN (aggregate_address,
5478 aggregate_address_cmd,
5479 "aggregate-address A.B.C.D/M",
5480 "Configure BGP aggregate entries\n"
5481 "Aggregate prefix\n")
5482 {
5483 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5484 }
5485
5486 DEFUN (aggregate_address_mask,
5487 aggregate_address_mask_cmd,
5488 "aggregate-address A.B.C.D A.B.C.D",
5489 "Configure BGP aggregate entries\n"
5490 "Aggregate address\n"
5491 "Aggregate mask\n")
5492 {
5493 int ret;
5494 char prefix_str[BUFSIZ];
5495
5496 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5497
5498 if (! ret)
5499 {
5500 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5501 return CMD_WARNING;
5502 }
5503
5504 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5505 0, 0);
5506 }
5507
5508 DEFUN (aggregate_address_summary_only,
5509 aggregate_address_summary_only_cmd,
5510 "aggregate-address A.B.C.D/M summary-only",
5511 "Configure BGP aggregate entries\n"
5512 "Aggregate prefix\n"
5513 "Filter more specific routes from updates\n")
5514 {
5515 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5516 AGGREGATE_SUMMARY_ONLY, 0);
5517 }
5518
5519 DEFUN (aggregate_address_mask_summary_only,
5520 aggregate_address_mask_summary_only_cmd,
5521 "aggregate-address A.B.C.D A.B.C.D summary-only",
5522 "Configure BGP aggregate entries\n"
5523 "Aggregate address\n"
5524 "Aggregate mask\n"
5525 "Filter more specific routes from updates\n")
5526 {
5527 int ret;
5528 char prefix_str[BUFSIZ];
5529
5530 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5531
5532 if (! ret)
5533 {
5534 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5535 return CMD_WARNING;
5536 }
5537
5538 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5539 AGGREGATE_SUMMARY_ONLY, 0);
5540 }
5541
5542 DEFUN (aggregate_address_as_set,
5543 aggregate_address_as_set_cmd,
5544 "aggregate-address A.B.C.D/M as-set",
5545 "Configure BGP aggregate entries\n"
5546 "Aggregate prefix\n"
5547 "Generate AS set path information\n")
5548 {
5549 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5550 0, AGGREGATE_AS_SET);
5551 }
5552
5553 DEFUN (aggregate_address_mask_as_set,
5554 aggregate_address_mask_as_set_cmd,
5555 "aggregate-address A.B.C.D A.B.C.D as-set",
5556 "Configure BGP aggregate entries\n"
5557 "Aggregate address\n"
5558 "Aggregate mask\n"
5559 "Generate AS set path information\n")
5560 {
5561 int ret;
5562 char prefix_str[BUFSIZ];
5563
5564 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5565
5566 if (! ret)
5567 {
5568 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5569 return CMD_WARNING;
5570 }
5571
5572 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5573 0, AGGREGATE_AS_SET);
5574 }
5575
5576
5577 DEFUN (aggregate_address_as_set_summary,
5578 aggregate_address_as_set_summary_cmd,
5579 "aggregate-address A.B.C.D/M as-set summary-only",
5580 "Configure BGP aggregate entries\n"
5581 "Aggregate prefix\n"
5582 "Generate AS set path information\n"
5583 "Filter more specific routes from updates\n")
5584 {
5585 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5586 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5587 }
5588
5589 ALIAS (aggregate_address_as_set_summary,
5590 aggregate_address_summary_as_set_cmd,
5591 "aggregate-address A.B.C.D/M summary-only as-set",
5592 "Configure BGP aggregate entries\n"
5593 "Aggregate prefix\n"
5594 "Filter more specific routes from updates\n"
5595 "Generate AS set path information\n")
5596
5597 DEFUN (aggregate_address_mask_as_set_summary,
5598 aggregate_address_mask_as_set_summary_cmd,
5599 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5600 "Configure BGP aggregate entries\n"
5601 "Aggregate address\n"
5602 "Aggregate mask\n"
5603 "Generate AS set path information\n"
5604 "Filter more specific routes from updates\n")
5605 {
5606 int ret;
5607 char prefix_str[BUFSIZ];
5608
5609 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5610
5611 if (! ret)
5612 {
5613 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5614 return CMD_WARNING;
5615 }
5616
5617 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5618 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5619 }
5620
5621 ALIAS (aggregate_address_mask_as_set_summary,
5622 aggregate_address_mask_summary_as_set_cmd,
5623 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5624 "Configure BGP aggregate entries\n"
5625 "Aggregate address\n"
5626 "Aggregate mask\n"
5627 "Filter more specific routes from updates\n"
5628 "Generate AS set path information\n")
5629
5630 DEFUN (no_aggregate_address,
5631 no_aggregate_address_cmd,
5632 "no aggregate-address A.B.C.D/M",
5633 NO_STR
5634 "Configure BGP aggregate entries\n"
5635 "Aggregate prefix\n")
5636 {
5637 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5638 }
5639
5640 ALIAS (no_aggregate_address,
5641 no_aggregate_address_summary_only_cmd,
5642 "no aggregate-address A.B.C.D/M summary-only",
5643 NO_STR
5644 "Configure BGP aggregate entries\n"
5645 "Aggregate prefix\n"
5646 "Filter more specific routes from updates\n")
5647
5648 ALIAS (no_aggregate_address,
5649 no_aggregate_address_as_set_cmd,
5650 "no aggregate-address A.B.C.D/M as-set",
5651 NO_STR
5652 "Configure BGP aggregate entries\n"
5653 "Aggregate prefix\n"
5654 "Generate AS set path information\n")
5655
5656 ALIAS (no_aggregate_address,
5657 no_aggregate_address_as_set_summary_cmd,
5658 "no aggregate-address A.B.C.D/M as-set summary-only",
5659 NO_STR
5660 "Configure BGP aggregate entries\n"
5661 "Aggregate prefix\n"
5662 "Generate AS set path information\n"
5663 "Filter more specific routes from updates\n")
5664
5665 ALIAS (no_aggregate_address,
5666 no_aggregate_address_summary_as_set_cmd,
5667 "no aggregate-address A.B.C.D/M summary-only as-set",
5668 NO_STR
5669 "Configure BGP aggregate entries\n"
5670 "Aggregate prefix\n"
5671 "Filter more specific routes from updates\n"
5672 "Generate AS set path information\n")
5673
5674 DEFUN (no_aggregate_address_mask,
5675 no_aggregate_address_mask_cmd,
5676 "no aggregate-address A.B.C.D A.B.C.D",
5677 NO_STR
5678 "Configure BGP aggregate entries\n"
5679 "Aggregate address\n"
5680 "Aggregate mask\n")
5681 {
5682 int ret;
5683 char prefix_str[BUFSIZ];
5684
5685 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5686
5687 if (! ret)
5688 {
5689 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5690 return CMD_WARNING;
5691 }
5692
5693 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5694 }
5695
5696 ALIAS (no_aggregate_address_mask,
5697 no_aggregate_address_mask_summary_only_cmd,
5698 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5699 NO_STR
5700 "Configure BGP aggregate entries\n"
5701 "Aggregate address\n"
5702 "Aggregate mask\n"
5703 "Filter more specific routes from updates\n")
5704
5705 ALIAS (no_aggregate_address_mask,
5706 no_aggregate_address_mask_as_set_cmd,
5707 "no aggregate-address A.B.C.D A.B.C.D as-set",
5708 NO_STR
5709 "Configure BGP aggregate entries\n"
5710 "Aggregate address\n"
5711 "Aggregate mask\n"
5712 "Generate AS set path information\n")
5713
5714 ALIAS (no_aggregate_address_mask,
5715 no_aggregate_address_mask_as_set_summary_cmd,
5716 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5717 NO_STR
5718 "Configure BGP aggregate entries\n"
5719 "Aggregate address\n"
5720 "Aggregate mask\n"
5721 "Generate AS set path information\n"
5722 "Filter more specific routes from updates\n")
5723
5724 ALIAS (no_aggregate_address_mask,
5725 no_aggregate_address_mask_summary_as_set_cmd,
5726 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5727 NO_STR
5728 "Configure BGP aggregate entries\n"
5729 "Aggregate address\n"
5730 "Aggregate mask\n"
5731 "Filter more specific routes from updates\n"
5732 "Generate AS set path information\n")
5733
5734 #ifdef HAVE_IPV6
5735 DEFUN (ipv6_aggregate_address,
5736 ipv6_aggregate_address_cmd,
5737 "aggregate-address X:X::X:X/M",
5738 "Configure BGP aggregate entries\n"
5739 "Aggregate prefix\n")
5740 {
5741 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5742 }
5743
5744 DEFUN (ipv6_aggregate_address_summary_only,
5745 ipv6_aggregate_address_summary_only_cmd,
5746 "aggregate-address X:X::X:X/M summary-only",
5747 "Configure BGP aggregate entries\n"
5748 "Aggregate prefix\n"
5749 "Filter more specific routes from updates\n")
5750 {
5751 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5752 AGGREGATE_SUMMARY_ONLY, 0);
5753 }
5754
5755 DEFUN (no_ipv6_aggregate_address,
5756 no_ipv6_aggregate_address_cmd,
5757 "no aggregate-address X:X::X:X/M",
5758 NO_STR
5759 "Configure BGP aggregate entries\n"
5760 "Aggregate prefix\n")
5761 {
5762 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5763 }
5764
5765 DEFUN (no_ipv6_aggregate_address_summary_only,
5766 no_ipv6_aggregate_address_summary_only_cmd,
5767 "no aggregate-address X:X::X:X/M summary-only",
5768 NO_STR
5769 "Configure BGP aggregate entries\n"
5770 "Aggregate prefix\n"
5771 "Filter more specific routes from updates\n")
5772 {
5773 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5774 }
5775
5776 ALIAS (ipv6_aggregate_address,
5777 old_ipv6_aggregate_address_cmd,
5778 "ipv6 bgp aggregate-address X:X::X:X/M",
5779 IPV6_STR
5780 BGP_STR
5781 "Configure BGP aggregate entries\n"
5782 "Aggregate prefix\n")
5783
5784 ALIAS (ipv6_aggregate_address_summary_only,
5785 old_ipv6_aggregate_address_summary_only_cmd,
5786 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5787 IPV6_STR
5788 BGP_STR
5789 "Configure BGP aggregate entries\n"
5790 "Aggregate prefix\n"
5791 "Filter more specific routes from updates\n")
5792
5793 ALIAS (no_ipv6_aggregate_address,
5794 old_no_ipv6_aggregate_address_cmd,
5795 "no ipv6 bgp aggregate-address X:X::X:X/M",
5796 NO_STR
5797 IPV6_STR
5798 BGP_STR
5799 "Configure BGP aggregate entries\n"
5800 "Aggregate prefix\n")
5801
5802 ALIAS (no_ipv6_aggregate_address_summary_only,
5803 old_no_ipv6_aggregate_address_summary_only_cmd,
5804 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5805 NO_STR
5806 IPV6_STR
5807 BGP_STR
5808 "Configure BGP aggregate entries\n"
5809 "Aggregate prefix\n"
5810 "Filter more specific routes from updates\n")
5811 #endif /* HAVE_IPV6 */
5812
5813 /* Redistribute route treatment. */
5814 void
5815 bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
5816 const struct in6_addr *nexthop6, unsigned int ifindex,
5817 u_int32_t metric, u_char type, u_short instance, route_tag_t tag)
5818 {
5819 struct bgp_info *new;
5820 struct bgp_info *bi;
5821 struct bgp_info info;
5822 struct bgp_node *bn;
5823 struct attr attr;
5824 struct attr *new_attr;
5825 afi_t afi;
5826 int ret;
5827 struct bgp_redist *red;
5828
5829 /* Make default attribute. */
5830 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5831 if (nexthop)
5832 attr.nexthop = *nexthop;
5833 attr.nh_ifindex = ifindex;
5834
5835 #ifdef HAVE_IPV6
5836 if (nexthop6)
5837 {
5838 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5839 extra->mp_nexthop_global = *nexthop6;
5840 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
5841 }
5842 #endif
5843
5844 attr.med = metric;
5845 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5846 attr.extra->tag = tag;
5847
5848 afi = family2afi (p->family);
5849
5850 red = bgp_redist_lookup(bgp, afi, type, instance);
5851 if (red)
5852 {
5853 struct attr attr_new;
5854 struct attr_extra extra_new;
5855
5856 /* Copy attribute for modification. */
5857 attr_new.extra = &extra_new;
5858 bgp_attr_dup (&attr_new, &attr);
5859
5860 if (red->redist_metric_flag)
5861 attr_new.med = red->redist_metric;
5862
5863 /* Apply route-map. */
5864 if (red->rmap.name)
5865 {
5866 info.peer = bgp->peer_self;
5867 info.attr = &attr_new;
5868
5869 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5870
5871 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5872
5873 bgp->peer_self->rmap_type = 0;
5874
5875 if (ret == RMAP_DENYMATCH)
5876 {
5877 /* Free uninterned attribute. */
5878 bgp_attr_flush (&attr_new);
5879
5880 /* Unintern original. */
5881 aspath_unintern (&attr.aspath);
5882 bgp_attr_extra_free (&attr);
5883 bgp_redistribute_delete (bgp, p, type, instance);
5884 return;
5885 }
5886 }
5887
5888 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5889 afi, SAFI_UNICAST, p, NULL);
5890
5891 new_attr = bgp_attr_intern (&attr_new);
5892
5893 for (bi = bn->info; bi; bi = bi->next)
5894 if (bi->peer == bgp->peer_self
5895 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5896 break;
5897
5898 if (bi)
5899 {
5900 /* Ensure the (source route) type is updated. */
5901 bi->type = type;
5902 if (attrhash_cmp (bi->attr, new_attr) &&
5903 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5904 {
5905 bgp_attr_unintern (&new_attr);
5906 aspath_unintern (&attr.aspath);
5907 bgp_attr_extra_free (&attr);
5908 bgp_unlock_node (bn);
5909 return;
5910 }
5911 else
5912 {
5913 /* The attribute is changed. */
5914 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5915
5916 /* Rewrite BGP route information. */
5917 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5918 bgp_info_restore(bn, bi);
5919 else
5920 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5921 bgp_attr_unintern (&bi->attr);
5922 bi->attr = new_attr;
5923 bi->uptime = bgp_clock ();
5924
5925 /* Process change. */
5926 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5927 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5928 bgp_unlock_node (bn);
5929 aspath_unintern (&attr.aspath);
5930 bgp_attr_extra_free (&attr);
5931 return;
5932 }
5933 }
5934
5935 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5936 new_attr, bn);
5937 SET_FLAG (new->flags, BGP_INFO_VALID);
5938
5939 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5940 bgp_info_add (bn, new);
5941 bgp_unlock_node (bn);
5942 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5943 }
5944
5945 /* Unintern original. */
5946 aspath_unintern (&attr.aspath);
5947 bgp_attr_extra_free (&attr);
5948 }
5949
5950 void
5951 bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
5952 {
5953 afi_t afi;
5954 struct bgp_node *rn;
5955 struct bgp_info *ri;
5956 struct bgp_redist *red;
5957
5958 afi = family2afi (p->family);
5959
5960 red = bgp_redist_lookup(bgp, afi, type, instance);
5961 if (red)
5962 {
5963 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5964
5965 for (ri = rn->info; ri; ri = ri->next)
5966 if (ri->peer == bgp->peer_self
5967 && ri->type == type)
5968 break;
5969
5970 if (ri)
5971 {
5972 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5973 bgp_info_delete (rn, ri);
5974 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5975 }
5976 bgp_unlock_node (rn);
5977 }
5978 }
5979
5980 /* Withdraw specified route type's route. */
5981 void
5982 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
5983 {
5984 struct bgp_node *rn;
5985 struct bgp_info *ri;
5986 struct bgp_table *table;
5987
5988 table = bgp->rib[afi][SAFI_UNICAST];
5989
5990 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5991 {
5992 for (ri = rn->info; ri; ri = ri->next)
5993 if (ri->peer == bgp->peer_self
5994 && ri->type == type
5995 && ri->instance == instance)
5996 break;
5997
5998 if (ri)
5999 {
6000 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
6001 bgp_info_delete (rn, ri);
6002 bgp_process (bgp, rn, afi, SAFI_UNICAST);
6003 }
6004 }
6005 }
6006
6007 /* Static function to display route. */
6008 static void
6009 route_vty_out_route (struct prefix *p, struct vty *vty)
6010 {
6011 int len;
6012 u_int32_t destination;
6013 char buf[BUFSIZ];
6014
6015 if (p->family == AF_INET)
6016 {
6017 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6018 destination = ntohl (p->u.prefix4.s_addr);
6019
6020 if ((IN_CLASSC (destination) && p->prefixlen == 24)
6021 || (IN_CLASSB (destination) && p->prefixlen == 16)
6022 || (IN_CLASSA (destination) && p->prefixlen == 8)
6023 || p->u.prefix4.s_addr == 0)
6024 {
6025 /* When mask is natural, mask is not displayed. */
6026 }
6027 else
6028 len += vty_out (vty, "/%d", p->prefixlen);
6029 }
6030 else
6031 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6032 p->prefixlen);
6033
6034 len = 17 - len;
6035 if (len < 1)
6036 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6037 else
6038 vty_out (vty, "%*s", len, " ");
6039 }
6040
6041 enum bgp_display_type
6042 {
6043 normal_list,
6044 };
6045
6046 /* Print the short form route status for a bgp_info */
6047 static void
6048 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
6049 json_object *json_path)
6050 {
6051 if (json_path)
6052 {
6053
6054 /* Route status display. */
6055 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6056 json_object_boolean_true_add(json_path, "removed");
6057
6058 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6059 json_object_boolean_true_add(json_path, "stale");
6060
6061 if (binfo->extra && binfo->extra->suppress)
6062 json_object_boolean_true_add(json_path, "suppressed");
6063
6064 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6065 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6066 json_object_boolean_true_add(json_path, "valid");
6067
6068 /* Selected */
6069 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6070 json_object_boolean_true_add(json_path, "history");
6071
6072 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6073 json_object_boolean_true_add(json_path, "damped");
6074
6075 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6076 json_object_boolean_true_add(json_path, "bestpath");
6077
6078 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6079 json_object_boolean_true_add(json_path, "multipath");
6080
6081 /* Internal route. */
6082 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6083 json_object_string_add(json_path, "pathFrom", "internal");
6084 else
6085 json_object_string_add(json_path, "pathFrom", "external");
6086
6087 return;
6088 }
6089
6090 /* Route status display. */
6091 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6092 vty_out (vty, "R");
6093 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6094 vty_out (vty, "S");
6095 else if (binfo->extra && binfo->extra->suppress)
6096 vty_out (vty, "s");
6097 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6098 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6099 vty_out (vty, "*");
6100 else
6101 vty_out (vty, " ");
6102
6103 /* Selected */
6104 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6105 vty_out (vty, "h");
6106 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6107 vty_out (vty, "d");
6108 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6109 vty_out (vty, ">");
6110 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6111 vty_out (vty, "=");
6112 else
6113 vty_out (vty, " ");
6114
6115 /* Internal route. */
6116 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6117 vty_out (vty, "i");
6118 else
6119 vty_out (vty, " ");
6120 }
6121
6122 /* called from terminal list command */
6123 void
6124 route_vty_out (struct vty *vty, struct prefix *p,
6125 struct bgp_info *binfo, int display, safi_t safi,
6126 json_object *json_paths)
6127 {
6128 struct attr *attr;
6129 json_object *json_path = NULL;
6130 json_object *json_nexthops = NULL;
6131 json_object *json_nexthop_global = NULL;
6132 json_object *json_nexthop_ll = NULL;
6133
6134 if (json_paths)
6135 json_path = json_object_new_object();
6136
6137 /* short status lead text */
6138 route_vty_short_status_out (vty, binfo, json_path);
6139
6140 if (!json_paths)
6141 {
6142 /* print prefix and mask */
6143 if (! display)
6144 route_vty_out_route (p, vty);
6145 else
6146 vty_out (vty, "%*s", 17, " ");
6147 }
6148
6149 /* Print attribute */
6150 attr = binfo->attr;
6151 if (attr)
6152 {
6153 /*
6154 * For ENCAP routes, nexthop address family is not
6155 * neccessarily the same as the prefix address family.
6156 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
6157 */
6158 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN))
6159 {
6160 if (attr->extra)
6161 {
6162 char buf[BUFSIZ];
6163 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
6164
6165 switch (af)
6166 {
6167 case AF_INET:
6168 vty_out (vty, "%s", inet_ntop(af,
6169 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
6170 break;
6171 #if HAVE_IPV6
6172 case AF_INET6:
6173 vty_out (vty, "%s", inet_ntop(af,
6174 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
6175 break;
6176 #endif
6177 default:
6178 vty_out(vty, "?");
6179 break;
6180 }
6181 }
6182 else
6183 vty_out(vty, "?");
6184 }
6185 /* IPv4 Next Hop */
6186 else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6187 {
6188 if (json_paths)
6189 {
6190 json_nexthop_global = json_object_new_object();
6191
6192 if (safi == SAFI_MPLS_VPN)
6193 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6194 else
6195 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6196
6197 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6198 json_object_boolean_true_add(json_nexthop_global, "used");
6199 }
6200 else
6201 {
6202 if (safi == SAFI_MPLS_VPN)
6203 vty_out (vty, "%-16s",
6204 inet_ntoa (attr->extra->mp_nexthop_global_in));
6205 else
6206 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6207 }
6208 }
6209
6210 /* IPv6 Next Hop */
6211 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6212 {
6213 int len;
6214 char buf[BUFSIZ];
6215
6216 if (json_paths)
6217 {
6218 json_nexthop_global = json_object_new_object();
6219 json_object_string_add(json_nexthop_global, "ip",
6220 inet_ntop (AF_INET6,
6221 &attr->extra->mp_nexthop_global,
6222 buf, BUFSIZ));
6223 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6224 json_object_string_add(json_nexthop_global, "scope", "global");
6225
6226 /* We display both LL & GL if both have been received */
6227 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
6228 {
6229 json_nexthop_ll = json_object_new_object();
6230 json_object_string_add(json_nexthop_ll, "ip",
6231 inet_ntop (AF_INET6,
6232 &attr->extra->mp_nexthop_local,
6233 buf, BUFSIZ));
6234 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6235 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6236
6237 if ((IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
6238 &attr->extra->mp_nexthop_local) != 0) &&
6239 !attr->extra->mp_nexthop_prefer_global)
6240 json_object_boolean_true_add(json_nexthop_ll, "used");
6241 else
6242 json_object_boolean_true_add(json_nexthop_global, "used");
6243 }
6244 else
6245 json_object_boolean_true_add(json_nexthop_global, "used");
6246 }
6247 else
6248 {
6249 /* Display LL if LL/Global both in table unless prefer-global is set */
6250 if (((attr->extra->mp_nexthop_len == 32) &&
6251 !attr->extra->mp_nexthop_prefer_global) ||
6252 (binfo->peer->conf_if))
6253 {
6254 if (binfo->peer->conf_if)
6255 {
6256 len = vty_out (vty, "%s",
6257 binfo->peer->conf_if);
6258 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
6259
6260 if (len < 1)
6261 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
6262 else
6263 vty_out (vty, "%*s", len, " ");
6264 }
6265 else
6266 {
6267 len = vty_out (vty, "%s",
6268 inet_ntop (AF_INET6,
6269 &attr->extra->mp_nexthop_local,
6270 buf, BUFSIZ));
6271 len = 16 - len;
6272
6273 if (len < 1)
6274 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6275 else
6276 vty_out (vty, "%*s", len, " ");
6277 }
6278 }
6279 else
6280 {
6281 len = vty_out (vty, "%s",
6282 inet_ntop (AF_INET6,
6283 &attr->extra->mp_nexthop_global,
6284 buf, BUFSIZ));
6285 len = 16 - len;
6286
6287 if (len < 1)
6288 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6289 else
6290 vty_out (vty, "%*s", len, " ");
6291 }
6292 }
6293 }
6294
6295 /* MED/Metric */
6296 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6297 if (json_paths)
6298 json_object_int_add(json_path, "med", attr->med);
6299 else
6300 vty_out (vty, "%10u", attr->med);
6301 else
6302 if (!json_paths)
6303 vty_out (vty, " ");
6304
6305 /* Local Pref */
6306 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6307 if (json_paths)
6308 json_object_int_add(json_path, "localpref", attr->local_pref);
6309 else
6310 vty_out (vty, "%7u", attr->local_pref);
6311 else
6312 if (!json_paths)
6313 vty_out (vty, " ");
6314
6315 if (json_paths)
6316 {
6317 if (attr->extra)
6318 json_object_int_add(json_path, "weight", attr->extra->weight);
6319 else
6320 json_object_int_add(json_path, "weight", 0);
6321 }
6322 else
6323 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6324
6325 if (json_paths) {
6326 char buf[BUFSIZ];
6327 json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6328 }
6329
6330 /* Print aspath */
6331 if (attr->aspath)
6332 {
6333 if (json_paths)
6334 json_object_string_add(json_path, "aspath", attr->aspath->str);
6335 else
6336 aspath_print_vty (vty, "%s", attr->aspath, " ");
6337 }
6338
6339 /* Print origin */
6340 if (json_paths)
6341 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6342 else
6343 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6344 }
6345 else
6346 {
6347 if (json_paths)
6348 json_object_string_add(json_path, "alert", "No attributes");
6349 else
6350 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6351 }
6352
6353 if (json_paths)
6354 {
6355 if (json_nexthop_global || json_nexthop_ll)
6356 {
6357 json_nexthops = json_object_new_array();
6358
6359 if (json_nexthop_global)
6360 json_object_array_add(json_nexthops, json_nexthop_global);
6361
6362 if (json_nexthop_ll)
6363 json_object_array_add(json_nexthops, json_nexthop_ll);
6364
6365 json_object_object_add(json_path, "nexthops", json_nexthops);
6366 }
6367
6368 json_object_array_add(json_paths, json_path);
6369 }
6370 else
6371 {
6372 vty_out (vty, "%s", VTY_NEWLINE);
6373 #if ENABLE_BGP_VNC
6374 /* prints an additional line, indented, with VNC info, if present */
6375 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
6376 rfapi_vty_out_vncinfo(vty, p, binfo, safi);
6377 #endif
6378 }
6379 }
6380
6381 /* called from terminal list command */
6382 void
6383 route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6384 u_char use_json, json_object *json_ar)
6385 {
6386 json_object *json_status = NULL;
6387 json_object *json_net = NULL;
6388 char buff[BUFSIZ];
6389 /* Route status display. */
6390 if (use_json)
6391 {
6392 json_status = json_object_new_object();
6393 json_net = json_object_new_object();
6394 }
6395 else
6396 {
6397 vty_out (vty, "*");
6398 vty_out (vty, ">");
6399 vty_out (vty, " ");
6400 }
6401
6402 /* print prefix and mask */
6403 if (use_json)
6404 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6405 else
6406 route_vty_out_route (p, vty);
6407
6408 /* Print attribute */
6409 if (attr)
6410 {
6411 if (use_json)
6412 {
6413 if (p->family == AF_INET &&
6414 (safi == SAFI_MPLS_VPN ||
6415 safi == SAFI_ENCAP ||
6416 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6417 {
6418 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6419 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6420 else
6421 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6422 }
6423 #ifdef HAVE_IPV6
6424 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6425 {
6426 char buf[BUFSIZ];
6427
6428 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6429 buf, BUFSIZ));
6430 }
6431 #endif /* HAVE_IPV6 */
6432
6433 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6434 json_object_int_add(json_net, "metric", attr->med);
6435
6436 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6437 json_object_int_add(json_net, "localPref", attr->local_pref);
6438
6439 if (attr->extra)
6440 json_object_int_add(json_net, "weight", attr->extra->weight);
6441 else
6442 json_object_int_add(json_net, "weight", 0);
6443
6444 /* Print aspath */
6445 if (attr->aspath)
6446 json_object_string_add(json_net, "asPath", attr->aspath->str);
6447
6448 /* Print origin */
6449 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
6450 }
6451 else
6452 {
6453 if (p->family == AF_INET &&
6454 (safi == SAFI_MPLS_VPN ||
6455 safi == SAFI_ENCAP ||
6456 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6457 {
6458 if (attr->extra &&
6459 (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP))
6460 vty_out (vty, "%-16s",
6461 inet_ntoa (attr->extra->mp_nexthop_global_in));
6462 else
6463 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6464 }
6465 #ifdef HAVE_IPV6
6466 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6467 {
6468 int len;
6469 char buf[BUFSIZ];
6470 if (attr->extra)
6471 {
6472 len = vty_out (vty, "%s",
6473 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6474 buf, BUFSIZ));
6475 len = 16 - len;
6476 }
6477 else
6478 len = 0;
6479 if (len < 1)
6480 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6481 else
6482 vty_out (vty, "%*s", len, " ");
6483 }
6484 #endif /* HAVE_IPV6 */
6485 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6486 vty_out (vty, "%10u", attr->med);
6487 else
6488 vty_out (vty, " ");
6489
6490 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6491 vty_out (vty, "%7u", attr->local_pref);
6492 else
6493 vty_out (vty, " ");
6494
6495 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6496
6497 /* Print aspath */
6498 if (attr->aspath)
6499 aspath_print_vty (vty, "%s", attr->aspath, " ");
6500
6501 /* Print origin */
6502 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6503 }
6504 }
6505 if (use_json)
6506 {
6507 json_object_boolean_true_add(json_status, "*");
6508 json_object_boolean_true_add(json_status, ">");
6509 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6510 char buf_cut[BUFSIZ];
6511 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6512 }
6513 else
6514 vty_out (vty, "%s", VTY_NEWLINE);
6515 }
6516
6517 void
6518 route_vty_out_tag (struct vty *vty, struct prefix *p,
6519 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
6520 {
6521 json_object *json_out = NULL;
6522 struct attr *attr;
6523 u_int32_t label = 0;
6524
6525 if (!binfo->extra)
6526 return;
6527
6528 if (json)
6529 json_out = json_object_new_object();
6530
6531 /* short status lead text */
6532 route_vty_short_status_out (vty, binfo, json_out);
6533
6534 /* print prefix and mask */
6535 if (json == NULL)
6536 {
6537 if (! display)
6538 route_vty_out_route (p, vty);
6539 else
6540 vty_out (vty, "%*s", 17, " ");
6541 }
6542
6543 /* Print attribute */
6544 attr = binfo->attr;
6545 if (attr)
6546 {
6547 if (p->family == AF_INET
6548 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6549 {
6550 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6551 {
6552 if (json)
6553 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6554 else
6555 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6556 }
6557 else
6558 {
6559 if (json)
6560 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6561 else
6562 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6563 }
6564 }
6565 #ifdef HAVE_IPV6
6566 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6567 {
6568 assert (attr->extra);
6569 char buf_a[BUFSIZ];
6570 char buf_b[BUFSIZ];
6571 char buf_c[BUFSIZ];
6572 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
6573 {
6574 if (json)
6575 json_object_string_add(json_out, "mpNexthopGlobalIn",
6576 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6577 else
6578 vty_out (vty, "%s",
6579 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6580 buf_a, BUFSIZ));
6581 }
6582 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6583 {
6584 if (json)
6585 {
6586 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6587 buf_a, BUFSIZ);
6588 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6589 buf_b, BUFSIZ);
6590 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6591 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6592 }
6593 else
6594 vty_out (vty, "%s(%s)",
6595 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6596 buf_a, BUFSIZ),
6597 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6598 buf_b, BUFSIZ));
6599 }
6600
6601 }
6602 #endif /* HAVE_IPV6 */
6603 }
6604
6605 label = decode_label (binfo->extra->tag);
6606
6607 if (json)
6608 {
6609 if (label)
6610 json_object_int_add(json_out, "notag", label);
6611 json_object_array_add(json, json_out);
6612 }
6613 else
6614 {
6615 vty_out (vty, "notag/%d", label);
6616 vty_out (vty, "%s", VTY_NEWLINE);
6617 }
6618 }
6619
6620 /* dampening route */
6621 static void
6622 damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6623 int display, safi_t safi, u_char use_json, json_object *json)
6624 {
6625 struct attr *attr;
6626 int len;
6627 char timebuf[BGP_UPTIME_LEN];
6628
6629 /* short status lead text */
6630 route_vty_short_status_out (vty, binfo, json);
6631
6632 /* print prefix and mask */
6633 if (!use_json)
6634 {
6635 if (! display)
6636 route_vty_out_route (p, vty);
6637 else
6638 vty_out (vty, "%*s", 17, " ");
6639 }
6640
6641 len = vty_out (vty, "%s", binfo->peer->host);
6642 len = 17 - len;
6643 if (len < 1)
6644 {
6645 if (!use_json)
6646 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6647 }
6648 else
6649 {
6650 if (use_json)
6651 json_object_int_add(json, "peerHost", len);
6652 else
6653 vty_out (vty, "%*s", len, " ");
6654 }
6655
6656 if (use_json)
6657 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6658 else
6659 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6660
6661 /* Print attribute */
6662 attr = binfo->attr;
6663 if (attr)
6664 {
6665 /* Print aspath */
6666 if (attr->aspath)
6667 {
6668 if (use_json)
6669 json_object_string_add(json, "asPath", attr->aspath->str);
6670 else
6671 aspath_print_vty (vty, "%s", attr->aspath, " ");
6672 }
6673
6674 /* Print origin */
6675 if (use_json)
6676 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6677 else
6678 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6679 }
6680 if (!use_json)
6681 vty_out (vty, "%s", VTY_NEWLINE);
6682 }
6683
6684 /* flap route */
6685 static void
6686 flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6687 int display, safi_t safi, u_char use_json, json_object *json)
6688 {
6689 struct attr *attr;
6690 struct bgp_damp_info *bdi;
6691 char timebuf[BGP_UPTIME_LEN];
6692 int len;
6693
6694 if (!binfo->extra)
6695 return;
6696
6697 bdi = binfo->extra->damp_info;
6698
6699 /* short status lead text */
6700 route_vty_short_status_out (vty, binfo, json);
6701
6702 /* print prefix and mask */
6703 if (!use_json)
6704 {
6705 if (! display)
6706 route_vty_out_route (p, vty);
6707 else
6708 vty_out (vty, "%*s", 17, " ");
6709 }
6710
6711 len = vty_out (vty, "%s", binfo->peer->host);
6712 len = 16 - len;
6713 if (len < 1)
6714 {
6715 if (!use_json)
6716 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6717 }
6718 else
6719 {
6720 if (use_json)
6721 json_object_int_add(json, "peerHost", len);
6722 else
6723 vty_out (vty, "%*s", len, " ");
6724 }
6725
6726 len = vty_out (vty, "%d", bdi->flap);
6727 len = 5 - len;
6728 if (len < 1)
6729 {
6730 if (!use_json)
6731 vty_out (vty, " ");
6732 }
6733 else
6734 {
6735 if (use_json)
6736 json_object_int_add(json, "bdiFlap", len);
6737 else
6738 vty_out (vty, "%*s", len, " ");
6739 }
6740
6741 if (use_json)
6742 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6743 else
6744 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6745 timebuf, BGP_UPTIME_LEN, 0, NULL));
6746
6747 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6748 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6749 {
6750 if (use_json)
6751 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6752 else
6753 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6754 }
6755 else
6756 {
6757 if (!use_json)
6758 vty_out (vty, "%*s ", 8, " ");
6759 }
6760
6761 /* Print attribute */
6762 attr = binfo->attr;
6763 if (attr)
6764 {
6765 /* Print aspath */
6766 if (attr->aspath)
6767 {
6768 if (use_json)
6769 json_object_string_add(json, "asPath", attr->aspath->str);
6770 else
6771 aspath_print_vty (vty, "%s", attr->aspath, " ");
6772 }
6773
6774 /* Print origin */
6775 if (use_json)
6776 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6777 else
6778 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6779 }
6780 if (!use_json)
6781 vty_out (vty, "%s", VTY_NEWLINE);
6782 }
6783
6784 static void
6785 route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6786 const char *header, json_object *json_adv_to)
6787 {
6788 char buf1[INET6_ADDRSTRLEN];
6789 json_object *json_peer = NULL;
6790
6791 if (json_adv_to)
6792 {
6793 /* 'advertised-to' is a dictionary of peers we have advertised this
6794 * prefix too. The key is the peer's IP or swpX, the value is the
6795 * hostname if we know it and "" if not.
6796 */
6797 json_peer = json_object_new_object();
6798
6799 if (peer->hostname)
6800 json_object_string_add(json_peer, "hostname", peer->hostname);
6801
6802 if (peer->conf_if)
6803 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6804 else
6805 json_object_object_add(json_adv_to,
6806 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6807 json_peer);
6808 }
6809 else
6810 {
6811 if (*first)
6812 {
6813 vty_out (vty, "%s", header);
6814 *first = 0;
6815 }
6816
6817 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6818 {
6819 if (peer->conf_if)
6820 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6821 else
6822 vty_out (vty, " %s(%s)", peer->hostname,
6823 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6824 }
6825 else
6826 {
6827 if (peer->conf_if)
6828 vty_out (vty, " %s", peer->conf_if);
6829 else
6830 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6831 }
6832 }
6833 }
6834
6835 static void
6836 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6837 struct bgp_info *binfo, afi_t afi, safi_t safi,
6838 json_object *json_paths)
6839 {
6840 char buf[INET6_ADDRSTRLEN];
6841 char buf1[BUFSIZ];
6842 struct attr *attr;
6843 int sockunion_vty_out (struct vty *, union sockunion *);
6844 #ifdef HAVE_CLOCK_MONOTONIC
6845 time_t tbuf;
6846 #endif
6847 json_object *json_bestpath = NULL;
6848 json_object *json_cluster_list = NULL;
6849 json_object *json_cluster_list_list = NULL;
6850 json_object *json_ext_community = NULL;
6851 json_object *json_last_update = NULL;
6852 json_object *json_nexthop_global = NULL;
6853 json_object *json_nexthop_ll = NULL;
6854 json_object *json_nexthops = NULL;
6855 json_object *json_path = NULL;
6856 json_object *json_peer = NULL;
6857 json_object *json_string = NULL;
6858 json_object *json_adv_to = NULL;
6859 int first = 0;
6860 struct listnode *node, *nnode;
6861 struct peer *peer;
6862 int addpath_capable;
6863 int has_adj;
6864 unsigned int first_as;
6865
6866 if (json_paths)
6867 {
6868 json_path = json_object_new_object();
6869 json_peer = json_object_new_object();
6870 json_nexthop_global = json_object_new_object();
6871 }
6872
6873 attr = binfo->attr;
6874
6875 if (attr)
6876 {
6877 /* Line1 display AS-path, Aggregator */
6878 if (attr->aspath)
6879 {
6880 if (json_paths)
6881 {
6882 json_object_lock(attr->aspath->json);
6883 json_object_object_add(json_path, "aspath", attr->aspath->json);
6884 }
6885 else
6886 {
6887 if (attr->aspath->segments)
6888 aspath_print_vty (vty, " %s", attr->aspath, "");
6889 else
6890 vty_out (vty, " Local");
6891 }
6892 }
6893
6894 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6895 {
6896 if (json_paths)
6897 json_object_boolean_true_add(json_path, "removed");
6898 else
6899 vty_out (vty, ", (removed)");
6900 }
6901
6902 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6903 {
6904 if (json_paths)
6905 json_object_boolean_true_add(json_path, "stale");
6906 else
6907 vty_out (vty, ", (stale)");
6908 }
6909
6910 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6911 {
6912 if (json_paths)
6913 {
6914 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6915 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
6916 }
6917 else
6918 {
6919 vty_out (vty, ", (aggregated by %u %s)",
6920 attr->extra->aggregator_as,
6921 inet_ntoa (attr->extra->aggregator_addr));
6922 }
6923 }
6924
6925 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6926 {
6927 if (json_paths)
6928 json_object_boolean_true_add(json_path, "rxedFromRrClient");
6929 else
6930 vty_out (vty, ", (Received from a RR-client)");
6931 }
6932
6933 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6934 {
6935 if (json_paths)
6936 json_object_boolean_true_add(json_path, "rxedFromRsClient");
6937 else
6938 vty_out (vty, ", (Received from a RS-client)");
6939 }
6940
6941 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6942 {
6943 if (json_paths)
6944 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
6945 else
6946 vty_out (vty, ", (history entry)");
6947 }
6948 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6949 {
6950 if (json_paths)
6951 json_object_boolean_true_add(json_path, "dampeningSuppressed");
6952 else
6953 vty_out (vty, ", (suppressed due to dampening)");
6954 }
6955
6956 if (!json_paths)
6957 vty_out (vty, "%s", VTY_NEWLINE);
6958
6959 /* Line2 display Next-hop, Neighbor, Router-id */
6960 /* Display the nexthop */
6961 if (p->family == AF_INET &&
6962 (safi == SAFI_MPLS_VPN ||
6963 safi == SAFI_ENCAP ||
6964 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6965 {
6966 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6967 {
6968 if (json_paths)
6969 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6970 else
6971 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6972 }
6973 else
6974 {
6975 if (json_paths)
6976 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6977 else
6978 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6979 }
6980
6981 if (json_paths)
6982 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6983 }
6984 else
6985 {
6986 assert (attr->extra);
6987 if (json_paths)
6988 {
6989 json_object_string_add(json_nexthop_global, "ip",
6990 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6991 buf, INET6_ADDRSTRLEN));
6992 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6993 json_object_string_add(json_nexthop_global, "scope", "global");
6994 }
6995 else
6996 {
6997 vty_out (vty, " %s",
6998 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6999 buf, INET6_ADDRSTRLEN));
7000 }
7001 }
7002
7003 /* Display the IGP cost or 'inaccessible' */
7004 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7005 {
7006 if (json_paths)
7007 json_object_boolean_false_add(json_nexthop_global, "accessible");
7008 else
7009 vty_out (vty, " (inaccessible)");
7010 }
7011 else
7012 {
7013 if (binfo->extra && binfo->extra->igpmetric)
7014 {
7015 if (json_paths)
7016 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
7017 else
7018 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
7019 }
7020
7021 /* IGP cost is 0, display this only for json */
7022 else
7023 {
7024 if (json_paths)
7025 json_object_int_add(json_nexthop_global, "metric", 0);
7026 }
7027
7028 if (json_paths)
7029 json_object_boolean_true_add(json_nexthop_global, "accessible");
7030 }
7031
7032 /* Display peer "from" output */
7033 /* This path was originated locally */
7034 if (binfo->peer == bgp->peer_self)
7035 {
7036
7037 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
7038 {
7039 if (json_paths)
7040 json_object_string_add(json_peer, "peerId", "0.0.0.0");
7041 else
7042 vty_out (vty, " from 0.0.0.0 ");
7043 }
7044 else
7045 {
7046 if (json_paths)
7047 json_object_string_add(json_peer, "peerId", "::");
7048 else
7049 vty_out (vty, " from :: ");
7050 }
7051
7052 if (json_paths)
7053 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
7054 else
7055 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
7056 }
7057
7058 /* We RXed this path from one of our peers */
7059 else
7060 {
7061
7062 if (json_paths)
7063 {
7064 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7065 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7066
7067 if (binfo->peer->hostname)
7068 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
7069
7070 if (binfo->peer->domainname)
7071 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
7072
7073 if (binfo->peer->conf_if)
7074 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
7075 }
7076 else
7077 {
7078 if (binfo->peer->conf_if)
7079 {
7080 if (binfo->peer->hostname &&
7081 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7082 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7083 binfo->peer->conf_if);
7084 else
7085 vty_out (vty, " from %s", binfo->peer->conf_if);
7086 }
7087 else
7088 {
7089 if (binfo->peer->hostname &&
7090 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7091 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7092 binfo->peer->host);
7093 else
7094 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7095 }
7096
7097 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7098 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
7099 else
7100 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7101 }
7102 }
7103
7104 if (!json_paths)
7105 vty_out (vty, "%s", VTY_NEWLINE);
7106
7107 /* display the link-local nexthop */
7108 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
7109 {
7110 if (json_paths)
7111 {
7112 json_nexthop_ll = json_object_new_object();
7113 json_object_string_add(json_nexthop_ll, "ip",
7114 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7115 buf, INET6_ADDRSTRLEN));
7116 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
7117 json_object_string_add(json_nexthop_ll, "scope", "link-local");
7118
7119 json_object_boolean_true_add(json_nexthop_ll, "accessible");
7120
7121 if (!attr->extra->mp_nexthop_prefer_global)
7122 json_object_boolean_true_add(json_nexthop_ll, "used");
7123 else
7124 json_object_boolean_true_add(json_nexthop_global, "used");
7125 }
7126 else
7127 {
7128 vty_out (vty, " (%s) %s%s",
7129 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7130 buf, INET6_ADDRSTRLEN),
7131 attr->extra->mp_nexthop_prefer_global ?
7132 "(prefer-global)" : "(used)",
7133 VTY_NEWLINE);
7134 }
7135 }
7136 /* If we do not have a link-local nexthop then we must flag the global as "used" */
7137 else
7138 {
7139 if (json_paths)
7140 json_object_boolean_true_add(json_nexthop_global, "used");
7141 }
7142
7143 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
7144 if (json_paths)
7145 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
7146 else
7147 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
7148
7149 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
7150 {
7151 if (json_paths)
7152 json_object_int_add(json_path, "med", attr->med);
7153 else
7154 vty_out (vty, ", metric %u", attr->med);
7155 }
7156
7157 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
7158 {
7159 if (json_paths)
7160 json_object_int_add(json_path, "localpref", attr->local_pref);
7161 else
7162 vty_out (vty, ", localpref %u", attr->local_pref);
7163 }
7164 else
7165 {
7166 if (json_paths)
7167 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
7168 else
7169 vty_out (vty, ", localpref %u", bgp->default_local_pref);
7170 }
7171
7172 if (attr->extra && attr->extra->weight != 0)
7173 {
7174 if (json_paths)
7175 json_object_int_add(json_path, "weight", attr->extra->weight);
7176 else
7177 vty_out (vty, ", weight %u", attr->extra->weight);
7178 }
7179
7180 if (attr->extra && attr->extra->tag != 0)
7181 {
7182 if (json_paths)
7183 json_object_int_add(json_path, "tag", attr->extra->tag);
7184 else
7185 vty_out (vty, ", tag %"ROUTE_TAG_PRI, attr->extra->tag);
7186 }
7187
7188 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7189 {
7190 if (json_paths)
7191 json_object_boolean_false_add(json_path, "valid");
7192 else
7193 vty_out (vty, ", invalid");
7194 }
7195 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
7196 {
7197 if (json_paths)
7198 json_object_boolean_true_add(json_path, "valid");
7199 else
7200 vty_out (vty, ", valid");
7201 }
7202
7203 if (binfo->peer != bgp->peer_self)
7204 {
7205 if (binfo->peer->as == binfo->peer->local_as)
7206 {
7207 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7208 {
7209 if (json_paths)
7210 json_object_string_add(json_peer, "type", "confed-internal");
7211 else
7212 vty_out (vty, ", confed-internal");
7213 }
7214 else
7215 {
7216 if (json_paths)
7217 json_object_string_add(json_peer, "type", "internal");
7218 else
7219 vty_out (vty, ", internal");
7220 }
7221 }
7222 else
7223 {
7224 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
7225 {
7226 if (json_paths)
7227 json_object_string_add(json_peer, "type", "confed-external");
7228 else
7229 vty_out (vty, ", confed-external");
7230 }
7231 else
7232 {
7233 if (json_paths)
7234 json_object_string_add(json_peer, "type", "external");
7235 else
7236 vty_out (vty, ", external");
7237 }
7238 }
7239 }
7240 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
7241 {
7242 if (json_paths)
7243 {
7244 json_object_boolean_true_add(json_path, "aggregated");
7245 json_object_boolean_true_add(json_path, "local");
7246 }
7247 else
7248 {
7249 vty_out (vty, ", aggregated, local");
7250 }
7251 }
7252 else if (binfo->type != ZEBRA_ROUTE_BGP)
7253 {
7254 if (json_paths)
7255 json_object_boolean_true_add(json_path, "sourced");
7256 else
7257 vty_out (vty, ", sourced");
7258 }
7259 else
7260 {
7261 if (json_paths)
7262 {
7263 json_object_boolean_true_add(json_path, "sourced");
7264 json_object_boolean_true_add(json_path, "local");
7265 }
7266 else
7267 {
7268 vty_out (vty, ", sourced, local");
7269 }
7270 }
7271
7272 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
7273 {
7274 if (json_paths)
7275 json_object_boolean_true_add(json_path, "atomicAggregate");
7276 else
7277 vty_out (vty, ", atomic-aggregate");
7278 }
7279
7280 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7281 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7282 bgp_info_mpath_count (binfo)))
7283 {
7284 if (json_paths)
7285 json_object_boolean_true_add(json_path, "multipath");
7286 else
7287 vty_out (vty, ", multipath");
7288 }
7289
7290 // Mark the bestpath(s)
7291 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
7292 {
7293 first_as = aspath_get_first_as(attr->aspath);
7294
7295 if (json_paths)
7296 {
7297 if (!json_bestpath)
7298 json_bestpath = json_object_new_object();
7299 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
7300 }
7301 else
7302 {
7303 if (first_as)
7304 vty_out (vty, ", bestpath-from-AS %d", first_as);
7305 else
7306 vty_out (vty, ", bestpath-from-AS Local");
7307 }
7308 }
7309
7310 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
7311 {
7312 if (json_paths)
7313 {
7314 if (!json_bestpath)
7315 json_bestpath = json_object_new_object();
7316 json_object_boolean_true_add(json_bestpath, "overall");
7317 }
7318 else
7319 vty_out (vty, ", best");
7320 }
7321
7322 if (json_bestpath)
7323 json_object_object_add(json_path, "bestpath", json_bestpath);
7324
7325 if (!json_paths)
7326 vty_out (vty, "%s", VTY_NEWLINE);
7327
7328 /* Line 4 display Community */
7329 if (attr->community)
7330 {
7331 if (json_paths)
7332 {
7333 json_object_lock(attr->community->json);
7334 json_object_object_add(json_path, "community", attr->community->json);
7335 }
7336 else
7337 {
7338 vty_out (vty, " Community: %s%s", attr->community->str,
7339 VTY_NEWLINE);
7340 }
7341 }
7342
7343 /* Line 5 display Extended-community */
7344 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
7345 {
7346 if (json_paths)
7347 {
7348 json_ext_community = json_object_new_object();
7349 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
7350 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
7351 }
7352 else
7353 {
7354 vty_out (vty, " Extended Community: %s%s",
7355 attr->extra->ecommunity->str, VTY_NEWLINE);
7356 }
7357 }
7358
7359 /* Line 6 display Originator, Cluster-id */
7360 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7361 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7362 {
7363 assert (attr->extra);
7364 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7365 {
7366 if (json_paths)
7367 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
7368 else
7369 vty_out (vty, " Originator: %s",
7370 inet_ntoa (attr->extra->originator_id));
7371 }
7372
7373 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7374 {
7375 int i;
7376
7377 if (json_paths)
7378 {
7379 json_cluster_list = json_object_new_object();
7380 json_cluster_list_list = json_object_new_array();
7381
7382 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7383 {
7384 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
7385 json_object_array_add(json_cluster_list_list, json_string);
7386 }
7387
7388 /* struct cluster_list does not have "str" variable like
7389 * aspath and community do. Add this someday if someone
7390 * asks for it.
7391 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7392 */
7393 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
7394 json_object_object_add(json_path, "clusterList", json_cluster_list);
7395 }
7396 else
7397 {
7398 vty_out (vty, ", Cluster list: ");
7399
7400 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7401 {
7402 vty_out (vty, "%s ",
7403 inet_ntoa (attr->extra->cluster->list[i]));
7404 }
7405 }
7406 }
7407
7408 if (!json_paths)
7409 vty_out (vty, "%s", VTY_NEWLINE);
7410 }
7411
7412 if (binfo->extra && binfo->extra->damp_info)
7413 bgp_damp_info_vty (vty, binfo, json_path);
7414
7415 /* Line 7 display Addpath IDs */
7416 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
7417 {
7418 if (json_paths)
7419 {
7420 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7421 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
7422 }
7423 else
7424 {
7425 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7426 binfo->addpath_rx_id, binfo->addpath_tx_id,
7427 VTY_NEWLINE);
7428 }
7429 }
7430
7431 /* If we used addpath to TX a non-bestpath we need to display
7432 * "Advertised to" on a path-by-path basis */
7433 if (bgp->addpath_tx_used[afi][safi])
7434 {
7435 first = 1;
7436
7437 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7438 {
7439 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7440 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7441
7442 if ((addpath_capable && has_adj) ||
7443 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7444 {
7445 if (json_path && !json_adv_to)
7446 json_adv_to = json_object_new_object();
7447
7448 route_vty_out_advertised_to(vty, peer, &first,
7449 " Advertised to:",
7450 json_adv_to);
7451 }
7452 }
7453
7454 if (json_path)
7455 {
7456 if (json_adv_to)
7457 {
7458 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7459 }
7460 }
7461 else
7462 {
7463 if (!first)
7464 {
7465 vty_out (vty, "%s", VTY_NEWLINE);
7466 }
7467 }
7468 }
7469
7470 /* Line 8 display Uptime */
7471 #ifdef HAVE_CLOCK_MONOTONIC
7472 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
7473 if (json_paths)
7474 {
7475 json_last_update = json_object_new_object();
7476 json_object_int_add(json_last_update, "epoch", tbuf);
7477 json_object_string_add(json_last_update, "string", ctime(&tbuf));
7478 json_object_object_add(json_path, "lastUpdate", json_last_update);
7479 }
7480 else
7481 vty_out (vty, " Last update: %s", ctime(&tbuf));
7482 #else
7483 if (json_paths)
7484 {
7485 json_last_update = json_object_new_object();
7486 json_object_int_add(json_last_update, "epoch", tbuf);
7487 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
7488 json_object_object_add(json_path, "lastUpdate", json_last_update);
7489 }
7490 else
7491 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
7492 #endif /* HAVE_CLOCK_MONOTONIC */
7493 }
7494
7495 /* We've constructed the json object for this path, add it to the json
7496 * array of paths
7497 */
7498 if (json_paths)
7499 {
7500 if (json_nexthop_global || json_nexthop_ll)
7501 {
7502 json_nexthops = json_object_new_array();
7503
7504 if (json_nexthop_global)
7505 json_object_array_add(json_nexthops, json_nexthop_global);
7506
7507 if (json_nexthop_ll)
7508 json_object_array_add(json_nexthops, json_nexthop_ll);
7509
7510 json_object_object_add(json_path, "nexthops", json_nexthops);
7511 }
7512
7513 json_object_object_add(json_path, "peer", json_peer);
7514 json_object_array_add(json_paths, json_path);
7515 }
7516 else
7517 vty_out (vty, "%s", VTY_NEWLINE);
7518 }
7519
7520 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
7521 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7522 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7523
7524 enum bgp_show_type
7525 {
7526 bgp_show_type_normal,
7527 bgp_show_type_regexp,
7528 bgp_show_type_prefix_list,
7529 bgp_show_type_filter_list,
7530 bgp_show_type_route_map,
7531 bgp_show_type_neighbor,
7532 bgp_show_type_cidr_only,
7533 bgp_show_type_prefix_longer,
7534 bgp_show_type_community_all,
7535 bgp_show_type_community,
7536 bgp_show_type_community_exact,
7537 bgp_show_type_community_list,
7538 bgp_show_type_community_list_exact,
7539 bgp_show_type_flap_statistics,
7540 bgp_show_type_flap_address,
7541 bgp_show_type_flap_prefix,
7542 bgp_show_type_flap_cidr_only,
7543 bgp_show_type_flap_regexp,
7544 bgp_show_type_flap_filter_list,
7545 bgp_show_type_flap_prefix_list,
7546 bgp_show_type_flap_prefix_longer,
7547 bgp_show_type_flap_route_map,
7548 bgp_show_type_flap_neighbor,
7549 bgp_show_type_dampend_paths,
7550 bgp_show_type_damp_neighbor
7551 };
7552
7553 static int
7554 bgp_show_prefix_list (struct vty *vty, const char *name,
7555 const char *prefix_list_str, afi_t afi,
7556 safi_t safi, enum bgp_show_type type);
7557 static int
7558 bgp_show_filter_list (struct vty *vty, const char *name,
7559 const char *filter, afi_t afi,
7560 safi_t safi, enum bgp_show_type type);
7561 static int
7562 bgp_show_route_map (struct vty *vty, const char *name,
7563 const char *rmap_str, afi_t afi,
7564 safi_t safi, enum bgp_show_type type);
7565 static int
7566 bgp_show_community_list (struct vty *vty, const char *name,
7567 const char *com, int exact,
7568 afi_t afi, safi_t safi);
7569 static int
7570 bgp_show_prefix_longer (struct vty *vty, const char *name,
7571 const char *prefix, afi_t afi,
7572 safi_t safi, enum bgp_show_type type);
7573
7574 static int
7575 bgp_show_table (struct vty *vty, struct bgp *bgp, struct bgp_table *table,
7576 enum bgp_show_type type, void *output_arg, u_char use_json)
7577 {
7578 struct bgp_info *ri;
7579 struct bgp_node *rn;
7580 int header = 1;
7581 int display;
7582 unsigned long output_count;
7583 unsigned long total_count;
7584 struct prefix *p;
7585 char buf[BUFSIZ];
7586 char buf2[BUFSIZ];
7587 json_object *json_paths = NULL;
7588 int first = 1;
7589
7590 if (use_json)
7591 {
7592 vty_out (vty, "{ \"vrfId\": %d, \"vrfName\": \"%s\", \"tableVersion\": %" PRId64 ", \"routerId\": \"%s\", \"routes\": { ",
7593 bgp->vrf_id == VRF_UNKNOWN ? -1 : bgp->vrf_id,
7594 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ? "Default" : bgp->name,
7595 table->version, inet_ntoa (bgp->router_id));
7596 json_paths = json_object_new_object();
7597 }
7598
7599 /* This is first entry point, so reset total line. */
7600 output_count = 0;
7601 total_count = 0;
7602
7603 /* Start processing of routes. */
7604 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7605 if (rn->info != NULL)
7606 {
7607 display = 0;
7608 if (!first && use_json)
7609 {
7610 vty_out (vty, ",");
7611 }
7612 if (use_json)
7613 json_paths = json_object_new_array();
7614 else
7615 json_paths = NULL;
7616
7617 for (ri = rn->info; ri; ri = ri->next)
7618 {
7619 total_count++;
7620 if (type == bgp_show_type_flap_statistics
7621 || type == bgp_show_type_flap_address
7622 || type == bgp_show_type_flap_prefix
7623 || type == bgp_show_type_flap_cidr_only
7624 || type == bgp_show_type_flap_regexp
7625 || type == bgp_show_type_flap_filter_list
7626 || type == bgp_show_type_flap_prefix_list
7627 || type == bgp_show_type_flap_prefix_longer
7628 || type == bgp_show_type_flap_route_map
7629 || type == bgp_show_type_flap_neighbor
7630 || type == bgp_show_type_dampend_paths
7631 || type == bgp_show_type_damp_neighbor)
7632 {
7633 if (!(ri->extra && ri->extra->damp_info))
7634 continue;
7635 }
7636 if (type == bgp_show_type_regexp
7637 || type == bgp_show_type_flap_regexp)
7638 {
7639 regex_t *regex = output_arg;
7640
7641 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7642 continue;
7643 }
7644 if (type == bgp_show_type_prefix_list
7645 || type == bgp_show_type_flap_prefix_list)
7646 {
7647 struct prefix_list *plist = output_arg;
7648
7649 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7650 continue;
7651 }
7652 if (type == bgp_show_type_filter_list
7653 || type == bgp_show_type_flap_filter_list)
7654 {
7655 struct as_list *as_list = output_arg;
7656
7657 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7658 continue;
7659 }
7660 if (type == bgp_show_type_route_map
7661 || type == bgp_show_type_flap_route_map)
7662 {
7663 struct route_map *rmap = output_arg;
7664 struct bgp_info binfo;
7665 struct attr dummy_attr;
7666 struct attr_extra dummy_extra;
7667 int ret;
7668
7669 dummy_attr.extra = &dummy_extra;
7670 bgp_attr_dup (&dummy_attr, ri->attr);
7671
7672 binfo.peer = ri->peer;
7673 binfo.attr = &dummy_attr;
7674
7675 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7676 if (ret == RMAP_DENYMATCH)
7677 continue;
7678 }
7679 if (type == bgp_show_type_neighbor
7680 || type == bgp_show_type_flap_neighbor
7681 || type == bgp_show_type_damp_neighbor)
7682 {
7683 union sockunion *su = output_arg;
7684
7685 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7686 continue;
7687 }
7688 if (type == bgp_show_type_cidr_only
7689 || type == bgp_show_type_flap_cidr_only)
7690 {
7691 u_int32_t destination;
7692
7693 destination = ntohl (rn->p.u.prefix4.s_addr);
7694 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7695 continue;
7696 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7697 continue;
7698 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7699 continue;
7700 }
7701 if (type == bgp_show_type_prefix_longer
7702 || type == bgp_show_type_flap_prefix_longer)
7703 {
7704 struct prefix *p = output_arg;
7705
7706 if (! prefix_match (p, &rn->p))
7707 continue;
7708 }
7709 if (type == bgp_show_type_community_all)
7710 {
7711 if (! ri->attr->community)
7712 continue;
7713 }
7714 if (type == bgp_show_type_community)
7715 {
7716 struct community *com = output_arg;
7717
7718 if (! ri->attr->community ||
7719 ! community_match (ri->attr->community, com))
7720 continue;
7721 }
7722 if (type == bgp_show_type_community_exact)
7723 {
7724 struct community *com = output_arg;
7725
7726 if (! ri->attr->community ||
7727 ! community_cmp (ri->attr->community, com))
7728 continue;
7729 }
7730 if (type == bgp_show_type_community_list)
7731 {
7732 struct community_list *list = output_arg;
7733
7734 if (! community_list_match (ri->attr->community, list))
7735 continue;
7736 }
7737 if (type == bgp_show_type_community_list_exact)
7738 {
7739 struct community_list *list = output_arg;
7740
7741 if (! community_list_exact_match (ri->attr->community, list))
7742 continue;
7743 }
7744 if (type == bgp_show_type_flap_address
7745 || type == bgp_show_type_flap_prefix)
7746 {
7747 struct prefix *p = output_arg;
7748
7749 if (! prefix_match (&rn->p, p))
7750 continue;
7751
7752 if (type == bgp_show_type_flap_prefix)
7753 if (p->prefixlen != rn->p.prefixlen)
7754 continue;
7755 }
7756 if (type == bgp_show_type_dampend_paths
7757 || type == bgp_show_type_damp_neighbor)
7758 {
7759 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7760 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7761 continue;
7762 }
7763
7764 if (!use_json && header)
7765 {
7766 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
7767 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7768 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7769 if (type == bgp_show_type_dampend_paths
7770 || type == bgp_show_type_damp_neighbor)
7771 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7772 else if (type == bgp_show_type_flap_statistics
7773 || type == bgp_show_type_flap_address
7774 || type == bgp_show_type_flap_prefix
7775 || type == bgp_show_type_flap_cidr_only
7776 || type == bgp_show_type_flap_regexp
7777 || type == bgp_show_type_flap_filter_list
7778 || type == bgp_show_type_flap_prefix_list
7779 || type == bgp_show_type_flap_prefix_longer
7780 || type == bgp_show_type_flap_route_map
7781 || type == bgp_show_type_flap_neighbor)
7782 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7783 else
7784 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7785 header = 0;
7786 }
7787
7788 if (type == bgp_show_type_dampend_paths
7789 || type == bgp_show_type_damp_neighbor)
7790 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7791 else if (type == bgp_show_type_flap_statistics
7792 || type == bgp_show_type_flap_address
7793 || type == bgp_show_type_flap_prefix
7794 || type == bgp_show_type_flap_cidr_only
7795 || type == bgp_show_type_flap_regexp
7796 || type == bgp_show_type_flap_filter_list
7797 || type == bgp_show_type_flap_prefix_list
7798 || type == bgp_show_type_flap_prefix_longer
7799 || type == bgp_show_type_flap_route_map
7800 || type == bgp_show_type_flap_neighbor)
7801 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7802 else
7803 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7804 display++;
7805 }
7806
7807 if (display)
7808 {
7809 output_count++;
7810 if (use_json)
7811 {
7812 p = &rn->p;
7813 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7814 vty_out (vty, "\"%s\": ", buf2);
7815 vty_out (vty, "%s", json_object_to_json_string (json_paths));
7816 json_object_free (json_paths);
7817 first = 0;
7818
7819 }
7820 }
7821 }
7822
7823 if (use_json)
7824 {
7825 json_object_free (json_paths);
7826 vty_out (vty, " } }%s", VTY_NEWLINE);
7827 }
7828 else
7829 {
7830 /* No route is displayed */
7831 if (output_count == 0)
7832 {
7833 if (type == bgp_show_type_normal)
7834 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
7835 }
7836 else
7837 vty_out (vty, "%sDisplayed %ld routes and %ld total paths%s",
7838 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
7839 }
7840
7841 return CMD_SUCCESS;
7842 }
7843
7844 static int
7845 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
7846 enum bgp_show_type type, void *output_arg, u_char use_json)
7847 {
7848 struct bgp_table *table;
7849
7850 if (bgp == NULL)
7851 {
7852 bgp = bgp_get_default ();
7853 }
7854
7855 if (bgp == NULL)
7856 {
7857 if (!use_json)
7858 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7859 return CMD_WARNING;
7860 }
7861
7862 table = bgp->rib[afi][safi];
7863
7864 return bgp_show_table (vty, bgp, table, type, output_arg,
7865 use_json);
7866 }
7867
7868 static void
7869 bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7870 u_char use_json)
7871 {
7872 struct listnode *node, *nnode;
7873 struct bgp *bgp;
7874 struct bgp_table *table;
7875 int is_first = 1;
7876
7877 if (use_json)
7878 vty_out (vty, "{%s", VTY_NEWLINE);
7879
7880 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7881 {
7882 if (use_json)
7883 {
7884 if (! is_first)
7885 vty_out (vty, ",%s", VTY_NEWLINE);
7886 else
7887 is_first = 0;
7888
7889 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7890 ? "Default" : bgp->name);
7891 }
7892 else
7893 {
7894 vty_out (vty, "%sInstance %s:%s",
7895 VTY_NEWLINE,
7896 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7897 ? "Default" : bgp->name,
7898 VTY_NEWLINE);
7899 }
7900 table = bgp->rib[afi][safi];
7901 bgp_show_table (vty, bgp, table,
7902 bgp_show_type_normal, NULL, use_json);
7903
7904 }
7905
7906 if (use_json)
7907 vty_out (vty, "}%s", VTY_NEWLINE);
7908 }
7909
7910 /* Header of detailed BGP route information */
7911 static void
7912 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7913 struct bgp_node *rn,
7914 struct prefix_rd *prd, afi_t afi, safi_t safi,
7915 json_object *json)
7916 {
7917 struct bgp_info *ri;
7918 struct prefix *p;
7919 struct peer *peer;
7920 struct listnode *node, *nnode;
7921 char buf1[INET6_ADDRSTRLEN];
7922 char buf2[INET6_ADDRSTRLEN];
7923 int count = 0;
7924 int best = 0;
7925 int suppress = 0;
7926 int no_export = 0;
7927 int no_advertise = 0;
7928 int local_as = 0;
7929 int first = 1;
7930 json_object *json_adv_to = NULL;
7931
7932 p = &rn->p;
7933
7934 if (json)
7935 {
7936 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7937 json_object_int_add(json, "prefixlen", p->prefixlen);
7938 }
7939 else
7940 {
7941 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7942 ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ?
7943 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7944 safi == SAFI_MPLS_VPN ? ":" : "",
7945 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7946 p->prefixlen, VTY_NEWLINE);
7947 }
7948
7949 for (ri = rn->info; ri; ri = ri->next)
7950 {
7951 count++;
7952 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7953 {
7954 best = count;
7955 if (ri->extra && ri->extra->suppress)
7956 suppress = 1;
7957 if (ri->attr->community != NULL)
7958 {
7959 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7960 no_advertise = 1;
7961 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7962 no_export = 1;
7963 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7964 local_as = 1;
7965 }
7966 }
7967 }
7968
7969 if (!json)
7970 {
7971 vty_out (vty, "Paths: (%d available", count);
7972 if (best)
7973 {
7974 vty_out (vty, ", best #%d", best);
7975 if (safi == SAFI_UNICAST)
7976 vty_out (vty, ", table %s",
7977 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7978 ? "Default-IP-Routing-Table" : bgp->name);
7979 }
7980 else
7981 vty_out (vty, ", no best path");
7982
7983 if (no_advertise)
7984 vty_out (vty, ", not advertised to any peer");
7985 else if (no_export)
7986 vty_out (vty, ", not advertised to EBGP peer");
7987 else if (local_as)
7988 vty_out (vty, ", not advertised outside local AS");
7989
7990 if (suppress)
7991 vty_out (vty, ", Advertisements suppressed by an aggregate.");
7992 vty_out (vty, ")%s", VTY_NEWLINE);
7993 }
7994
7995 /* If we are not using addpath then we can display Advertised to and that will
7996 * show what peers we advertised the bestpath to. If we are using addpath
7997 * though then we must display Advertised to on a path-by-path basis. */
7998 if (!bgp->addpath_tx_used[afi][safi])
7999 {
8000 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
8001 {
8002 if (bgp_adj_out_lookup (peer, rn, 0))
8003 {
8004 if (json && !json_adv_to)
8005 json_adv_to = json_object_new_object();
8006
8007 route_vty_out_advertised_to(vty, peer, &first,
8008 " Advertised to non peer-group peers:\n ",
8009 json_adv_to);
8010 }
8011 }
8012
8013 if (json)
8014 {
8015 if (json_adv_to)
8016 {
8017 json_object_object_add(json, "advertisedTo", json_adv_to);
8018 }
8019 }
8020 else
8021 {
8022 if (first)
8023 vty_out (vty, " Not advertised to any peer");
8024 vty_out (vty, "%s", VTY_NEWLINE);
8025 }
8026 }
8027 }
8028
8029 /* Display specified route of BGP table. */
8030 static int
8031 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
8032 struct bgp_table *rib, const char *ip_str,
8033 afi_t afi, safi_t safi, struct prefix_rd *prd,
8034 int prefix_check, enum bgp_path_type pathtype,
8035 u_char use_json)
8036 {
8037 int ret;
8038 int header;
8039 int display = 0;
8040 struct prefix match;
8041 struct bgp_node *rn;
8042 struct bgp_node *rm;
8043 struct bgp_info *ri;
8044 struct bgp_table *table;
8045 json_object *json = NULL;
8046 json_object *json_paths = NULL;
8047
8048 /* Check IP address argument. */
8049 ret = str2prefix (ip_str, &match);
8050 if (! ret)
8051 {
8052 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
8053 return CMD_WARNING;
8054 }
8055
8056 match.family = afi2family (afi);
8057
8058 if (use_json)
8059 {
8060 json = json_object_new_object();
8061 json_paths = json_object_new_array();
8062 }
8063
8064 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
8065 {
8066 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
8067 {
8068 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8069 continue;
8070
8071 if ((table = rn->info) != NULL)
8072 {
8073 header = 1;
8074
8075 if ((rm = bgp_node_match (table, &match)) != NULL)
8076 {
8077 if (prefix_check && rm->p.prefixlen != match.prefixlen)
8078 {
8079 bgp_unlock_node (rm);
8080 continue;
8081 }
8082
8083 for (ri = rm->info; ri; ri = ri->next)
8084 {
8085 if (header)
8086 {
8087 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
8088 AFI_IP, safi, json);
8089 header = 0;
8090 }
8091 display++;
8092
8093 if (pathtype == BGP_PATH_ALL ||
8094 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8095 (pathtype == BGP_PATH_MULTIPATH &&
8096 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8097 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths);
8098 }
8099
8100 bgp_unlock_node (rm);
8101 }
8102 }
8103 }
8104 }
8105 else
8106 {
8107 header = 1;
8108
8109 if ((rn = bgp_node_match (rib, &match)) != NULL)
8110 {
8111 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8112 {
8113 for (ri = rn->info; ri; ri = ri->next)
8114 {
8115 if (header)
8116 {
8117 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
8118 header = 0;
8119 }
8120 display++;
8121
8122 if (pathtype == BGP_PATH_ALL ||
8123 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8124 (pathtype == BGP_PATH_MULTIPATH &&
8125 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8126 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
8127 }
8128 }
8129
8130 bgp_unlock_node (rn);
8131 }
8132 }
8133
8134 if (use_json)
8135 {
8136 if (display)
8137 json_object_object_add(json, "paths", json_paths);
8138
8139 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
8140 json_object_free(json);
8141 }
8142 else
8143 {
8144 if (!display)
8145 {
8146 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
8147 return CMD_WARNING;
8148 }
8149 }
8150
8151 return CMD_SUCCESS;
8152 }
8153
8154 /* Display specified route of Main RIB */
8155 static int
8156 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
8157 afi_t afi, safi_t safi, struct prefix_rd *prd,
8158 int prefix_check, enum bgp_path_type pathtype,
8159 u_char use_json)
8160 {
8161 struct bgp *bgp;
8162
8163 /* BGP structure lookup. */
8164 if (view_name)
8165 {
8166 bgp = bgp_lookup_by_name (view_name);
8167 if (bgp == NULL)
8168 {
8169 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
8170 return CMD_WARNING;
8171 }
8172 }
8173 else
8174 {
8175 bgp = bgp_get_default ();
8176 if (bgp == NULL)
8177 {
8178 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8179 return CMD_WARNING;
8180 }
8181 }
8182
8183 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
8184 afi, safi, prd, prefix_check, pathtype,
8185 use_json);
8186 }
8187
8188 /* BGP route print out function. */
8189 DEFUN (show_ip_bgp,
8190 show_ip_bgp_cmd,
8191 "show ip bgp {json}",
8192 SHOW_STR
8193 IP_STR
8194 BGP_STR
8195 "JavaScript Object Notation\n")
8196 {
8197 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8198 }
8199
8200 DEFUN (show_ip_bgp_ipv4,
8201 show_ip_bgp_ipv4_cmd,
8202 "show ip bgp ipv4 (unicast|multicast) {json}",
8203 SHOW_STR
8204 IP_STR
8205 BGP_STR
8206 "Address family\n"
8207 "Address Family modifier\n"
8208 "Address Family modifier\n"
8209 "JavaScript Object Notation\n")
8210 {
8211 u_char uj = use_json(argc, argv);
8212
8213 return bgp_show (vty, NULL, AFI_IP,
8214 bgp_vty_safi_from_arg(argv[0]),
8215 bgp_show_type_normal, NULL, uj);
8216 }
8217
8218 ALIAS (show_ip_bgp_ipv4,
8219 show_bgp_ipv4_safi_cmd,
8220 "show bgp ipv4 (unicast|multicast) {json}",
8221 SHOW_STR
8222 BGP_STR
8223 "Address family\n"
8224 "Address Family modifier\n"
8225 "Address Family modifier\n"
8226 "JavaScript Object Notation\n")
8227
8228 DEFUN (show_ip_bgp_route,
8229 show_ip_bgp_route_cmd,
8230 "show ip bgp A.B.C.D {json}",
8231 SHOW_STR
8232 IP_STR
8233 BGP_STR
8234 "Network in the BGP routing table to display\n"
8235 "JavaScript Object Notation\n")
8236 {
8237 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8238 }
8239
8240 DEFUN (show_ip_bgp_route_pathtype,
8241 show_ip_bgp_route_pathtype_cmd,
8242 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
8243 SHOW_STR
8244 IP_STR
8245 BGP_STR
8246 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8247 "Display only the bestpath\n"
8248 "Display only multipaths\n"
8249 "JavaScript Object Notation\n")
8250 {
8251 u_char uj = use_json(argc, argv);
8252
8253 if (strncmp (argv[1], "b", 1) == 0)
8254 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8255 else
8256 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8257 }
8258
8259 DEFUN (show_bgp_ipv4_safi_route_pathtype,
8260 show_bgp_ipv4_safi_route_pathtype_cmd,
8261 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D (bestpath|multipath) {json}",
8262 SHOW_STR
8263 BGP_STR
8264 BGP_AFI_SAFI_HELP_STR
8265 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8266 "Display only the bestpath\n"
8267 "Display only multipaths\n"
8268 "JavaScript Object Notation\n")
8269 {
8270 u_char uj = use_json(argc, argv);
8271
8272 if (strncmp (argv[2], "b", 1) == 0)
8273 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8274 bgp_vty_safi_from_arg(argv[0]),
8275 NULL, 0, BGP_PATH_BESTPATH, uj);
8276 else
8277 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8278 bgp_vty_safi_from_arg(argv[0]),
8279 NULL, 0, BGP_PATH_MULTIPATH, uj);
8280 }
8281
8282 DEFUN (show_bgp_ipv4_prefix,
8283 show_bgp_ipv4_prefix_cmd,
8284 "show bgp ipv4 A.B.C.D/M {json}",
8285 SHOW_STR
8286 BGP_STR
8287 IP_STR
8288 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8289 JSON_STR)
8290 {
8291 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc, argv));
8292 }
8293
8294 DEFUN (show_bgp_ipv6_route,
8295 show_bgp_ipv6_route_cmd,
8296 "show bgp ipv6 X:X::X:X {json}",
8297 SHOW_STR
8298 BGP_STR
8299 "Address family\n"
8300 "Network in the BGP routing table to display\n"
8301 JSON_STR)
8302 {
8303 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
8304 }
8305
8306 DEFUN (show_bgp_ipv6_prefix,
8307 show_bgp_ipv6_prefix_cmd,
8308 "show bgp ipv6 X:X::X:X/M {json}",
8309 SHOW_STR
8310 BGP_STR
8311 IP_STR
8312 "IPv6 prefix <network>/<length>\n"
8313 JSON_STR)
8314 {
8315 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc,argv));
8316 }
8317
8318 DEFUN (show_ip_bgp_ipv4_route,
8319 show_ip_bgp_ipv4_route_cmd,
8320 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}",
8321 SHOW_STR
8322 IP_STR
8323 BGP_STR
8324 BGP_AFI_SAFI_HELP_STR
8325 "Network in the BGP routing table to display\n"
8326 "JavaScript Object Notation\n")
8327 {
8328 u_char uj = use_json(argc, argv);
8329
8330 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8331 bgp_vty_safi_from_arg(argv[0]),
8332 NULL, 0, BGP_PATH_ALL, uj);
8333 }
8334
8335 ALIAS (show_ip_bgp_ipv4_route,
8336 show_bgp_ipv4_safi_route_cmd,
8337 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}",
8338 SHOW_STR
8339 BGP_STR
8340 BGP_AFI_SAFI_HELP_STR
8341 "Network in the BGP routing table to display\n"
8342 "JavaScript Object Notation\n")
8343
8344 DEFUN (show_bgp_ipv4_safi_rd_route,
8345 show_bgp_ipv4_safi_rd_route_cmd,
8346 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
8347 SHOW_STR
8348 BGP_STR
8349 "Address Family\n"
8350 "Address Family Modifier\n"
8351 "Address Family Modifier\n"
8352 "Display information for a route distinguisher\n"
8353 "ENCAP Route Distinguisher\n"
8354 "Network in the BGP routing table to display\n")
8355 {
8356 int ret;
8357 struct prefix_rd prd;
8358 safi_t safi;
8359
8360 if (bgp_parse_safi(argv[0], &safi)) {
8361 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8362 return CMD_WARNING;
8363 }
8364 ret = str2prefix_rd (argv[1], &prd);
8365 if (! ret)
8366 {
8367 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8368 return CMD_WARNING;
8369 }
8370 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8371 }
8372
8373 DEFUN (show_bgp_ipv6_safi_rd_route,
8374 show_bgp_ipv6_safi_rd_route_cmd,
8375 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X {json}",
8376 SHOW_STR
8377 BGP_STR
8378 "Address Family\n"
8379 "Address Family Modifier\n"
8380 "Address Family Modifier\n"
8381 "Display information for a route distinguisher\n"
8382 "ENCAP Route Distinguisher\n"
8383 "Network in the BGP routing table to display\n")
8384 {
8385 int ret;
8386 struct prefix_rd prd;
8387 safi_t safi;
8388
8389 if (bgp_parse_safi(argv[0], &safi)) {
8390 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8391 return CMD_WARNING;
8392 }
8393 ret = str2prefix_rd (argv[1], &prd);
8394 if (! ret)
8395 {
8396 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8397 return CMD_WARNING;
8398 }
8399 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8400 }
8401
8402
8403 DEFUN (show_bgp_ipv4_safi_rd_prefix,
8404 show_bgp_ipv4_safi_rd_prefix_cmd,
8405 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
8406 SHOW_STR
8407 BGP_STR
8408 "Address Family\n"
8409 "Address Family Modifier\n"
8410 "Address Family Modifier\n"
8411 "Display information for a route distinguisher\n"
8412 "ENCAP Route Distinguisher\n"
8413 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8414 {
8415 int ret;
8416 struct prefix_rd prd;
8417 safi_t safi;
8418
8419 if (bgp_parse_safi(argv[0], &safi)) {
8420 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8421 return CMD_WARNING;
8422 }
8423
8424 ret = str2prefix_rd (argv[1], &prd);
8425 if (! ret)
8426 {
8427 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8428 return CMD_WARNING;
8429 }
8430 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv));
8431 }
8432
8433 DEFUN (show_bgp_ipv6_safi_rd_prefix,
8434 show_bgp_ipv6_safi_rd_prefix_cmd,
8435 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M {json}",
8436 SHOW_STR
8437 BGP_STR
8438 "Address Family\n"
8439 "Address Family Modifier\n"
8440 "Address Family Modifier\n"
8441 "Display information for a route distinguisher\n"
8442 "ENCAP Route Distinguisher\n"
8443 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8444 {
8445 int ret;
8446 struct prefix_rd prd;
8447 safi_t safi;
8448
8449 if (bgp_parse_safi(argv[0], &safi)) {
8450 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8451 return CMD_WARNING;
8452 }
8453
8454 ret = str2prefix_rd (argv[1], &prd);
8455 if (! ret)
8456 {
8457 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8458 return CMD_WARNING;
8459 }
8460 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv));
8461 }
8462
8463 DEFUN (show_ip_bgp_prefix,
8464 show_ip_bgp_prefix_cmd,
8465 "show ip bgp A.B.C.D/M {json}",
8466 SHOW_STR
8467 IP_STR
8468 BGP_STR
8469 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8470 "JavaScript Object Notation\n")
8471 {
8472 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8473 }
8474
8475 DEFUN (show_ip_bgp_prefix_pathtype,
8476 show_ip_bgp_prefix_pathtype_cmd,
8477 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
8478 SHOW_STR
8479 IP_STR
8480 BGP_STR
8481 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8482 "Display only the bestpath\n"
8483 "Display only multipaths\n"
8484 "JavaScript Object Notation\n")
8485 {
8486 u_char uj = use_json(argc, argv);
8487 if (strncmp (argv[1], "b", 1) == 0)
8488 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8489 else
8490 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8491 }
8492
8493 DEFUN (show_ip_bgp_ipv4_prefix,
8494 show_ip_bgp_ipv4_prefix_cmd,
8495 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}",
8496 SHOW_STR
8497 IP_STR
8498 BGP_STR
8499 BGP_AFI_SAFI_HELP_STR
8500 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8501 "JavaScript Object Notation\n")
8502 {
8503 u_char uj = use_json(argc, argv);
8504
8505 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8506 bgp_vty_safi_from_arg(argv[0]),
8507 NULL, 1, BGP_PATH_ALL, uj);
8508 }
8509
8510 ALIAS (show_ip_bgp_ipv4_prefix,
8511 show_bgp_ipv4_safi_prefix_cmd,
8512 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}",
8513 SHOW_STR
8514 BGP_STR
8515 BGP_AFI_SAFI_HELP_STR
8516 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8517 "JavaScript Object Notation\n")
8518
8519 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8520 show_ip_bgp_ipv4_prefix_pathtype_cmd,
8521 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}",
8522 SHOW_STR
8523 IP_STR
8524 BGP_STR
8525 BGP_AFI_SAFI_HELP_STR
8526 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8527 "Display only the bestpath\n"
8528 "Display only multipaths\n"
8529 "JavaScript Object Notation\n")
8530 {
8531 u_char uj = use_json(argc, argv);
8532
8533 if (strncmp (argv[2], "b", 1) == 0)
8534 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8535 bgp_vty_safi_from_arg(argv[0]),
8536 NULL, 1, BGP_PATH_BESTPATH, uj);
8537 else
8538 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8539 bgp_vty_safi_from_arg(argv[0]),
8540 NULL, 1, BGP_PATH_MULTIPATH, uj);
8541 }
8542
8543 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8544 show_bgp_ipv4_safi_prefix_pathtype_cmd,
8545 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}",
8546 SHOW_STR
8547 BGP_STR
8548 BGP_AFI_SAFI_HELP_STR
8549 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8550 "Display only the bestpath\n"
8551 "Display only multipaths\n"
8552 "JavaScript Object Notation\n")
8553
8554
8555 DEFUN (show_ip_bgp_view,
8556 show_ip_bgp_instance_cmd,
8557 "show ip bgp " BGP_INSTANCE_CMD " {json}",
8558 SHOW_STR
8559 IP_STR
8560 BGP_STR
8561 BGP_INSTANCE_HELP_STR
8562 "JavaScript Object Notation\n")
8563 {
8564 struct bgp *bgp;
8565
8566 /* BGP structure lookup. */
8567 bgp = bgp_lookup_by_name (argv[1]);
8568 if (bgp == NULL)
8569 {
8570 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8571 return CMD_WARNING;
8572 }
8573
8574 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8575 }
8576
8577 DEFUN (show_ip_bgp_instance_all,
8578 show_ip_bgp_instance_all_cmd,
8579 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
8580 SHOW_STR
8581 IP_STR
8582 BGP_STR
8583 BGP_INSTANCE_ALL_HELP_STR
8584 "JavaScript Object Notation\n")
8585 {
8586 u_char uj = use_json(argc, argv);
8587
8588 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8589 return CMD_SUCCESS;
8590 }
8591
8592 DEFUN (show_ip_bgp_instance_route,
8593 show_ip_bgp_instance_route_cmd,
8594 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
8595 SHOW_STR
8596 IP_STR
8597 BGP_STR
8598 BGP_INSTANCE_HELP_STR
8599 "Network in the BGP routing table to display\n"
8600 "JavaScript Object Notation\n")
8601 {
8602 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8603 }
8604
8605 DEFUN (show_ip_bgp_instance_route_pathtype,
8606 show_ip_bgp_instance_route_pathtype_cmd,
8607 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
8608 SHOW_STR
8609 IP_STR
8610 BGP_STR
8611 BGP_INSTANCE_HELP_STR
8612 "Network in the BGP routing table to display\n"
8613 "Display only the bestpath\n"
8614 "Display only multipaths\n"
8615 "JavaScript Object Notation\n")
8616 {
8617 u_char uj = use_json(argc, argv);
8618
8619 if (strncmp (argv[3], "b", 1) == 0)
8620 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8621 else
8622 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8623 }
8624
8625 DEFUN (show_ip_bgp_instance_prefix,
8626 show_ip_bgp_instance_prefix_cmd,
8627 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
8628 SHOW_STR
8629 IP_STR
8630 BGP_STR
8631 BGP_INSTANCE_HELP_STR
8632 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8633 "JavaScript Object Notation\n")
8634 {
8635 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8636 }
8637
8638 DEFUN (show_ip_bgp_instance_prefix_pathtype,
8639 show_ip_bgp_instance_prefix_pathtype_cmd,
8640 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
8641 SHOW_STR
8642 IP_STR
8643 BGP_STR
8644 BGP_INSTANCE_HELP_STR
8645 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8646 "Display only the bestpath\n"
8647 "Display only multipaths\n"
8648 "JavaScript Object Notation\n")
8649 {
8650 u_char uj = use_json(argc, argv);
8651 if (strncmp (argv[3], "b", 1) == 0)
8652 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8653 else
8654 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8655 }
8656
8657 #ifdef HAVE_IPV6
8658 DEFUN (show_bgp,
8659 show_bgp_cmd,
8660 "show bgp {json}",
8661 SHOW_STR
8662 BGP_STR
8663 "JavaScript Object Notation\n")
8664 {
8665 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8666 NULL, use_json(argc, argv));
8667 }
8668
8669 ALIAS (show_bgp,
8670 show_bgp_ipv6_cmd,
8671 "show bgp ipv6 {json}",
8672 SHOW_STR
8673 BGP_STR
8674 "Address family\n"
8675 "JavaScript Object Notation\n")
8676
8677 DEFUN (show_bgp_ipv6_safi,
8678 show_bgp_ipv6_safi_cmd,
8679 "show bgp ipv6 (unicast|multicast) {json}",
8680 SHOW_STR
8681 BGP_STR
8682 "Address family\n"
8683 "Address Family modifier\n"
8684 "Address Family modifier\n"
8685 "JavaScript Object Notation\n")
8686 {
8687 u_char uj = use_json(argc, argv);
8688
8689 return bgp_show (vty, NULL, AFI_IP6,
8690 bgp_vty_safi_from_arg(argv[0]),
8691 bgp_show_type_normal, NULL, uj);
8692 }
8693
8694 static void
8695 bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8696 {
8697 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8698 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8699 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8700 }
8701
8702 /* old command */
8703 DEFUN (show_ipv6_bgp,
8704 show_ipv6_bgp_cmd,
8705 "show ipv6 bgp {json}",
8706 SHOW_STR
8707 IP_STR
8708 BGP_STR
8709 "JavaScript Object Notation\n")
8710 {
8711 bgp_show_ipv6_bgp_deprecate_warning(vty);
8712 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8713 NULL, use_json(argc, argv));
8714 }
8715
8716 DEFUN (show_bgp_route,
8717 show_bgp_route_cmd,
8718 "show bgp X:X::X:X {json}",
8719 SHOW_STR
8720 BGP_STR
8721 "Network in the BGP routing table to display\n"
8722 "JavaScript Object Notation\n")
8723 {
8724 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8725 }
8726
8727 DEFUN (show_bgp_ipv6_safi_route,
8728 show_bgp_ipv6_safi_route_cmd,
8729 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X {json}",
8730 SHOW_STR
8731 BGP_STR
8732 BGP_AFI_SAFI_HELP_STR
8733 "Network in the BGP routing table to display\n"
8734 "JavaScript Object Notation\n")
8735 {
8736 u_char uj = use_json(argc, argv);
8737
8738 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8739 bgp_vty_safi_from_arg(argv[0]),
8740 NULL, 0, BGP_PATH_ALL, uj);
8741 }
8742
8743 DEFUN (show_bgp_route_pathtype,
8744 show_bgp_route_pathtype_cmd,
8745 "show bgp X:X::X:X (bestpath|multipath) {json}",
8746 SHOW_STR
8747 BGP_STR
8748 "Network in the BGP routing table to display\n"
8749 "Display only the bestpath\n"
8750 "Display only multipaths\n"
8751 "JavaScript Object Notation\n")
8752 {
8753 u_char uj = use_json(argc, argv);
8754 if (strncmp (argv[1], "b", 1) == 0)
8755 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8756 else
8757 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8758 }
8759
8760 ALIAS (show_bgp_route_pathtype,
8761 show_bgp_ipv6_route_pathtype_cmd,
8762 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
8763 SHOW_STR
8764 BGP_STR
8765 "Address family\n"
8766 "Network in the BGP routing table to display\n"
8767 "Display only the bestpath\n"
8768 "Display only multipaths\n"
8769 "JavaScript Object Notation\n")
8770
8771 DEFUN (show_bgp_ipv6_safi_route_pathtype,
8772 show_bgp_ipv6_safi_route_pathtype_cmd,
8773 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X (bestpath|multipath) {json}",
8774 SHOW_STR
8775 BGP_STR
8776 BGP_AFI_SAFI_HELP_STR
8777 "Network in the BGP routing table to display\n"
8778 "Display only the bestpath\n"
8779 "Display only multipaths\n"
8780 "JavaScript Object Notation\n")
8781 {
8782 u_char uj = use_json(argc, argv);
8783 if (strncmp (argv[2], "b", 1) == 0)
8784 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8785 bgp_vty_safi_from_arg(argv[0]),
8786 NULL, 0, BGP_PATH_BESTPATH, uj);
8787 else
8788 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8789 bgp_vty_safi_from_arg(argv[0]),
8790 NULL, 0, BGP_PATH_MULTIPATH, uj);
8791 }
8792
8793 /* old command */
8794 DEFUN (show_ipv6_bgp_route,
8795 show_ipv6_bgp_route_cmd,
8796 "show ipv6 bgp X:X::X:X {json}",
8797 SHOW_STR
8798 IP_STR
8799 BGP_STR
8800 "Network in the BGP routing table to display\n"
8801 "JavaScript Object Notation\n")
8802 {
8803 bgp_show_ipv6_bgp_deprecate_warning(vty);
8804 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8805 }
8806
8807 DEFUN (show_bgp_prefix,
8808 show_bgp_prefix_cmd,
8809 "show bgp X:X::X:X/M {json}",
8810 SHOW_STR
8811 BGP_STR
8812 "IPv6 prefix <network>/<length>\n"
8813 "JavaScript Object Notation\n")
8814 {
8815 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8816 }
8817
8818 DEFUN (show_bgp_ipv6_safi_prefix,
8819 show_bgp_ipv6_safi_prefix_cmd,
8820 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M {json}",
8821 SHOW_STR
8822 BGP_STR
8823 BGP_AFI_SAFI_HELP_STR
8824 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8825 "JavaScript Object Notation\n")
8826 {
8827 u_char uj = use_json(argc, argv);
8828
8829 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8830 bgp_vty_safi_from_arg(argv[0]),
8831 NULL, 1, BGP_PATH_ALL, uj);
8832 }
8833
8834 DEFUN (show_bgp_prefix_pathtype,
8835 show_bgp_prefix_pathtype_cmd,
8836 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
8837 SHOW_STR
8838 BGP_STR
8839 "IPv6 prefix <network>/<length>\n"
8840 "Display only the bestpath\n"
8841 "Display only multipaths\n"
8842 "JavaScript Object Notation\n")
8843 {
8844 u_char uj = use_json(argc, argv);
8845 if (strncmp (argv[1], "b", 1) == 0)
8846 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8847 else
8848 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8849 }
8850
8851 ALIAS (show_bgp_prefix_pathtype,
8852 show_bgp_ipv6_prefix_pathtype_cmd,
8853 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8854 SHOW_STR
8855 BGP_STR
8856 "Address family\n"
8857 "IPv6 prefix <network>/<length>\n"
8858 "Display only the bestpath\n"
8859 "Display only multipaths\n"
8860 "JavaScript Object Notation\n")
8861
8862 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8863 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8864 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M (bestpath|multipath) {json}",
8865 SHOW_STR
8866 BGP_STR
8867 BGP_AFI_SAFI_HELP_STR
8868 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8869 "Display only the bestpath\n"
8870 "Display only multipaths\n"
8871 "JavaScript Object Notation\n")
8872 {
8873 u_char uj = use_json(argc, argv);
8874 if (strncmp (argv[2], "b", 1) == 0)
8875 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8876 bgp_vty_safi_from_arg(argv[0]),
8877 NULL, 1, BGP_PATH_BESTPATH, uj);
8878 else
8879 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8880 bgp_vty_safi_from_arg(argv[0]), NULL, 1, BGP_PATH_MULTIPATH, uj);
8881 }
8882
8883 /* old command */
8884 DEFUN (show_ipv6_bgp_prefix,
8885 show_ipv6_bgp_prefix_cmd,
8886 "show ipv6 bgp X:X::X:X/M {json}",
8887 SHOW_STR
8888 IP_STR
8889 BGP_STR
8890 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8891 "JavaScript Object Notation\n")
8892 {
8893 bgp_show_ipv6_bgp_deprecate_warning(vty);
8894 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8895 }
8896
8897 DEFUN (show_bgp_view,
8898 show_bgp_instance_cmd,
8899 "show bgp " BGP_INSTANCE_CMD " {json}",
8900 SHOW_STR
8901 BGP_STR
8902 BGP_INSTANCE_HELP_STR
8903 "JavaScript Object Notation\n")
8904 {
8905 struct bgp *bgp;
8906
8907 /* BGP structure lookup. */
8908 bgp = bgp_lookup_by_name (argv[1]);
8909 if (bgp == NULL)
8910 {
8911 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8912 return CMD_WARNING;
8913 }
8914
8915 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8916 }
8917
8918 DEFUN (show_bgp_instance_all,
8919 show_bgp_instance_all_cmd,
8920 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
8921 SHOW_STR
8922 BGP_STR
8923 BGP_INSTANCE_ALL_HELP_STR
8924 "JavaScript Object Notation\n")
8925 {
8926 u_char uj = use_json(argc, argv);
8927
8928 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
8929 return CMD_SUCCESS;
8930 }
8931
8932 ALIAS (show_bgp_view,
8933 show_bgp_instance_ipv6_cmd,
8934 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
8935 SHOW_STR
8936 BGP_STR
8937 BGP_INSTANCE_HELP_STR
8938 "Address family\n"
8939 "JavaScript Object Notation\n")
8940
8941 DEFUN (show_bgp_instance_route,
8942 show_bgp_instance_route_cmd,
8943 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
8944 SHOW_STR
8945 BGP_STR
8946 BGP_INSTANCE_HELP_STR
8947 "Network in the BGP routing table to display\n"
8948 "JavaScript Object Notation\n")
8949 {
8950 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8951 }
8952
8953 ALIAS (show_bgp_instance_route,
8954 show_bgp_instance_ipv6_route_cmd,
8955 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
8956 SHOW_STR
8957 BGP_STR
8958 BGP_INSTANCE_HELP_STR
8959 "Address family\n"
8960 "Network in the BGP routing table to display\n"
8961 "JavaScript Object Notation\n")
8962
8963 DEFUN (show_bgp_instance_route_pathtype,
8964 show_bgp_instance_route_pathtype_cmd,
8965 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
8966 SHOW_STR
8967 BGP_STR
8968 BGP_INSTANCE_HELP_STR
8969 "Network in the BGP routing table to display\n"
8970 "Display only the bestpath\n"
8971 "Display only multipaths\n"
8972 "JavaScript Object Notation\n")
8973 {
8974 u_char uj = use_json(argc, argv);
8975 if (strncmp (argv[3], "b", 1) == 0)
8976 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8977 else
8978 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8979 }
8980
8981 ALIAS (show_bgp_instance_route_pathtype,
8982 show_bgp_instance_ipv6_route_pathtype_cmd,
8983 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
8984 SHOW_STR
8985 BGP_STR
8986 BGP_INSTANCE_HELP_STR
8987 "Address family\n"
8988 "Network in the BGP routing table to display\n"
8989 "Display only the bestpath\n"
8990 "Display only multipaths\n"
8991 "JavaScript Object Notation\n")
8992
8993 DEFUN (show_bgp_instance_prefix,
8994 show_bgp_instance_prefix_cmd,
8995 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
8996 SHOW_STR
8997 BGP_STR
8998 BGP_INSTANCE_HELP_STR
8999 "IPv6 prefix <network>/<length>\n"
9000 "JavaScript Object Notation\n")
9001 {
9002 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
9003 }
9004
9005 ALIAS (show_bgp_instance_prefix,
9006 show_bgp_instance_ipv6_prefix_cmd,
9007 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
9008 SHOW_STR
9009 BGP_STR
9010 BGP_INSTANCE_HELP_STR
9011 "Address family\n"
9012 "IPv6 prefix <network>/<length>\n"
9013 "JavaScript Object Notation\n")
9014
9015 DEFUN (show_bgp_instance_prefix_pathtype,
9016 show_bgp_instance_prefix_pathtype_cmd,
9017 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
9018 SHOW_STR
9019 BGP_STR
9020 BGP_INSTANCE_HELP_STR
9021 "IPv6 prefix <network>/<length>\n"
9022 "Display only the bestpath\n"
9023 "Display only multipaths\n"
9024 "JavaScript Object Notation\n")
9025 {
9026 u_char uj = use_json(argc, argv);
9027 if (strncmp (argv[3], "b", 1) == 0)
9028 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
9029 else
9030 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
9031 }
9032
9033 ALIAS (show_bgp_instance_prefix_pathtype,
9034 show_bgp_instance_ipv6_prefix_pathtype_cmd,
9035 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
9036 SHOW_STR
9037 BGP_STR
9038 BGP_INSTANCE_HELP_STR
9039 "Address family\n"
9040 "IPv6 prefix <network>/<length>\n"
9041 "Display only the bestpath\n"
9042 "Display only multipaths\n"
9043 "JavaScript Object Notation\n")
9044
9045 DEFUN (show_bgp_instance_prefix_list,
9046 show_bgp_instance_prefix_list_cmd,
9047 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9048 SHOW_STR
9049 BGP_STR
9050 BGP_INSTANCE_HELP_STR
9051 "Display routes conforming to the prefix-list\n"
9052 "IPv6 prefix-list name\n")
9053 {
9054 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9055 bgp_show_type_prefix_list);
9056 }
9057
9058 ALIAS (show_bgp_instance_prefix_list,
9059 show_bgp_instance_ipv6_prefix_list_cmd,
9060 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
9061 SHOW_STR
9062 BGP_STR
9063 BGP_INSTANCE_HELP_STR
9064 "Address family\n"
9065 "Display routes conforming to the prefix-list\n"
9066 "IPv6 prefix-list name\n")
9067
9068 DEFUN (show_bgp_instance_filter_list,
9069 show_bgp_instance_filter_list_cmd,
9070 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
9071 SHOW_STR
9072 BGP_STR
9073 BGP_INSTANCE_HELP_STR
9074 "Display routes conforming to the filter-list\n"
9075 "Regular expression access list name\n")
9076 {
9077 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9078 bgp_show_type_filter_list);
9079 }
9080
9081 ALIAS (show_bgp_instance_filter_list,
9082 show_bgp_instance_ipv6_filter_list_cmd,
9083 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
9084 SHOW_STR
9085 BGP_STR
9086 BGP_INSTANCE_HELP_STR
9087 "Address family\n"
9088 "Display routes conforming to the filter-list\n"
9089 "Regular expression access list name\n")
9090
9091 DEFUN (show_bgp_instance_route_map,
9092 show_bgp_instance_route_map_cmd,
9093 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
9094 SHOW_STR
9095 BGP_STR
9096 BGP_INSTANCE_HELP_STR
9097 "Display routes matching the route-map\n"
9098 "A route-map to match on\n")
9099 {
9100 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9101 bgp_show_type_route_map);
9102 }
9103
9104 ALIAS (show_bgp_instance_route_map,
9105 show_bgp_instance_ipv6_route_map_cmd,
9106 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
9107 SHOW_STR
9108 BGP_STR
9109 BGP_INSTANCE_HELP_STR
9110 "Address family\n"
9111 "Display routes matching the route-map\n"
9112 "A route-map to match on\n")
9113
9114 DEFUN (show_bgp_instance_community_list,
9115 show_bgp_instance_community_list_cmd,
9116 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
9117 SHOW_STR
9118 BGP_STR
9119 BGP_INSTANCE_HELP_STR
9120 "Display routes matching the community-list\n"
9121 "community-list number\n"
9122 "community-list name\n")
9123 {
9124 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
9125 }
9126
9127 ALIAS (show_bgp_instance_community_list,
9128 show_bgp_instance_ipv6_community_list_cmd,
9129 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
9130 SHOW_STR
9131 BGP_STR
9132 BGP_INSTANCE_HELP_STR
9133 "Address family\n"
9134 "Display routes matching the community-list\n"
9135 "community-list number\n"
9136 "community-list name\n")
9137
9138 DEFUN (show_bgp_instance_prefix_longer,
9139 show_bgp_instance_prefix_longer_cmd,
9140 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
9141 SHOW_STR
9142 BGP_STR
9143 BGP_INSTANCE_HELP_STR
9144 "IPv6 prefix <network>/<length>\n"
9145 "Display route and more specific routes\n")
9146 {
9147 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9148 bgp_show_type_prefix_longer);
9149 }
9150
9151 ALIAS (show_bgp_instance_prefix_longer,
9152 show_bgp_instance_ipv6_prefix_longer_cmd,
9153 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
9154 SHOW_STR
9155 BGP_STR
9156 BGP_INSTANCE_HELP_STR
9157 "Address family\n"
9158 "IPv6 prefix <network>/<length>\n"
9159 "Display route and more specific routes\n")
9160
9161 /* old command */
9162 DEFUN (show_ipv6_mbgp,
9163 show_ipv6_mbgp_cmd,
9164 "show ipv6 mbgp {json}",
9165 SHOW_STR
9166 IP_STR
9167 MBGP_STR
9168 "JavaScript Object Notation\n")
9169 {
9170 bgp_show_ipv6_bgp_deprecate_warning(vty);
9171 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
9172 NULL, use_json(argc, argv));
9173 }
9174
9175 /* old command */
9176 DEFUN (show_ipv6_mbgp_route,
9177 show_ipv6_mbgp_route_cmd,
9178 "show ipv6 mbgp X:X::X:X {json}",
9179 SHOW_STR
9180 IP_STR
9181 MBGP_STR
9182 "Network in the MBGP routing table to display\n"
9183 "JavaScript Object Notation\n")
9184 {
9185 bgp_show_ipv6_bgp_deprecate_warning(vty);
9186 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
9187 }
9188
9189 /* old command */
9190 DEFUN (show_ipv6_mbgp_prefix,
9191 show_ipv6_mbgp_prefix_cmd,
9192 "show ipv6 mbgp X:X::X:X/M {json}",
9193 SHOW_STR
9194 IP_STR
9195 MBGP_STR
9196 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9197 "JavaScript Object Notation\n")
9198 {
9199 bgp_show_ipv6_bgp_deprecate_warning(vty);
9200 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
9201 }
9202 #endif
9203
9204
9205 static int
9206 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
9207 safi_t safi, enum bgp_show_type type)
9208 {
9209 int i;
9210 struct buffer *b;
9211 char *regstr;
9212 int first;
9213 regex_t *regex;
9214 int rc;
9215
9216 first = 0;
9217 b = buffer_new (1024);
9218 for (i = 0; i < argc; i++)
9219 {
9220 if (first)
9221 buffer_putc (b, ' ');
9222 else
9223 {
9224 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9225 continue;
9226 first = 1;
9227 }
9228
9229 buffer_putstr (b, argv[i]);
9230 }
9231 buffer_putc (b, '\0');
9232
9233 regstr = buffer_getstr (b);
9234 buffer_free (b);
9235
9236 regex = bgp_regcomp (regstr);
9237 XFREE(MTYPE_TMP, regstr);
9238 if (! regex)
9239 {
9240 vty_out (vty, "Can't compile regexp %s%s", argv[0],
9241 VTY_NEWLINE);
9242 return CMD_WARNING;
9243 }
9244
9245 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
9246 bgp_regex_free (regex);
9247 return rc;
9248 }
9249
9250 DEFUN (show_ip_bgp_regexp,
9251 show_ip_bgp_regexp_cmd,
9252 "show ip bgp regexp .LINE",
9253 SHOW_STR
9254 IP_STR
9255 BGP_STR
9256 "Display routes matching the AS path regular expression\n"
9257 "A regular-expression to match the BGP AS paths\n")
9258 {
9259 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9260 bgp_show_type_regexp);
9261 }
9262
9263 DEFUN (show_ip_bgp_flap_regexp,
9264 show_ip_bgp_flap_regexp_cmd,
9265 "show ip bgp flap-statistics regexp .LINE",
9266 SHOW_STR
9267 IP_STR
9268 BGP_STR
9269 "Display flap statistics of routes\n"
9270 "Display routes matching the AS path regular expression\n"
9271 "A regular-expression to match the BGP AS paths\n")
9272 {
9273 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9274 bgp_show_type_flap_regexp);
9275 }
9276
9277 ALIAS (show_ip_bgp_flap_regexp,
9278 show_ip_bgp_damp_flap_regexp_cmd,
9279 "show ip bgp dampening flap-statistics regexp .LINE",
9280 SHOW_STR
9281 IP_STR
9282 BGP_STR
9283 "Display detailed information about dampening\n"
9284 "Display flap statistics of routes\n"
9285 "Display routes matching the AS path regular expression\n"
9286 "A regular-expression to match the BGP AS paths\n")
9287
9288 DEFUN (show_ip_bgp_ipv4_regexp,
9289 show_ip_bgp_ipv4_regexp_cmd,
9290 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
9291 SHOW_STR
9292 IP_STR
9293 BGP_STR
9294 "Address family\n"
9295 "Address Family modifier\n"
9296 "Address Family modifier\n"
9297 "Display routes matching the AS path regular expression\n"
9298 "A regular-expression to match the BGP AS paths\n")
9299 {
9300 safi_t safi;
9301 safi = bgp_vty_safi_from_arg(argv[0]);
9302 return bgp_show_regexp (vty, argc, argv, AFI_IP, safi,
9303 bgp_show_type_regexp);
9304 }
9305
9306 #ifdef HAVE_IPV6
9307 DEFUN (show_bgp_regexp,
9308 show_bgp_regexp_cmd,
9309 "show bgp regexp .LINE",
9310 SHOW_STR
9311 BGP_STR
9312 "Display routes matching the AS path regular expression\n"
9313 "A regular-expression to match the BGP AS paths\n")
9314 {
9315 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9316 bgp_show_type_regexp);
9317 }
9318
9319 ALIAS (show_bgp_regexp,
9320 show_bgp_ipv6_regexp_cmd,
9321 "show bgp ipv6 regexp .LINE",
9322 SHOW_STR
9323 BGP_STR
9324 "Address family\n"
9325 "Display routes matching the AS path regular expression\n"
9326 "A regular-expression to match the BGP AS paths\n")
9327
9328 /* old command */
9329 DEFUN (show_ipv6_bgp_regexp,
9330 show_ipv6_bgp_regexp_cmd,
9331 "show ipv6 bgp regexp .LINE",
9332 SHOW_STR
9333 IP_STR
9334 BGP_STR
9335 "Display routes matching the AS path regular expression\n"
9336 "A regular-expression to match the BGP AS paths\n")
9337 {
9338 bgp_show_ipv6_bgp_deprecate_warning(vty);
9339 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9340 bgp_show_type_regexp);
9341 }
9342
9343 /* old command */
9344 DEFUN (show_ipv6_mbgp_regexp,
9345 show_ipv6_mbgp_regexp_cmd,
9346 "show ipv6 mbgp regexp .LINE",
9347 SHOW_STR
9348 IP_STR
9349 BGP_STR
9350 "Display routes matching the AS path regular expression\n"
9351 "A regular-expression to match the MBGP AS paths\n")
9352 {
9353 bgp_show_ipv6_bgp_deprecate_warning(vty);
9354 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9355 bgp_show_type_regexp);
9356 }
9357 #endif /* HAVE_IPV6 */
9358
9359 static int
9360 bgp_show_prefix_list (struct vty *vty, const char *name,
9361 const char *prefix_list_str, afi_t afi,
9362 safi_t safi, enum bgp_show_type type)
9363 {
9364 struct prefix_list *plist;
9365 struct bgp *bgp = NULL;
9366
9367 if (name && !(bgp = bgp_lookup_by_name(name)))
9368 {
9369 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9370 return CMD_WARNING;
9371 }
9372
9373 plist = prefix_list_lookup (afi, prefix_list_str);
9374 if (plist == NULL)
9375 {
9376 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9377 prefix_list_str, VTY_NEWLINE);
9378 return CMD_WARNING;
9379 }
9380
9381 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
9382 }
9383
9384 DEFUN (show_ip_bgp_prefix_list,
9385 show_ip_bgp_prefix_list_cmd,
9386 "show ip bgp prefix-list WORD",
9387 SHOW_STR
9388 IP_STR
9389 BGP_STR
9390 "Display routes conforming to the prefix-list\n"
9391 "IP prefix-list name\n")
9392 {
9393 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9394 bgp_show_type_prefix_list);
9395 }
9396
9397 DEFUN (show_ip_bgp_instance_prefix_list,
9398 show_ip_bgp_instance_prefix_list_cmd,
9399 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9400 SHOW_STR
9401 IP_STR
9402 BGP_STR
9403 BGP_INSTANCE_HELP_STR
9404 "Display routes conforming to the prefix-list\n"
9405 "IP prefix-list name\n")
9406 {
9407 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9408 bgp_show_type_prefix_list);
9409 }
9410
9411 DEFUN (show_ip_bgp_flap_prefix_list,
9412 show_ip_bgp_flap_prefix_list_cmd,
9413 "show ip bgp flap-statistics prefix-list WORD",
9414 SHOW_STR
9415 IP_STR
9416 BGP_STR
9417 "Display flap statistics of routes\n"
9418 "Display routes conforming to the prefix-list\n"
9419 "IP prefix-list name\n")
9420 {
9421 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9422 bgp_show_type_flap_prefix_list);
9423 }
9424
9425 ALIAS (show_ip_bgp_flap_prefix_list,
9426 show_ip_bgp_damp_flap_prefix_list_cmd,
9427 "show ip bgp dampening flap-statistics prefix-list WORD",
9428 SHOW_STR
9429 IP_STR
9430 BGP_STR
9431 "Display detailed information about dampening\n"
9432 "Display flap statistics of routes\n"
9433 "Display routes conforming to the prefix-list\n"
9434 "IP prefix-list name\n")
9435
9436 DEFUN (show_ip_bgp_ipv4_prefix_list,
9437 show_ip_bgp_ipv4_prefix_list_cmd,
9438 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9439 SHOW_STR
9440 IP_STR
9441 BGP_STR
9442 "Address family\n"
9443 "Address Family modifier\n"
9444 "Address Family modifier\n"
9445 "Display routes conforming to the prefix-list\n"
9446 "IP prefix-list name\n")
9447 {
9448 safi_t safi;
9449 safi = bgp_vty_safi_from_arg(argv[0]);
9450 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, safi,
9451 bgp_show_type_prefix_list);
9452 }
9453
9454 #ifdef HAVE_IPV6
9455 DEFUN (show_bgp_prefix_list,
9456 show_bgp_prefix_list_cmd,
9457 "show bgp prefix-list WORD",
9458 SHOW_STR
9459 BGP_STR
9460 "Display routes conforming to the prefix-list\n"
9461 "IPv6 prefix-list name\n")
9462 {
9463 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9464 bgp_show_type_prefix_list);
9465 }
9466
9467 ALIAS (show_bgp_prefix_list,
9468 show_bgp_ipv6_prefix_list_cmd,
9469 "show bgp ipv6 prefix-list WORD",
9470 SHOW_STR
9471 BGP_STR
9472 "Address family\n"
9473 "Display routes conforming to the prefix-list\n"
9474 "IPv6 prefix-list name\n")
9475
9476 /* old command */
9477 DEFUN (show_ipv6_bgp_prefix_list,
9478 show_ipv6_bgp_prefix_list_cmd,
9479 "show ipv6 bgp prefix-list WORD",
9480 SHOW_STR
9481 IPV6_STR
9482 BGP_STR
9483 "Display routes matching the prefix-list\n"
9484 "IPv6 prefix-list name\n")
9485 {
9486 bgp_show_ipv6_bgp_deprecate_warning(vty);
9487 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9488 bgp_show_type_prefix_list);
9489 }
9490
9491 /* old command */
9492 DEFUN (show_ipv6_mbgp_prefix_list,
9493 show_ipv6_mbgp_prefix_list_cmd,
9494 "show ipv6 mbgp prefix-list WORD",
9495 SHOW_STR
9496 IPV6_STR
9497 MBGP_STR
9498 "Display routes matching the prefix-list\n"
9499 "IPv6 prefix-list name\n")
9500 {
9501 bgp_show_ipv6_bgp_deprecate_warning(vty);
9502 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9503 bgp_show_type_prefix_list);
9504 }
9505 #endif /* HAVE_IPV6 */
9506
9507 static int
9508 bgp_show_filter_list (struct vty *vty, const char *name,
9509 const char *filter, afi_t afi,
9510 safi_t safi, enum bgp_show_type type)
9511 {
9512 struct as_list *as_list;
9513 struct bgp *bgp = NULL;
9514
9515 if (name && !(bgp = bgp_lookup_by_name(name)))
9516 {
9517 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9518 return CMD_WARNING;
9519 }
9520
9521 as_list = as_list_lookup (filter);
9522 if (as_list == NULL)
9523 {
9524 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9525 return CMD_WARNING;
9526 }
9527
9528 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
9529 }
9530
9531 DEFUN (show_ip_bgp_filter_list,
9532 show_ip_bgp_filter_list_cmd,
9533 "show ip bgp filter-list WORD",
9534 SHOW_STR
9535 IP_STR
9536 BGP_STR
9537 "Display routes conforming to the filter-list\n"
9538 "Regular expression access list name\n")
9539 {
9540 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9541 bgp_show_type_filter_list);
9542 }
9543
9544 DEFUN (show_ip_bgp_instance_filter_list,
9545 show_ip_bgp_instance_filter_list_cmd,
9546 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
9547 SHOW_STR
9548 IP_STR
9549 BGP_STR
9550 BGP_INSTANCE_HELP_STR
9551 "Display routes conforming to the filter-list\n"
9552 "Regular expression access list name\n")
9553 {
9554 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9555 bgp_show_type_filter_list);
9556 }
9557
9558 DEFUN (show_ip_bgp_flap_filter_list,
9559 show_ip_bgp_flap_filter_list_cmd,
9560 "show ip bgp flap-statistics filter-list WORD",
9561 SHOW_STR
9562 IP_STR
9563 BGP_STR
9564 "Display flap statistics of routes\n"
9565 "Display routes conforming to the filter-list\n"
9566 "Regular expression access list name\n")
9567 {
9568 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9569 bgp_show_type_flap_filter_list);
9570 }
9571
9572 ALIAS (show_ip_bgp_flap_filter_list,
9573 show_ip_bgp_damp_flap_filter_list_cmd,
9574 "show ip bgp dampening flap-statistics filter-list WORD",
9575 SHOW_STR
9576 IP_STR
9577 BGP_STR
9578 "Display detailed information about dampening\n"
9579 "Display flap statistics of routes\n"
9580 "Display routes conforming to the filter-list\n"
9581 "Regular expression access list name\n")
9582
9583 DEFUN (show_ip_bgp_ipv4_filter_list,
9584 show_ip_bgp_ipv4_filter_list_cmd,
9585 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9586 SHOW_STR
9587 IP_STR
9588 BGP_STR
9589 "Address family\n"
9590 "Address Family modifier\n"
9591 "Address Family modifier\n"
9592 "Display routes conforming to the filter-list\n"
9593 "Regular expression access list name\n")
9594 {
9595 safi_t safi;
9596 safi = bgp_vty_safi_from_arg(argv[0]);
9597 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, safi,
9598 bgp_show_type_filter_list);
9599 }
9600
9601 #ifdef HAVE_IPV6
9602 DEFUN (show_bgp_filter_list,
9603 show_bgp_filter_list_cmd,
9604 "show bgp filter-list WORD",
9605 SHOW_STR
9606 BGP_STR
9607 "Display routes conforming to the filter-list\n"
9608 "Regular expression access list name\n")
9609 {
9610 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9611 bgp_show_type_filter_list);
9612 }
9613
9614 ALIAS (show_bgp_filter_list,
9615 show_bgp_ipv6_filter_list_cmd,
9616 "show bgp ipv6 filter-list WORD",
9617 SHOW_STR
9618 BGP_STR
9619 "Address family\n"
9620 "Display routes conforming to the filter-list\n"
9621 "Regular expression access list name\n")
9622
9623 /* old command */
9624 DEFUN (show_ipv6_bgp_filter_list,
9625 show_ipv6_bgp_filter_list_cmd,
9626 "show ipv6 bgp filter-list WORD",
9627 SHOW_STR
9628 IPV6_STR
9629 BGP_STR
9630 "Display routes conforming to the filter-list\n"
9631 "Regular expression access list name\n")
9632 {
9633 bgp_show_ipv6_bgp_deprecate_warning(vty);
9634 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9635 bgp_show_type_filter_list);
9636 }
9637
9638 /* old command */
9639 DEFUN (show_ipv6_mbgp_filter_list,
9640 show_ipv6_mbgp_filter_list_cmd,
9641 "show ipv6 mbgp filter-list WORD",
9642 SHOW_STR
9643 IPV6_STR
9644 MBGP_STR
9645 "Display routes conforming to the filter-list\n"
9646 "Regular expression access list name\n")
9647 {
9648 bgp_show_ipv6_bgp_deprecate_warning(vty);
9649 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9650 bgp_show_type_filter_list);
9651 }
9652 #endif /* HAVE_IPV6 */
9653
9654 DEFUN (show_ip_bgp_dampening_info,
9655 show_ip_bgp_dampening_params_cmd,
9656 "show ip bgp dampening parameters",
9657 SHOW_STR
9658 IP_STR
9659 BGP_STR
9660 "Display detailed information about dampening\n"
9661 "Display detail of configured dampening parameters\n")
9662 {
9663 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9664 }
9665
9666
9667 DEFUN (show_ip_bgp_ipv4_dampening_parameters,
9668 show_ip_bgp_ipv4_dampening_parameters_cmd,
9669 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
9670 SHOW_STR
9671 IP_STR
9672 BGP_STR
9673 "Address family\n"
9674 "Address Family modifier\n"
9675 "Address Family modifier\n"
9676 "Display detailed information about dampening\n"
9677 "Display detail of configured dampening parameters\n")
9678 {
9679 safi_t safi;
9680 safi = bgp_vty_safi_from_arg(argv[0]);
9681 return bgp_show_dampening_parameters (vty, AFI_IP, safi);
9682 }
9683
9684
9685 DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
9686 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
9687 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
9688 SHOW_STR
9689 IP_STR
9690 BGP_STR
9691 "Address family\n"
9692 "Address Family modifier\n"
9693 "Address Family modifier\n"
9694 "Display detailed information about dampening\n"
9695 "Display flap statistics of routes\n")
9696 {
9697 safi_t safi;
9698 safi = bgp_vty_safi_from_arg(argv[0]);
9699 return bgp_show (vty, NULL, AFI_IP, safi,
9700 bgp_show_type_flap_statistics, NULL, 0);
9701 }
9702
9703 DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
9704 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
9705 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
9706 SHOW_STR
9707 IP_STR
9708 BGP_STR
9709 "Address family\n"
9710 "Address Family modifier\n"
9711 "Address Family modifier\n"
9712 "Display detailed information about dampening\n"
9713 "Display paths suppressed due to dampening\n")
9714 {
9715 safi_t safi;
9716 safi = bgp_vty_safi_from_arg(argv[0]);
9717 return bgp_show (vty, NULL, AFI_IP, safi,
9718 bgp_show_type_dampend_paths, NULL, 0);
9719 }
9720
9721 static int
9722 bgp_show_route_map (struct vty *vty, const char *name,
9723 const char *rmap_str, afi_t afi,
9724 safi_t safi, enum bgp_show_type type)
9725 {
9726 struct route_map *rmap;
9727 struct bgp *bgp = NULL;
9728
9729 if (name && !(bgp = bgp_lookup_by_name(name)))
9730 {
9731 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9732 return CMD_WARNING;
9733 }
9734
9735 rmap = route_map_lookup_by_name (rmap_str);
9736 if (! rmap)
9737 {
9738 vty_out (vty, "%% %s is not a valid route-map name%s",
9739 rmap_str, VTY_NEWLINE);
9740 return CMD_WARNING;
9741 }
9742
9743 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
9744 }
9745
9746 DEFUN (show_ip_bgp_route_map,
9747 show_ip_bgp_route_map_cmd,
9748 "show ip bgp route-map WORD",
9749 SHOW_STR
9750 IP_STR
9751 BGP_STR
9752 "Display routes matching the route-map\n"
9753 "A route-map to match on\n")
9754 {
9755 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9756 bgp_show_type_route_map);
9757 }
9758
9759 DEFUN (show_ip_bgp_instance_route_map,
9760 show_ip_bgp_instance_route_map_cmd,
9761 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
9762 SHOW_STR
9763 IP_STR
9764 BGP_STR
9765 BGP_INSTANCE_HELP_STR
9766 "Display routes matching the route-map\n"
9767 "A route-map to match on\n")
9768 {
9769 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9770 bgp_show_type_route_map);
9771 }
9772
9773 DEFUN (show_ip_bgp_flap_route_map,
9774 show_ip_bgp_flap_route_map_cmd,
9775 "show ip bgp flap-statistics route-map WORD",
9776 SHOW_STR
9777 IP_STR
9778 BGP_STR
9779 "Display flap statistics of routes\n"
9780 "Display routes matching the route-map\n"
9781 "A route-map to match on\n")
9782 {
9783 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9784 bgp_show_type_flap_route_map);
9785 }
9786
9787 ALIAS (show_ip_bgp_flap_route_map,
9788 show_ip_bgp_damp_flap_route_map_cmd,
9789 "show ip bgp dampening flap-statistics route-map WORD",
9790 SHOW_STR
9791 IP_STR
9792 BGP_STR
9793 "Display detailed information about dampening\n"
9794 "Display flap statistics of routes\n"
9795 "Display routes matching the route-map\n"
9796 "A route-map to match on\n")
9797
9798 DEFUN (show_ip_bgp_ipv4_route_map,
9799 show_ip_bgp_ipv4_route_map_cmd,
9800 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9801 SHOW_STR
9802 IP_STR
9803 BGP_STR
9804 "Address family\n"
9805 "Address Family modifier\n"
9806 "Address Family modifier\n"
9807 "Display routes matching the route-map\n"
9808 "A route-map to match on\n")
9809 {
9810 safi_t safi;
9811 safi = bgp_vty_safi_from_arg(argv[0]);
9812 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, safi,
9813 bgp_show_type_route_map);
9814 }
9815
9816 DEFUN (show_bgp_route_map,
9817 show_bgp_route_map_cmd,
9818 "show bgp route-map WORD",
9819 SHOW_STR
9820 BGP_STR
9821 "Display routes matching the route-map\n"
9822 "A route-map to match on\n")
9823 {
9824 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9825 bgp_show_type_route_map);
9826 }
9827
9828 ALIAS (show_bgp_route_map,
9829 show_bgp_ipv6_route_map_cmd,
9830 "show bgp ipv6 route-map WORD",
9831 SHOW_STR
9832 BGP_STR
9833 "Address family\n"
9834 "Display routes matching the route-map\n"
9835 "A route-map to match on\n")
9836
9837 DEFUN (show_ip_bgp_cidr_only,
9838 show_ip_bgp_cidr_only_cmd,
9839 "show ip bgp cidr-only",
9840 SHOW_STR
9841 IP_STR
9842 BGP_STR
9843 "Display only routes with non-natural netmasks\n")
9844 {
9845 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9846 bgp_show_type_cidr_only, NULL, 0);
9847 }
9848
9849 DEFUN (show_ip_bgp_flap_cidr_only,
9850 show_ip_bgp_flap_cidr_only_cmd,
9851 "show ip bgp flap-statistics cidr-only",
9852 SHOW_STR
9853 IP_STR
9854 BGP_STR
9855 "Display flap statistics of routes\n"
9856 "Display only routes with non-natural netmasks\n")
9857 {
9858 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9859 bgp_show_type_flap_cidr_only, NULL, 0);
9860 }
9861
9862 ALIAS (show_ip_bgp_flap_cidr_only,
9863 show_ip_bgp_damp_flap_cidr_only_cmd,
9864 "show ip bgp dampening flap-statistics cidr-only",
9865 SHOW_STR
9866 IP_STR
9867 BGP_STR
9868 "Display detailed information about dampening\n"
9869 "Display flap statistics of routes\n"
9870 "Display only routes with non-natural netmasks\n")
9871
9872 DEFUN (show_ip_bgp_ipv4_cidr_only,
9873 show_ip_bgp_ipv4_cidr_only_cmd,
9874 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9875 SHOW_STR
9876 IP_STR
9877 BGP_STR
9878 "Address family\n"
9879 "Address Family modifier\n"
9880 "Address Family modifier\n"
9881 "Display only routes with non-natural netmasks\n")
9882 {
9883 safi_t safi;
9884 safi = bgp_vty_safi_from_arg(argv[0]);
9885 return bgp_show (vty, NULL, AFI_IP, safi,
9886 bgp_show_type_cidr_only, NULL, 0);
9887 }
9888
9889 DEFUN (show_ip_bgp_community_all,
9890 show_ip_bgp_community_all_cmd,
9891 "show ip bgp community",
9892 SHOW_STR
9893 IP_STR
9894 BGP_STR
9895 "Display routes matching the communities\n")
9896 {
9897 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9898 bgp_show_type_community_all, NULL, 0);
9899 }
9900
9901 DEFUN (show_ip_bgp_ipv4_community_all,
9902 show_ip_bgp_ipv4_community_all_cmd,
9903 "show ip bgp ipv4 (unicast|multicast) community",
9904 SHOW_STR
9905 IP_STR
9906 BGP_STR
9907 "Address family\n"
9908 "Address Family modifier\n"
9909 "Address Family modifier\n"
9910 "Display routes matching the communities\n")
9911 {
9912 safi_t safi;
9913 safi = bgp_vty_safi_from_arg(argv[0]);
9914 return bgp_show (vty, NULL, AFI_IP, safi,
9915 bgp_show_type_community_all, NULL, 0);
9916 }
9917
9918 #ifdef HAVE_IPV6
9919 DEFUN (show_bgp_community_all,
9920 show_bgp_community_all_cmd,
9921 "show bgp community",
9922 SHOW_STR
9923 BGP_STR
9924 "Display routes matching the communities\n")
9925 {
9926 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9927 bgp_show_type_community_all, NULL, 0);
9928 }
9929
9930 ALIAS (show_bgp_community_all,
9931 show_bgp_ipv6_community_all_cmd,
9932 "show bgp ipv6 community",
9933 SHOW_STR
9934 BGP_STR
9935 "Address family\n"
9936 "Display routes matching the communities\n")
9937
9938 /* old command */
9939 DEFUN (show_ipv6_bgp_community_all,
9940 show_ipv6_bgp_community_all_cmd,
9941 "show ipv6 bgp community",
9942 SHOW_STR
9943 IPV6_STR
9944 BGP_STR
9945 "Display routes matching the communities\n")
9946 {
9947 bgp_show_ipv6_bgp_deprecate_warning(vty);
9948 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9949 bgp_show_type_community_all, NULL, 0);
9950 }
9951
9952 /* old command */
9953 DEFUN (show_ipv6_mbgp_community_all,
9954 show_ipv6_mbgp_community_all_cmd,
9955 "show ipv6 mbgp community",
9956 SHOW_STR
9957 IPV6_STR
9958 MBGP_STR
9959 "Display routes matching the communities\n")
9960 {
9961 bgp_show_ipv6_bgp_deprecate_warning(vty);
9962 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9963 bgp_show_type_community_all, NULL, 0);
9964 }
9965 #endif /* HAVE_IPV6 */
9966
9967 static int
9968 bgp_show_community (struct vty *vty, const char *view_name, int argc,
9969 const char **argv, int exact, afi_t afi, safi_t safi)
9970 {
9971 struct community *com;
9972 struct buffer *b;
9973 struct bgp *bgp;
9974 int i;
9975 char *str;
9976 int first = 0;
9977
9978 /* BGP structure lookup */
9979 if (view_name)
9980 {
9981 bgp = bgp_lookup_by_name (view_name);
9982 if (bgp == NULL)
9983 {
9984 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
9985 return CMD_WARNING;
9986 }
9987 }
9988 else
9989 {
9990 bgp = bgp_get_default ();
9991 if (bgp == NULL)
9992 {
9993 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9994 return CMD_WARNING;
9995 }
9996 }
9997
9998 b = buffer_new (1024);
9999 for (i = 0; i < argc; i++)
10000 {
10001 if (first)
10002 buffer_putc (b, ' ');
10003 else
10004 {
10005 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
10006 continue;
10007 first = 1;
10008 }
10009
10010 buffer_putstr (b, argv[i]);
10011 }
10012 buffer_putc (b, '\0');
10013
10014 str = buffer_getstr (b);
10015 buffer_free (b);
10016
10017 com = community_str2com (str);
10018 XFREE (MTYPE_TMP, str);
10019 if (! com)
10020 {
10021 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
10022 return CMD_WARNING;
10023 }
10024
10025 return bgp_show (vty, bgp, afi, safi,
10026 (exact ? bgp_show_type_community_exact :
10027 bgp_show_type_community), com, 0);
10028 }
10029
10030 DEFUN (show_ip_bgp_community,
10031 show_ip_bgp_community_cmd,
10032 "show ip bgp community (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 {
10042 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
10043 }
10044
10045 ALIAS (show_ip_bgp_community,
10046 show_ip_bgp_community2_cmd,
10047 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10048 SHOW_STR
10049 IP_STR
10050 BGP_STR
10051 "Display routes matching the communities\n"
10052 COMMUNITY_AANN_STR
10053 "Do not send outside local AS (well-known community)\n"
10054 "Do not advertise to any peer (well-known community)\n"
10055 "Do not export to next AS (well-known community)\n"
10056 COMMUNITY_AANN_STR
10057 "Do not send outside local AS (well-known community)\n"
10058 "Do not advertise to any peer (well-known community)\n"
10059 "Do not export to next AS (well-known community)\n")
10060
10061 ALIAS (show_ip_bgp_community,
10062 show_ip_bgp_community3_cmd,
10063 "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)",
10064 SHOW_STR
10065 IP_STR
10066 BGP_STR
10067 "Display routes matching the communities\n"
10068 COMMUNITY_AANN_STR
10069 "Do not send outside local AS (well-known community)\n"
10070 "Do not advertise to any peer (well-known community)\n"
10071 "Do not export to next AS (well-known community)\n"
10072 COMMUNITY_AANN_STR
10073 "Do not send outside local AS (well-known community)\n"
10074 "Do not advertise to any peer (well-known community)\n"
10075 "Do not export to next AS (well-known community)\n"
10076 COMMUNITY_AANN_STR
10077 "Do not send outside local AS (well-known community)\n"
10078 "Do not advertise to any peer (well-known community)\n"
10079 "Do not export to next AS (well-known community)\n")
10080
10081 ALIAS (show_ip_bgp_community,
10082 show_ip_bgp_community4_cmd,
10083 "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)",
10084 SHOW_STR
10085 IP_STR
10086 BGP_STR
10087 "Display routes matching the communities\n"
10088 COMMUNITY_AANN_STR
10089 "Do not send outside local AS (well-known community)\n"
10090 "Do not advertise to any peer (well-known community)\n"
10091 "Do not export to next AS (well-known community)\n"
10092 COMMUNITY_AANN_STR
10093 "Do not send outside local AS (well-known community)\n"
10094 "Do not advertise to any peer (well-known community)\n"
10095 "Do not export to next AS (well-known community)\n"
10096 COMMUNITY_AANN_STR
10097 "Do not send outside local AS (well-known community)\n"
10098 "Do not advertise to any peer (well-known community)\n"
10099 "Do not export to next AS (well-known community)\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
10105 DEFUN (show_ip_bgp_ipv4_community,
10106 show_ip_bgp_ipv4_community_cmd,
10107 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10108 SHOW_STR
10109 IP_STR
10110 BGP_STR
10111 "Address family\n"
10112 "Address Family modifier\n"
10113 "Address Family modifier\n"
10114 "Display routes matching the communities\n"
10115 COMMUNITY_AANN_STR
10116 "Do not send outside local AS (well-known community)\n"
10117 "Do not advertise to any peer (well-known community)\n"
10118 "Do not export to next AS (well-known community)\n")
10119 {
10120 safi_t safi;
10121 safi = bgp_vty_safi_from_arg(argv[0]);
10122 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, safi);
10123 }
10124
10125 ALIAS (show_ip_bgp_ipv4_community,
10126 show_ip_bgp_ipv4_community2_cmd,
10127 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10128 SHOW_STR
10129 IP_STR
10130 BGP_STR
10131 "Address family\n"
10132 "Address Family modifier\n"
10133 "Address Family modifier\n"
10134 "Display routes matching the communities\n"
10135 COMMUNITY_AANN_STR
10136 "Do not send outside local AS (well-known community)\n"
10137 "Do not advertise to any peer (well-known community)\n"
10138 "Do not export to next AS (well-known community)\n"
10139 COMMUNITY_AANN_STR
10140 "Do not send outside local AS (well-known community)\n"
10141 "Do not advertise to any peer (well-known community)\n"
10142 "Do not export to next AS (well-known community)\n")
10143
10144 ALIAS (show_ip_bgp_ipv4_community,
10145 show_ip_bgp_ipv4_community3_cmd,
10146 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10147 SHOW_STR
10148 IP_STR
10149 BGP_STR
10150 "Address family\n"
10151 "Address Family modifier\n"
10152 "Address Family modifier\n"
10153 "Display routes matching the communities\n"
10154 COMMUNITY_AANN_STR
10155 "Do not send outside local AS (well-known community)\n"
10156 "Do not advertise to any peer (well-known community)\n"
10157 "Do not export to next AS (well-known community)\n"
10158 COMMUNITY_AANN_STR
10159 "Do not send outside local AS (well-known community)\n"
10160 "Do not advertise to any peer (well-known community)\n"
10161 "Do not export to next AS (well-known community)\n"
10162 COMMUNITY_AANN_STR
10163 "Do not send outside local AS (well-known community)\n"
10164 "Do not advertise to any peer (well-known community)\n"
10165 "Do not export to next AS (well-known community)\n")
10166
10167 ALIAS (show_ip_bgp_ipv4_community,
10168 show_ip_bgp_ipv4_community4_cmd,
10169 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10170 SHOW_STR
10171 IP_STR
10172 BGP_STR
10173 "Address family\n"
10174 "Address Family modifier\n"
10175 "Address Family modifier\n"
10176 "Display routes matching the communities\n"
10177 COMMUNITY_AANN_STR
10178 "Do not send outside local AS (well-known community)\n"
10179 "Do not advertise to any peer (well-known community)\n"
10180 "Do not export to next AS (well-known community)\n"
10181 COMMUNITY_AANN_STR
10182 "Do not send outside local AS (well-known community)\n"
10183 "Do not advertise to any peer (well-known community)\n"
10184 "Do not export to next AS (well-known community)\n"
10185 COMMUNITY_AANN_STR
10186 "Do not send outside local AS (well-known community)\n"
10187 "Do not advertise to any peer (well-known community)\n"
10188 "Do not export to next AS (well-known community)\n"
10189 COMMUNITY_AANN_STR
10190 "Do not send outside local AS (well-known community)\n"
10191 "Do not advertise to any peer (well-known community)\n"
10192 "Do not export to next AS (well-known community)\n")
10193
10194 DEFUN (show_bgp_instance_afi_safi_community_all,
10195 show_bgp_instance_afi_safi_community_all_cmd,
10196 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
10197 SHOW_STR
10198 BGP_STR
10199 BGP_INSTANCE_HELP_STR
10200 "Address family\n"
10201 "Address family\n"
10202 "Address Family modifier\n"
10203 "Address Family modifier\n"
10204 "Display routes matching the communities\n")
10205 {
10206 int afi;
10207 int safi;
10208 struct bgp *bgp;
10209
10210 /* BGP structure lookup. */
10211 bgp = bgp_lookup_by_name (argv[1]);
10212 if (bgp == NULL)
10213 {
10214 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
10215 return CMD_WARNING;
10216 }
10217
10218 afi = bgp_vty_safi_from_arg(argv[2]);
10219 safi = bgp_vty_safi_from_arg(argv[3]);
10220 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
10221 }
10222
10223 DEFUN (show_bgp_instance_afi_safi_community,
10224 show_bgp_instance_afi_safi_community_cmd,
10225 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10226 SHOW_STR
10227 BGP_STR
10228 BGP_INSTANCE_HELP_STR
10229 "Address family\n"
10230 "Address family\n"
10231 "Address family modifier\n"
10232 "Address family modifier\n"
10233 "Display routes matching the communities\n"
10234 COMMUNITY_AANN_STR
10235 "Do not send outside local AS (well-known community)\n"
10236 "Do not advertise to any peer (well-known community)\n"
10237 "Do not export to next AS (well-known community)\n")
10238 {
10239 int afi;
10240 int safi;
10241
10242 afi = bgp_vty_safi_from_arg(argv[2]);
10243 safi = bgp_vty_safi_from_arg(argv[3]);
10244 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
10245 }
10246
10247 ALIAS (show_bgp_instance_afi_safi_community,
10248 show_bgp_instance_afi_safi_community2_cmd,
10249 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10250 SHOW_STR
10251 BGP_STR
10252 BGP_INSTANCE_HELP_STR
10253 "Address family\n"
10254 "Address family\n"
10255 "Address family modifier\n"
10256 "Address family modifier\n"
10257 "Display routes matching the communities\n"
10258 COMMUNITY_AANN_STR
10259 "Do not send outside local AS (well-known community)\n"
10260 "Do not advertise to any peer (well-known community)\n"
10261 "Do not export to next AS (well-known community)\n"
10262 COMMUNITY_AANN_STR
10263 "Do not send outside local AS (well-known community)\n"
10264 "Do not advertise to any peer (well-known community)\n"
10265 "Do not export to next AS (well-known community)\n")
10266
10267 ALIAS (show_bgp_instance_afi_safi_community,
10268 show_bgp_instance_afi_safi_community3_cmd,
10269 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10270 SHOW_STR
10271 BGP_STR
10272 BGP_INSTANCE_HELP_STR
10273 "Address family\n"
10274 "Address family\n"
10275 "Address family modifier\n"
10276 "Address family modifier\n"
10277 "Display routes matching the communities\n"
10278 COMMUNITY_AANN_STR
10279 "Do not send outside local AS (well-known community)\n"
10280 "Do not advertise to any peer (well-known community)\n"
10281 "Do not export to next AS (well-known community)\n"
10282 COMMUNITY_AANN_STR
10283 "Do not send outside local AS (well-known community)\n"
10284 "Do not advertise to any peer (well-known community)\n"
10285 "Do not export to next AS (well-known community)\n"
10286 COMMUNITY_AANN_STR
10287 "Do not send outside local AS (well-known community)\n"
10288 "Do not advertise to any peer (well-known community)\n"
10289 "Do not export to next AS (well-known community)\n")
10290
10291 ALIAS (show_bgp_instance_afi_safi_community,
10292 show_bgp_instance_afi_safi_community4_cmd,
10293 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10294 SHOW_STR
10295 BGP_STR
10296 BGP_INSTANCE_HELP_STR
10297 "Address family\n"
10298 "Address family\n"
10299 "Address family modifier\n"
10300 "Address family modifier\n"
10301 "Display routes matching the communities\n"
10302 COMMUNITY_AANN_STR
10303 "Do not send outside local AS (well-known community)\n"
10304 "Do not advertise to any peer (well-known community)\n"
10305 "Do not export to next AS (well-known community)\n"
10306 COMMUNITY_AANN_STR
10307 "Do not send outside local AS (well-known community)\n"
10308 "Do not advertise to any peer (well-known community)\n"
10309 "Do not export to next AS (well-known community)\n"
10310 COMMUNITY_AANN_STR
10311 "Do not send outside local AS (well-known community)\n"
10312 "Do not advertise to any peer (well-known community)\n"
10313 "Do not export to next AS (well-known community)\n"
10314 COMMUNITY_AANN_STR
10315 "Do not send outside local AS (well-known community)\n"
10316 "Do not advertise to any peer (well-known community)\n"
10317 "Do not export to next AS (well-known community)\n")
10318
10319 DEFUN (show_ip_bgp_community_exact,
10320 show_ip_bgp_community_exact_cmd,
10321 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10322 SHOW_STR
10323 IP_STR
10324 BGP_STR
10325 "Display routes matching the communities\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 "Exact match of the communities")
10331 {
10332 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10333 }
10334
10335 ALIAS (show_ip_bgp_community_exact,
10336 show_ip_bgp_community2_exact_cmd,
10337 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10338 SHOW_STR
10339 IP_STR
10340 BGP_STR
10341 "Display routes matching the communities\n"
10342 COMMUNITY_AANN_STR
10343 "Do not send outside local AS (well-known community)\n"
10344 "Do not advertise to any peer (well-known community)\n"
10345 "Do not export to next AS (well-known community)\n"
10346 COMMUNITY_AANN_STR
10347 "Do not send outside local AS (well-known community)\n"
10348 "Do not advertise to any peer (well-known community)\n"
10349 "Do not export to next AS (well-known community)\n"
10350 "Exact match of the communities")
10351
10352 ALIAS (show_ip_bgp_community_exact,
10353 show_ip_bgp_community3_exact_cmd,
10354 "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",
10355 SHOW_STR
10356 IP_STR
10357 BGP_STR
10358 "Display routes matching the communities\n"
10359 COMMUNITY_AANN_STR
10360 "Do not send outside local AS (well-known community)\n"
10361 "Do not advertise to any peer (well-known community)\n"
10362 "Do not export to next AS (well-known community)\n"
10363 COMMUNITY_AANN_STR
10364 "Do not send outside local AS (well-known community)\n"
10365 "Do not advertise to any peer (well-known community)\n"
10366 "Do not export to next AS (well-known community)\n"
10367 COMMUNITY_AANN_STR
10368 "Do not send outside local AS (well-known community)\n"
10369 "Do not advertise to any peer (well-known community)\n"
10370 "Do not export to next AS (well-known community)\n"
10371 "Exact match of the communities")
10372
10373 ALIAS (show_ip_bgp_community_exact,
10374 show_ip_bgp_community4_exact_cmd,
10375 "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",
10376 SHOW_STR
10377 IP_STR
10378 BGP_STR
10379 "Display routes matching the communities\n"
10380 COMMUNITY_AANN_STR
10381 "Do not send outside local AS (well-known community)\n"
10382 "Do not advertise to any peer (well-known community)\n"
10383 "Do not export to next AS (well-known community)\n"
10384 COMMUNITY_AANN_STR
10385 "Do not send outside local AS (well-known community)\n"
10386 "Do not advertise to any peer (well-known community)\n"
10387 "Do not export to next AS (well-known community)\n"
10388 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 "Exact match of the communities")
10397
10398 DEFUN (show_ip_bgp_ipv4_community_exact,
10399 show_ip_bgp_ipv4_community_exact_cmd,
10400 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10401 SHOW_STR
10402 IP_STR
10403 BGP_STR
10404 "Address family\n"
10405 "Address Family modifier\n"
10406 "Address Family modifier\n"
10407 "Display routes matching the communities\n"
10408 COMMUNITY_AANN_STR
10409 "Do not send outside local AS (well-known community)\n"
10410 "Do not advertise to any peer (well-known community)\n"
10411 "Do not export to next AS (well-known community)\n"
10412 "Exact match of the communities")
10413 {
10414 safi_t safi;
10415 safi = bgp_vty_safi_from_arg(argv[0]);
10416 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, safi);
10417 }
10418
10419 ALIAS (show_ip_bgp_ipv4_community_exact,
10420 show_ip_bgp_ipv4_community2_exact_cmd,
10421 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10422 SHOW_STR
10423 IP_STR
10424 BGP_STR
10425 "Address family\n"
10426 "Address Family modifier\n"
10427 "Address Family modifier\n"
10428 "Display routes matching the communities\n"
10429 COMMUNITY_AANN_STR
10430 "Do not send outside local AS (well-known community)\n"
10431 "Do not advertise to any peer (well-known community)\n"
10432 "Do not export to next AS (well-known community)\n"
10433 COMMUNITY_AANN_STR
10434 "Do not send outside local AS (well-known community)\n"
10435 "Do not advertise to any peer (well-known community)\n"
10436 "Do not export to next AS (well-known community)\n"
10437 "Exact match of the communities")
10438
10439 ALIAS (show_ip_bgp_ipv4_community_exact,
10440 show_ip_bgp_ipv4_community3_exact_cmd,
10441 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10442 SHOW_STR
10443 IP_STR
10444 BGP_STR
10445 "Address family\n"
10446 "Address Family modifier\n"
10447 "Address Family modifier\n"
10448 "Display routes matching the communities\n"
10449 COMMUNITY_AANN_STR
10450 "Do not send outside local AS (well-known community)\n"
10451 "Do not advertise to any peer (well-known community)\n"
10452 "Do not export to next AS (well-known community)\n"
10453 COMMUNITY_AANN_STR
10454 "Do not send outside local AS (well-known community)\n"
10455 "Do not advertise to any peer (well-known community)\n"
10456 "Do not export to next AS (well-known community)\n"
10457 COMMUNITY_AANN_STR
10458 "Do not send outside local AS (well-known community)\n"
10459 "Do not advertise to any peer (well-known community)\n"
10460 "Do not export to next AS (well-known community)\n"
10461 "Exact match of the communities")
10462
10463 ALIAS (show_ip_bgp_ipv4_community_exact,
10464 show_ip_bgp_ipv4_community4_exact_cmd,
10465 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10466 SHOW_STR
10467 IP_STR
10468 BGP_STR
10469 "Address family\n"
10470 "Address Family modifier\n"
10471 "Address Family modifier\n"
10472 "Display routes matching the communities\n"
10473 COMMUNITY_AANN_STR
10474 "Do not send outside local AS (well-known community)\n"
10475 "Do not advertise to any peer (well-known community)\n"
10476 "Do not export to next AS (well-known community)\n"
10477 COMMUNITY_AANN_STR
10478 "Do not send outside local AS (well-known community)\n"
10479 "Do not advertise to any peer (well-known community)\n"
10480 "Do not export to next AS (well-known community)\n"
10481 COMMUNITY_AANN_STR
10482 "Do not send outside local AS (well-known community)\n"
10483 "Do not advertise to any peer (well-known community)\n"
10484 "Do not export to next AS (well-known community)\n"
10485 COMMUNITY_AANN_STR
10486 "Do not send outside local AS (well-known community)\n"
10487 "Do not advertise to any peer (well-known community)\n"
10488 "Do not export to next AS (well-known community)\n"
10489 "Exact match of the communities")
10490
10491 #ifdef HAVE_IPV6
10492 DEFUN (show_bgp_community,
10493 show_bgp_community_cmd,
10494 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10495 SHOW_STR
10496 BGP_STR
10497 "Display routes matching the communities\n"
10498 COMMUNITY_AANN_STR
10499 "Do not send outside local AS (well-known community)\n"
10500 "Do not advertise to any peer (well-known community)\n"
10501 "Do not export to next AS (well-known community)\n")
10502 {
10503 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10504 }
10505
10506 ALIAS (show_bgp_community,
10507 show_bgp_ipv6_community_cmd,
10508 "show bgp ipv6 community (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
10518 ALIAS (show_bgp_community,
10519 show_bgp_community2_cmd,
10520 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10521 SHOW_STR
10522 BGP_STR
10523 "Display routes matching the communities\n"
10524 COMMUNITY_AANN_STR
10525 "Do not send outside local AS (well-known community)\n"
10526 "Do not advertise to any peer (well-known community)\n"
10527 "Do not export to next AS (well-known community)\n"
10528 COMMUNITY_AANN_STR
10529 "Do not send outside local AS (well-known community)\n"
10530 "Do not advertise to any peer (well-known community)\n"
10531 "Do not export to next AS (well-known community)\n")
10532
10533 ALIAS (show_bgp_community,
10534 show_bgp_ipv6_community2_cmd,
10535 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10536 SHOW_STR
10537 BGP_STR
10538 "Address family\n"
10539 "Display routes matching the communities\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_community3_cmd,
10551 "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)",
10552 SHOW_STR
10553 BGP_STR
10554 "Display routes matching the communities\n"
10555 COMMUNITY_AANN_STR
10556 "Do not send outside local AS (well-known community)\n"
10557 "Do not advertise to any peer (well-known community)\n"
10558 "Do not export to next AS (well-known community)\n"
10559 COMMUNITY_AANN_STR
10560 "Do not send outside local AS (well-known community)\n"
10561 "Do not advertise to any peer (well-known community)\n"
10562 "Do not export to next AS (well-known community)\n"
10563 COMMUNITY_AANN_STR
10564 "Do not send outside local AS (well-known community)\n"
10565 "Do not advertise to any peer (well-known community)\n"
10566 "Do not export to next AS (well-known community)\n")
10567
10568 ALIAS (show_bgp_community,
10569 show_bgp_ipv6_community3_cmd,
10570 "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)",
10571 SHOW_STR
10572 BGP_STR
10573 "Address family\n"
10574 "Display routes matching the communities\n"
10575 COMMUNITY_AANN_STR
10576 "Do not send outside local AS (well-known community)\n"
10577 "Do not advertise to any peer (well-known community)\n"
10578 "Do not export to next AS (well-known community)\n"
10579 COMMUNITY_AANN_STR
10580 "Do not send outside local AS (well-known community)\n"
10581 "Do not advertise to any peer (well-known community)\n"
10582 "Do not export to next AS (well-known community)\n"
10583 COMMUNITY_AANN_STR
10584 "Do not send outside local AS (well-known community)\n"
10585 "Do not advertise to any peer (well-known community)\n"
10586 "Do not export to next AS (well-known community)\n")
10587
10588 ALIAS (show_bgp_community,
10589 show_bgp_community4_cmd,
10590 "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)",
10591 SHOW_STR
10592 BGP_STR
10593 "Display routes matching the communities\n"
10594 COMMUNITY_AANN_STR
10595 "Do not send outside local AS (well-known community)\n"
10596 "Do not advertise to any peer (well-known community)\n"
10597 "Do not export to next AS (well-known community)\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 COMMUNITY_AANN_STR
10607 "Do not send outside local AS (well-known community)\n"
10608 "Do not advertise to any peer (well-known community)\n"
10609 "Do not export to next AS (well-known community)\n")
10610
10611 ALIAS (show_bgp_community,
10612 show_bgp_ipv6_community4_cmd,
10613 "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)",
10614 SHOW_STR
10615 BGP_STR
10616 "Address family\n"
10617 "Display routes matching the communities\n"
10618 COMMUNITY_AANN_STR
10619 "Do not send outside local AS (well-known community)\n"
10620 "Do not advertise to any peer (well-known community)\n"
10621 "Do not export to next AS (well-known community)\n"
10622 COMMUNITY_AANN_STR
10623 "Do not send outside local AS (well-known community)\n"
10624 "Do not advertise to any peer (well-known community)\n"
10625 "Do not export to next AS (well-known community)\n"
10626 COMMUNITY_AANN_STR
10627 "Do not send outside local AS (well-known community)\n"
10628 "Do not advertise to any peer (well-known community)\n"
10629 "Do not export to next AS (well-known community)\n"
10630 COMMUNITY_AANN_STR
10631 "Do not send outside local AS (well-known community)\n"
10632 "Do not advertise to any peer (well-known community)\n"
10633 "Do not export to next AS (well-known community)\n")
10634
10635 /* old command */
10636 DEFUN (show_ipv6_bgp_community,
10637 show_ipv6_bgp_community_cmd,
10638 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10639 SHOW_STR
10640 IPV6_STR
10641 BGP_STR
10642 "Display routes matching the communities\n"
10643 COMMUNITY_AANN_STR
10644 "Do not send outside local AS (well-known community)\n"
10645 "Do not advertise to any peer (well-known community)\n"
10646 "Do not export to next AS (well-known community)\n")
10647 {
10648 bgp_show_ipv6_bgp_deprecate_warning(vty);
10649 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10650 }
10651
10652 /* old command */
10653 ALIAS (show_ipv6_bgp_community,
10654 show_ipv6_bgp_community2_cmd,
10655 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10656 SHOW_STR
10657 IPV6_STR
10658 BGP_STR
10659 "Display routes matching the communities\n"
10660 COMMUNITY_AANN_STR
10661 "Do not send outside local AS (well-known community)\n"
10662 "Do not advertise to any peer (well-known community)\n"
10663 "Do not export to next AS (well-known community)\n"
10664 COMMUNITY_AANN_STR
10665 "Do not send outside local AS (well-known community)\n"
10666 "Do not advertise to any peer (well-known community)\n"
10667 "Do not export to next AS (well-known community)\n")
10668
10669 /* old command */
10670 ALIAS (show_ipv6_bgp_community,
10671 show_ipv6_bgp_community3_cmd,
10672 "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)",
10673 SHOW_STR
10674 IPV6_STR
10675 BGP_STR
10676 "Display routes matching the communities\n"
10677 COMMUNITY_AANN_STR
10678 "Do not send outside local AS (well-known community)\n"
10679 "Do not advertise to any peer (well-known community)\n"
10680 "Do not export to next AS (well-known community)\n"
10681 COMMUNITY_AANN_STR
10682 "Do not send outside local AS (well-known community)\n"
10683 "Do not advertise to any peer (well-known community)\n"
10684 "Do not export to next AS (well-known community)\n"
10685 COMMUNITY_AANN_STR
10686 "Do not send outside local AS (well-known community)\n"
10687 "Do not advertise to any peer (well-known community)\n"
10688 "Do not export to next AS (well-known community)\n")
10689
10690 /* old command */
10691 ALIAS (show_ipv6_bgp_community,
10692 show_ipv6_bgp_community4_cmd,
10693 "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)",
10694 SHOW_STR
10695 IPV6_STR
10696 BGP_STR
10697 "Display routes matching the communities\n"
10698 COMMUNITY_AANN_STR
10699 "Do not send outside local AS (well-known community)\n"
10700 "Do not advertise to any peer (well-known community)\n"
10701 "Do not export to next AS (well-known community)\n"
10702 COMMUNITY_AANN_STR
10703 "Do not send outside local AS (well-known community)\n"
10704 "Do not advertise to any peer (well-known community)\n"
10705 "Do not export to next AS (well-known community)\n"
10706 COMMUNITY_AANN_STR
10707 "Do not send outside local AS (well-known community)\n"
10708 "Do not advertise to any peer (well-known community)\n"
10709 "Do not export to next AS (well-known community)\n"
10710 COMMUNITY_AANN_STR
10711 "Do not send outside local AS (well-known community)\n"
10712 "Do not advertise to any peer (well-known community)\n"
10713 "Do not export to next AS (well-known community)\n")
10714
10715 DEFUN (show_bgp_community_exact,
10716 show_bgp_community_exact_cmd,
10717 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10718 SHOW_STR
10719 BGP_STR
10720 "Display routes matching the communities\n"
10721 COMMUNITY_AANN_STR
10722 "Do not send outside local AS (well-known community)\n"
10723 "Do not advertise to any peer (well-known community)\n"
10724 "Do not export to next AS (well-known community)\n"
10725 "Exact match of the communities")
10726 {
10727 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10728 }
10729
10730 ALIAS (show_bgp_community_exact,
10731 show_bgp_ipv6_community_exact_cmd,
10732 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10733 SHOW_STR
10734 BGP_STR
10735 "Address family\n"
10736 "Display routes matching the communities\n"
10737 COMMUNITY_AANN_STR
10738 "Do not send outside local AS (well-known community)\n"
10739 "Do not advertise to any peer (well-known community)\n"
10740 "Do not export to next AS (well-known community)\n"
10741 "Exact match of the communities")
10742
10743 ALIAS (show_bgp_community_exact,
10744 show_bgp_community2_exact_cmd,
10745 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10746 SHOW_STR
10747 BGP_STR
10748 "Display routes matching the communities\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 COMMUNITY_AANN_STR
10754 "Do not send outside local AS (well-known community)\n"
10755 "Do not advertise to any peer (well-known community)\n"
10756 "Do not export to next AS (well-known community)\n"
10757 "Exact match of the communities")
10758
10759 ALIAS (show_bgp_community_exact,
10760 show_bgp_ipv6_community2_exact_cmd,
10761 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10762 SHOW_STR
10763 BGP_STR
10764 "Address family\n"
10765 "Display routes matching the communities\n"
10766 COMMUNITY_AANN_STR
10767 "Do not send outside local AS (well-known community)\n"
10768 "Do not advertise to any peer (well-known community)\n"
10769 "Do not export to next AS (well-known community)\n"
10770 COMMUNITY_AANN_STR
10771 "Do not send outside local AS (well-known community)\n"
10772 "Do not advertise to any peer (well-known community)\n"
10773 "Do not export to next AS (well-known community)\n"
10774 "Exact match of the communities")
10775
10776 ALIAS (show_bgp_community_exact,
10777 show_bgp_community3_exact_cmd,
10778 "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",
10779 SHOW_STR
10780 BGP_STR
10781 "Display routes matching the communities\n"
10782 COMMUNITY_AANN_STR
10783 "Do not send outside local AS (well-known community)\n"
10784 "Do not advertise to any peer (well-known community)\n"
10785 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10795
10796 ALIAS (show_bgp_community_exact,
10797 show_bgp_ipv6_community3_exact_cmd,
10798 "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",
10799 SHOW_STR
10800 BGP_STR
10801 "Address family\n"
10802 "Display routes matching the communities\n"
10803 COMMUNITY_AANN_STR
10804 "Do not send outside local AS (well-known community)\n"
10805 "Do not advertise to any peer (well-known community)\n"
10806 "Do not export to next AS (well-known community)\n"
10807 COMMUNITY_AANN_STR
10808 "Do not send outside local AS (well-known community)\n"
10809 "Do not advertise to any peer (well-known community)\n"
10810 "Do not export to next AS (well-known community)\n"
10811 COMMUNITY_AANN_STR
10812 "Do not send outside local AS (well-known community)\n"
10813 "Do not advertise to any peer (well-known community)\n"
10814 "Do not export to next AS (well-known community)\n"
10815 "Exact match of the communities")
10816
10817 ALIAS (show_bgp_community_exact,
10818 show_bgp_community4_exact_cmd,
10819 "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",
10820 SHOW_STR
10821 BGP_STR
10822 "Display routes matching the communities\n"
10823 COMMUNITY_AANN_STR
10824 "Do not send outside local AS (well-known community)\n"
10825 "Do not advertise to any peer (well-known community)\n"
10826 "Do not export to next AS (well-known community)\n"
10827 COMMUNITY_AANN_STR
10828 "Do not send outside local AS (well-known community)\n"
10829 "Do not advertise to any peer (well-known community)\n"
10830 "Do not export to next AS (well-known community)\n"
10831 COMMUNITY_AANN_STR
10832 "Do not send outside local AS (well-known community)\n"
10833 "Do not advertise to any peer (well-known community)\n"
10834 "Do not export to next AS (well-known community)\n"
10835 COMMUNITY_AANN_STR
10836 "Do not send outside local AS (well-known community)\n"
10837 "Do not advertise to any peer (well-known community)\n"
10838 "Do not export to next AS (well-known community)\n"
10839 "Exact match of the communities")
10840
10841 ALIAS (show_bgp_community_exact,
10842 show_bgp_ipv6_community4_exact_cmd,
10843 "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",
10844 SHOW_STR
10845 BGP_STR
10846 "Address family\n"
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 COMMUNITY_AANN_STR
10861 "Do not send outside local AS (well-known community)\n"
10862 "Do not advertise to any peer (well-known community)\n"
10863 "Do not export to next AS (well-known community)\n"
10864 "Exact match of the communities")
10865
10866 /* old command */
10867 DEFUN (show_ipv6_bgp_community_exact,
10868 show_ipv6_bgp_community_exact_cmd,
10869 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10870 SHOW_STR
10871 IPV6_STR
10872 BGP_STR
10873 "Display routes matching the communities\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 "Exact match of the communities")
10879 {
10880 bgp_show_ipv6_bgp_deprecate_warning(vty);
10881 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10882 }
10883
10884 /* old command */
10885 ALIAS (show_ipv6_bgp_community_exact,
10886 show_ipv6_bgp_community2_exact_cmd,
10887 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10888 SHOW_STR
10889 IPV6_STR
10890 BGP_STR
10891 "Display routes matching the communities\n"
10892 COMMUNITY_AANN_STR
10893 "Do not send outside local AS (well-known community)\n"
10894 "Do not advertise to any peer (well-known community)\n"
10895 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10901
10902 /* old command */
10903 ALIAS (show_ipv6_bgp_community_exact,
10904 show_ipv6_bgp_community3_exact_cmd,
10905 "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",
10906 SHOW_STR
10907 IPV6_STR
10908 BGP_STR
10909 "Display routes matching the communities\n"
10910 COMMUNITY_AANN_STR
10911 "Do not send outside local AS (well-known community)\n"
10912 "Do not advertise to any peer (well-known community)\n"
10913 "Do not export to next AS (well-known community)\n"
10914 COMMUNITY_AANN_STR
10915 "Do not send outside local AS (well-known community)\n"
10916 "Do not advertise to any peer (well-known community)\n"
10917 "Do not export to next AS (well-known community)\n"
10918 COMMUNITY_AANN_STR
10919 "Do not send outside local AS (well-known community)\n"
10920 "Do not advertise to any peer (well-known community)\n"
10921 "Do not export to next AS (well-known community)\n"
10922 "Exact match of the communities")
10923
10924 /* old command */
10925 ALIAS (show_ipv6_bgp_community_exact,
10926 show_ipv6_bgp_community4_exact_cmd,
10927 "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",
10928 SHOW_STR
10929 IPV6_STR
10930 BGP_STR
10931 "Display routes matching the communities\n"
10932 COMMUNITY_AANN_STR
10933 "Do not send outside local AS (well-known community)\n"
10934 "Do not advertise to any peer (well-known community)\n"
10935 "Do not export to next AS (well-known community)\n"
10936 COMMUNITY_AANN_STR
10937 "Do not send outside local AS (well-known community)\n"
10938 "Do not advertise to any peer (well-known community)\n"
10939 "Do not export to next AS (well-known community)\n"
10940 COMMUNITY_AANN_STR
10941 "Do not send outside local AS (well-known community)\n"
10942 "Do not advertise to any peer (well-known community)\n"
10943 "Do not export to next AS (well-known community)\n"
10944 COMMUNITY_AANN_STR
10945 "Do not send outside local AS (well-known community)\n"
10946 "Do not advertise to any peer (well-known community)\n"
10947 "Do not export to next AS (well-known community)\n"
10948 "Exact match of the communities")
10949
10950 /* old command */
10951 DEFUN (show_ipv6_mbgp_community,
10952 show_ipv6_mbgp_community_cmd,
10953 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10954 SHOW_STR
10955 IPV6_STR
10956 MBGP_STR
10957 "Display routes matching the communities\n"
10958 COMMUNITY_AANN_STR
10959 "Do not send outside local AS (well-known community)\n"
10960 "Do not advertise to any peer (well-known community)\n"
10961 "Do not export to next AS (well-known community)\n")
10962 {
10963 bgp_show_ipv6_bgp_deprecate_warning(vty);
10964 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10965 }
10966
10967 /* old command */
10968 ALIAS (show_ipv6_mbgp_community,
10969 show_ipv6_mbgp_community2_cmd,
10970 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10971 SHOW_STR
10972 IPV6_STR
10973 MBGP_STR
10974 "Display routes matching the communities\n"
10975 COMMUNITY_AANN_STR
10976 "Do not send outside local AS (well-known community)\n"
10977 "Do not advertise to any peer (well-known community)\n"
10978 "Do not export to next AS (well-known community)\n"
10979 COMMUNITY_AANN_STR
10980 "Do not send outside local AS (well-known community)\n"
10981 "Do not advertise to any peer (well-known community)\n"
10982 "Do not export to next AS (well-known community)\n")
10983
10984 /* old command */
10985 ALIAS (show_ipv6_mbgp_community,
10986 show_ipv6_mbgp_community3_cmd,
10987 "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)",
10988 SHOW_STR
10989 IPV6_STR
10990 MBGP_STR
10991 "Display routes matching the communities\n"
10992 COMMUNITY_AANN_STR
10993 "Do not send outside local AS (well-known community)\n"
10994 "Do not advertise to any peer (well-known community)\n"
10995 "Do not export to next AS (well-known community)\n"
10996 COMMUNITY_AANN_STR
10997 "Do not send outside local AS (well-known community)\n"
10998 "Do not advertise to any peer (well-known community)\n"
10999 "Do not export to next AS (well-known community)\n"
11000 COMMUNITY_AANN_STR
11001 "Do not send outside local AS (well-known community)\n"
11002 "Do not advertise to any peer (well-known community)\n"
11003 "Do not export to next AS (well-known community)\n")
11004
11005 /* old command */
11006 ALIAS (show_ipv6_mbgp_community,
11007 show_ipv6_mbgp_community4_cmd,
11008 "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)",
11009 SHOW_STR
11010 IPV6_STR
11011 MBGP_STR
11012 "Display routes matching the communities\n"
11013 COMMUNITY_AANN_STR
11014 "Do not send outside local AS (well-known community)\n"
11015 "Do not advertise to any peer (well-known community)\n"
11016 "Do not export to next AS (well-known community)\n"
11017 COMMUNITY_AANN_STR
11018 "Do not send outside local AS (well-known community)\n"
11019 "Do not advertise to any peer (well-known community)\n"
11020 "Do not export to next AS (well-known community)\n"
11021 COMMUNITY_AANN_STR
11022 "Do not send outside local AS (well-known community)\n"
11023 "Do not advertise to any peer (well-known community)\n"
11024 "Do not export to next AS (well-known community)\n"
11025 COMMUNITY_AANN_STR
11026 "Do not send outside local AS (well-known community)\n"
11027 "Do not advertise to any peer (well-known community)\n"
11028 "Do not export to next AS (well-known community)\n")
11029
11030 /* old command */
11031 DEFUN (show_ipv6_mbgp_community_exact,
11032 show_ipv6_mbgp_community_exact_cmd,
11033 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
11034 SHOW_STR
11035 IPV6_STR
11036 MBGP_STR
11037 "Display routes matching the communities\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 "Exact match of the communities")
11043 {
11044 bgp_show_ipv6_bgp_deprecate_warning(vty);
11045 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
11046 }
11047
11048 /* old command */
11049 ALIAS (show_ipv6_mbgp_community_exact,
11050 show_ipv6_mbgp_community2_exact_cmd,
11051 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
11052 SHOW_STR
11053 IPV6_STR
11054 MBGP_STR
11055 "Display routes matching the communities\n"
11056 COMMUNITY_AANN_STR
11057 "Do not send outside local AS (well-known community)\n"
11058 "Do not advertise to any peer (well-known community)\n"
11059 "Do not export to next AS (well-known community)\n"
11060 COMMUNITY_AANN_STR
11061 "Do not send outside local AS (well-known community)\n"
11062 "Do not advertise to any peer (well-known community)\n"
11063 "Do not export to next AS (well-known community)\n"
11064 "Exact match of the communities")
11065
11066 /* old command */
11067 ALIAS (show_ipv6_mbgp_community_exact,
11068 show_ipv6_mbgp_community3_exact_cmd,
11069 "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",
11070 SHOW_STR
11071 IPV6_STR
11072 MBGP_STR
11073 "Display routes matching the communities\n"
11074 COMMUNITY_AANN_STR
11075 "Do not send outside local AS (well-known community)\n"
11076 "Do not advertise to any peer (well-known community)\n"
11077 "Do not export to next AS (well-known community)\n"
11078 COMMUNITY_AANN_STR
11079 "Do not send outside local AS (well-known community)\n"
11080 "Do not advertise to any peer (well-known community)\n"
11081 "Do not export to next AS (well-known community)\n"
11082 COMMUNITY_AANN_STR
11083 "Do not send outside local AS (well-known community)\n"
11084 "Do not advertise to any peer (well-known community)\n"
11085 "Do not export to next AS (well-known community)\n"
11086 "Exact match of the communities")
11087
11088 /* old command */
11089 ALIAS (show_ipv6_mbgp_community_exact,
11090 show_ipv6_mbgp_community4_exact_cmd,
11091 "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",
11092 SHOW_STR
11093 IPV6_STR
11094 MBGP_STR
11095 "Display routes matching the communities\n"
11096 COMMUNITY_AANN_STR
11097 "Do not send outside local AS (well-known community)\n"
11098 "Do not advertise to any peer (well-known community)\n"
11099 "Do not export to next AS (well-known community)\n"
11100 COMMUNITY_AANN_STR
11101 "Do not send outside local AS (well-known community)\n"
11102 "Do not advertise to any peer (well-known community)\n"
11103 "Do not export to next AS (well-known community)\n"
11104 COMMUNITY_AANN_STR
11105 "Do not send outside local AS (well-known community)\n"
11106 "Do not advertise to any peer (well-known community)\n"
11107 "Do not export to next AS (well-known community)\n"
11108 COMMUNITY_AANN_STR
11109 "Do not send outside local AS (well-known community)\n"
11110 "Do not advertise to any peer (well-known community)\n"
11111 "Do not export to next AS (well-known community)\n"
11112 "Exact match of the communities")
11113 #endif /* HAVE_IPV6 */
11114
11115 static int
11116 bgp_show_community_list (struct vty *vty, const char *name,
11117 const char *com, int exact,
11118 afi_t afi, safi_t safi)
11119 {
11120 struct community_list *list;
11121 struct bgp *bgp = NULL;
11122
11123 if (name && !(bgp = bgp_lookup_by_name(name)))
11124 {
11125 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11126 return CMD_WARNING;
11127 }
11128
11129 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
11130 if (list == NULL)
11131 {
11132 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11133 VTY_NEWLINE);
11134 return CMD_WARNING;
11135 }
11136
11137 return bgp_show (vty, bgp, afi, safi,
11138 (exact ? bgp_show_type_community_list_exact :
11139 bgp_show_type_community_list), list, 0);
11140 }
11141
11142 DEFUN (show_ip_bgp_community_list,
11143 show_ip_bgp_community_list_cmd,
11144 "show ip bgp community-list (<1-500>|WORD)",
11145 SHOW_STR
11146 IP_STR
11147 BGP_STR
11148 "Display routes matching the community-list\n"
11149 "community-list number\n"
11150 "community-list name\n")
11151 {
11152 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
11153 }
11154
11155 DEFUN (show_ip_bgp_instance_community_list,
11156 show_ip_bgp_instance_community_list_cmd,
11157 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
11158 SHOW_STR
11159 IP_STR
11160 BGP_STR
11161 BGP_INSTANCE_HELP_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, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
11167 }
11168
11169 DEFUN (show_ip_bgp_ipv4_community_list,
11170 show_ip_bgp_ipv4_community_list_cmd,
11171 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11172 SHOW_STR
11173 IP_STR
11174 BGP_STR
11175 "Address family\n"
11176 "Address Family modifier\n"
11177 "Address Family modifier\n"
11178 "Display routes matching the community-list\n"
11179 "community-list number\n"
11180 "community-list name\n")
11181 {
11182 safi_t safi;
11183 safi = bgp_vty_safi_from_arg(argv[0]);
11184 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, safi);
11185 }
11186
11187 DEFUN (show_ip_bgp_community_list_exact,
11188 show_ip_bgp_community_list_exact_cmd,
11189 "show ip bgp community-list (<1-500>|WORD) exact-match",
11190 SHOW_STR
11191 IP_STR
11192 BGP_STR
11193 "Display routes matching the community-list\n"
11194 "community-list number\n"
11195 "community-list name\n"
11196 "Exact match of the communities\n")
11197 {
11198 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
11199 }
11200
11201 DEFUN (show_ip_bgp_ipv4_community_list_exact,
11202 show_ip_bgp_ipv4_community_list_exact_cmd,
11203 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11204 SHOW_STR
11205 IP_STR
11206 BGP_STR
11207 "Address family\n"
11208 "Address Family modifier\n"
11209 "Address Family modifier\n"
11210 "Display routes matching the community-list\n"
11211 "community-list number\n"
11212 "community-list name\n"
11213 "Exact match of the communities\n")
11214 {
11215 safi_t safi;
11216 safi = bgp_vty_safi_from_arg(argv[0]);
11217 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, safi);
11218 }
11219
11220 #ifdef HAVE_IPV6
11221 DEFUN (show_bgp_community_list,
11222 show_bgp_community_list_cmd,
11223 "show bgp community-list (<1-500>|WORD)",
11224 SHOW_STR
11225 BGP_STR
11226 "Display routes matching the community-list\n"
11227 "community-list number\n"
11228 "community-list name\n")
11229 {
11230 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11231 }
11232
11233 ALIAS (show_bgp_community_list,
11234 show_bgp_ipv6_community_list_cmd,
11235 "show bgp ipv6 community-list (<1-500>|WORD)",
11236 SHOW_STR
11237 BGP_STR
11238 "Address family\n"
11239 "Display routes matching the community-list\n"
11240 "community-list number\n"
11241 "community-list name\n")
11242
11243 /* old command */
11244 DEFUN (show_ipv6_bgp_community_list,
11245 show_ipv6_bgp_community_list_cmd,
11246 "show ipv6 bgp community-list WORD",
11247 SHOW_STR
11248 IPV6_STR
11249 BGP_STR
11250 "Display routes matching the community-list\n"
11251 "community-list name\n")
11252 {
11253 bgp_show_ipv6_bgp_deprecate_warning(vty);
11254 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11255 }
11256
11257 /* old command */
11258 DEFUN (show_ipv6_mbgp_community_list,
11259 show_ipv6_mbgp_community_list_cmd,
11260 "show ipv6 mbgp community-list WORD",
11261 SHOW_STR
11262 IPV6_STR
11263 MBGP_STR
11264 "Display routes matching the community-list\n"
11265 "community-list name\n")
11266 {
11267 bgp_show_ipv6_bgp_deprecate_warning(vty);
11268 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11269 }
11270
11271 DEFUN (show_bgp_community_list_exact,
11272 show_bgp_community_list_exact_cmd,
11273 "show bgp community-list (<1-500>|WORD) exact-match",
11274 SHOW_STR
11275 BGP_STR
11276 "Display routes matching the community-list\n"
11277 "community-list number\n"
11278 "community-list name\n"
11279 "Exact match of the communities\n")
11280 {
11281 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11282 }
11283
11284 ALIAS (show_bgp_community_list_exact,
11285 show_bgp_ipv6_community_list_exact_cmd,
11286 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11287 SHOW_STR
11288 BGP_STR
11289 "Address family\n"
11290 "Display routes matching the community-list\n"
11291 "community-list number\n"
11292 "community-list name\n"
11293 "Exact match of the communities\n")
11294
11295 /* old command */
11296 DEFUN (show_ipv6_bgp_community_list_exact,
11297 show_ipv6_bgp_community_list_exact_cmd,
11298 "show ipv6 bgp community-list WORD exact-match",
11299 SHOW_STR
11300 IPV6_STR
11301 BGP_STR
11302 "Display routes matching the community-list\n"
11303 "community-list name\n"
11304 "Exact match of the communities\n")
11305 {
11306 bgp_show_ipv6_bgp_deprecate_warning(vty);
11307 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11308 }
11309
11310 /* old command */
11311 DEFUN (show_ipv6_mbgp_community_list_exact,
11312 show_ipv6_mbgp_community_list_exact_cmd,
11313 "show ipv6 mbgp community-list WORD exact-match",
11314 SHOW_STR
11315 IPV6_STR
11316 MBGP_STR
11317 "Display routes matching the community-list\n"
11318 "community-list name\n"
11319 "Exact match of the communities\n")
11320 {
11321 bgp_show_ipv6_bgp_deprecate_warning(vty);
11322 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11323 }
11324 #endif /* HAVE_IPV6 */
11325
11326 static int
11327 bgp_show_prefix_longer (struct vty *vty, const char *name,
11328 const char *prefix, afi_t afi,
11329 safi_t safi, enum bgp_show_type type)
11330 {
11331 int ret;
11332 struct prefix *p;
11333 struct bgp *bgp = NULL;
11334
11335 if (name && !(bgp = bgp_lookup_by_name(name)))
11336 {
11337 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11338 return CMD_WARNING;
11339 }
11340
11341 p = prefix_new();
11342
11343 ret = str2prefix (prefix, p);
11344 if (! ret)
11345 {
11346 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11347 return CMD_WARNING;
11348 }
11349
11350 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
11351 prefix_free(p);
11352 return ret;
11353 }
11354
11355 DEFUN (show_ip_bgp_prefix_longer,
11356 show_ip_bgp_prefix_longer_cmd,
11357 "show ip bgp A.B.C.D/M longer-prefixes",
11358 SHOW_STR
11359 IP_STR
11360 BGP_STR
11361 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11362 "Display route and more specific routes\n")
11363 {
11364 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11365 bgp_show_type_prefix_longer);
11366 }
11367
11368 DEFUN (show_ip_bgp_instance_prefix_longer,
11369 show_ip_bgp_instance_prefix_longer_cmd,
11370 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
11371 SHOW_STR
11372 IP_STR
11373 BGP_STR
11374 BGP_INSTANCE_HELP_STR
11375 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11376 "Display route and more specific routes\n")
11377 {
11378 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
11379 bgp_show_type_prefix_longer);
11380 }
11381
11382 DEFUN (show_ip_bgp_flap_prefix_longer,
11383 show_ip_bgp_flap_prefix_longer_cmd,
11384 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11385 SHOW_STR
11386 IP_STR
11387 BGP_STR
11388 "Display flap statistics of routes\n"
11389 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11390 "Display route and more specific routes\n")
11391 {
11392 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11393 bgp_show_type_flap_prefix_longer);
11394 }
11395
11396 ALIAS (show_ip_bgp_flap_prefix_longer,
11397 show_ip_bgp_damp_flap_prefix_longer_cmd,
11398 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
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 "Display route and more specific routes\n")
11406
11407 DEFUN (show_ip_bgp_ipv4_prefix_longer,
11408 show_ip_bgp_ipv4_prefix_longer_cmd,
11409 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11410 SHOW_STR
11411 IP_STR
11412 BGP_STR
11413 "Address family\n"
11414 "Address Family modifier\n"
11415 "Address Family modifier\n"
11416 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11417 "Display route and more specific routes\n")
11418 {
11419 safi_t safi;
11420 safi = bgp_vty_safi_from_arg(argv[0]);
11421 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, safi,
11422 bgp_show_type_prefix_longer);
11423 }
11424
11425 DEFUN (show_ip_bgp_flap_address,
11426 show_ip_bgp_flap_address_cmd,
11427 "show ip bgp flap-statistics A.B.C.D",
11428 SHOW_STR
11429 IP_STR
11430 BGP_STR
11431 "Display flap statistics of routes\n"
11432 "Network in the BGP routing table to display\n")
11433 {
11434 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11435 bgp_show_type_flap_address);
11436 }
11437
11438 ALIAS (show_ip_bgp_flap_address,
11439 show_ip_bgp_damp_flap_address_cmd,
11440 "show ip bgp dampening flap-statistics A.B.C.D",
11441 SHOW_STR
11442 IP_STR
11443 BGP_STR
11444 "Display detailed information about dampening\n"
11445 "Display flap statistics of routes\n"
11446 "Network in the BGP routing table to display\n")
11447
11448 DEFUN (show_ip_bgp_flap_prefix,
11449 show_ip_bgp_flap_prefix_cmd,
11450 "show ip bgp flap-statistics A.B.C.D/M",
11451 SHOW_STR
11452 IP_STR
11453 BGP_STR
11454 "Display flap statistics of routes\n"
11455 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11456 {
11457 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11458 bgp_show_type_flap_prefix);
11459 }
11460
11461 ALIAS (show_ip_bgp_flap_prefix,
11462 show_ip_bgp_damp_flap_prefix_cmd,
11463 "show ip bgp dampening flap-statistics A.B.C.D/M",
11464 SHOW_STR
11465 IP_STR
11466 BGP_STR
11467 "Display detailed information about dampening\n"
11468 "Display flap statistics of routes\n"
11469 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11470
11471 #ifdef HAVE_IPV6
11472 DEFUN (show_bgp_prefix_longer,
11473 show_bgp_prefix_longer_cmd,
11474 "show bgp X:X::X:X/M longer-prefixes",
11475 SHOW_STR
11476 BGP_STR
11477 "IPv6 prefix <network>/<length>\n"
11478 "Display route and more specific routes\n")
11479 {
11480 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11481 bgp_show_type_prefix_longer);
11482 }
11483
11484 ALIAS (show_bgp_prefix_longer,
11485 show_bgp_ipv6_prefix_longer_cmd,
11486 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11487 SHOW_STR
11488 BGP_STR
11489 "Address family\n"
11490 "IPv6 prefix <network>/<length>\n"
11491 "Display route and more specific routes\n")
11492
11493 /* old command */
11494 DEFUN (show_ipv6_bgp_prefix_longer,
11495 show_ipv6_bgp_prefix_longer_cmd,
11496 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11497 SHOW_STR
11498 IPV6_STR
11499 BGP_STR
11500 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11501 "Display route and more specific routes\n")
11502 {
11503 bgp_show_ipv6_bgp_deprecate_warning(vty);
11504 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11505 bgp_show_type_prefix_longer);
11506 }
11507
11508 /* old command */
11509 DEFUN (show_ipv6_mbgp_prefix_longer,
11510 show_ipv6_mbgp_prefix_longer_cmd,
11511 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11512 SHOW_STR
11513 IPV6_STR
11514 MBGP_STR
11515 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11516 "Display route and more specific routes\n")
11517 {
11518 bgp_show_ipv6_bgp_deprecate_warning(vty);
11519 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
11520 bgp_show_type_prefix_longer);
11521 }
11522 #endif /* HAVE_IPV6 */
11523
11524 static struct peer *
11525 peer_lookup_in_view (struct vty *vty, const char *view_name,
11526 const char *ip_str, u_char use_json)
11527 {
11528 int ret;
11529 struct bgp *bgp;
11530 struct peer *peer;
11531 union sockunion su;
11532
11533 /* BGP structure lookup. */
11534 if (view_name)
11535 {
11536 bgp = bgp_lookup_by_name (view_name);
11537 if (! bgp)
11538 {
11539 if (use_json)
11540 {
11541 json_object *json_no = NULL;
11542 json_no = json_object_new_object();
11543 json_object_string_add(json_no, "warning", "Can't find BGP view");
11544 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11545 json_object_free(json_no);
11546 }
11547 else
11548 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
11549 return NULL;
11550 }
11551 }
11552 else
11553 {
11554 bgp = bgp_get_default ();
11555 if (! bgp)
11556 {
11557 if (use_json)
11558 {
11559 json_object *json_no = NULL;
11560 json_no = json_object_new_object();
11561 json_object_string_add(json_no, "warning", "No BGP process configured");
11562 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11563 json_object_free(json_no);
11564 }
11565 else
11566 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11567 return NULL;
11568 }
11569 }
11570
11571 /* Get peer sockunion. */
11572 ret = str2sockunion (ip_str, &su);
11573 if (ret < 0)
11574 {
11575 peer = peer_lookup_by_conf_if (bgp, ip_str);
11576 if (!peer)
11577 {
11578 peer = peer_lookup_by_hostname(bgp, ip_str);
11579
11580 if (!peer)
11581 {
11582 if (use_json)
11583 {
11584 json_object *json_no = NULL;
11585 json_no = json_object_new_object();
11586 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11587 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11588 json_object_free(json_no);
11589 }
11590 else
11591 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11592 return NULL;
11593 }
11594 }
11595 return peer;
11596 }
11597
11598 /* Peer structure lookup. */
11599 peer = peer_lookup (bgp, &su);
11600 if (! peer)
11601 {
11602 if (use_json)
11603 {
11604 json_object *json_no = NULL;
11605 json_no = json_object_new_object();
11606 json_object_string_add(json_no, "warning","No such neighbor");
11607 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11608 json_object_free(json_no);
11609 }
11610 else
11611 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11612 return NULL;
11613 }
11614
11615 return peer;
11616 }
11617
11618 enum bgp_stats
11619 {
11620 BGP_STATS_MAXBITLEN = 0,
11621 BGP_STATS_RIB,
11622 BGP_STATS_PREFIXES,
11623 BGP_STATS_TOTPLEN,
11624 BGP_STATS_UNAGGREGATEABLE,
11625 BGP_STATS_MAX_AGGREGATEABLE,
11626 BGP_STATS_AGGREGATES,
11627 BGP_STATS_SPACE,
11628 BGP_STATS_ASPATH_COUNT,
11629 BGP_STATS_ASPATH_MAXHOPS,
11630 BGP_STATS_ASPATH_TOTHOPS,
11631 BGP_STATS_ASPATH_MAXSIZE,
11632 BGP_STATS_ASPATH_TOTSIZE,
11633 BGP_STATS_ASN_HIGHEST,
11634 BGP_STATS_MAX,
11635 };
11636
11637 static const char *table_stats_strs[] =
11638 {
11639 [BGP_STATS_PREFIXES] = "Total Prefixes",
11640 [BGP_STATS_TOTPLEN] = "Average prefix length",
11641 [BGP_STATS_RIB] = "Total Advertisements",
11642 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11643 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11644 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11645 [BGP_STATS_SPACE] = "Address space advertised",
11646 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11647 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11648 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11649 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11650 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11651 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11652 [BGP_STATS_MAX] = NULL,
11653 };
11654
11655 struct bgp_table_stats
11656 {
11657 struct bgp_table *table;
11658 unsigned long long counts[BGP_STATS_MAX];
11659 };
11660
11661 #if 0
11662 #define TALLY_SIGFIG 100000
11663 static unsigned long
11664 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11665 {
11666 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11667 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11668 unsigned long ret = newtot / count;
11669
11670 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11671 return ret + 1;
11672 else
11673 return ret;
11674 }
11675 #endif
11676
11677 static int
11678 bgp_table_stats_walker (struct thread *t)
11679 {
11680 struct bgp_node *rn;
11681 struct bgp_node *top;
11682 struct bgp_table_stats *ts = THREAD_ARG (t);
11683 unsigned int space = 0;
11684
11685 if (!(top = bgp_table_top (ts->table)))
11686 return 0;
11687
11688 switch (top->p.family)
11689 {
11690 case AF_INET:
11691 space = IPV4_MAX_BITLEN;
11692 break;
11693 case AF_INET6:
11694 space = IPV6_MAX_BITLEN;
11695 break;
11696 }
11697
11698 ts->counts[BGP_STATS_MAXBITLEN] = space;
11699
11700 for (rn = top; rn; rn = bgp_route_next (rn))
11701 {
11702 struct bgp_info *ri;
11703 struct bgp_node *prn = bgp_node_parent_nolock (rn);
11704 unsigned int rinum = 0;
11705
11706 if (rn == top)
11707 continue;
11708
11709 if (!rn->info)
11710 continue;
11711
11712 ts->counts[BGP_STATS_PREFIXES]++;
11713 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11714
11715 #if 0
11716 ts->counts[BGP_STATS_AVGPLEN]
11717 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11718 ts->counts[BGP_STATS_AVGPLEN],
11719 rn->p.prefixlen);
11720 #endif
11721
11722 /* check if the prefix is included by any other announcements */
11723 while (prn && !prn->info)
11724 prn = bgp_node_parent_nolock (prn);
11725
11726 if (prn == NULL || prn == top)
11727 {
11728 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11729 /* announced address space */
11730 if (space)
11731 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11732 }
11733 else if (prn->info)
11734 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11735
11736 for (ri = rn->info; ri; ri = ri->next)
11737 {
11738 rinum++;
11739 ts->counts[BGP_STATS_RIB]++;
11740
11741 if (ri->attr &&
11742 (CHECK_FLAG (ri->attr->flag,
11743 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11744 ts->counts[BGP_STATS_AGGREGATES]++;
11745
11746 /* as-path stats */
11747 if (ri->attr && ri->attr->aspath)
11748 {
11749 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11750 unsigned int size = aspath_size (ri->attr->aspath);
11751 as_t highest = aspath_highest (ri->attr->aspath);
11752
11753 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11754
11755 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11756 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11757
11758 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11759 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11760
11761 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11762 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11763 #if 0
11764 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11765 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11766 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11767 hops);
11768 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11769 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11770 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11771 size);
11772 #endif
11773 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11774 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11775 }
11776 }
11777 }
11778 return 0;
11779 }
11780
11781 static int
11782 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11783 {
11784 struct bgp_table_stats ts;
11785 unsigned int i;
11786
11787 if (!bgp->rib[afi][safi])
11788 {
11789 vty_out (vty, "%% No RIB exists for the AFI(%d)/SAFI(%d)%s",
11790 afi, safi, VTY_NEWLINE);
11791 return CMD_WARNING;
11792 }
11793
11794 memset (&ts, 0, sizeof (ts));
11795 ts.table = bgp->rib[afi][safi];
11796 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11797
11798 vty_out (vty, "BGP %s RIB statistics%s%s",
11799 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11800
11801 for (i = 0; i < BGP_STATS_MAX; i++)
11802 {
11803 if (!table_stats_strs[i])
11804 continue;
11805
11806 switch (i)
11807 {
11808 #if 0
11809 case BGP_STATS_ASPATH_AVGHOPS:
11810 case BGP_STATS_ASPATH_AVGSIZE:
11811 case BGP_STATS_AVGPLEN:
11812 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11813 vty_out (vty, "%12.2f",
11814 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11815 break;
11816 #endif
11817 case BGP_STATS_ASPATH_TOTHOPS:
11818 case BGP_STATS_ASPATH_TOTSIZE:
11819 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11820 vty_out (vty, "%12.2f",
11821 ts.counts[i] ?
11822 (float)ts.counts[i] /
11823 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11824 : 0);
11825 break;
11826 case BGP_STATS_TOTPLEN:
11827 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11828 vty_out (vty, "%12.2f",
11829 ts.counts[i] ?
11830 (float)ts.counts[i] /
11831 (float)ts.counts[BGP_STATS_PREFIXES]
11832 : 0);
11833 break;
11834 case BGP_STATS_SPACE:
11835 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11836 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11837 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11838 break;
11839 vty_out (vty, "%30s: ", "%% announced ");
11840 vty_out (vty, "%12.2f%s",
11841 100 * (float)ts.counts[BGP_STATS_SPACE] /
11842 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
11843 VTY_NEWLINE);
11844 vty_out (vty, "%30s: ", "/8 equivalent ");
11845 vty_out (vty, "%12.2f%s",
11846 (float)ts.counts[BGP_STATS_SPACE] /
11847 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11848 VTY_NEWLINE);
11849 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11850 break;
11851 vty_out (vty, "%30s: ", "/24 equivalent ");
11852 vty_out (vty, "%12.2f",
11853 (float)ts.counts[BGP_STATS_SPACE] /
11854 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11855 break;
11856 default:
11857 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11858 vty_out (vty, "%12llu", ts.counts[i]);
11859 }
11860
11861 vty_out (vty, "%s", VTY_NEWLINE);
11862 }
11863 return CMD_SUCCESS;
11864 }
11865
11866 static int
11867 bgp_table_stats_vty (struct vty *vty, const char *name,
11868 const char *afi_str, const char *safi_str)
11869 {
11870 struct bgp *bgp;
11871 afi_t afi;
11872 safi_t safi;
11873
11874 if (name)
11875 bgp = bgp_lookup_by_name (name);
11876 else
11877 bgp = bgp_get_default ();
11878
11879 if (!bgp)
11880 {
11881 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11882 return CMD_WARNING;
11883 }
11884 afi = bgp_vty_afi_from_arg(afi_str);
11885 if (afi == AFI_MAX)
11886 {
11887 vty_out (vty, "%% Invalid address family \"%s\"%s",
11888 afi_str, VTY_NEWLINE);
11889 return CMD_WARNING;
11890 }
11891 safi = bgp_vty_safi_from_arg(safi_str);
11892 if (safi == SAFI_MAX)
11893 {
11894 vty_out (vty, "%% Invalid subsequent address family %s%s",
11895 safi_str, VTY_NEWLINE);
11896 return CMD_WARNING;
11897 }
11898
11899 return bgp_table_stats (vty, bgp, afi, safi);
11900 }
11901
11902 DEFUN (show_bgp_statistics,
11903 show_bgp_statistics_cmd,
11904 "show bgp "BGP_AFI_SAFI_CMD_STR" statistics",
11905 SHOW_STR
11906 BGP_STR
11907 BGP_AFI_SAFI_HELP_STR
11908 "BGP RIB advertisement statistics\n")
11909 {
11910 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11911 }
11912
11913 DEFUN (show_bgp_statistics_view,
11914 show_bgp_statistics_view_cmd,
11915 "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" statistics",
11916 SHOW_STR
11917 BGP_STR
11918 BGP_INSTANCE_HELP_STR
11919 BGP_AFI_SAFI_HELP_STR
11920 "BGP RIB advertisement statistics\n")
11921 {
11922 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
11923 }
11924
11925 enum bgp_pcounts
11926 {
11927 PCOUNT_ADJ_IN = 0,
11928 PCOUNT_DAMPED,
11929 PCOUNT_REMOVED,
11930 PCOUNT_HISTORY,
11931 PCOUNT_STALE,
11932 PCOUNT_VALID,
11933 PCOUNT_ALL,
11934 PCOUNT_COUNTED,
11935 PCOUNT_PFCNT, /* the figure we display to users */
11936 PCOUNT_MAX,
11937 };
11938
11939 static const char *pcount_strs[] =
11940 {
11941 [PCOUNT_ADJ_IN] = "Adj-in",
11942 [PCOUNT_DAMPED] = "Damped",
11943 [PCOUNT_REMOVED] = "Removed",
11944 [PCOUNT_HISTORY] = "History",
11945 [PCOUNT_STALE] = "Stale",
11946 [PCOUNT_VALID] = "Valid",
11947 [PCOUNT_ALL] = "All RIB",
11948 [PCOUNT_COUNTED] = "PfxCt counted",
11949 [PCOUNT_PFCNT] = "Useable",
11950 [PCOUNT_MAX] = NULL,
11951 };
11952
11953 struct peer_pcounts
11954 {
11955 unsigned int count[PCOUNT_MAX];
11956 const struct peer *peer;
11957 const struct bgp_table *table;
11958 };
11959
11960 static int
11961 bgp_peer_count_walker (struct thread *t)
11962 {
11963 struct bgp_node *rn;
11964 struct peer_pcounts *pc = THREAD_ARG (t);
11965 const struct peer *peer = pc->peer;
11966
11967 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
11968 {
11969 struct bgp_adj_in *ain;
11970 struct bgp_info *ri;
11971
11972 for (ain = rn->adj_in; ain; ain = ain->next)
11973 if (ain->peer == peer)
11974 pc->count[PCOUNT_ADJ_IN]++;
11975
11976 for (ri = rn->info; ri; ri = ri->next)
11977 {
11978 char buf[SU_ADDRSTRLEN];
11979
11980 if (ri->peer != peer)
11981 continue;
11982
11983 pc->count[PCOUNT_ALL]++;
11984
11985 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
11986 pc->count[PCOUNT_DAMPED]++;
11987 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
11988 pc->count[PCOUNT_HISTORY]++;
11989 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
11990 pc->count[PCOUNT_REMOVED]++;
11991 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
11992 pc->count[PCOUNT_STALE]++;
11993 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
11994 pc->count[PCOUNT_VALID]++;
11995 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
11996 pc->count[PCOUNT_PFCNT]++;
11997
11998 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
11999 {
12000 pc->count[PCOUNT_COUNTED]++;
12001 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12002 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
12003 peer->host,
12004 inet_ntop(rn->p.family, &rn->p.u.prefix,
12005 buf, SU_ADDRSTRLEN),
12006 rn->p.prefixlen,
12007 ri->flags);
12008 }
12009 else
12010 {
12011 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12012 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
12013 peer->host,
12014 inet_ntop(rn->p.family, &rn->p.u.prefix,
12015 buf, SU_ADDRSTRLEN),
12016 rn->p.prefixlen,
12017 ri->flags);
12018 }
12019 }
12020 }
12021 return 0;
12022 }
12023
12024 static int
12025 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
12026 {
12027 struct peer_pcounts pcounts = { .peer = peer };
12028 unsigned int i;
12029 json_object *json = NULL;
12030 json_object *json_loop = NULL;
12031
12032 if (use_json)
12033 {
12034 json = json_object_new_object();
12035 json_loop = json_object_new_object();
12036 }
12037
12038 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12039 || !peer->bgp->rib[afi][safi])
12040 {
12041 if (use_json)
12042 {
12043 json_object_string_add(json, "warning", "No such neighbor or address family");
12044 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12045 json_object_free(json);
12046 }
12047 else
12048 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12049
12050 return CMD_WARNING;
12051 }
12052
12053 memset (&pcounts, 0, sizeof(pcounts));
12054 pcounts.peer = peer;
12055 pcounts.table = peer->bgp->rib[afi][safi];
12056
12057 /* in-place call via thread subsystem so as to record execution time
12058 * * stats for the thread-walk (i.e. ensure this can't be blamed on
12059 * * on just vty_read()).
12060 * */
12061 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12062
12063 if (use_json)
12064 {
12065 json_object_string_add(json, "prefixCountsFor", peer->host);
12066 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
12067 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
12068
12069 for (i = 0; i < PCOUNT_MAX; i++)
12070 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
12071
12072 json_object_object_add(json, "ribTableWalkCounters", json_loop);
12073
12074 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12075 {
12076 json_object_string_add(json, "pfxctDriftFor", peer->host);
12077 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
12078 }
12079 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12080 json_object_free(json);
12081 }
12082 else
12083 {
12084
12085 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
12086 {
12087 vty_out (vty, "Prefix counts for %s/%s, %s%s",
12088 peer->hostname, peer->host, afi_safi_print (afi, safi),
12089 VTY_NEWLINE);
12090 }
12091 else
12092 {
12093 vty_out (vty, "Prefix counts for %s, %s%s",
12094 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12095 }
12096
12097 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12098 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12099 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12100
12101 for (i = 0; i < PCOUNT_MAX; i++)
12102 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
12103
12104 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12105 {
12106 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12107 peer->host, VTY_NEWLINE);
12108 vty_out (vty, "Please report this bug, with the above command output%s",
12109 VTY_NEWLINE);
12110 }
12111 }
12112
12113 return CMD_SUCCESS;
12114 }
12115
12116 DEFUN (show_ip_bgp_neighbor_prefix_counts,
12117 show_ip_bgp_neighbor_prefix_counts_cmd,
12118 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12119 SHOW_STR
12120 IP_STR
12121 BGP_STR
12122 "Detailed information on TCP and BGP neighbor connections\n"
12123 "Neighbor to display information about\n"
12124 "Neighbor to display information about\n"
12125 "Neighbor on bgp configured interface\n"
12126 "Display detailed prefix count information\n"
12127 "JavaScript Object Notation\n")
12128 {
12129 struct peer *peer;
12130 u_char uj = use_json(argc, argv);
12131
12132 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12133 if (! peer)
12134 return CMD_WARNING;
12135
12136 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12137 }
12138
12139 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
12140 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
12141 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12142 SHOW_STR
12143 IP_STR
12144 BGP_STR
12145 BGP_INSTANCE_HELP_STR
12146 "Detailed information on TCP and BGP neighbor connections\n"
12147 "Neighbor to display information about\n"
12148 "Neighbor to display information about\n"
12149 "Neighbor on bgp configured interface\n"
12150 "Display detailed prefix count information\n"
12151 "JavaScript Object Notation\n")
12152 {
12153 struct peer *peer;
12154 u_char uj = use_json(argc, argv);
12155
12156 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12157 if (! peer)
12158 return CMD_WARNING;
12159
12160 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12161 }
12162
12163 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12164 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12165 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12166 SHOW_STR
12167 BGP_STR
12168 "Address family\n"
12169 "Detailed information on TCP and BGP neighbor connections\n"
12170 "Neighbor to display information about\n"
12171 "Neighbor to display information about\n"
12172 "Neighbor on bgp configured interface\n"
12173 "Display detailed prefix count information\n"
12174 "JavaScript Object Notation\n")
12175 {
12176 struct peer *peer;
12177 u_char uj = use_json(argc, argv);
12178
12179 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12180 if (! peer)
12181 return CMD_WARNING;
12182
12183 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12184 }
12185
12186 DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
12187 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
12188 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12189 SHOW_STR
12190 BGP_STR
12191 BGP_INSTANCE_HELP_STR
12192 "Address family\n"
12193 "Detailed information on TCP and BGP neighbor connections\n"
12194 "Neighbor to display information about\n"
12195 "Neighbor to display information about\n"
12196 "Neighbor on bgp configured interface\n"
12197 "Display detailed prefix count information\n"
12198 "JavaScript Object Notation\n")
12199 {
12200 struct peer *peer;
12201 u_char uj = use_json(argc, argv);
12202
12203 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12204 if (! peer)
12205 return CMD_WARNING;
12206
12207 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12208 }
12209
12210 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12211 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12212 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12213 SHOW_STR
12214 IP_STR
12215 BGP_STR
12216 "Address family\n"
12217 "Address Family modifier\n"
12218 "Address Family modifier\n"
12219 "Detailed information on TCP and BGP neighbor connections\n"
12220 "Neighbor to display information about\n"
12221 "Neighbor to display information about\n"
12222 "Neighbor on bgp configured interface\n"
12223 "Display detailed prefix count information\n"
12224 "JavaScript Object Notation\n")
12225 {
12226 struct peer *peer;
12227 u_char uj = use_json(argc, argv);
12228
12229 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12230 if (! peer)
12231 return CMD_WARNING;
12232
12233 safi_t safi;
12234 safi = bgp_vty_safi_from_arg(argv[0]);
12235 return bgp_peer_counts (vty, peer, AFI_IP, safi, uj);
12236 }
12237
12238 static void
12239 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12240 int in, const char *rmap_name, u_char use_json, json_object *json)
12241 {
12242 struct bgp_table *table;
12243 struct bgp_adj_in *ain;
12244 struct bgp_adj_out *adj;
12245 unsigned long output_count;
12246 unsigned long filtered_count;
12247 struct bgp_node *rn;
12248 int header1 = 1;
12249 struct bgp *bgp;
12250 int header2 = 1;
12251 struct attr attr;
12252 struct attr_extra extra;
12253 int ret;
12254 struct update_subgroup *subgrp;
12255 json_object *json_scode = NULL;
12256 json_object *json_ocode = NULL;
12257 json_object *json_ar = NULL;
12258 struct peer_af *paf;
12259
12260 if (use_json)
12261 {
12262 json_scode = json_object_new_object();
12263 json_ocode = json_object_new_object();
12264 json_ar = json_object_new_object();
12265
12266 json_object_string_add(json_scode, "suppressed", "s");
12267 json_object_string_add(json_scode, "damped", "d");
12268 json_object_string_add(json_scode, "history", "h");
12269 json_object_string_add(json_scode, "valid", "*");
12270 json_object_string_add(json_scode, "best", ">");
12271 json_object_string_add(json_scode, "multipath", "=");
12272 json_object_string_add(json_scode, "internal", "i");
12273 json_object_string_add(json_scode, "ribFailure", "r");
12274 json_object_string_add(json_scode, "stale", "S");
12275 json_object_string_add(json_scode, "removed", "R");
12276
12277 json_object_string_add(json_ocode, "igp", "i");
12278 json_object_string_add(json_ocode, "egp", "e");
12279 json_object_string_add(json_ocode, "incomplete", "?");
12280 }
12281
12282 bgp = peer->bgp;
12283
12284 if (! bgp)
12285 {
12286 if (use_json)
12287 {
12288 json_object_string_add(json, "alert", "no BGP");
12289 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12290 json_object_free(json);
12291 }
12292 else
12293 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
12294 return;
12295 }
12296
12297 table = bgp->rib[afi][safi];
12298
12299 output_count = filtered_count = 0;
12300 subgrp = peer_subgroup(peer, afi, safi);
12301
12302 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
12303 {
12304 if (use_json)
12305 {
12306 json_object_int_add(json, "bgpTableVersion", table->version);
12307 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12308 json_object_object_add(json, "bgpStatusCodes", json_scode);
12309 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12310 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
12311 }
12312 else
12313 {
12314 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
12315 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12316 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12317
12318 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12319 VTY_NEWLINE, VTY_NEWLINE);
12320 }
12321 header1 = 0;
12322 }
12323
12324 attr.extra = &extra;
12325 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12326 {
12327 if (in)
12328 {
12329 for (ain = rn->adj_in; ain; ain = ain->next)
12330 {
12331 if (ain->peer == peer)
12332 {
12333 if (header1)
12334 {
12335 if (use_json)
12336 {
12337 json_object_int_add(json, "bgpTableVersion", 0);
12338 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12339 json_object_object_add(json, "bgpStatusCodes", json_scode);
12340 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12341 }
12342 else
12343 {
12344 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12345 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12346 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12347 }
12348 header1 = 0;
12349 }
12350 if (header2)
12351 {
12352 if (!use_json)
12353 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12354 header2 = 0;
12355 }
12356 if (ain->attr)
12357 {
12358 bgp_attr_dup(&attr, ain->attr);
12359 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12360 {
12361 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12362 output_count++;
12363 }
12364 else
12365 filtered_count++;
12366 }
12367 }
12368 }
12369 }
12370 else
12371 {
12372 for (adj = rn->adj_out; adj; adj = adj->next)
12373 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12374 if (paf->peer == peer)
12375 {
12376 if (header1)
12377 {
12378 if (use_json)
12379 {
12380 json_object_int_add(json, "bgpTableVersion", table->version);
12381 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12382 json_object_object_add(json, "bgpStatusCodes", json_scode);
12383 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12384 }
12385 else
12386 {
12387 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12388 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12389 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12390 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12391 }
12392 header1 = 0;
12393 }
12394
12395 if (header2)
12396 {
12397 if (!use_json)
12398 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12399 header2 = 0;
12400 }
12401
12402 if (adj->attr)
12403 {
12404 bgp_attr_dup(&attr, adj->attr);
12405 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12406 if (ret != RMAP_DENY)
12407 {
12408 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12409 output_count++;
12410 }
12411 else
12412 filtered_count++;
12413 }
12414 }
12415 }
12416 }
12417 if (use_json)
12418 json_object_object_add(json, "advertisedRoutes", json_ar);
12419
12420 if (output_count != 0)
12421 {
12422 if (use_json)
12423 json_object_int_add(json, "totalPrefixCounter", output_count);
12424 else
12425 vty_out (vty, "%sTotal number of prefixes %ld%s",
12426 VTY_NEWLINE, output_count, VTY_NEWLINE);
12427 }
12428 if (use_json)
12429 {
12430 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12431 json_object_free(json);
12432 }
12433
12434 }
12435
12436 static int
12437 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12438 int in, const char *rmap_name, u_char use_json)
12439 {
12440 json_object *json = NULL;
12441
12442 if (use_json)
12443 json = json_object_new_object();
12444
12445 if (!peer || !peer->afc[afi][safi])
12446 {
12447 if (use_json)
12448 {
12449 json_object_string_add(json, "warning", "No such neighbor or address family");
12450 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12451 json_object_free(json);
12452 }
12453 else
12454 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12455
12456 return CMD_WARNING;
12457 }
12458
12459 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12460 {
12461 if (use_json)
12462 {
12463 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12464 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12465 json_object_free(json);
12466 }
12467 else
12468 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12469
12470 return CMD_WARNING;
12471 }
12472
12473 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
12474
12475 return CMD_SUCCESS;
12476 }
12477
12478 DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12479 show_ip_bgp_instance_neighbor_advertised_route_cmd,
12480 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12481 SHOW_STR
12482 IP_STR
12483 BGP_STR
12484 BGP_INSTANCE_HELP_STR
12485 "Detailed information on TCP and BGP neighbor connections\n"
12486 "Neighbor to display information about\n"
12487 "Neighbor to display information about\n"
12488 "Display the routes advertised to a BGP neighbor\n"
12489 "JavaScript Object Notation\n")
12490 {
12491 struct peer *peer;
12492 u_char uj = use_json(argc, argv);
12493
12494 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12495 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12496 else
12497 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12498
12499 if (! peer)
12500 return CMD_WARNING;
12501
12502 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
12503 }
12504
12505 DEFUN (show_ip_bgp_neighbor_advertised_route,
12506 show_ip_bgp_neighbor_advertised_route_cmd,
12507 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12508 SHOW_STR
12509 IP_STR
12510 BGP_STR
12511 "Detailed information on TCP and BGP neighbor connections\n"
12512 "Neighbor to display information about\n"
12513 "Neighbor to display information about\n"
12514 "Neighbor on bgp configured interface\n"
12515 "Display the routes advertised to a BGP neighbor\n"
12516 "JavaScript Object Notation\n")
12517
12518 {
12519 struct peer *peer;
12520 const char *rmap_name = NULL;
12521 u_char uj = use_json(argc, argv);
12522
12523 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12524
12525 if (! peer)
12526 return CMD_WARNING;
12527
12528 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12529 || (argc == 3))
12530 rmap_name = argv[1];
12531
12532 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12533 }
12534
12535 ALIAS (show_ip_bgp_neighbor_advertised_route,
12536 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
12537 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12538 SHOW_STR
12539 IP_STR
12540 BGP_STR
12541 "Detailed information on TCP and BGP neighbor connections\n"
12542 "Neighbor to display information about\n"
12543 "Neighbor to display information about\n"
12544 "Neighbor on bgp configured interface\n"
12545 "Display the routes advertised to a BGP neighbor\n"
12546 "JavaScript Object Notation\n")
12547
12548 ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12549 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12550 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12551 SHOW_STR
12552 IP_STR
12553 BGP_STR
12554 BGP_INSTANCE_HELP_STR
12555 "Detailed information on TCP and BGP neighbor connections\n"
12556 "Neighbor to display information about\n"
12557 "Neighbor to display information about\n"
12558 "Neighbor on bgp configured interface\n"
12559 "Display the routes advertised to a BGP neighbor\n"
12560 "JavaScript Object Notation\n")
12561 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12562 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12563 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12564 SHOW_STR
12565 IP_STR
12566 BGP_STR
12567 "Address family\n"
12568 "Address Family modifier\n"
12569 "Address Family modifier\n"
12570 "Detailed information on TCP and BGP neighbor connections\n"
12571 "Neighbor to display information about\n"
12572 "Neighbor to display information about\n"
12573 "Neighbor on bgp configured interface\n"
12574 "Display the routes advertised to a BGP neighbor\n"
12575 "JavaScript Object Notation\n")
12576 {
12577 struct peer *peer;
12578 const char *rmap_name = NULL;
12579 safi_t safi;
12580
12581 u_char uj = use_json(argc, argv);
12582
12583 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12584 if (! peer)
12585 return CMD_WARNING;
12586
12587 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12588 rmap_name = argv[2];
12589
12590 safi = bgp_vty_safi_from_arg(argv[0]);
12591 return peer_adj_routes (vty, peer, AFI_IP, safi, 0, rmap_name, uj);
12592 }
12593
12594 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12595 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
12596 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12597 SHOW_STR
12598 IP_STR
12599 BGP_STR
12600 "Address family\n"
12601 "Address Family modifier\n"
12602 "Address Family modifier\n"
12603 "Detailed information on TCP and BGP neighbor connections\n"
12604 "Neighbor to display information about\n"
12605 "Neighbor to display information about\n"
12606 "Neighbor on bgp configured interface\n"
12607 "Display the routes advertised to a BGP neighbor\n"
12608 "Route-map to control what is displayed\n"
12609 "JavaScript Object Notation\n")
12610
12611 #ifdef HAVE_IPV6
12612 DEFUN (show_bgp_instance_neighbor_advertised_route,
12613 show_bgp_instance_neighbor_advertised_route_cmd,
12614 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12615 SHOW_STR
12616 BGP_STR
12617 BGP_INSTANCE_HELP_STR
12618 "Detailed information on TCP and BGP neighbor connections\n"
12619 "Neighbor to display information about\n"
12620 "Neighbor to display information about\n"
12621 "Neighbor on bgp configured interface\n"
12622 "Display the routes advertised to a BGP neighbor\n"
12623 "JavaScript Object Notation\n")
12624 {
12625 struct peer *peer;
12626 u_char uj = use_json(argc, argv);
12627
12628 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12629 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12630 else
12631 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12632
12633 if (! peer)
12634 return CMD_WARNING;
12635
12636 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
12637 }
12638
12639 ALIAS (show_bgp_instance_neighbor_advertised_route,
12640 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12641 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12642 SHOW_STR
12643 BGP_STR
12644 BGP_INSTANCE_HELP_STR
12645 "Address family\n"
12646 "Detailed information on TCP and BGP neighbor connections\n"
12647 "Neighbor to display information about\n"
12648 "Neighbor to display information about\n"
12649 "Neighbor on bgp configured interface\n"
12650 "Display the routes advertised to a BGP neighbor\n"
12651 "JavaScript Object Notation\n")
12652
12653 DEFUN (show_bgp_neighbor_advertised_route,
12654 show_bgp_neighbor_advertised_route_cmd,
12655 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12656 SHOW_STR
12657 BGP_STR
12658 "Detailed information on TCP and BGP neighbor connections\n"
12659 "Neighbor to display information about\n"
12660 "Neighbor to display information about\n"
12661 "Neighbor on bgp configured interface\n"
12662 "Display the routes advertised to a BGP neighbor\n"
12663 "JavaScript Object Notation\n")
12664
12665 {
12666 struct peer *peer;
12667 const char *rmap_name = NULL;
12668 u_char uj = use_json(argc, argv);
12669
12670 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12671
12672 if (!peer)
12673 return CMD_WARNING;
12674
12675 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12676 rmap_name = argv[1];
12677
12678 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
12679 }
12680
12681 ALIAS (show_bgp_neighbor_advertised_route,
12682 show_bgp_ipv6_neighbor_advertised_route_cmd,
12683 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12684 SHOW_STR
12685 BGP_STR
12686 "Address family\n"
12687 "Detailed information on TCP and BGP neighbor connections\n"
12688 "Neighbor to display information about\n"
12689 "Neighbor to display information about\n"
12690 "Neighbor on bgp configured interface\n"
12691 "Display the routes advertised to a BGP neighbor\n"
12692 "JavaScript Object Notation\n")
12693
12694 /* old command */
12695 ALIAS (show_bgp_neighbor_advertised_route,
12696 ipv6_bgp_neighbor_advertised_route_cmd,
12697 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12698 SHOW_STR
12699 IPV6_STR
12700 BGP_STR
12701 "Detailed information on TCP and BGP neighbor connections\n"
12702 "Neighbor to display information about\n"
12703 "Neighbor to display information about\n"
12704 "Neighbor on bgp configured interface\n"
12705 "Display the routes advertised to a BGP neighbor\n"
12706 "JavaScript Object Notation\n")
12707
12708 /* old command */
12709 DEFUN (ipv6_mbgp_neighbor_advertised_route,
12710 ipv6_mbgp_neighbor_advertised_route_cmd,
12711 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12712 SHOW_STR
12713 IPV6_STR
12714 MBGP_STR
12715 "Detailed information on TCP and BGP neighbor connections\n"
12716 "Neighbor to display information about\n"
12717 "Neighbor to display information about\n"
12718 "Neighbor on bgp configured interface\n"
12719 "Neighbor on bgp configured interface\n"
12720 "Display the routes advertised to a BGP neighbor\n"
12721 "JavaScript Object Notation\n")
12722 {
12723 struct peer *peer;
12724 u_char uj = use_json(argc, argv);
12725
12726 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12727 if (! peer)
12728 return CMD_WARNING;
12729
12730 bgp_show_ipv6_bgp_deprecate_warning(vty);
12731 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
12732 }
12733 #endif /* HAVE_IPV6 */
12734
12735 DEFUN (show_bgp_instance_neighbor_received_routes,
12736 show_bgp_instance_neighbor_received_routes_cmd,
12737 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12738 SHOW_STR
12739 BGP_STR
12740 BGP_INSTANCE_HELP_STR
12741 "Detailed information on TCP and BGP neighbor connections\n"
12742 "Neighbor to display information about\n"
12743 "Neighbor to display information about\n"
12744 "Neighbor on bgp configured interface\n"
12745 "Display the received routes from neighbor\n"
12746 "JavaScript Object Notation\n")
12747 {
12748 struct peer *peer;
12749 u_char uj = use_json(argc, argv);
12750
12751 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12752 if (! peer)
12753 return CMD_WARNING;
12754
12755 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
12756 }
12757
12758 DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12759 show_ip_bgp_instance_neighbor_received_routes_cmd,
12760 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12761 SHOW_STR
12762 IP_STR
12763 BGP_STR
12764 BGP_INSTANCE_HELP_STR
12765 "Detailed information on TCP and BGP neighbor connections\n"
12766 "Neighbor to display information about\n"
12767 "Neighbor to display information about\n"
12768 "Neighbor on bgp configured interface\n"
12769 "Display the received routes from neighbor\n"
12770 "JavaScript Object Notation\n")
12771 {
12772 struct peer *peer;
12773 u_char uj = use_json(argc, argv);
12774
12775 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12776 if (! peer)
12777 return CMD_WARNING;
12778
12779 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
12780 }
12781
12782 ALIAS (show_bgp_instance_neighbor_received_routes,
12783 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12784 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12785 SHOW_STR
12786 BGP_STR
12787 BGP_INSTANCE_HELP_STR
12788 "Address family\n"
12789 "Detailed information on TCP and BGP neighbor connections\n"
12790 "Neighbor to display information about\n"
12791 "Neighbor to display information about\n"
12792 "Neighbor on bgp configured interface\n"
12793 "Display the received routes from neighbor\n"
12794 "JavaScript Object Notation\n")
12795
12796 DEFUN (show_ip_bgp_neighbor_received_routes,
12797 show_ip_bgp_neighbor_received_routes_cmd,
12798 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12799 SHOW_STR
12800 IP_STR
12801 BGP_STR
12802 "Detailed information on TCP and BGP neighbor connections\n"
12803 "Neighbor to display information about\n"
12804 "Neighbor to display information about\n"
12805 "Neighbor on bgp configured interface\n"
12806 "Display the received routes from neighbor\n"
12807 "JavaScript Object Notation\n")
12808
12809 {
12810 struct peer *peer;
12811 const char *rmap_name = NULL;
12812 u_char uj = use_json(argc, argv);
12813
12814 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12815
12816 if (! peer)
12817 return CMD_WARNING;
12818
12819 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12820 rmap_name = argv[1];
12821
12822 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12823 }
12824
12825 ALIAS (show_ip_bgp_neighbor_received_routes,
12826 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12827 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12828 SHOW_STR
12829 IP_STR
12830 BGP_STR
12831 "Detailed information on TCP and BGP neighbor connections\n"
12832 "Neighbor to display information about\n"
12833 "Neighbor to display information about\n"
12834 "Neighbor on bgp configured interface\n"
12835 "Display the received routes from neighbor\n"
12836 "JavaScript Object Notation\n")
12837
12838 ALIAS (show_ip_bgp_instance_neighbor_received_routes,
12839 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
12840 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12841 SHOW_STR
12842 IP_STR
12843 BGP_STR
12844 BGP_INSTANCE_HELP_STR
12845 "Detailed information on TCP and BGP neighbor connections\n"
12846 "Neighbor to display information about\n"
12847 "Neighbor to display information about\n"
12848 "Neighbor on bgp configured interface\n"
12849 "Display the received routes from neighbor\n"
12850 "JavaScript Object Notation\n")
12851
12852 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12853 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12854 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12855 SHOW_STR
12856 IP_STR
12857 BGP_STR
12858 "Address family\n"
12859 "Address Family modifier\n"
12860 "Address Family modifier\n"
12861 "Detailed information on TCP and BGP neighbor connections\n"
12862 "Neighbor to display information about\n"
12863 "Neighbor to display information about\n"
12864 "Neighbor on bgp configured interface\n"
12865 "Display the received routes from neighbor\n"
12866 "JavaScript Object Notation\n")
12867 {
12868 struct peer *peer;
12869 const char *rmap_name = NULL;
12870 safi_t safi;
12871 u_char uj = use_json(argc, argv);
12872
12873 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12874 if (! peer)
12875 return CMD_WARNING;
12876
12877 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12878 rmap_name = argv[2];
12879
12880 safi = bgp_vty_safi_from_arg(argv[0]);
12881 return peer_adj_routes (vty, peer, AFI_IP, safi, 1, rmap_name, uj);
12882 }
12883
12884 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12885 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
12886 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12887 SHOW_STR
12888 IP_STR
12889 BGP_STR
12890 "Address family\n"
12891 "Address Family modifier\n"
12892 "Address Family modifier\n"
12893 "Detailed information on TCP and BGP neighbor connections\n"
12894 "Neighbor to display information about\n"
12895 "Neighbor to display information about\n"
12896 "Neighbor on bgp configured interface\n"
12897 "Display the received routes from neighbor\n"
12898 "JavaScript Object Notation\n")
12899
12900 DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12901 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
12902 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
12903 SHOW_STR
12904 BGP_STR
12905 BGP_INSTANCE_HELP_STR
12906 "Address family\n"
12907 "Address family\n"
12908 "Address family modifier\n"
12909 "Address family modifier\n"
12910 "Detailed information on TCP and BGP neighbor connections\n"
12911 "Neighbor to display information about\n"
12912 "Neighbor to display information about\n"
12913 "Neighbor on bgp configured interface\n"
12914 "Display the advertised routes to neighbor\n"
12915 "Display the received routes from neighbor\n"
12916 "JavaScript Object Notation\n")
12917 {
12918 int afi;
12919 int safi;
12920 int in;
12921 struct peer *peer;
12922 u_char uj = use_json(argc, argv);
12923
12924 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
12925
12926 if (! peer)
12927 return CMD_WARNING;
12928
12929 afi = bgp_vty_safi_from_arg(argv[2]);
12930 safi = bgp_vty_safi_from_arg(argv[3]);
12931 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
12932
12933 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
12934 }
12935
12936 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12937 show_ip_bgp_neighbor_received_prefix_filter_cmd,
12938 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12939 SHOW_STR
12940 IP_STR
12941 BGP_STR
12942 "Detailed information on TCP and BGP neighbor connections\n"
12943 "Neighbor to display information about\n"
12944 "Neighbor to display information about\n"
12945 "Neighbor on bgp configured interface\n"
12946 "Display information received from a BGP neighbor\n"
12947 "Display the prefixlist filter\n"
12948 "JavaScript Object Notation\n")
12949 {
12950 char name[BUFSIZ];
12951 union sockunion su;
12952 struct peer *peer;
12953 int count, ret;
12954 u_char uj = use_json(argc, argv);
12955
12956 ret = str2sockunion (argv[0], &su);
12957 if (ret < 0)
12958 {
12959 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12960 if (! peer)
12961 {
12962 if (uj)
12963 {
12964 json_object *json_no = NULL;
12965 json_object *json_sub = NULL;
12966 json_no = json_object_new_object();
12967 json_sub = json_object_new_object();
12968 json_object_string_add(json_no, "warning", "Malformed address or name");
12969 json_object_string_add(json_sub, "warningCause", argv[0]);
12970 json_object_object_add(json_no, "detail", json_sub);
12971 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12972 json_object_free(json_no);
12973 }
12974 else
12975 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12976 return CMD_WARNING;
12977 }
12978 }
12979 else
12980 {
12981 peer = peer_lookup (NULL, &su);
12982 if (! peer)
12983 {
12984 if (uj)
12985 {
12986 json_object *json_no = NULL;
12987 json_no = json_object_new_object();
12988 json_object_string_add(json_no, "warning", "Peer not found");
12989 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12990 json_object_free(json_no);
12991 }
12992 else
12993 vty_out (vty, "No peer%s", VTY_NEWLINE);
12994 return CMD_WARNING;
12995 }
12996 }
12997
12998 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12999 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13000 if (count)
13001 {
13002 if (!uj)
13003 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13004 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13005 }
13006 else
13007 {
13008 if (uj)
13009 {
13010 json_object *json_no = NULL;
13011 json_no = json_object_new_object();
13012 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13013 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13014 json_object_free(json_no);
13015 }
13016 else
13017 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13018 }
13019
13020 return CMD_SUCCESS;
13021 }
13022
13023 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13024 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13025 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13026 SHOW_STR
13027 IP_STR
13028 BGP_STR
13029 "Address family\n"
13030 "Address Family modifier\n"
13031 "Address Family modifier\n"
13032 "Detailed information on TCP and BGP neighbor connections\n"
13033 "Neighbor to display information about\n"
13034 "Neighbor to display information about\n"
13035 "Neighbor on bgp configured interface\n"
13036 "Display information received from a BGP neighbor\n"
13037 "Display the prefixlist filter\n"
13038 "JavaScript Object Notation\n")
13039 {
13040 char name[BUFSIZ];
13041 union sockunion su;
13042 struct peer *peer;
13043 int count, ret;
13044 u_char uj = use_json(argc, argv);
13045
13046 ret = str2sockunion (argv[1], &su);
13047 if (ret < 0)
13048 {
13049 peer = peer_lookup_by_conf_if (NULL, argv[1]);
13050 if (! peer)
13051 {
13052 if (uj)
13053 {
13054 json_object *json_no = NULL;
13055 json_object *json_sub = NULL;
13056 json_no = json_object_new_object();
13057 json_sub = json_object_new_object();
13058 json_object_string_add(json_no, "warning", "Malformed address or name");
13059 json_object_string_add(json_sub, "warningCause", argv[1]);
13060 json_object_object_add(json_no, "detail", json_sub);
13061 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13062 json_object_free(json_no);
13063 }
13064 else
13065 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
13066 return CMD_WARNING;
13067 }
13068 }
13069 else
13070 {
13071 peer = peer_lookup (NULL, &su);
13072 if (! peer)
13073 {
13074 if (uj)
13075 {
13076 json_object *json_no = NULL;
13077 json_no = json_object_new_object();
13078 json_object_string_add(json_no, "warning", "Peer not found");
13079 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13080 json_object_free(json_no);
13081 }
13082 else
13083 vty_out (vty, "No peer%s", VTY_NEWLINE);
13084 return CMD_WARNING;
13085 }
13086 }
13087
13088 {
13089 safi_t safi;
13090 safi = bgp_vty_safi_from_arg(argv[0]);
13091 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13092 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13093 if (count)
13094 {
13095 if (!uj)
13096 vty_out (vty, "Address family: %s%s",
13097 afi_safi_print (AFI_IP, safi), VTY_NEWLINE);
13098 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13099 }
13100 else
13101 {
13102 if (uj)
13103 {
13104 json_object *json_no = NULL;
13105 json_no = json_object_new_object();
13106 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13107 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13108 json_object_free(json_no);
13109 }
13110 else
13111 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13112 }
13113 }
13114
13115 return CMD_SUCCESS;
13116 }
13117 #ifdef HAVE_IPV6
13118 DEFUN (show_bgp_neighbor_received_routes,
13119 show_bgp_neighbor_received_routes_cmd,
13120 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13121 SHOW_STR
13122 BGP_STR
13123 "Detailed information on TCP and BGP neighbor connections\n"
13124 "Neighbor to display information about\n"
13125 "Neighbor to display information about\n"
13126 "Neighbor on bgp configured interface\n"
13127 "Display the received routes from neighbor\n"
13128 "JavaScript Object Notation\n")
13129 {
13130 struct peer *peer;
13131 const char *rmap_name = NULL;
13132 u_char uj = use_json(argc, argv);
13133
13134 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13135
13136 if (! peer)
13137 return CMD_WARNING;
13138
13139 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
13140 rmap_name = argv[1];
13141
13142 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
13143 }
13144
13145 ALIAS (show_bgp_neighbor_received_routes,
13146 show_bgp_ipv6_neighbor_received_routes_cmd,
13147 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13148 SHOW_STR
13149 BGP_STR
13150 "Address family\n"
13151 "Detailed information on TCP and BGP neighbor connections\n"
13152 "Neighbor to display information about\n"
13153 "Neighbor to display information about\n"
13154 "Neighbor on bgp configured interface\n"
13155 "Display the received routes from neighbor\n"
13156 "JavaScript Object Notation\n")
13157
13158 DEFUN (show_bgp_neighbor_received_prefix_filter,
13159 show_bgp_neighbor_received_prefix_filter_cmd,
13160 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13161 SHOW_STR
13162 BGP_STR
13163 "Detailed information on TCP and BGP neighbor connections\n"
13164 "Neighbor to display information about\n"
13165 "Neighbor to display information about\n"
13166 "Neighbor on bgp configured interface\n"
13167 "Display information received from a BGP neighbor\n"
13168 "Display the prefixlist filter\n"
13169 "JavaScript Object Notation\n")
13170 {
13171 char name[BUFSIZ];
13172 union sockunion su;
13173 struct peer *peer;
13174 int count, ret;
13175 u_char uj = use_json(argc, argv);
13176
13177 ret = str2sockunion (argv[0], &su);
13178 if (ret < 0)
13179 {
13180 peer = peer_lookup_by_conf_if (NULL, argv[0]);
13181 if (! peer)
13182 {
13183 if (uj)
13184 {
13185 json_object *json_no = NULL;
13186 json_object *json_sub = NULL;
13187 json_no = json_object_new_object();
13188 json_sub = json_object_new_object();
13189 json_object_string_add(json_no, "warning", "Malformed address or name");
13190 json_object_string_add(json_sub, "warningCause", argv[0]);
13191 json_object_object_add(json_no, "detail", json_sub);
13192 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13193 json_object_free(json_no);
13194 }
13195 else
13196 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
13197 return CMD_WARNING;
13198 }
13199 }
13200 else
13201 {
13202 peer = peer_lookup (NULL, &su);
13203 if (! peer)
13204 {
13205 if (uj)
13206 {
13207 json_object *json_no = NULL;
13208 json_no = json_object_new_object();
13209 json_object_string_add(json_no, "warning", "No Peer");
13210 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13211 json_object_free(json_no);
13212 }
13213 else
13214 vty_out (vty, "No peer%s", VTY_NEWLINE);
13215 return CMD_WARNING;
13216 }
13217 }
13218
13219 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13220 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13221 if (count)
13222 {
13223 if (!uj)
13224 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13225 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13226 }
13227 else
13228 {
13229 if (uj)
13230 {
13231 json_object *json_no = NULL;
13232 json_no = json_object_new_object();
13233 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13234 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13235 json_object_free(json_no);
13236 }
13237 else
13238 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13239 }
13240
13241 return CMD_SUCCESS;
13242 }
13243
13244 ALIAS (show_bgp_neighbor_received_prefix_filter,
13245 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13246 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13247 SHOW_STR
13248 BGP_STR
13249 "Address family\n"
13250 "Detailed information on TCP and BGP neighbor connections\n"
13251 "Neighbor to display information about\n"
13252 "Neighbor to display information about\n"
13253 "Neighbor on bgp configured interface\n"
13254 "Display information received from a BGP neighbor\n"
13255 "Display the prefixlist filter\n"
13256 "JavaScript Object Notation\n")
13257
13258 /* old command */
13259 ALIAS (show_bgp_neighbor_received_routes,
13260 ipv6_bgp_neighbor_received_routes_cmd,
13261 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13262 SHOW_STR
13263 IPV6_STR
13264 BGP_STR
13265 "Detailed information on TCP and BGP neighbor connections\n"
13266 "Neighbor to display information about\n"
13267 "Neighbor to display information about\n"
13268 "Neighbor on bgp configured interface\n"
13269 "Display the received routes from neighbor\n"
13270 "JavaScript Object Notation\n")
13271
13272 /* old command */
13273 DEFUN (ipv6_mbgp_neighbor_received_routes,
13274 ipv6_mbgp_neighbor_received_routes_cmd,
13275 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13276 SHOW_STR
13277 IPV6_STR
13278 MBGP_STR
13279 "Detailed information on TCP and BGP neighbor connections\n"
13280 "Neighbor to display information about\n"
13281 "Neighbor to display information about\n"
13282 "Neighbor on bgp configured interface\n"
13283 "Display the received routes from neighbor\n"
13284 "JavaScript Object Notation\n")
13285 {
13286 struct peer *peer;
13287 u_char uj = use_json(argc, argv);
13288
13289 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13290 if (! peer)
13291 return CMD_WARNING;
13292
13293 bgp_show_ipv6_bgp_deprecate_warning(vty);
13294 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
13295 }
13296
13297 DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
13298 show_bgp_instance_neighbor_received_prefix_filter_cmd,
13299 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13300 SHOW_STR
13301 BGP_STR
13302 BGP_INSTANCE_HELP_STR
13303 "Detailed information on TCP and BGP neighbor connections\n"
13304 "Neighbor to display information about\n"
13305 "Neighbor to display information about\n"
13306 "Neighbor on bgp configured interface\n"
13307 "Display information received from a BGP neighbor\n"
13308 "Display the prefixlist filter\n"
13309 "JavaScript Object Notation\n")
13310 {
13311 char name[BUFSIZ];
13312 union sockunion su;
13313 struct peer *peer;
13314 struct bgp *bgp;
13315 int count, ret;
13316 u_char uj = use_json(argc, argv);
13317
13318 /* BGP structure lookup. */
13319 bgp = bgp_lookup_by_name (argv[1]);
13320 if (bgp == NULL)
13321 {
13322 if (uj)
13323 {
13324 json_object *json_no = NULL;
13325 json_no = json_object_new_object();
13326 json_object_string_add(json_no, "warning", "Can't find BGP view");
13327 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13328 json_object_free(json_no);
13329 }
13330 else
13331 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
13332 return CMD_WARNING;
13333 }
13334
13335 ret = str2sockunion (argv[2], &su);
13336 if (ret < 0)
13337 {
13338 peer = peer_lookup_by_conf_if (bgp, argv[2]);
13339 if (! peer)
13340 {
13341 if (uj)
13342 {
13343 json_object *json_no = NULL;
13344 json_object *json_sub = NULL;
13345 json_no = json_object_new_object();
13346 json_sub = json_object_new_object();
13347 json_object_string_add(json_no, "warning", "Malformed address or name");
13348 json_object_string_add(json_sub, "warningCause", argv[2]);
13349 json_object_object_add(json_no, "detail", json_sub);
13350 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13351 json_object_free(json_no);
13352 }
13353 else
13354 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
13355 return CMD_WARNING;
13356 }
13357 }
13358 else
13359 {
13360 peer = peer_lookup (bgp, &su);
13361 if (! peer)
13362 {
13363 if (uj)
13364 {
13365 json_object *json_no = NULL;
13366 json_no = json_object_new_object();
13367 json_object_boolean_true_add(json_no, "noPeer");
13368 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13369 json_object_free(json_no);
13370 }
13371 else
13372 vty_out (vty, "No peer%s", VTY_NEWLINE);
13373 return CMD_WARNING;
13374 }
13375
13376 }
13377
13378 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13379 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13380 if (count)
13381 {
13382 if (!uj)
13383 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13384 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13385 }
13386
13387 return CMD_SUCCESS;
13388 }
13389 ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
13390 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
13391 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13392 SHOW_STR
13393 BGP_STR
13394 BGP_INSTANCE_HELP_STR
13395 "Address family\n"
13396 "Detailed information on TCP and BGP neighbor connections\n"
13397 "Neighbor to display information about\n"
13398 "Neighbor to display information about\n"
13399 "Neighbor on bgp configured interface\n"
13400 "Display information received from a BGP neighbor\n"
13401 "Display the prefixlist filter\n"
13402 "JavaScript Object NOtation\n")
13403 #endif /* HAVE_IPV6 */
13404
13405 static int
13406 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
13407 safi_t safi, enum bgp_show_type type, u_char use_json)
13408 {
13409 if (! peer || ! peer->afc[afi][safi])
13410 {
13411 if (use_json)
13412 {
13413 json_object *json_no = NULL;
13414 json_no = json_object_new_object();
13415 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13416 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13417 json_object_free(json_no);
13418 }
13419 else
13420 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
13421 return CMD_WARNING;
13422 }
13423
13424 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
13425 }
13426
13427 DEFUN (show_ip_bgp_neighbor_routes,
13428 show_ip_bgp_neighbor_routes_cmd,
13429 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13430 SHOW_STR
13431 IP_STR
13432 BGP_STR
13433 "Detailed information on TCP and BGP neighbor connections\n"
13434 "Neighbor to display information about\n"
13435 "Neighbor to display information about\n"
13436 "Neighbor on bgp configured interface\n"
13437 "Display routes learned from neighbor\n"
13438 "JavaScript Object Notation\n")
13439 {
13440 struct peer *peer;
13441 u_char uj = use_json(argc, argv);
13442
13443 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13444 if (! peer)
13445 return CMD_WARNING;
13446
13447 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13448 bgp_show_type_neighbor, uj);
13449 }
13450
13451 DEFUN (show_ip_bgp_instance_neighbor_routes,
13452 show_ip_bgp_instance_neighbor_routes_cmd,
13453 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13454 SHOW_STR
13455 IP_STR
13456 BGP_STR
13457 BGP_INSTANCE_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 u_char uj = use_json(argc, argv);
13467
13468 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13469 if (! peer)
13470 return CMD_WARNING;
13471
13472 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13473 bgp_show_type_neighbor, uj);
13474 }
13475
13476 DEFUN (show_ip_bgp_neighbor_flap,
13477 show_ip_bgp_neighbor_flap_cmd,
13478 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13479 SHOW_STR
13480 IP_STR
13481 BGP_STR
13482 "Detailed information on TCP and BGP neighbor connections\n"
13483 "Neighbor to display information about\n"
13484 "Neighbor to display information about\n"
13485 "Neighbor on bgp configured interface\n"
13486 "Display flap statistics of the routes learned from neighbor\n"
13487 "JavaScript Object Notation\n")
13488 {
13489 struct peer *peer;
13490 u_char uj = use_json(argc, argv);
13491
13492 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13493 if (! peer)
13494 return CMD_WARNING;
13495
13496 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13497 bgp_show_type_flap_neighbor, uj);
13498 }
13499
13500 DEFUN (show_ip_bgp_neighbor_damp,
13501 show_ip_bgp_neighbor_damp_cmd,
13502 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13503 SHOW_STR
13504 IP_STR
13505 BGP_STR
13506 "Detailed information on TCP and BGP neighbor connections\n"
13507 "Neighbor to display information about\n"
13508 "Neighbor to display information about\n"
13509 "Neighbor on bgp configured interface\n"
13510 "Display the dampened routes received from neighbor\n"
13511 "JavaScript Object Notation\n")
13512 {
13513 struct peer *peer;
13514 u_char uj = use_json(argc, argv);
13515
13516 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13517 if (! peer)
13518 return CMD_WARNING;
13519
13520 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13521 bgp_show_type_damp_neighbor, uj);
13522 }
13523
13524 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13525 show_ip_bgp_ipv4_neighbor_routes_cmd,
13526 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13527 SHOW_STR
13528 IP_STR
13529 BGP_STR
13530 "Address family\n"
13531 "Address Family modifier\n"
13532 "Address Family modifier\n"
13533 "Detailed information on TCP and BGP neighbor connections\n"
13534 "Neighbor to display information about\n"
13535 "Neighbor to display information about\n"
13536 "Neighbor on bgp configured interface\n"
13537 "Display routes learned from neighbor\n"
13538 "JavaScript Object Notation\n")
13539 {
13540 struct peer *peer;
13541 safi_t safi;
13542 u_char uj = use_json(argc, argv);
13543
13544 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13545 if (! peer)
13546 return CMD_WARNING;
13547
13548 safi = bgp_vty_safi_from_arg(argv[0]);
13549 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
13550 bgp_show_type_neighbor, uj);
13551 }
13552
13553 #ifdef HAVE_IPV6
13554 DEFUN (show_bgp_instance_neighbor_routes,
13555 show_bgp_instance_neighbor_routes_cmd,
13556 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13557 SHOW_STR
13558 BGP_STR
13559 BGP_INSTANCE_HELP_STR
13560 "Detailed information on TCP and BGP neighbor connections\n"
13561 "Neighbor to display information about\n"
13562 "Neighbor to display information about\n"
13563 "Neighbor on bgp configured interface\n"
13564 "Display routes learned from neighbor\n"
13565 "JavaScript Object Notation\n")
13566 {
13567 struct peer *peer;
13568 u_char uj = use_json(argc, argv);
13569
13570 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13571 if (! peer)
13572 return CMD_WARNING;
13573
13574 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13575 bgp_show_type_neighbor, uj);
13576 }
13577
13578 ALIAS (show_bgp_instance_neighbor_routes,
13579 show_bgp_instance_ipv6_neighbor_routes_cmd,
13580 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13581 SHOW_STR
13582 BGP_STR
13583 BGP_INSTANCE_HELP_STR
13584 "Address family\n"
13585 "Detailed information on TCP and BGP neighbor connections\n"
13586 "Neighbor to display information about\n"
13587 "Neighbor to display information about\n"
13588 "Neighbor on bgp configured interface\n"
13589 "Display routes learned from neighbor\n"
13590 "JavaScript Object Notation\n")
13591
13592 DEFUN (show_bgp_instance_neighbor_damp,
13593 show_bgp_instance_neighbor_damp_cmd,
13594 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13595 SHOW_STR
13596 BGP_STR
13597 BGP_INSTANCE_HELP_STR
13598 "Detailed information on TCP and BGP neighbor connections\n"
13599 "Neighbor to display information about\n"
13600 "Neighbor to display information about\n"
13601 "Neighbor on bgp configured interface\n"
13602 "Display the dampened routes received from neighbor\n"
13603 "JavaScript Object Notation\n")
13604 {
13605 struct peer *peer;
13606 u_char uj = use_json(argc, argv);
13607
13608 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13609 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13610 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13611 else
13612 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13613
13614 if (! peer)
13615 return CMD_WARNING;
13616
13617 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13618 bgp_show_type_damp_neighbor, uj);
13619 }
13620
13621 ALIAS (show_bgp_instance_neighbor_damp,
13622 show_bgp_instance_ipv6_neighbor_damp_cmd,
13623 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13624 SHOW_STR
13625 BGP_STR
13626 BGP_INSTANCE_HELP_STR
13627 "Address family\n"
13628 "Detailed information on TCP and BGP neighbor connections\n"
13629 "Neighbor to display information about\n"
13630 "Neighbor to display information about\n"
13631 "Neighbor on bgp configured interface\n"
13632 "Display the dampened routes received from neighbor\n"
13633 "JavaScript Object Notation\n")
13634
13635 DEFUN (show_bgp_instance_neighbor_flap,
13636 show_bgp_instance_neighbor_flap_cmd,
13637 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13638 SHOW_STR
13639 BGP_STR
13640 BGP_INSTANCE_HELP_STR
13641 "Detailed information on TCP and BGP neighbor connections\n"
13642 "Neighbor to display information about\n"
13643 "Neighbor to display information about\n"
13644 "Neighbor on bgp configured interface\n"
13645 "Display flap statistics of the routes learned from neighbor\n"
13646 "JavaScript Object Notation\n")
13647 {
13648 struct peer *peer;
13649 u_char uj = use_json(argc, argv);
13650
13651 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13652 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13653 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13654 else
13655 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13656
13657 if (! peer)
13658 return CMD_WARNING;
13659
13660 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13661 bgp_show_type_flap_neighbor, uj);
13662 }
13663
13664 ALIAS (show_bgp_instance_neighbor_flap,
13665 show_bgp_instance_ipv6_neighbor_flap_cmd,
13666 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13667 SHOW_STR
13668 BGP_STR
13669 BGP_INSTANCE_HELP_STR
13670 "Address family\n"
13671 "Detailed information on TCP and BGP neighbor connections\n"
13672 "Neighbor to display information about\n"
13673 "Neighbor to display information about\n"
13674 "Neighbor on bgp configured interface\n"
13675 "Display flap statistics of the routes learned from neighbor\n"
13676 "JavaScript Object Notation\n")
13677
13678 DEFUN (show_bgp_neighbor_routes,
13679 show_bgp_neighbor_routes_cmd,
13680 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13681 SHOW_STR
13682 BGP_STR
13683 "Detailed information on TCP and BGP neighbor connections\n"
13684 "Neighbor to display information about\n"
13685 "Neighbor to display information about\n"
13686 "Neighbor on bgp configured interface\n"
13687 "Display routes learned from neighbor\n"
13688 "JavaScript Object Notation\n")
13689 {
13690 struct peer *peer;
13691 u_char uj = use_json(argc, argv);
13692
13693 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13694 if (! peer)
13695 return CMD_WARNING;
13696
13697 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13698 bgp_show_type_neighbor, uj);
13699 }
13700
13701
13702 ALIAS (show_bgp_neighbor_routes,
13703 show_bgp_ipv6_neighbor_routes_cmd,
13704 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13705 SHOW_STR
13706 BGP_STR
13707 "Address family\n"
13708 "Detailed information on TCP and BGP neighbor connections\n"
13709 "Neighbor to display information about\n"
13710 "Neighbor to display information about\n"
13711 "Neighbor on bgp configured interface\n"
13712 "Display routes learned from neighbor\n"
13713 "JavaScript Object Notation\n")
13714
13715 /* old command */
13716 ALIAS (show_bgp_neighbor_routes,
13717 ipv6_bgp_neighbor_routes_cmd,
13718 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13719 SHOW_STR
13720 IPV6_STR
13721 BGP_STR
13722 "Detailed information on TCP and BGP neighbor connections\n"
13723 "Neighbor to display information about\n"
13724 "Neighbor to display information about\n"
13725 "Neighbor on bgp configured interface\n"
13726 "Display routes learned from neighbor\n"
13727 "JavaScript Object Notation\n")
13728
13729 /* old command */
13730 DEFUN (ipv6_mbgp_neighbor_routes,
13731 ipv6_mbgp_neighbor_routes_cmd,
13732 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13733 SHOW_STR
13734 IPV6_STR
13735 MBGP_STR
13736 "Detailed information on TCP and BGP neighbor connections\n"
13737 "Neighbor to display information about\n"
13738 "Neighbor to display information about\n"
13739 "Neighbor on bgp configured interface\n"
13740 "Display routes learned from neighbor\n"
13741 "JavaScript Object Notation\n")
13742 {
13743 struct peer *peer;
13744 u_char uj = use_json(argc, argv);
13745
13746 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13747 if (! peer)
13748 return CMD_WARNING;
13749
13750 bgp_show_ipv6_bgp_deprecate_warning(vty);
13751 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
13752 bgp_show_type_neighbor, uj);
13753 }
13754
13755 ALIAS (show_bgp_instance_neighbor_flap,
13756 show_bgp_neighbor_flap_cmd,
13757 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13758 SHOW_STR
13759 BGP_STR
13760 "Detailed information on TCP and BGP neighbor connections\n"
13761 "Neighbor to display information about\n"
13762 "Neighbor to display information about\n"
13763 "Neighbor on bgp configured interface\n"
13764 "Display flap statistics of the routes learned from neighbor\n"
13765 "JavaScript Object Notation\n")
13766
13767 ALIAS (show_bgp_instance_neighbor_flap,
13768 show_bgp_ipv6_neighbor_flap_cmd,
13769 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13770 SHOW_STR
13771 BGP_STR
13772 "Address family\n"
13773 "Detailed information on TCP and BGP neighbor connections\n"
13774 "Neighbor to display information about\n"
13775 "Neighbor to display information about\n"
13776 "Neighbor on bgp configured interface\n"
13777 "Display flap statistics of the routes learned from neighbor\n"
13778 "JavaScript Object Notation\n")
13779
13780 ALIAS (show_bgp_instance_neighbor_damp,
13781 show_bgp_neighbor_damp_cmd,
13782 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13783 SHOW_STR
13784 BGP_STR
13785 "Detailed information on TCP and BGP neighbor connections\n"
13786 "Neighbor to display information about\n"
13787 "Neighbor to display information about\n"
13788 "Neighbor on bgp configured interface\n"
13789 "Display the dampened routes received from neighbor\n"
13790 "JavaScript Object Notation\n")
13791
13792 ALIAS (show_bgp_instance_neighbor_damp,
13793 show_bgp_ipv6_neighbor_damp_cmd,
13794 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13795 SHOW_STR
13796 BGP_STR
13797 "Address family\n"
13798 "Detailed information on TCP and BGP neighbor connections\n"
13799 "Neighbor to display information about\n"
13800 "Neighbor to display information about\n"
13801 "Neighbor on bgp configured interface\n"
13802 "Display the dampened routes received from neighbor\n"
13803 "JavaScript Object Notation\n")
13804
13805 #endif /* HAVE_IPV6 */
13806
13807 struct bgp_table *bgp_distance_table[AFI_MAX][SAFI_MAX];
13808
13809 struct bgp_distance
13810 {
13811 /* Distance value for the IP source prefix. */
13812 u_char distance;
13813
13814 /* Name of the access-list to be matched. */
13815 char *access_list;
13816 };
13817
13818 static struct bgp_distance *
13819 bgp_distance_new (void)
13820 {
13821 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
13822 }
13823
13824 static void
13825 bgp_distance_free (struct bgp_distance *bdistance)
13826 {
13827 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13828 }
13829
13830 static int
13831 bgp_distance_set (struct vty *vty, const char *distance_str,
13832 const char *ip_str, const char *access_list_str)
13833 {
13834 int ret;
13835 afi_t afi;
13836 safi_t safi;
13837 struct prefix p;
13838 u_char distance;
13839 struct bgp_node *rn;
13840 struct bgp_distance *bdistance;
13841
13842 afi = bgp_node_afi (vty);
13843 safi = bgp_node_safi (vty);
13844
13845 ret = str2prefix (ip_str, &p);
13846 if (ret == 0)
13847 {
13848 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13849 return CMD_WARNING;
13850 }
13851
13852 distance = atoi (distance_str);
13853
13854 /* Get BGP distance node. */
13855 rn = bgp_node_get (bgp_distance_table[afi][safi], (struct prefix *) &p);
13856 if (rn->info)
13857 {
13858 bdistance = rn->info;
13859 bgp_unlock_node (rn);
13860 }
13861 else
13862 {
13863 bdistance = bgp_distance_new ();
13864 rn->info = bdistance;
13865 }
13866
13867 /* Set distance value. */
13868 bdistance->distance = distance;
13869
13870 /* Reset access-list configuration. */
13871 if (bdistance->access_list)
13872 {
13873 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13874 bdistance->access_list = NULL;
13875 }
13876 if (access_list_str)
13877 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
13878
13879 return CMD_SUCCESS;
13880 }
13881
13882 static int
13883 bgp_distance_unset (struct vty *vty, const char *distance_str,
13884 const char *ip_str, const char *access_list_str)
13885 {
13886 int ret;
13887 afi_t afi;
13888 safi_t safi;
13889 struct prefix p;
13890 int distance;
13891 struct bgp_node *rn;
13892 struct bgp_distance *bdistance;
13893
13894 afi = bgp_node_afi (vty);
13895 safi = bgp_node_safi (vty);
13896
13897 ret = str2prefix (ip_str, &p);
13898 if (ret == 0)
13899 {
13900 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13901 return CMD_WARNING;
13902 }
13903
13904 rn = bgp_node_lookup (bgp_distance_table[afi][safi], (struct prefix *)&p);
13905 if (! rn)
13906 {
13907 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13908 return CMD_WARNING;
13909 }
13910
13911 bdistance = rn->info;
13912 distance = atoi(distance_str);
13913
13914 if (bdistance->distance != distance)
13915 {
13916 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
13917 return CMD_WARNING;
13918 }
13919
13920 if (bdistance->access_list)
13921 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13922 bgp_distance_free (bdistance);
13923
13924 rn->info = NULL;
13925 bgp_unlock_node (rn);
13926 bgp_unlock_node (rn);
13927
13928 return CMD_SUCCESS;
13929 }
13930
13931 /* Apply BGP information to distance method. */
13932 u_char
13933 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, afi_t afi,
13934 safi_t safi, struct bgp *bgp)
13935 {
13936 struct bgp_node *rn;
13937 struct prefix q;
13938 struct peer *peer;
13939 struct bgp_distance *bdistance;
13940 struct access_list *alist;
13941 struct bgp_static *bgp_static;
13942
13943 if (! bgp)
13944 return 0;
13945
13946 peer = rinfo->peer;
13947
13948 /* Check source address. */
13949 sockunion2hostprefix (&peer->su, &q);
13950 rn = bgp_node_match (bgp_distance_table[afi][safi], &q);
13951 if (rn)
13952 {
13953 bdistance = rn->info;
13954 bgp_unlock_node (rn);
13955
13956 if (bdistance->access_list)
13957 {
13958 alist = access_list_lookup (afi, bdistance->access_list);
13959 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13960 return bdistance->distance;
13961 }
13962 else
13963 return bdistance->distance;
13964 }
13965
13966 /* Backdoor check. */
13967 rn = bgp_node_lookup (bgp->route[afi][safi], p);
13968 if (rn)
13969 {
13970 bgp_static = rn->info;
13971 bgp_unlock_node (rn);
13972
13973 if (bgp_static->backdoor)
13974 {
13975 if (bgp->distance_local[afi][safi])
13976 return bgp->distance_local[afi][safi];
13977 else
13978 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13979 }
13980 }
13981
13982 if (peer->sort == BGP_PEER_EBGP)
13983 {
13984 if (bgp->distance_ebgp[afi][safi])
13985 return bgp->distance_ebgp[afi][safi];
13986 return ZEBRA_EBGP_DISTANCE_DEFAULT;
13987 }
13988 else
13989 {
13990 if (bgp->distance_ibgp[afi][safi])
13991 return bgp->distance_ibgp[afi][safi];
13992 return ZEBRA_IBGP_DISTANCE_DEFAULT;
13993 }
13994 }
13995
13996 DEFUN (bgp_distance,
13997 bgp_distance_cmd,
13998 "distance bgp <1-255> <1-255> <1-255>",
13999 "Define an administrative distance\n"
14000 "BGP distance\n"
14001 "Distance for routes external to the AS\n"
14002 "Distance for routes internal to the AS\n"
14003 "Distance for local routes\n")
14004 {
14005 struct bgp *bgp;
14006 afi_t afi;
14007 safi_t safi;
14008
14009 bgp = vty->index;
14010 afi = bgp_node_afi (vty);
14011 safi = bgp_node_safi (vty);
14012
14013 bgp->distance_ebgp[afi][safi] = atoi (argv[0]);
14014 bgp->distance_ibgp[afi][safi] = atoi (argv[1]);
14015 bgp->distance_local[afi][safi] = atoi (argv[2]);
14016 return CMD_SUCCESS;
14017 }
14018
14019 DEFUN (no_bgp_distance,
14020 no_bgp_distance_cmd,
14021 "no distance bgp <1-255> <1-255> <1-255>",
14022 NO_STR
14023 "Define an administrative distance\n"
14024 "BGP distance\n"
14025 "Distance for routes external to the AS\n"
14026 "Distance for routes internal to the AS\n"
14027 "Distance for local routes\n")
14028 {
14029 struct bgp *bgp;
14030 afi_t afi;
14031 safi_t safi;
14032
14033 bgp = vty->index;
14034 afi = bgp_node_afi (vty);
14035 safi = bgp_node_safi (vty);
14036
14037 bgp->distance_ebgp[afi][safi] = 0;
14038 bgp->distance_ibgp[afi][safi] = 0;
14039 bgp->distance_local[afi][safi] = 0;
14040 return CMD_SUCCESS;
14041 }
14042
14043 ALIAS (no_bgp_distance,
14044 no_bgp_distance2_cmd,
14045 "no distance bgp",
14046 NO_STR
14047 "Define an administrative distance\n"
14048 "BGP distance\n")
14049
14050 DEFUN (bgp_distance_source,
14051 bgp_distance_source_cmd,
14052 "distance <1-255> A.B.C.D/M",
14053 "Define an administrative distance\n"
14054 "Administrative distance\n"
14055 "IP source prefix\n")
14056 {
14057 bgp_distance_set (vty, argv[0], argv[1], NULL);
14058 return CMD_SUCCESS;
14059 }
14060
14061 DEFUN (no_bgp_distance_source,
14062 no_bgp_distance_source_cmd,
14063 "no distance <1-255> A.B.C.D/M",
14064 NO_STR
14065 "Define an administrative distance\n"
14066 "Administrative distance\n"
14067 "IP source prefix\n")
14068 {
14069 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14070 return CMD_SUCCESS;
14071 }
14072
14073 DEFUN (bgp_distance_source_access_list,
14074 bgp_distance_source_access_list_cmd,
14075 "distance <1-255> A.B.C.D/M WORD",
14076 "Define an administrative distance\n"
14077 "Administrative distance\n"
14078 "IP source prefix\n"
14079 "Access list name\n")
14080 {
14081 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14082 return CMD_SUCCESS;
14083 }
14084
14085 DEFUN (no_bgp_distance_source_access_list,
14086 no_bgp_distance_source_access_list_cmd,
14087 "no distance <1-255> A.B.C.D/M WORD",
14088 NO_STR
14089 "Define an administrative distance\n"
14090 "Administrative distance\n"
14091 "IP source prefix\n"
14092 "Access list name\n")
14093 {
14094 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14095 return CMD_SUCCESS;
14096 }
14097
14098 DEFUN (ipv6_bgp_distance_source,
14099 ipv6_bgp_distance_source_cmd,
14100 "distance <1-255> X:X::X:X/M",
14101 "Define an administrative distance\n"
14102 "Administrative distance\n"
14103 "IP source prefix\n")
14104 {
14105 bgp_distance_set (vty, argv[0], argv[1], NULL);
14106 return CMD_SUCCESS;
14107 }
14108
14109 DEFUN (no_ipv6_bgp_distance_source,
14110 no_ipv6_bgp_distance_source_cmd,
14111 "no distance <1-255> X:X::X:X/M",
14112 NO_STR
14113 "Define an administrative distance\n"
14114 "Administrative distance\n"
14115 "IP source prefix\n")
14116 {
14117 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14118 return CMD_SUCCESS;
14119 }
14120
14121 DEFUN (ipv6_bgp_distance_source_access_list,
14122 ipv6_bgp_distance_source_access_list_cmd,
14123 "distance <1-255> X:X::X:X/M WORD",
14124 "Define an administrative distance\n"
14125 "Administrative distance\n"
14126 "IP source prefix\n"
14127 "Access list name\n")
14128 {
14129 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14130 return CMD_SUCCESS;
14131 }
14132
14133 DEFUN (no_ipv6_bgp_distance_source_access_list,
14134 no_ipv6_bgp_distance_source_access_list_cmd,
14135 "no distance <1-255> X:X::X:X/M WORD",
14136 NO_STR
14137 "Define an administrative distance\n"
14138 "Administrative distance\n"
14139 "IP source prefix\n"
14140 "Access list name\n")
14141 {
14142 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14143 return CMD_SUCCESS;
14144 }
14145
14146 DEFUN (bgp_damp_set,
14147 bgp_damp_set_cmd,
14148 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14149 "BGP Specific commands\n"
14150 "Enable route-flap dampening\n"
14151 "Half-life time for the penalty\n"
14152 "Value to start reusing a route\n"
14153 "Value to start suppressing a route\n"
14154 "Maximum duration to suppress a stable route\n")
14155 {
14156 struct bgp *bgp;
14157 int half = DEFAULT_HALF_LIFE * 60;
14158 int reuse = DEFAULT_REUSE;
14159 int suppress = DEFAULT_SUPPRESS;
14160 int max = 4 * half;
14161
14162 if (argc == 4)
14163 {
14164 half = atoi (argv[0]) * 60;
14165 reuse = atoi (argv[1]);
14166 suppress = atoi (argv[2]);
14167 max = atoi (argv[3]) * 60;
14168 }
14169 else if (argc == 1)
14170 {
14171 half = atoi (argv[0]) * 60;
14172 max = 4 * half;
14173 }
14174
14175 bgp = vty->index;
14176
14177 if (suppress < reuse)
14178 {
14179 vty_out (vty, "Suppress value cannot be less than reuse value %s",
14180 VTY_NEWLINE);
14181 return 0;
14182 }
14183
14184 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14185 half, reuse, suppress, max);
14186 }
14187
14188 ALIAS (bgp_damp_set,
14189 bgp_damp_set2_cmd,
14190 "bgp dampening <1-45>",
14191 "BGP Specific commands\n"
14192 "Enable route-flap dampening\n"
14193 "Half-life time for the penalty\n")
14194
14195 ALIAS (bgp_damp_set,
14196 bgp_damp_set3_cmd,
14197 "bgp dampening",
14198 "BGP Specific commands\n"
14199 "Enable route-flap dampening\n")
14200
14201 DEFUN (bgp_damp_unset,
14202 bgp_damp_unset_cmd,
14203 "no bgp dampening",
14204 NO_STR
14205 "BGP Specific commands\n"
14206 "Enable route-flap dampening\n")
14207 {
14208 struct bgp *bgp;
14209
14210 bgp = vty->index;
14211 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14212 }
14213
14214 ALIAS (bgp_damp_unset,
14215 bgp_damp_unset2_cmd,
14216 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14217 NO_STR
14218 "BGP Specific commands\n"
14219 "Enable route-flap dampening\n"
14220 "Half-life time for the penalty\n"
14221 "Value to start reusing a route\n"
14222 "Value to start suppressing a route\n"
14223 "Maximum duration to suppress a stable route\n")
14224
14225 ALIAS (bgp_damp_unset,
14226 bgp_damp_unset3_cmd,
14227 "no bgp dampening <1-45>",
14228 NO_STR
14229 "BGP Specific commands\n"
14230 "Enable route-flap dampening\n"
14231 "Half-life time for the penalty\n")
14232
14233 DEFUN (show_ip_bgp_dampened_paths,
14234 show_ip_bgp_dampened_paths_cmd,
14235 "show ip bgp dampened-paths",
14236 SHOW_STR
14237 IP_STR
14238 BGP_STR
14239 "Display paths suppressed due to dampening\n")
14240 {
14241 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
14242 NULL, 0);
14243 }
14244
14245 ALIAS (show_ip_bgp_dampened_paths,
14246 show_ip_bgp_damp_dampened_paths_cmd,
14247 "show ip bgp dampening dampened-paths",
14248 SHOW_STR
14249 IP_STR
14250 BGP_STR
14251 "Display detailed information about dampening\n"
14252 "Display paths suppressed due to dampening\n")
14253
14254 DEFUN (show_ip_bgp_flap_statistics,
14255 show_ip_bgp_flap_statistics_cmd,
14256 "show ip bgp flap-statistics",
14257 SHOW_STR
14258 IP_STR
14259 BGP_STR
14260 "Display flap statistics of routes\n")
14261 {
14262 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
14263 bgp_show_type_flap_statistics, NULL, 0);
14264 }
14265
14266 ALIAS (show_ip_bgp_flap_statistics,
14267 show_ip_bgp_damp_flap_statistics_cmd,
14268 "show ip bgp dampening flap-statistics",
14269 SHOW_STR
14270 IP_STR
14271 BGP_STR
14272 "Display detailed information about dampening\n"
14273 "Display flap statistics of routes\n")
14274
14275 /* Display specified route of BGP table. */
14276 static int
14277 bgp_clear_damp_route (struct vty *vty, const char *view_name,
14278 const char *ip_str, afi_t afi, safi_t safi,
14279 struct prefix_rd *prd, int prefix_check)
14280 {
14281 int ret;
14282 struct prefix match;
14283 struct bgp_node *rn;
14284 struct bgp_node *rm;
14285 struct bgp_info *ri;
14286 struct bgp_info *ri_temp;
14287 struct bgp *bgp;
14288 struct bgp_table *table;
14289
14290 /* BGP structure lookup. */
14291 if (view_name)
14292 {
14293 bgp = bgp_lookup_by_name (view_name);
14294 if (bgp == NULL)
14295 {
14296 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
14297 return CMD_WARNING;
14298 }
14299 }
14300 else
14301 {
14302 bgp = bgp_get_default ();
14303 if (bgp == NULL)
14304 {
14305 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14306 return CMD_WARNING;
14307 }
14308 }
14309
14310 /* Check IP address argument. */
14311 ret = str2prefix (ip_str, &match);
14312 if (! ret)
14313 {
14314 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14315 return CMD_WARNING;
14316 }
14317
14318 match.family = afi2family (afi);
14319
14320 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
14321 {
14322 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
14323 {
14324 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14325 continue;
14326
14327 if ((table = rn->info) != NULL)
14328 if ((rm = bgp_node_match (table, &match)) != NULL)
14329 {
14330 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14331 {
14332 ri = rm->info;
14333 while (ri)
14334 {
14335 if (ri->extra && ri->extra->damp_info)
14336 {
14337 ri_temp = ri->next;
14338 bgp_damp_info_free (ri->extra->damp_info, 1);
14339 ri = ri_temp;
14340 }
14341 else
14342 ri = ri->next;
14343 }
14344 }
14345
14346 bgp_unlock_node (rm);
14347 }
14348 }
14349 }
14350 else
14351 {
14352 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
14353 {
14354 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14355 {
14356 ri = rn->info;
14357 while (ri)
14358 {
14359 if (ri->extra && ri->extra->damp_info)
14360 {
14361 ri_temp = ri->next;
14362 bgp_damp_info_free (ri->extra->damp_info, 1);
14363 ri = ri_temp;
14364 }
14365 else
14366 ri = ri->next;
14367 }
14368 }
14369
14370 bgp_unlock_node (rn);
14371 }
14372 }
14373
14374 return CMD_SUCCESS;
14375 }
14376
14377 DEFUN (clear_ip_bgp_dampening,
14378 clear_ip_bgp_dampening_cmd,
14379 "clear ip bgp dampening",
14380 CLEAR_STR
14381 IP_STR
14382 BGP_STR
14383 "Clear route flap dampening information\n")
14384 {
14385 bgp_damp_info_clean ();
14386 return CMD_SUCCESS;
14387 }
14388
14389 DEFUN (clear_ip_bgp_dampening_prefix,
14390 clear_ip_bgp_dampening_prefix_cmd,
14391 "clear ip bgp dampening A.B.C.D/M",
14392 CLEAR_STR
14393 IP_STR
14394 BGP_STR
14395 "Clear route flap dampening information\n"
14396 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14397 {
14398 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14399 SAFI_UNICAST, NULL, 1);
14400 }
14401
14402 DEFUN (clear_ip_bgp_dampening_address,
14403 clear_ip_bgp_dampening_address_cmd,
14404 "clear ip bgp dampening A.B.C.D",
14405 CLEAR_STR
14406 IP_STR
14407 BGP_STR
14408 "Clear route flap dampening information\n"
14409 "Network to clear damping information\n")
14410 {
14411 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14412 SAFI_UNICAST, NULL, 0);
14413 }
14414
14415 DEFUN (clear_ip_bgp_dampening_address_mask,
14416 clear_ip_bgp_dampening_address_mask_cmd,
14417 "clear ip bgp dampening A.B.C.D A.B.C.D",
14418 CLEAR_STR
14419 IP_STR
14420 BGP_STR
14421 "Clear route flap dampening information\n"
14422 "Network to clear damping information\n"
14423 "Network mask\n")
14424 {
14425 int ret;
14426 char prefix_str[BUFSIZ];
14427
14428 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14429 if (! ret)
14430 {
14431 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14432 return CMD_WARNING;
14433 }
14434
14435 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14436 SAFI_UNICAST, NULL, 0);
14437 }
14438
14439 /* also used for encap safi */
14440 static int
14441 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14442 afi_t afi, safi_t safi, int *write)
14443 {
14444 struct bgp_node *prn;
14445 struct bgp_node *rn;
14446 struct bgp_table *table;
14447 struct prefix *p;
14448 struct prefix_rd *prd;
14449 struct bgp_static *bgp_static;
14450 u_int32_t label;
14451 char buf[SU_ADDRSTRLEN];
14452 char rdbuf[RD_ADDRSTRLEN];
14453
14454 /* Network configuration. */
14455 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14456 if ((table = prn->info) != NULL)
14457 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14458 if ((bgp_static = rn->info) != NULL)
14459 {
14460 p = &rn->p;
14461 prd = (struct prefix_rd *) &prn->p;
14462
14463 /* "address-family" display. */
14464 bgp_config_write_family_header (vty, afi, safi, write);
14465
14466 /* "network" configuration display. */
14467 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14468 label = decode_label (bgp_static->tag);
14469
14470 vty_out (vty, " network %s/%d rd %s tag %d",
14471 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14472 p->prefixlen,
14473 rdbuf, label);
14474 vty_out (vty, "%s", VTY_NEWLINE);
14475 }
14476 return 0;
14477 }
14478
14479 /* Configuration of static route announcement and aggregate
14480 information. */
14481 int
14482 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14483 afi_t afi, safi_t safi, int *write)
14484 {
14485 struct bgp_node *rn;
14486 struct prefix *p;
14487 struct bgp_static *bgp_static;
14488 struct bgp_aggregate *bgp_aggregate;
14489 char buf[SU_ADDRSTRLEN];
14490
14491 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
14492 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14493
14494 /* Network configuration. */
14495 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14496 if ((bgp_static = rn->info) != NULL)
14497 {
14498 p = &rn->p;
14499
14500 /* "address-family" display. */
14501 bgp_config_write_family_header (vty, afi, safi, write);
14502
14503 /* "network" configuration display. */
14504 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14505 {
14506 u_int32_t destination;
14507 struct in_addr netmask;
14508
14509 destination = ntohl (p->u.prefix4.s_addr);
14510 masklen2ip (p->prefixlen, &netmask);
14511 vty_out (vty, " network %s",
14512 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14513
14514 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14515 || (IN_CLASSB (destination) && p->prefixlen == 16)
14516 || (IN_CLASSA (destination) && p->prefixlen == 8)
14517 || p->u.prefix4.s_addr == 0)
14518 {
14519 /* Natural mask is not display. */
14520 }
14521 else
14522 vty_out (vty, " mask %s", inet_ntoa (netmask));
14523 }
14524 else
14525 {
14526 vty_out (vty, " network %s/%d",
14527 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14528 p->prefixlen);
14529 }
14530
14531 if (bgp_static->rmap.name)
14532 vty_out (vty, " route-map %s", bgp_static->rmap.name);
14533 else
14534 {
14535 if (bgp_static->backdoor)
14536 vty_out (vty, " backdoor");
14537 }
14538
14539 vty_out (vty, "%s", VTY_NEWLINE);
14540 }
14541
14542 /* Aggregate-address configuration. */
14543 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14544 if ((bgp_aggregate = rn->info) != NULL)
14545 {
14546 p = &rn->p;
14547
14548 /* "address-family" display. */
14549 bgp_config_write_family_header (vty, afi, safi, write);
14550
14551 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14552 {
14553 struct in_addr netmask;
14554
14555 masklen2ip (p->prefixlen, &netmask);
14556 vty_out (vty, " aggregate-address %s %s",
14557 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14558 inet_ntoa (netmask));
14559 }
14560 else
14561 {
14562 vty_out (vty, " aggregate-address %s/%d",
14563 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14564 p->prefixlen);
14565 }
14566
14567 if (bgp_aggregate->as_set)
14568 vty_out (vty, " as-set");
14569
14570 if (bgp_aggregate->summary_only)
14571 vty_out (vty, " summary-only");
14572
14573 vty_out (vty, "%s", VTY_NEWLINE);
14574 }
14575
14576 return 0;
14577 }
14578
14579 int
14580 bgp_config_write_distance (struct vty *vty, struct bgp *bgp, afi_t afi,
14581 safi_t safi, int *write)
14582 {
14583 struct bgp_node *rn;
14584 struct bgp_distance *bdistance;
14585
14586 /* Distance configuration. */
14587 if (bgp->distance_ebgp[afi][safi]
14588 && bgp->distance_ibgp[afi][safi]
14589 && bgp->distance_local[afi][safi]
14590 && (bgp->distance_ebgp[afi][safi] != ZEBRA_EBGP_DISTANCE_DEFAULT
14591 || bgp->distance_ibgp[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT
14592 || bgp->distance_local[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT))
14593 {
14594 bgp_config_write_family_header (vty, afi, safi, write);
14595 vty_out (vty, " distance bgp %d %d %d%s",
14596 bgp->distance_ebgp[afi][safi], bgp->distance_ibgp[afi][safi],
14597 bgp->distance_local[afi][safi], VTY_NEWLINE);
14598 }
14599
14600 for (rn = bgp_table_top (bgp_distance_table[afi][safi]); rn;
14601 rn = bgp_route_next (rn))
14602 if ((bdistance = rn->info) != NULL)
14603 {
14604 char buf[PREFIX_STRLEN];
14605
14606 bgp_config_write_family_header (vty, afi, safi, write);
14607 vty_out (vty, " distance %d %s %s%s", bdistance->distance,
14608 prefix2str (&rn->p, buf, sizeof (buf)),
14609 bdistance->access_list ? bdistance->access_list : "",
14610 VTY_NEWLINE);
14611 }
14612
14613 return *write;
14614 }
14615
14616 /* Allocate routing table structure and install commands. */
14617 void
14618 bgp_route_init (void)
14619 {
14620 afi_t afi;
14621 safi_t safi;
14622
14623 /* Init BGP distance table. */
14624 for (afi = AFI_IP; afi < AFI_MAX; afi++)
14625 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
14626 bgp_distance_table[afi][safi] = bgp_table_init (afi, safi);
14627
14628 /* IPv4 BGP commands. */
14629 install_element (BGP_NODE, &bgp_table_map_cmd);
14630 install_element (BGP_NODE, &bgp_network_cmd);
14631 install_element (BGP_NODE, &bgp_network_mask_cmd);
14632 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14633 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14634 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14635 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14636 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14637 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14638 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
14639 install_element (BGP_NODE, &no_bgp_table_map_cmd);
14640 install_element (BGP_NODE, &no_bgp_network_cmd);
14641 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14642 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14643 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14644 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14645 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14646 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14647 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14648 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14649
14650 install_element (BGP_NODE, &aggregate_address_cmd);
14651 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14652 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14653 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14654 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14655 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14656 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14657 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14658 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14659 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14660 install_element (BGP_NODE, &no_aggregate_address_cmd);
14661 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14662 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14663 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14664 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14665 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14666 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14667 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14668 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14669 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14670
14671 /* IPv4 unicast configuration. */
14672 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
14673 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14674 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14675 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14676 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14677 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14678 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
14679 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
14680 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
14681 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14682 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14683 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14684 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14685 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14686
14687 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14688 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14689 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14690 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14691 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14692 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14693 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14694 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14695 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14696 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14697 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14698 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14699 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14700 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14701 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14702 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14703 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14704 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14705 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14706 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14707
14708 /* IPv4 multicast configuration. */
14709 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
14710 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14711 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14712 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14713 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14714 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14715 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
14716 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
14717 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14718 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14719 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14720 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14721 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14722 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14723 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14724 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14725 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14726 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14727 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14728 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14729 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14730 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14731 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14732 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14733 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14734 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14735 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14736 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14737 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14738 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14739 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14740 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14741 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14742 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14743
14744 install_element (VIEW_NODE, &show_ip_bgp_cmd);
14745 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
14746 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
14747 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
14748 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
14749 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
14750 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
14751 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14752 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14753 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14754 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
14755 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
14756 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14757 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
14758 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14759 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14760 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14761 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14762 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14763 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14764
14765 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14766 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14767 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14768 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14769 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14770 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14771 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
14772 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14773 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14774 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
14775 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14776 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14777 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14778 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14779 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14780 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14781 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14782 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14783 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14784 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14785 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14786 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14787 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
14788 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14789 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14790 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14791 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14792 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14793 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14794 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14795 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14796 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14797 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14798 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14799 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14800 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14801 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14802 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
14803 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14804 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14805 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14806 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14807 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14808 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14809 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14810 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14811 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14812 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14813 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14814 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14815 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14816 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14817 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14818 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14819 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14820 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14821 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14822 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
14823 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14824 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14825 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14826 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14827 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
14828 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
14829 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14830 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
14831 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
14832 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
14833 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14834 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
14835 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14836 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
14837 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14838 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14839 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
14840 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14841 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14842 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
14843 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14844 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14845 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14846 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
14847 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14848 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
14849 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14850 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
14851
14852 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
14853 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
14854 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
14855 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
14856 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
14857
14858 /* BGP dampening clear commands */
14859 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14860 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14861 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14862 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14863
14864 /* prefix count */
14865 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14866 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
14867 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14868 #ifdef HAVE_IPV6
14869 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14870 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
14871
14872 /* New config IPv6 BGP commands. */
14873 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
14874 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14875 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
14876 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
14877 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14878 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14879
14880 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14881 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14882 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14883 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
14884
14885 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14886 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
14887
14888 /* Old config IPv6 BGP commands. */
14889 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14890 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14891
14892 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14893 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14894 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14895 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14896
14897 install_element (VIEW_NODE, &show_bgp_cmd);
14898 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
14899 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
14900 install_element (VIEW_NODE, &show_bgp_route_cmd);
14901 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
14902 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
14903 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14904 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14905 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14906 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14907 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
14908 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14909 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14910 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14911 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14912 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14913 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14914 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14915 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14916 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14917 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14918 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14919 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14920 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14921 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14922 install_element (VIEW_NODE, &show_bgp_community_cmd);
14923 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14924 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14925 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14926 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14927 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14928 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14929 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14930 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14931 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14932 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14933 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14934 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14935 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14936 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14937 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14938 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14939 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14940 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14941 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14942 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14943 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14944 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14945 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14946 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14947 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14948 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14949 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14950 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14951 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14952 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14953 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14954 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14955 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14956 install_element (VIEW_NODE, &show_bgp_instance_cmd);
14957 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
14958 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
14959 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
14960 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
14961 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
14962 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14963 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
14964 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14965 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14966 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14967 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
14968 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14969 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
14970 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14971 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
14972 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14973 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
14974 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14975 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
14976 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
14977 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
14978 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
14979 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
14980 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
14981 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
14982 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
14983 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
14984 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
14985 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
14986 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
14987 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
14988 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
14989
14990 /* Statistics */
14991 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
14992 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
14993 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
14994 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
14995
14996 /* old command */
14997 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
14998 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
14999 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
15000 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
15001 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
15002 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
15003 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
15004 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
15005 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
15006 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
15007 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
15008 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
15009 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
15010 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
15011 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
15012 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
15013 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15014 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15015 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
15016 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
15017 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
15018 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
15019 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15020 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
15021 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
15022 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
15023 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
15024 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
15025 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
15026 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
15027 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15028 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15029 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15030 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15031 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15032 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15033
15034 /* old command */
15035 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15036 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15037
15038 /* old command */
15039 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15040 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15041
15042 /* old command */
15043 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
15044 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15045 #endif /* HAVE_IPV6 */
15046
15047 install_element (BGP_NODE, &bgp_distance_cmd);
15048 install_element (BGP_NODE, &no_bgp_distance_cmd);
15049 install_element (BGP_NODE, &no_bgp_distance2_cmd);
15050 install_element (BGP_NODE, &bgp_distance_source_cmd);
15051 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15052 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15053 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
15054 install_element (BGP_IPV4_NODE, &bgp_distance_cmd);
15055 install_element (BGP_IPV4_NODE, &no_bgp_distance_cmd);
15056 install_element (BGP_IPV4_NODE, &no_bgp_distance2_cmd);
15057 install_element (BGP_IPV4_NODE, &bgp_distance_source_cmd);
15058 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_cmd);
15059 install_element (BGP_IPV4_NODE, &bgp_distance_source_access_list_cmd);
15060 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_access_list_cmd);
15061 install_element (BGP_IPV4M_NODE, &bgp_distance_cmd);
15062 install_element (BGP_IPV4M_NODE, &no_bgp_distance_cmd);
15063 install_element (BGP_IPV4M_NODE, &no_bgp_distance2_cmd);
15064 install_element (BGP_IPV4M_NODE, &bgp_distance_source_cmd);
15065 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_cmd);
15066 install_element (BGP_IPV4M_NODE, &bgp_distance_source_access_list_cmd);
15067 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_access_list_cmd);
15068 install_element (BGP_IPV6_NODE, &bgp_distance_cmd);
15069 install_element (BGP_IPV6_NODE, &no_bgp_distance_cmd);
15070 install_element (BGP_IPV6_NODE, &no_bgp_distance2_cmd);
15071 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
15072 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
15073 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
15074 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
15075 install_element (BGP_IPV6M_NODE, &bgp_distance_cmd);
15076 install_element (BGP_IPV6M_NODE, &no_bgp_distance_cmd);
15077 install_element (BGP_IPV6M_NODE, &no_bgp_distance2_cmd);
15078 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_cmd);
15079 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_cmd);
15080 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_access_list_cmd);
15081 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
15082
15083 install_element (BGP_NODE, &bgp_damp_set_cmd);
15084 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15085 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15086 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15087 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
15088 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
15089 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15090 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15091 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15092 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15093 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
15094 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
15095
15096 /* IPv4 Multicast Mode */
15097 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
15098 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
15099 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
15100 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
15101 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
15102 }
15103
15104 void
15105 bgp_route_finish (void)
15106 {
15107 afi_t afi;
15108 safi_t safi;
15109
15110 for (afi = AFI_IP; afi < AFI_MAX; afi++)
15111 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
15112 {
15113 bgp_table_unlock (bgp_distance_table[afi][safi]);
15114 bgp_distance_table[afi][safi] = NULL;
15115 }
15116 }