]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.c
redhat: Fix missing packages in requirements section of README
[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 return;
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 return;
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 else
2285 buf[0] = '\0';
2286 }
2287
2288
2289 /* Check if received nexthop is valid or not. */
2290 static int
2291 bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
2292 {
2293 struct attr_extra *attre = attr->extra;
2294 int ret = 0;
2295
2296 /* Only validated for unicast and multicast currently. */
2297 if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
2298 return 0;
2299
2300 /* If NEXT_HOP is present, validate it. */
2301 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP))
2302 {
2303 if (attr->nexthop.s_addr == 0 ||
2304 IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
2305 bgp_nexthop_self (bgp, attr))
2306 ret = 1;
2307 }
2308
2309 /* If MP_NEXTHOP is present, validate it. */
2310 /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
2311 * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
2312 * it is not an IPv6 link-local address.
2313 */
2314 if (attre && attre->mp_nexthop_len)
2315 {
2316 switch (attre->mp_nexthop_len)
2317 {
2318 case BGP_ATTR_NHLEN_IPV4:
2319 case BGP_ATTR_NHLEN_VPNV4:
2320 ret = (attre->mp_nexthop_global_in.s_addr == 0 ||
2321 IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr)));
2322 break;
2323
2324 #ifdef HAVE_IPV6
2325 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
2326 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
2327 case BGP_ATTR_NHLEN_VPNV6_GLOBAL:
2328 ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) ||
2329 IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) ||
2330 IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global));
2331 break;
2332 #endif /* HAVE_IPV6 */
2333
2334 default:
2335 ret = 1;
2336 break;
2337 }
2338 }
2339
2340 return ret;
2341 }
2342
2343 int
2344 bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2345 struct attr *attr, afi_t afi, safi_t safi, int type,
2346 int sub_type, struct prefix_rd *prd, u_char *tag,
2347 int soft_reconfig)
2348 {
2349 int ret;
2350 int aspath_loop_count = 0;
2351 struct bgp_node *rn;
2352 struct bgp *bgp;
2353 struct attr new_attr;
2354 struct attr_extra new_extra;
2355 struct attr *attr_new;
2356 struct bgp_info *ri;
2357 struct bgp_info *new;
2358 const char *reason;
2359 char buf[SU_ADDRSTRLEN];
2360 char buf2[30];
2361 int connected = 0;
2362 int do_loop_check = 1;
2363 #if ENABLE_BGP_VNC
2364 int vnc_implicit_withdraw = 0;
2365 #endif
2366
2367 memset (&new_attr, 0, sizeof(struct attr));
2368 memset (&new_extra, 0, sizeof(struct attr_extra));
2369
2370 bgp = peer->bgp;
2371 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2372
2373 /* When peer's soft reconfiguration enabled. Record input packet in
2374 Adj-RIBs-In. */
2375 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2376 && peer != bgp->peer_self)
2377 bgp_adj_in_set (rn, peer, attr, addpath_id);
2378
2379 /* Check previously received route. */
2380 for (ri = rn->info; ri; ri = ri->next)
2381 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2382 ri->addpath_rx_id == addpath_id)
2383 break;
2384
2385 /* AS path local-as loop check. */
2386 if (peer->change_local_as)
2387 {
2388 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2389 aspath_loop_count = 1;
2390
2391 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2392 {
2393 reason = "as-path contains our own AS;";
2394 goto filtered;
2395 }
2396 }
2397
2398 /* If the peer is configured for "allowas-in origin" and the last ASN in the
2399 * as-path is our ASN then we do not need to call aspath_loop_check
2400 */
2401 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN_ORIGIN))
2402 if (aspath_get_last_as(attr->aspath) == bgp->as)
2403 do_loop_check = 0;
2404
2405 /* AS path loop check. */
2406 if (do_loop_check)
2407 {
2408 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2409 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2410 && aspath_loop_check(attr->aspath, bgp->confed_id) > peer->allowas_in[afi][safi]))
2411 {
2412 reason = "as-path contains our own AS;";
2413 goto filtered;
2414 }
2415 }
2416
2417 /* Route reflector originator ID check. */
2418 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2419 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2420 {
2421 reason = "originator is us;";
2422 goto filtered;
2423 }
2424
2425 /* Route reflector cluster ID check. */
2426 if (bgp_cluster_filter (peer, attr))
2427 {
2428 reason = "reflected from the same cluster;";
2429 goto filtered;
2430 }
2431
2432 /* Apply incoming filter. */
2433 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2434 {
2435 reason = "filter;";
2436 goto filtered;
2437 }
2438
2439 new_attr.extra = &new_extra;
2440 bgp_attr_dup (&new_attr, attr);
2441
2442 /* Apply incoming route-map.
2443 * NB: new_attr may now contain newly allocated values from route-map "set"
2444 * commands, so we need bgp_attr_flush in the error paths, until we intern
2445 * the attr (which takes over the memory references) */
2446 if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY)
2447 {
2448 reason = "route-map;";
2449 bgp_attr_flush (&new_attr);
2450 goto filtered;
2451 }
2452
2453 /* next hop check. */
2454 if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
2455 {
2456 reason = "martian or self next-hop;";
2457 bgp_attr_flush (&new_attr);
2458 goto filtered;
2459 }
2460
2461 attr_new = bgp_attr_intern (&new_attr);
2462
2463 /* If the update is implicit withdraw. */
2464 if (ri)
2465 {
2466 ri->uptime = bgp_clock ();
2467
2468 /* Same attribute comes in. */
2469 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2470 && attrhash_cmp (ri->attr, attr_new))
2471 {
2472 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2473 && peer->sort == BGP_PEER_EBGP
2474 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2475 {
2476 if (bgp_debug_update(peer, p, NULL, 1))
2477 {
2478 bgp_info_addpath_rx_str(addpath_id, buf2);
2479 zlog_debug ("%s rcvd %s/%d%s",
2480 peer->host,
2481 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2482 p->prefixlen, buf2);
2483 }
2484
2485 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2486 {
2487 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2488 bgp_process (bgp, rn, afi, safi);
2489 }
2490 }
2491 else /* Duplicate - odd */
2492 {
2493 if (bgp_debug_update(peer, p, NULL, 1))
2494 {
2495 if (!peer->rcvd_attr_printed)
2496 {
2497 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2498 peer->rcvd_attr_printed = 1;
2499 }
2500
2501 bgp_info_addpath_rx_str(addpath_id, buf2);
2502 zlog_debug ("%s rcvd %s/%d%s...duplicate ignored",
2503 peer->host,
2504 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2505 p->prefixlen, buf2);
2506 }
2507
2508 /* graceful restart STALE flag unset. */
2509 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2510 {
2511 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2512 bgp_process (bgp, rn, afi, safi);
2513 }
2514 }
2515
2516 bgp_unlock_node (rn);
2517 bgp_attr_unintern (&attr_new);
2518
2519 return 0;
2520 }
2521
2522 /* Withdraw/Announce before we fully processed the withdraw */
2523 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2524 {
2525 if (bgp_debug_update(peer, p, NULL, 1))
2526 {
2527 bgp_info_addpath_rx_str(addpath_id, buf2);
2528 zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing",
2529 peer->host,
2530 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2531 p->prefixlen, buf2);
2532 }
2533 bgp_info_restore (rn, ri);
2534 }
2535
2536 /* Received Logging. */
2537 if (bgp_debug_update(peer, p, NULL, 1))
2538 {
2539 bgp_info_addpath_rx_str(addpath_id, buf2);
2540 zlog_debug ("%s rcvd %s/%d%s",
2541 peer->host,
2542 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2543 p->prefixlen, buf2);
2544 }
2545
2546 /* graceful restart STALE flag unset. */
2547 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2548 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2549
2550 /* The attribute is changed. */
2551 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2552
2553 /* implicit withdraw, decrement aggregate and pcount here.
2554 * only if update is accepted, they'll increment below.
2555 */
2556 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2557
2558 /* Update bgp route dampening information. */
2559 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2560 && peer->sort == BGP_PEER_EBGP)
2561 {
2562 /* This is implicit withdraw so we should update dampening
2563 information. */
2564 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2565 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2566 }
2567 #if ENABLE_BGP_VNC
2568 if (safi == SAFI_MPLS_VPN) {
2569 struct bgp_node *prn = NULL;
2570 struct bgp_table *table = NULL;
2571
2572 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2573 if (prn->info) {
2574 table = (struct bgp_table *)(prn->info);
2575
2576 vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
2577 bgp,
2578 prd,
2579 table,
2580 p,
2581 ri);
2582 }
2583 bgp_unlock_node(prn);
2584 }
2585 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
2586 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) {
2587 /*
2588 * Implicit withdraw case.
2589 */
2590 ++vnc_implicit_withdraw;
2591 vnc_import_bgp_del_route(bgp, p, ri);
2592 vnc_import_bgp_exterior_del_route(bgp, p, ri);
2593 }
2594 }
2595 #endif
2596
2597 /* Update to new attribute. */
2598 bgp_attr_unintern (&ri->attr);
2599 ri->attr = attr_new;
2600
2601 /* Update MPLS tag. */
2602 if (safi == SAFI_MPLS_VPN)
2603 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2604
2605 #if ENABLE_BGP_VNC
2606 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
2607 {
2608 if (vnc_implicit_withdraw)
2609 {
2610 /*
2611 * Add back the route with its new attributes (e.g., nexthop).
2612 * The route is still selected, until the route selection
2613 * queued by bgp_process actually runs. We have to make this
2614 * update to the VNC side immediately to avoid racing against
2615 * configuration changes (e.g., route-map changes) which
2616 * trigger re-importation of the entire RIB.
2617 */
2618 vnc_import_bgp_add_route(bgp, p, ri);
2619 vnc_import_bgp_exterior_add_route(bgp, p, ri);
2620 }
2621 }
2622 #endif
2623
2624 /* Update bgp route dampening information. */
2625 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2626 && peer->sort == BGP_PEER_EBGP)
2627 {
2628 /* Now we do normal update dampening. */
2629 ret = bgp_damp_update (ri, rn, afi, safi);
2630 if (ret == BGP_DAMP_SUPPRESSED)
2631 {
2632 bgp_unlock_node (rn);
2633 return 0;
2634 }
2635 }
2636
2637 /* Nexthop reachability check. */
2638 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2639 {
2640 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2641 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2642 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2643 connected = 1;
2644 else
2645 connected = 0;
2646
2647 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected))
2648 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2649 else
2650 {
2651 if (BGP_DEBUG(nht, NHT))
2652 {
2653 char buf1[INET6_ADDRSTRLEN];
2654 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2655 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2656 }
2657 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2658 }
2659 }
2660 else
2661 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2662
2663 #if ENABLE_BGP_VNC
2664 if (safi == SAFI_MPLS_VPN)
2665 {
2666 struct bgp_node *prn = NULL;
2667 struct bgp_table *table = NULL;
2668
2669 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2670 if (prn->info)
2671 {
2672 table = (struct bgp_table *)(prn->info);
2673
2674 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2675 bgp,
2676 prd,
2677 table,
2678 p,
2679 ri);
2680 }
2681 bgp_unlock_node(prn);
2682 }
2683 #endif
2684
2685 /* Process change. */
2686 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2687
2688 bgp_process (bgp, rn, afi, safi);
2689 bgp_unlock_node (rn);
2690
2691 #if ENABLE_BGP_VNC
2692 if (SAFI_MPLS_VPN == safi)
2693 {
2694 uint32_t label = decode_label(tag);
2695
2696 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2697 &label);
2698 }
2699 if (SAFI_ENCAP == safi)
2700 {
2701 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2702 NULL);
2703 }
2704 #endif
2705
2706 return 0;
2707 } // End of implicit withdraw
2708
2709 /* Received Logging. */
2710 if (bgp_debug_update(peer, p, NULL, 1))
2711 {
2712 if (!peer->rcvd_attr_printed)
2713 {
2714 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2715 peer->rcvd_attr_printed = 1;
2716 }
2717
2718 bgp_info_addpath_rx_str(addpath_id, buf2);
2719 zlog_debug ("%s rcvd %s/%d%s",
2720 peer->host,
2721 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2722 p->prefixlen, buf2);
2723 }
2724
2725 /* Make new BGP info. */
2726 new = info_make(type, sub_type, 0, peer, attr_new, rn);
2727
2728 /* Update MPLS tag. */
2729 if (safi == SAFI_MPLS_VPN)
2730 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2731
2732 /* Nexthop reachability check. */
2733 if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)
2734 {
2735 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 &&
2736 ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
2737 && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
2738 connected = 1;
2739 else
2740 connected = 0;
2741
2742 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected))
2743 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2744 else
2745 {
2746 if (BGP_DEBUG(nht, NHT))
2747 {
2748 char buf1[INET6_ADDRSTRLEN];
2749 inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN);
2750 zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1);
2751 }
2752 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2753 }
2754 }
2755 else
2756 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2757
2758 /* Addpath ID */
2759 new->addpath_rx_id = addpath_id;
2760
2761 /* Increment prefix */
2762 bgp_aggregate_increment (bgp, p, new, afi, safi);
2763
2764 /* Register new BGP information. */
2765 bgp_info_add (rn, new);
2766
2767 /* route_node_get lock */
2768 bgp_unlock_node (rn);
2769
2770 #if ENABLE_BGP_VNC
2771 if (safi == SAFI_MPLS_VPN)
2772 {
2773 struct bgp_node *prn = NULL;
2774 struct bgp_table *table = NULL;
2775
2776 prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *) prd);
2777 if (prn->info)
2778 {
2779 table = (struct bgp_table *)(prn->info);
2780
2781 vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
2782 bgp,
2783 prd,
2784 table,
2785 p,
2786 new);
2787 }
2788 bgp_unlock_node(prn);
2789 }
2790 #endif
2791
2792 /* If maximum prefix count is configured and current prefix
2793 count exeed it. */
2794 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2795 return -1;
2796
2797 /* Process change. */
2798 bgp_process (bgp, rn, afi, safi);
2799
2800 #if ENABLE_BGP_VNC
2801 if (SAFI_MPLS_VPN == safi)
2802 {
2803 uint32_t label = decode_label(tag);
2804
2805 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2806 &label);
2807 }
2808 if (SAFI_ENCAP == safi)
2809 {
2810 rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type, sub_type,
2811 NULL);
2812 }
2813 #endif
2814
2815 return 0;
2816
2817 /* This BGP update is filtered. Log the reason then update BGP
2818 entry. */
2819 filtered:
2820 if (bgp_debug_update(peer, p, NULL, 1))
2821 {
2822 if (!peer->rcvd_attr_printed)
2823 {
2824 zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str);
2825 peer->rcvd_attr_printed = 1;
2826 }
2827
2828 bgp_info_addpath_rx_str(addpath_id, buf2);
2829 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s",
2830 peer->host,
2831 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2832 p->prefixlen, buf2, reason);
2833 }
2834
2835 if (ri)
2836 bgp_rib_remove (rn, ri, peer, afi, safi);
2837
2838 bgp_unlock_node (rn);
2839
2840 #if ENABLE_BGP_VNC
2841 /*
2842 * Filtered update is treated as an implicit withdrawal (see bgp_rib_remove()
2843 * a few lines above)
2844 */
2845 if ((SAFI_MPLS_VPN == safi) || (SAFI_ENCAP == safi))
2846 {
2847 rfapiProcessWithdraw(peer, NULL, p, prd, NULL, afi, safi, type, 0);
2848 }
2849 #endif
2850
2851 return 0;
2852 }
2853
2854 int
2855 bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
2856 struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type,
2857 struct prefix_rd *prd, u_char *tag)
2858 {
2859 struct bgp *bgp;
2860 char buf[SU_ADDRSTRLEN];
2861 char buf2[30];
2862 struct bgp_node *rn;
2863 struct bgp_info *ri;
2864
2865 #if ENABLE_BGP_VNC
2866 if ((SAFI_MPLS_VPN == safi) || (SAFI_ENCAP == safi))
2867 {
2868 rfapiProcessWithdraw(peer, NULL, p, prd, NULL, afi, safi, type, 0);
2869 }
2870 #endif
2871
2872 bgp = peer->bgp;
2873
2874 /* Lookup node. */
2875 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2876
2877 /* If peer is soft reconfiguration enabled. Record input packet for
2878 * further calculation.
2879 *
2880 * Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2881 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2882 * the iteration over all RS clients.
2883 * Since we need to remove the entry from adj_in anyway, do that first and
2884 * if there was no entry, we don't need to do anything more.
2885 */
2886 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2887 && peer != bgp->peer_self)
2888 if (!bgp_adj_in_unset (rn, peer, addpath_id))
2889 {
2890 if (bgp_debug_update (peer, p, NULL, 1))
2891 zlog_debug ("%s withdrawing route %s/%d "
2892 "not in adj-in", peer->host,
2893 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2894 p->prefixlen);
2895 bgp_unlock_node (rn);
2896 return 0;
2897 }
2898
2899 /* Lookup withdrawn route. */
2900 for (ri = rn->info; ri; ri = ri->next)
2901 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type &&
2902 ri->addpath_rx_id == addpath_id)
2903 break;
2904
2905 /* Logging. */
2906 if (bgp_debug_update(peer, p, NULL, 1))
2907 {
2908 bgp_info_addpath_rx_str(addpath_id, buf2);
2909 zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn",
2910 peer->host,
2911 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2912 p->prefixlen, buf2);
2913 }
2914
2915 /* Withdraw specified route from routing table. */
2916 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2917 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
2918 else if (bgp_debug_update(peer, p, NULL, 1))
2919 zlog_debug ("%s Can't find the route %s/%d", peer->host,
2920 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2921 p->prefixlen);
2922
2923 /* Unlock bgp_node_get() lock. */
2924 bgp_unlock_node (rn);
2925
2926 return 0;
2927 }
2928
2929 void
2930 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2931 {
2932 struct update_subgroup *subgrp;
2933 subgrp = peer_subgroup(peer, afi, safi);
2934 subgroup_default_originate(subgrp, withdraw);
2935 }
2936
2937
2938 /*
2939 * bgp_stop_announce_route_timer
2940 */
2941 void
2942 bgp_stop_announce_route_timer (struct peer_af *paf)
2943 {
2944 if (!paf->t_announce_route)
2945 return;
2946
2947 THREAD_TIMER_OFF (paf->t_announce_route);
2948 }
2949
2950 /*
2951 * bgp_announce_route_timer_expired
2952 *
2953 * Callback that is invoked when the route announcement timer for a
2954 * peer_af expires.
2955 */
2956 static int
2957 bgp_announce_route_timer_expired (struct thread *t)
2958 {
2959 struct peer_af *paf;
2960 struct peer *peer;
2961
2962 paf = THREAD_ARG (t);
2963 peer = paf->peer;
2964
2965 assert (paf->t_announce_route);
2966 paf->t_announce_route = NULL;
2967
2968 if (peer->status != Established)
2969 return 0;
2970
2971 if (!peer->afc_nego[paf->afi][paf->safi])
2972 return 0;
2973
2974 peer_af_announce_route (paf, 1);
2975 return 0;
2976 }
2977
2978 /*
2979 * bgp_announce_route
2980 *
2981 * *Triggers* announcement of routes of a given AFI/SAFI to a peer.
2982 */
2983 void
2984 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2985 {
2986 struct peer_af *paf;
2987 struct update_subgroup *subgrp;
2988
2989 paf = peer_af_find (peer, afi, safi);
2990 if (!paf)
2991 return;
2992 subgrp = PAF_SUBGRP(paf);
2993
2994 /*
2995 * Ignore if subgroup doesn't exist (implies AF is not negotiated)
2996 * or a refresh has already been triggered.
2997 */
2998 if (!subgrp || paf->t_announce_route)
2999 return;
3000
3001 /*
3002 * Start a timer to stagger/delay the announce. This serves
3003 * two purposes - announcement can potentially be combined for
3004 * multiple peers and the announcement doesn't happen in the
3005 * vty context.
3006 */
3007 THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
3008 bgp_announce_route_timer_expired, paf,
3009 (subgrp->peer_count == 1) ?
3010 BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
3011 BGP_ANNOUNCE_ROUTE_DELAY_MS);
3012 }
3013
3014 /*
3015 * Announce routes from all AF tables to a peer.
3016 *
3017 * This should ONLY be called when there is a need to refresh the
3018 * routes to the peer based on a policy change for this peer alone
3019 * or a route refresh request received from the peer.
3020 * The operation will result in splitting the peer from its existing
3021 * subgroups and putting it in new subgroups.
3022 */
3023 void
3024 bgp_announce_route_all (struct peer *peer)
3025 {
3026 afi_t afi;
3027 safi_t safi;
3028
3029 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3030 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3031 bgp_announce_route (peer, afi, safi);
3032 }
3033
3034 static void
3035 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
3036 struct bgp_table *table, struct prefix_rd *prd)
3037 {
3038 int ret;
3039 struct bgp_node *rn;
3040 struct bgp_adj_in *ain;
3041
3042 if (! table)
3043 table = peer->bgp->rib[afi][safi];
3044
3045 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3046 for (ain = rn->adj_in; ain; ain = ain->next)
3047 {
3048 if (ain->peer == peer)
3049 {
3050 struct bgp_info *ri = rn->info;
3051 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
3052
3053 ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr,
3054 afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
3055 prd, tag, 1);
3056
3057 if (ret < 0)
3058 {
3059 bgp_unlock_node (rn);
3060 return;
3061 }
3062 }
3063 }
3064 }
3065
3066 void
3067 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
3068 {
3069 struct bgp_node *rn;
3070 struct bgp_table *table;
3071
3072 if (peer->status != Established)
3073 return;
3074
3075 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
3076 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
3077 else
3078 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3079 rn = bgp_route_next (rn))
3080 if ((table = rn->info) != NULL)
3081 {
3082 struct prefix_rd prd;
3083 prd.family = AF_UNSPEC;
3084 prd.prefixlen = 64;
3085 memcpy(&prd.val, rn->p.u.val, 8);
3086
3087 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
3088 }
3089 }
3090
3091
3092 struct bgp_clear_node_queue
3093 {
3094 struct bgp_node *rn;
3095 };
3096
3097 static wq_item_status
3098 bgp_clear_route_node (struct work_queue *wq, void *data)
3099 {
3100 struct bgp_clear_node_queue *cnq = data;
3101 struct bgp_node *rn = cnq->rn;
3102 struct peer *peer = wq->spec.data;
3103 struct bgp_info *ri;
3104 afi_t afi = bgp_node_table (rn)->afi;
3105 safi_t safi = bgp_node_table (rn)->safi;
3106
3107 assert (rn && peer);
3108
3109 /* It is possible that we have multiple paths for a prefix from a peer
3110 * if that peer is using AddPath.
3111 */
3112 for (ri = rn->info; ri; ri = ri->next)
3113 if (ri->peer == peer)
3114 {
3115 /* graceful restart STALE flag set. */
3116 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
3117 && peer->nsf[afi][safi]
3118 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
3119 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
3120 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
3121 else
3122 bgp_rib_remove (rn, ri, peer, afi, safi);
3123 }
3124 return WQ_SUCCESS;
3125 }
3126
3127 static void
3128 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
3129 {
3130 struct bgp_clear_node_queue *cnq = data;
3131 struct bgp_node *rn = cnq->rn;
3132 struct bgp_table *table = bgp_node_table (rn);
3133
3134 bgp_unlock_node (rn);
3135 bgp_table_unlock (table);
3136 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
3137 }
3138
3139 static void
3140 bgp_clear_node_complete (struct work_queue *wq)
3141 {
3142 struct peer *peer = wq->spec.data;
3143
3144 /* Tickle FSM to start moving again */
3145 BGP_EVENT_ADD (peer, Clearing_Completed);
3146
3147 peer_unlock (peer); /* bgp_clear_route */
3148 }
3149
3150 static void
3151 bgp_clear_node_queue_init (struct peer *peer)
3152 {
3153 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
3154
3155 snprintf (wname, sizeof(wname), "clear %s", peer->host);
3156 #undef CLEAR_QUEUE_NAME_LEN
3157
3158 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
3159 {
3160 zlog_err ("%s: Failed to allocate work queue", __func__);
3161 exit (1);
3162 }
3163 peer->clear_node_queue->spec.hold = 10;
3164 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
3165 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
3166 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
3167 peer->clear_node_queue->spec.max_retries = 0;
3168
3169 /* we only 'lock' this peer reference when the queue is actually active */
3170 peer->clear_node_queue->spec.data = peer;
3171 }
3172
3173 static void
3174 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
3175 struct bgp_table *table)
3176 {
3177 struct bgp_node *rn;
3178 int force = bm->process_main_queue ? 0 : 1;
3179
3180 if (! table)
3181 table = peer->bgp->rib[afi][safi];
3182
3183 /* If still no table => afi/safi isn't configured at all or smth. */
3184 if (! table)
3185 return;
3186
3187 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3188 {
3189 struct bgp_info *ri, *next;
3190 struct bgp_adj_in *ain;
3191 struct bgp_adj_in *ain_next;
3192
3193 /* XXX:TODO: This is suboptimal, every non-empty route_node is
3194 * queued for every clearing peer, regardless of whether it is
3195 * relevant to the peer at hand.
3196 *
3197 * Overview: There are 3 different indices which need to be
3198 * scrubbed, potentially, when a peer is removed:
3199 *
3200 * 1 peer's routes visible via the RIB (ie accepted routes)
3201 * 2 peer's routes visible by the (optional) peer's adj-in index
3202 * 3 other routes visible by the peer's adj-out index
3203 *
3204 * 3 there is no hurry in scrubbing, once the struct peer is
3205 * removed from bgp->peer, we could just GC such deleted peer's
3206 * adj-outs at our leisure.
3207 *
3208 * 1 and 2 must be 'scrubbed' in some way, at least made
3209 * invisible via RIB index before peer session is allowed to be
3210 * brought back up. So one needs to know when such a 'search' is
3211 * complete.
3212 *
3213 * Ideally:
3214 *
3215 * - there'd be a single global queue or a single RIB walker
3216 * - rather than tracking which route_nodes still need to be
3217 * examined on a peer basis, we'd track which peers still
3218 * aren't cleared
3219 *
3220 * Given that our per-peer prefix-counts now should be reliable,
3221 * this may actually be achievable. It doesn't seem to be a huge
3222 * problem at this time,
3223 *
3224 * It is possible that we have multiple paths for a prefix from a peer
3225 * if that peer is using AddPath.
3226 */
3227 ain = rn->adj_in;
3228 while (ain)
3229 {
3230 ain_next = ain->next;
3231
3232 if (ain->peer == peer)
3233 {
3234 bgp_adj_in_remove (rn, ain);
3235 bgp_unlock_node (rn);
3236 }
3237
3238 ain = ain_next;
3239 }
3240
3241 for (ri = rn->info; ri; ri = next)
3242 {
3243 next = ri->next;
3244 if (ri->peer != peer)
3245 continue;
3246
3247 if (force)
3248 bgp_info_reap (rn, ri);
3249 else
3250 {
3251 struct bgp_clear_node_queue *cnq;
3252
3253 /* both unlocked in bgp_clear_node_queue_del */
3254 bgp_table_lock (bgp_node_table (rn));
3255 bgp_lock_node (rn);
3256 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
3257 sizeof (struct bgp_clear_node_queue));
3258 cnq->rn = rn;
3259 work_queue_add (peer->clear_node_queue, cnq);
3260 break;
3261 }
3262 }
3263 }
3264 return;
3265 }
3266
3267 void
3268 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
3269 {
3270 struct bgp_node *rn;
3271 struct bgp_table *table;
3272
3273 if (peer->clear_node_queue == NULL)
3274 bgp_clear_node_queue_init (peer);
3275
3276 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3277 * Idle until it receives a Clearing_Completed event. This protects
3278 * against peers which flap faster than we can we clear, which could
3279 * lead to:
3280 *
3281 * a) race with routes from the new session being installed before
3282 * clear_route_node visits the node (to delete the route of that
3283 * peer)
3284 * b) resource exhaustion, clear_route_node likely leads to an entry
3285 * on the process_main queue. Fast-flapping could cause that queue
3286 * to grow and grow.
3287 */
3288
3289 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3290 * the unlock will happen upon work-queue completion; other wise, the
3291 * unlock happens at the end of this function.
3292 */
3293 if (!peer->clear_node_queue->thread)
3294 peer_lock (peer);
3295
3296 if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP)
3297 bgp_clear_route_table (peer, afi, safi, NULL);
3298 else
3299 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3300 rn = bgp_route_next (rn))
3301 if ((table = rn->info) != NULL)
3302 bgp_clear_route_table (peer, afi, safi, table);
3303
3304 /* unlock if no nodes got added to the clear-node-queue. */
3305 if (!peer->clear_node_queue->thread)
3306 peer_unlock (peer);
3307
3308 }
3309
3310 void
3311 bgp_clear_route_all (struct peer *peer)
3312 {
3313 afi_t afi;
3314 safi_t safi;
3315
3316 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3317 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3318 bgp_clear_route (peer, afi, safi);
3319
3320 #if ENABLE_BGP_VNC
3321 rfapiProcessPeerDown(peer);
3322 #endif
3323 }
3324
3325 void
3326 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3327 {
3328 struct bgp_table *table;
3329 struct bgp_node *rn;
3330 struct bgp_adj_in *ain;
3331 struct bgp_adj_in *ain_next;
3332
3333 table = peer->bgp->rib[afi][safi];
3334
3335 /* It is possible that we have multiple paths for a prefix from a peer
3336 * if that peer is using AddPath.
3337 */
3338 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3339 {
3340 ain = rn->adj_in;
3341
3342 while (ain)
3343 {
3344 ain_next = ain->next;
3345
3346 if (ain->peer == peer)
3347 {
3348 bgp_adj_in_remove (rn, ain);
3349 bgp_unlock_node (rn);
3350 }
3351
3352 ain = ain_next;
3353 }
3354 }
3355 }
3356
3357 void
3358 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3359 {
3360 struct bgp_node *rn;
3361 struct bgp_info *ri;
3362 struct bgp_table *table;
3363
3364 table = peer->bgp->rib[afi][safi];
3365
3366 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3367 {
3368 for (ri = rn->info; ri; ri = ri->next)
3369 if (ri->peer == peer)
3370 {
3371 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3372 bgp_rib_remove (rn, ri, peer, afi, safi);
3373 break;
3374 }
3375 }
3376 }
3377
3378 static void
3379 bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3380 {
3381 struct bgp_node *rn;
3382 struct bgp_info *ri;
3383 struct bgp_info *next;
3384
3385 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3386 for (ri = rn->info; ri; ri = next)
3387 {
3388 next = ri->next;
3389 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3390 && ri->type == ZEBRA_ROUTE_BGP
3391 && (ri->sub_type == BGP_ROUTE_NORMAL ||
3392 ri->sub_type == BGP_ROUTE_AGGREGATE))
3393 {
3394 #if ENABLE_BGP_VNC
3395 if (table->owner && table->owner->bgp)
3396 vnc_import_bgp_del_route(table->owner->bgp, &rn->p, ri);
3397 #endif
3398 bgp_zebra_withdraw (&rn->p, ri, safi);
3399 bgp_info_reap (rn, ri);
3400 }
3401 }
3402 }
3403
3404 /* Delete all kernel routes. */
3405 void
3406 bgp_cleanup_routes (struct bgp *bgp)
3407 {
3408 afi_t afi;
3409
3410 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3411 {
3412 struct bgp_node *rn;
3413
3414 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
3415
3416 /*
3417 * VPN and ENCAP tables are two-level (RD is top level)
3418 */
3419 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3420 rn = bgp_route_next (rn))
3421 {
3422 if (rn->info)
3423 {
3424 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3425 bgp_table_finish ((struct bgp_table **)&(rn->info));
3426 rn->info = NULL;
3427 bgp_unlock_node(rn);
3428 }
3429 }
3430
3431 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3432 rn = bgp_route_next (rn))
3433 {
3434 if (rn->info)
3435 {
3436 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3437 bgp_table_finish ((struct bgp_table **)&(rn->info));
3438 rn->info = NULL;
3439 bgp_unlock_node(rn);
3440 }
3441 }
3442 }
3443 }
3444
3445 void
3446 bgp_reset (void)
3447 {
3448 vty_reset ();
3449 bgp_zclient_reset ();
3450 access_list_reset ();
3451 prefix_list_reset ();
3452 }
3453
3454 static int
3455 bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi)
3456 {
3457 return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
3458 CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
3459 }
3460
3461 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3462 value. */
3463 int
3464 bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3465 struct bgp_nlri *packet)
3466 {
3467 u_char *pnt;
3468 u_char *lim;
3469 struct prefix p;
3470 int psize;
3471 int ret;
3472 afi_t afi;
3473 safi_t safi;
3474 int addpath_encoded;
3475 u_int32_t addpath_id;
3476
3477 /* Check peer status. */
3478 if (peer->status != Established)
3479 return 0;
3480
3481 pnt = packet->nlri;
3482 lim = pnt + packet->length;
3483 afi = packet->afi;
3484 safi = packet->safi;
3485 addpath_id = 0;
3486 addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi);
3487
3488 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3489 syntactic validity. If the field is syntactically incorrect,
3490 then the Error Subcode is set to Invalid Network Field. */
3491 for (; pnt < lim; pnt += psize)
3492 {
3493 /* Clear prefix structure. */
3494 memset (&p, 0, sizeof (struct prefix));
3495
3496 if (addpath_encoded)
3497 {
3498
3499 /* When packet overflow occurs return immediately. */
3500 if (pnt + BGP_ADDPATH_ID_LEN > lim)
3501 return -1;
3502
3503 addpath_id = ntohl(*((uint32_t*) pnt));
3504 pnt += BGP_ADDPATH_ID_LEN;
3505 }
3506
3507 /* Fetch prefix length. */
3508 p.prefixlen = *pnt++;
3509 /* afi/safi validity already verified by caller, bgp_update_receive */
3510 p.family = afi2family (afi);
3511
3512 /* Prefix length check. */
3513 if (p.prefixlen > prefix_blen (&p) * 8)
3514 {
3515 zlog_err("%s [Error] Update packet error (wrong perfix length %d for afi %u)",
3516 peer->host, p.prefixlen, packet->afi);
3517 return -1;
3518 }
3519
3520 /* Packet size overflow check. */
3521 psize = PSIZE (p.prefixlen);
3522
3523 /* When packet overflow occur return immediately. */
3524 if (pnt + psize > lim)
3525 {
3526 zlog_err("%s [Error] Update packet error (prefix length %d overflows packet)",
3527 peer->host, p.prefixlen);
3528 return -1;
3529 }
3530
3531 /* Defensive coding, double-check the psize fits in a struct prefix */
3532 if (psize > (ssize_t) sizeof(p.u))
3533 {
3534 zlog_err("%s [Error] Update packet error (prefix length %d too large for prefix storage %zu)",
3535 peer->host, p.prefixlen, sizeof(p.u));
3536 return -1;
3537 }
3538
3539 /* Fetch prefix from NLRI packet. */
3540 memcpy (&p.u.prefix, pnt, psize);
3541
3542 /* Check address. */
3543 if (afi == AFI_IP && safi == SAFI_UNICAST)
3544 {
3545 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3546 {
3547 /* From RFC4271 Section 6.3:
3548 *
3549 * If a prefix in the NLRI field is semantically incorrect
3550 * (e.g., an unexpected multicast IP address), an error SHOULD
3551 * be logged locally, and the prefix SHOULD be ignored.
3552 */
3553 zlog_err ("%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3554 peer->host, inet_ntoa (p.u.prefix4));
3555 continue;
3556 }
3557 }
3558
3559 #ifdef HAVE_IPV6
3560 /* Check address. */
3561 if (afi == AFI_IP6 && safi == SAFI_UNICAST)
3562 {
3563 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3564 {
3565 char buf[BUFSIZ];
3566
3567 zlog_err ("%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3568 peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3569
3570 continue;
3571 }
3572 if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3573 {
3574 char buf[BUFSIZ];
3575
3576 zlog_err ("%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3577 peer->host, inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3578
3579 continue;
3580 }
3581 }
3582 #endif /* HAVE_IPV6 */
3583
3584 /* Normal process. */
3585 if (attr)
3586 ret = bgp_update (peer, &p, addpath_id, attr, afi, safi,
3587 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3588 else
3589 ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi,
3590 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3591
3592 /* Address family configuration mismatch or maximum-prefix count
3593 overflow. */
3594 if (ret < 0)
3595 return -1;
3596 }
3597
3598 /* Packet length consistency check. */
3599 if (pnt != lim)
3600 {
3601 zlog_err ("%s [Error] Update packet error (prefix length mismatch with total length)",
3602 peer->host);
3603 return -1;
3604 }
3605
3606 return 0;
3607 }
3608
3609 static struct bgp_static *
3610 bgp_static_new (void)
3611 {
3612 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3613 }
3614
3615 static void
3616 bgp_static_free (struct bgp_static *bgp_static)
3617 {
3618 if (bgp_static->rmap.name)
3619 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
3620 XFREE (MTYPE_BGP_STATIC, bgp_static);
3621 }
3622
3623 static void
3624 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3625 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3626 {
3627 struct bgp_node *rn;
3628 struct bgp_info *ri;
3629 struct bgp_info *new;
3630 struct bgp_info info;
3631 struct attr attr;
3632 struct attr *attr_new;
3633 int ret;
3634 #if ENABLE_BGP_VNC
3635 int vnc_implicit_withdraw = 0;
3636 #endif
3637
3638 assert (bgp_static);
3639 if (!bgp_static)
3640 return;
3641
3642 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3643
3644 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3645
3646 attr.nexthop = bgp_static->igpnexthop;
3647 attr.med = bgp_static->igpmetric;
3648 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3649
3650 if (bgp_static->atomic)
3651 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3652
3653 /* Apply route-map. */
3654 if (bgp_static->rmap.name)
3655 {
3656 struct attr attr_tmp = attr;
3657 info.peer = bgp->peer_self;
3658 info.attr = &attr_tmp;
3659
3660 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3661
3662 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3663
3664 bgp->peer_self->rmap_type = 0;
3665
3666 if (ret == RMAP_DENYMATCH)
3667 {
3668 /* Free uninterned attribute. */
3669 bgp_attr_flush (&attr_tmp);
3670
3671 /* Unintern original. */
3672 aspath_unintern (&attr.aspath);
3673 bgp_attr_extra_free (&attr);
3674 bgp_static_withdraw (bgp, p, afi, safi);
3675 return;
3676 }
3677 attr_new = bgp_attr_intern (&attr_tmp);
3678 }
3679 else
3680 attr_new = bgp_attr_intern (&attr);
3681
3682 for (ri = rn->info; ri; ri = ri->next)
3683 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3684 && ri->sub_type == BGP_ROUTE_STATIC)
3685 break;
3686
3687 if (ri)
3688 {
3689 if (attrhash_cmp (ri->attr, attr_new) &&
3690 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) &&
3691 !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS))
3692 {
3693 bgp_unlock_node (rn);
3694 bgp_attr_unintern (&attr_new);
3695 aspath_unintern (&attr.aspath);
3696 bgp_attr_extra_free (&attr);
3697 return;
3698 }
3699 else
3700 {
3701 /* The attribute is changed. */
3702 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3703
3704 /* Rewrite BGP route information. */
3705 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3706 bgp_info_restore(rn, ri);
3707 else
3708 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3709 #if ENABLE_BGP_VNC
3710 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3711 {
3712 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
3713 {
3714 /*
3715 * Implicit withdraw case.
3716 * We have to do this before ri is changed
3717 */
3718 ++vnc_implicit_withdraw;
3719 vnc_import_bgp_del_route(bgp, p, ri);
3720 vnc_import_bgp_exterior_del_route(bgp, p, ri);
3721 }
3722 }
3723 #endif
3724 bgp_attr_unintern (&ri->attr);
3725 ri->attr = attr_new;
3726 ri->uptime = bgp_clock ();
3727 #if ENABLE_BGP_VNC
3728 if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST))
3729 {
3730 if (vnc_implicit_withdraw)
3731 {
3732 vnc_import_bgp_add_route(bgp, p, ri);
3733 vnc_import_bgp_exterior_add_route(bgp, p, ri);
3734 }
3735 }
3736 #endif
3737
3738 /* Nexthop reachability check. */
3739 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3740 {
3741 if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
3742 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3743 else
3744 {
3745 if (BGP_DEBUG(nht, NHT))
3746 {
3747 char buf1[INET6_ADDRSTRLEN];
3748 inet_ntop(p->family, &p->u.prefix, buf1,
3749 INET6_ADDRSTRLEN);
3750 zlog_debug("%s(%s): Route not in table, not advertising",
3751 __FUNCTION__, buf1);
3752 }
3753 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
3754 }
3755 }
3756 else
3757 {
3758 /* Delete the NHT structure if any, if we're toggling between
3759 * enabling/disabling import check. We deregister the route
3760 * from NHT to avoid overloading NHT and the process interaction
3761 */
3762 bgp_unlink_nexthop(ri);
3763 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
3764 }
3765 /* Process change. */
3766 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3767 bgp_process (bgp, rn, afi, safi);
3768 bgp_unlock_node (rn);
3769 aspath_unintern (&attr.aspath);
3770 bgp_attr_extra_free (&attr);
3771 return;
3772 }
3773 }
3774
3775 /* Make new BGP info. */
3776 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
3777 rn);
3778 /* Nexthop reachability check. */
3779 if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3780 {
3781 if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
3782 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3783 else
3784 {
3785 if (BGP_DEBUG(nht, NHT))
3786 {
3787 char buf1[INET6_ADDRSTRLEN];
3788 inet_ntop(p->family, &p->u.prefix, buf1,
3789 INET6_ADDRSTRLEN);
3790 zlog_debug("%s(%s): Route not in table, not advertising",
3791 __FUNCTION__, buf1);
3792 }
3793 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
3794 }
3795 }
3796 else
3797 {
3798 /* Delete the NHT structure if any, if we're toggling between
3799 * enabling/disabling import check. We deregister the route
3800 * from NHT to avoid overloading NHT and the process interaction
3801 */
3802 bgp_unlink_nexthop(new);
3803
3804 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
3805 }
3806
3807 /* Aggregate address increment. */
3808 bgp_aggregate_increment (bgp, p, new, afi, safi);
3809
3810 /* Register new BGP information. */
3811 bgp_info_add (rn, new);
3812
3813 /* route_node_get lock */
3814 bgp_unlock_node (rn);
3815
3816 /* Process change. */
3817 bgp_process (bgp, rn, afi, safi);
3818
3819 /* Unintern original. */
3820 aspath_unintern (&attr.aspath);
3821 bgp_attr_extra_free (&attr);
3822 }
3823
3824 void
3825 bgp_static_update (struct bgp *bgp, struct prefix *p,
3826 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3827 {
3828 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3829 }
3830
3831 void
3832 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3833 safi_t safi)
3834 {
3835 struct bgp_node *rn;
3836 struct bgp_info *ri;
3837
3838 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3839
3840 /* Check selected route and self inserted route. */
3841 for (ri = rn->info; ri; ri = ri->next)
3842 if (ri->peer == bgp->peer_self
3843 && ri->type == ZEBRA_ROUTE_BGP
3844 && ri->sub_type == BGP_ROUTE_STATIC)
3845 break;
3846
3847 /* Withdraw static BGP route from routing table. */
3848 if (ri)
3849 {
3850 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3851 bgp_unlink_nexthop(ri);
3852 bgp_info_delete (rn, ri);
3853 bgp_process (bgp, rn, afi, safi);
3854 }
3855
3856 /* Unlock bgp_node_lookup. */
3857 bgp_unlock_node (rn);
3858 }
3859
3860 /*
3861 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3862 */
3863 static void
3864 bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3865 safi_t safi, struct prefix_rd *prd, u_char *tag)
3866 {
3867 struct bgp_node *rn;
3868 struct bgp_info *ri;
3869
3870 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3871
3872 /* Check selected route and self inserted route. */
3873 for (ri = rn->info; ri; ri = ri->next)
3874 if (ri->peer == bgp->peer_self
3875 && ri->type == ZEBRA_ROUTE_BGP
3876 && ri->sub_type == BGP_ROUTE_STATIC)
3877 break;
3878
3879 /* Withdraw static BGP route from routing table. */
3880 if (ri)
3881 {
3882 #if ENABLE_BGP_VNC
3883 rfapiProcessWithdraw(
3884 ri->peer,
3885 NULL,
3886 p,
3887 prd,
3888 ri->attr,
3889 afi,
3890 safi,
3891 ri->type,
3892 1); /* Kill, since it is an administrative change */
3893 #endif
3894 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3895 bgp_info_delete (rn, ri);
3896 bgp_process (bgp, rn, afi, safi);
3897 }
3898
3899 /* Unlock bgp_node_lookup. */
3900 bgp_unlock_node (rn);
3901 }
3902
3903 static void
3904 bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3905 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3906 {
3907 struct bgp_node *rn;
3908 struct bgp_info *new;
3909 struct attr *attr_new;
3910 struct attr attr = { 0 };
3911 struct bgp_info *ri;
3912 #if ENABLE_BGP_VNC
3913 u_int32_t label = 0;
3914 #endif
3915
3916 assert (bgp_static);
3917
3918 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3919
3920 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3921
3922 attr.nexthop = bgp_static->igpnexthop;
3923 attr.med = bgp_static->igpmetric;
3924 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3925
3926 /* Apply route-map. */
3927 if (bgp_static->rmap.name)
3928 {
3929 struct attr attr_tmp = attr;
3930 struct bgp_info info;
3931 int ret;
3932
3933 info.peer = bgp->peer_self;
3934 info.attr = &attr_tmp;
3935
3936 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3937
3938 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3939
3940 bgp->peer_self->rmap_type = 0;
3941
3942 if (ret == RMAP_DENYMATCH)
3943 {
3944 /* Free uninterned attribute. */
3945 bgp_attr_flush (&attr_tmp);
3946
3947 /* Unintern original. */
3948 aspath_unintern (&attr.aspath);
3949 bgp_attr_extra_free (&attr);
3950 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3951 bgp_static->tag);
3952 return;
3953 }
3954
3955 attr_new = bgp_attr_intern (&attr_tmp);
3956 }
3957 else
3958 {
3959 attr_new = bgp_attr_intern (&attr);
3960 }
3961
3962 for (ri = rn->info; ri; ri = ri->next)
3963 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3964 && ri->sub_type == BGP_ROUTE_STATIC)
3965 break;
3966
3967 if (ri)
3968 {
3969 if (attrhash_cmp (ri->attr, attr_new) &&
3970 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3971 {
3972 bgp_unlock_node (rn);
3973 bgp_attr_unintern (&attr_new);
3974 aspath_unintern (&attr.aspath);
3975 bgp_attr_extra_free (&attr);
3976 return;
3977 }
3978 else
3979 {
3980 /* The attribute is changed. */
3981 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3982
3983 /* Rewrite BGP route information. */
3984 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3985 bgp_info_restore(rn, ri);
3986 else
3987 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3988 bgp_attr_unintern (&ri->attr);
3989 ri->attr = attr_new;
3990 ri->uptime = bgp_clock ();
3991 #if ENABLE_BGP_VNC
3992 if (ri->extra)
3993 label = decode_label (ri->extra->tag);
3994 #endif
3995
3996 /* Process change. */
3997 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3998 bgp_process (bgp, rn, afi, safi);
3999 #if ENABLE_BGP_VNC
4000 rfapiProcessUpdate(ri->peer, NULL, p, &bgp_static->prd,
4001 ri->attr, afi, safi,
4002 ri->type, ri->sub_type, &label);
4003 #endif
4004 bgp_unlock_node (rn);
4005 aspath_unintern (&attr.aspath);
4006 bgp_attr_extra_free (&attr);
4007 return;
4008 }
4009 }
4010
4011
4012 /* Make new BGP info. */
4013 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
4014 rn);
4015 SET_FLAG (new->flags, BGP_INFO_VALID);
4016 new->extra = bgp_info_extra_new();
4017 memcpy (new->extra->tag, bgp_static->tag, 3);
4018 #if ENABLE_BGP_VNC
4019 label = decode_label (bgp_static->tag);
4020 #endif
4021
4022 /* Aggregate address increment. */
4023 bgp_aggregate_increment (bgp, p, new, afi, safi);
4024
4025 /* Register new BGP information. */
4026 bgp_info_add (rn, new);
4027
4028 /* route_node_get lock */
4029 bgp_unlock_node (rn);
4030
4031 /* Process change. */
4032 bgp_process (bgp, rn, afi, safi);
4033
4034 #if ENABLE_BGP_VNC
4035 rfapiProcessUpdate(new->peer, NULL, p, &bgp_static->prd,
4036 new->attr, afi, safi,
4037 new->type, new->sub_type, &label);
4038 #endif
4039
4040 /* Unintern original. */
4041 aspath_unintern (&attr.aspath);
4042 bgp_attr_extra_free (&attr);
4043 }
4044
4045 /* Configure static BGP network. When user don't run zebra, static
4046 route should be installed as valid. */
4047 static int
4048 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
4049 afi_t afi, safi_t safi, const char *rmap, int backdoor)
4050 {
4051 int ret;
4052 struct prefix p;
4053 struct bgp_static *bgp_static;
4054 struct bgp_node *rn;
4055 u_char need_update = 0;
4056
4057 /* Convert IP prefix string to struct prefix. */
4058 ret = str2prefix (ip_str, &p);
4059 if (! ret)
4060 {
4061 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4062 return CMD_WARNING;
4063 }
4064 #ifdef HAVE_IPV6
4065 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4066 {
4067 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4068 VTY_NEWLINE);
4069 return CMD_WARNING;
4070 }
4071 #endif /* HAVE_IPV6 */
4072
4073 apply_mask (&p);
4074
4075 /* Set BGP static route configuration. */
4076 rn = bgp_node_get (bgp->route[afi][safi], &p);
4077
4078 if (rn->info)
4079 {
4080 /* Configuration change. */
4081 bgp_static = rn->info;
4082
4083 /* Check previous routes are installed into BGP. */
4084 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4085 need_update = 1;
4086
4087 bgp_static->backdoor = backdoor;
4088
4089 if (rmap)
4090 {
4091 if (bgp_static->rmap.name)
4092 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4093 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4094 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4095 }
4096 else
4097 {
4098 if (bgp_static->rmap.name)
4099 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4100 bgp_static->rmap.name = NULL;
4101 bgp_static->rmap.map = NULL;
4102 bgp_static->valid = 0;
4103 }
4104 bgp_unlock_node (rn);
4105 }
4106 else
4107 {
4108 /* New configuration. */
4109 bgp_static = bgp_static_new ();
4110 bgp_static->backdoor = backdoor;
4111 bgp_static->valid = 0;
4112 bgp_static->igpmetric = 0;
4113 bgp_static->igpnexthop.s_addr = 0;
4114
4115 if (rmap)
4116 {
4117 if (bgp_static->rmap.name)
4118 XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
4119 bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
4120 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4121 }
4122 rn->info = bgp_static;
4123 }
4124
4125 bgp_static->valid = 1;
4126 if (need_update)
4127 bgp_static_withdraw (bgp, &p, afi, safi);
4128
4129 if (! bgp_static->backdoor)
4130 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4131
4132 return CMD_SUCCESS;
4133 }
4134
4135 /* Configure static BGP network. */
4136 static int
4137 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
4138 afi_t afi, safi_t safi)
4139 {
4140 int ret;
4141 struct prefix p;
4142 struct bgp_static *bgp_static;
4143 struct bgp_node *rn;
4144
4145 /* Convert IP prefix string to struct prefix. */
4146 ret = str2prefix (ip_str, &p);
4147 if (! ret)
4148 {
4149 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4150 return CMD_WARNING;
4151 }
4152 #ifdef HAVE_IPV6
4153 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4154 {
4155 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4156 VTY_NEWLINE);
4157 return CMD_WARNING;
4158 }
4159 #endif /* HAVE_IPV6 */
4160
4161 apply_mask (&p);
4162
4163 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4164 if (! rn)
4165 {
4166 vty_out (vty, "%% Can't find specified static route configuration.%s",
4167 VTY_NEWLINE);
4168 return CMD_WARNING;
4169 }
4170
4171 bgp_static = rn->info;
4172
4173 /* Update BGP RIB. */
4174 if (! bgp_static->backdoor)
4175 bgp_static_withdraw (bgp, &p, afi, safi);
4176
4177 /* Clear configuration. */
4178 bgp_static_free (bgp_static);
4179 rn->info = NULL;
4180 bgp_unlock_node (rn);
4181 bgp_unlock_node (rn);
4182
4183 return CMD_SUCCESS;
4184 }
4185
4186 void
4187 bgp_static_add (struct bgp *bgp)
4188 {
4189 afi_t afi;
4190 safi_t safi;
4191 struct bgp_node *rn;
4192 struct bgp_node *rm;
4193 struct bgp_table *table;
4194 struct bgp_static *bgp_static;
4195
4196 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4197 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4198 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4199 if (rn->info != NULL)
4200 {
4201 if (safi == SAFI_MPLS_VPN)
4202 {
4203 table = rn->info;
4204
4205 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4206 {
4207 bgp_static = rn->info;
4208 bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
4209 }
4210 }
4211 else
4212 {
4213 bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
4214 }
4215 }
4216 }
4217
4218 /* Called from bgp_delete(). Delete all static routes from the BGP
4219 instance. */
4220 void
4221 bgp_static_delete (struct bgp *bgp)
4222 {
4223 afi_t afi;
4224 safi_t safi;
4225 struct bgp_node *rn;
4226 struct bgp_node *rm;
4227 struct bgp_table *table;
4228 struct bgp_static *bgp_static;
4229
4230 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4231 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4232 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4233 if (rn->info != NULL)
4234 {
4235 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
4236 {
4237 table = rn->info;
4238
4239 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4240 {
4241 bgp_static = rn->info;
4242 bgp_static_withdraw_safi (bgp, &rm->p,
4243 AFI_IP, safi,
4244 (struct prefix_rd *)&rn->p,
4245 bgp_static->tag);
4246 bgp_static_free (bgp_static);
4247 rn->info = NULL;
4248 bgp_unlock_node (rn);
4249 }
4250 }
4251 else
4252 {
4253 bgp_static = rn->info;
4254 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4255 bgp_static_free (bgp_static);
4256 rn->info = NULL;
4257 bgp_unlock_node (rn);
4258 }
4259 }
4260 }
4261
4262 void
4263 bgp_static_redo_import_check (struct bgp *bgp)
4264 {
4265 afi_t afi;
4266 safi_t safi;
4267 struct bgp_node *rn;
4268 struct bgp_static *bgp_static;
4269
4270 /* Use this flag to force reprocessing of the route */
4271 bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4272 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4273 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4274 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4275 if (rn->info != NULL)
4276 {
4277 bgp_static = rn->info;
4278 bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
4279 }
4280 bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
4281 }
4282
4283 static void
4284 bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi)
4285 {
4286 struct bgp_table *table;
4287 struct bgp_node *rn;
4288 struct bgp_info *ri;
4289
4290 table = bgp->rib[afi][safi];
4291 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4292 {
4293 for (ri = rn->info; ri; ri = ri->next)
4294 {
4295 if (ri->peer == bgp->peer_self &&
4296 ((ri->type == ZEBRA_ROUTE_BGP &&
4297 ri->sub_type == BGP_ROUTE_STATIC) ||
4298 (ri->type != ZEBRA_ROUTE_BGP &&
4299 ri->sub_type == BGP_ROUTE_REDISTRIBUTE)))
4300 {
4301 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
4302 bgp_unlink_nexthop(ri);
4303 bgp_info_delete (rn, ri);
4304 bgp_process (bgp, rn, afi, safi);
4305 }
4306 }
4307 }
4308 }
4309
4310 /*
4311 * Purge all networks and redistributed routes from routing table.
4312 * Invoked upon the instance going down.
4313 */
4314 void
4315 bgp_purge_static_redist_routes (struct bgp *bgp)
4316 {
4317 afi_t afi;
4318 safi_t safi;
4319
4320 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4321 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4322 bgp_purge_af_static_redist_routes (bgp, afi, safi);
4323 }
4324
4325 /*
4326 * gpz 110624
4327 * Currently this is used to set static routes for VPN and ENCAP.
4328 * I think it can probably be factored with bgp_static_set.
4329 */
4330 int
4331 bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4332 const char *rd_str, const char *tag_str,
4333 const char *rmap_str)
4334 {
4335 int ret;
4336 struct prefix p;
4337 struct prefix_rd prd;
4338 struct bgp *bgp;
4339 struct bgp_node *prn;
4340 struct bgp_node *rn;
4341 struct bgp_table *table;
4342 struct bgp_static *bgp_static;
4343 u_char tag[3];
4344
4345 bgp = vty->index;
4346
4347 ret = str2prefix (ip_str, &p);
4348 if (! ret)
4349 {
4350 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4351 return CMD_WARNING;
4352 }
4353 apply_mask (&p);
4354
4355 ret = str2prefix_rd (rd_str, &prd);
4356 if (! ret)
4357 {
4358 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4359 return CMD_WARNING;
4360 }
4361
4362 ret = str2tag (tag_str, tag);
4363 if (! ret)
4364 {
4365 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4366 return CMD_WARNING;
4367 }
4368
4369 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4370 (struct prefix *)&prd);
4371 if (prn->info == NULL)
4372 prn->info = bgp_table_init (AFI_IP, safi);
4373 else
4374 bgp_unlock_node (prn);
4375 table = prn->info;
4376
4377 rn = bgp_node_get (table, &p);
4378
4379 if (rn->info)
4380 {
4381 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4382 bgp_unlock_node (rn);
4383 }
4384 else
4385 {
4386 /* New configuration. */
4387 bgp_static = bgp_static_new ();
4388 bgp_static->backdoor = 0;
4389 bgp_static->valid = 0;
4390 bgp_static->igpmetric = 0;
4391 bgp_static->igpnexthop.s_addr = 0;
4392 memcpy(bgp_static->tag, tag, 3);
4393 bgp_static->prd = prd;
4394
4395 if (rmap_str)
4396 {
4397 if (bgp_static->rmap.name)
4398 free (bgp_static->rmap.name);
4399 bgp_static->rmap.name = strdup (rmap_str);
4400 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4401 }
4402 rn->info = bgp_static;
4403
4404 bgp_static->valid = 1;
4405 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
4406 }
4407
4408 return CMD_SUCCESS;
4409 }
4410
4411 /* Configure static BGP network. */
4412 int
4413 bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4414 const char *rd_str, const char *tag_str)
4415 {
4416 int ret;
4417 struct bgp *bgp;
4418 struct prefix p;
4419 struct prefix_rd prd;
4420 struct bgp_node *prn;
4421 struct bgp_node *rn;
4422 struct bgp_table *table;
4423 struct bgp_static *bgp_static;
4424 u_char tag[3];
4425
4426 bgp = vty->index;
4427
4428 /* Convert IP prefix string to struct prefix. */
4429 ret = str2prefix (ip_str, &p);
4430 if (! ret)
4431 {
4432 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4433 return CMD_WARNING;
4434 }
4435 apply_mask (&p);
4436
4437 ret = str2prefix_rd (rd_str, &prd);
4438 if (! ret)
4439 {
4440 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4441 return CMD_WARNING;
4442 }
4443
4444 ret = str2tag (tag_str, tag);
4445 if (! ret)
4446 {
4447 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4448 return CMD_WARNING;
4449 }
4450
4451 prn = bgp_node_get (bgp->route[AFI_IP][safi],
4452 (struct prefix *)&prd);
4453 if (prn->info == NULL)
4454 prn->info = bgp_table_init (AFI_IP, safi);
4455 else
4456 bgp_unlock_node (prn);
4457 table = prn->info;
4458
4459 rn = bgp_node_lookup (table, &p);
4460
4461 if (rn)
4462 {
4463 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
4464
4465 bgp_static = rn->info;
4466 bgp_static_free (bgp_static);
4467 rn->info = NULL;
4468 bgp_unlock_node (rn);
4469 bgp_unlock_node (rn);
4470 }
4471 else
4472 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4473
4474 return CMD_SUCCESS;
4475 }
4476
4477 static int
4478 bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4479 const char *rmap_name)
4480 {
4481 struct bgp_rmap *rmap;
4482
4483 rmap = &bgp->table_map[afi][safi];
4484 if (rmap_name)
4485 {
4486 if (rmap->name)
4487 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4488 rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
4489 rmap->map = route_map_lookup_by_name (rmap_name);
4490 }
4491 else
4492 {
4493 if (rmap->name)
4494 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4495 rmap->name = NULL;
4496 rmap->map = NULL;
4497 }
4498
4499 bgp_zebra_announce_table(bgp, afi, safi);
4500
4501 return CMD_SUCCESS;
4502 }
4503
4504 static int
4505 bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
4506 const char *rmap_name)
4507 {
4508 struct bgp_rmap *rmap;
4509
4510 rmap = &bgp->table_map[afi][safi];
4511 if (rmap->name)
4512 XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
4513 rmap->name = NULL;
4514 rmap->map = NULL;
4515
4516 bgp_zebra_announce_table(bgp, afi, safi);
4517
4518 return CMD_SUCCESS;
4519 }
4520
4521 int
4522 bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi,
4523 safi_t safi, int *write)
4524 {
4525 if (bgp->table_map[afi][safi].name)
4526 {
4527 bgp_config_write_family_header (vty, afi, safi, write);
4528 vty_out (vty, " table-map %s%s",
4529 bgp->table_map[afi][safi].name, VTY_NEWLINE);
4530 }
4531
4532 return 0;
4533 }
4534
4535 DEFUN (bgp_table_map,
4536 bgp_table_map_cmd,
4537 "table-map WORD",
4538 "BGP table to RIB route download filter\n"
4539 "Name of the route map\n")
4540 {
4541 return bgp_table_map_set (vty, vty->index,
4542 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4543 }
4544 DEFUN (no_bgp_table_map,
4545 no_bgp_table_map_cmd,
4546 "no table-map WORD",
4547 "BGP table to RIB route download filter\n"
4548 "Name of the route map\n")
4549 {
4550 return bgp_table_map_unset (vty, vty->index,
4551 bgp_node_afi (vty), bgp_node_safi (vty), argv[0]);
4552 }
4553
4554 DEFUN (bgp_network,
4555 bgp_network_cmd,
4556 "network A.B.C.D/M",
4557 "Specify a network to announce via BGP\n"
4558 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4559 {
4560 return bgp_static_set (vty, vty->index, argv[0],
4561 AFI_IP, bgp_node_safi (vty), NULL, 0);
4562 }
4563
4564 DEFUN (bgp_network_route_map,
4565 bgp_network_route_map_cmd,
4566 "network A.B.C.D/M route-map WORD",
4567 "Specify a network to announce via BGP\n"
4568 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4569 "Route-map to modify the attributes\n"
4570 "Name of the route map\n")
4571 {
4572 return bgp_static_set (vty, vty->index, argv[0],
4573 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4574 }
4575
4576 DEFUN (bgp_network_backdoor,
4577 bgp_network_backdoor_cmd,
4578 "network A.B.C.D/M backdoor",
4579 "Specify a network to announce via BGP\n"
4580 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4581 "Specify a BGP backdoor route\n")
4582 {
4583 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4584 NULL, 1);
4585 }
4586
4587 DEFUN (bgp_network_mask,
4588 bgp_network_mask_cmd,
4589 "network A.B.C.D mask A.B.C.D",
4590 "Specify a network to announce via BGP\n"
4591 "Network number\n"
4592 "Network mask\n"
4593 "Network mask\n")
4594 {
4595 int ret;
4596 char prefix_str[BUFSIZ];
4597
4598 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4599 if (! ret)
4600 {
4601 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4602 return CMD_WARNING;
4603 }
4604
4605 return bgp_static_set (vty, vty->index, prefix_str,
4606 AFI_IP, bgp_node_safi (vty), NULL, 0);
4607 }
4608
4609 DEFUN (bgp_network_mask_route_map,
4610 bgp_network_mask_route_map_cmd,
4611 "network A.B.C.D mask A.B.C.D route-map WORD",
4612 "Specify a network to announce via BGP\n"
4613 "Network number\n"
4614 "Network mask\n"
4615 "Network mask\n"
4616 "Route-map to modify the attributes\n"
4617 "Name of the route map\n")
4618 {
4619 int ret;
4620 char prefix_str[BUFSIZ];
4621
4622 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4623 if (! ret)
4624 {
4625 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4626 return CMD_WARNING;
4627 }
4628
4629 return bgp_static_set (vty, vty->index, prefix_str,
4630 AFI_IP, bgp_node_safi (vty), argv[2], 0);
4631 }
4632
4633 DEFUN (bgp_network_mask_backdoor,
4634 bgp_network_mask_backdoor_cmd,
4635 "network A.B.C.D mask A.B.C.D backdoor",
4636 "Specify a network to announce via BGP\n"
4637 "Network number\n"
4638 "Network mask\n"
4639 "Network mask\n"
4640 "Specify a BGP backdoor route\n")
4641 {
4642 int ret;
4643 char prefix_str[BUFSIZ];
4644
4645 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4646 if (! ret)
4647 {
4648 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4649 return CMD_WARNING;
4650 }
4651
4652 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4653 NULL, 1);
4654 }
4655
4656 DEFUN (bgp_network_mask_natural,
4657 bgp_network_mask_natural_cmd,
4658 "network A.B.C.D",
4659 "Specify a network to announce via BGP\n"
4660 "Network number\n")
4661 {
4662 int ret;
4663 char prefix_str[BUFSIZ];
4664
4665 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4666 if (! ret)
4667 {
4668 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4669 return CMD_WARNING;
4670 }
4671
4672 return bgp_static_set (vty, vty->index, prefix_str,
4673 AFI_IP, bgp_node_safi (vty), NULL, 0);
4674 }
4675
4676 DEFUN (bgp_network_mask_natural_route_map,
4677 bgp_network_mask_natural_route_map_cmd,
4678 "network A.B.C.D route-map WORD",
4679 "Specify a network to announce via BGP\n"
4680 "Network number\n"
4681 "Route-map to modify the attributes\n"
4682 "Name of the route map\n")
4683 {
4684 int ret;
4685 char prefix_str[BUFSIZ];
4686
4687 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4688 if (! ret)
4689 {
4690 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4691 return CMD_WARNING;
4692 }
4693
4694 return bgp_static_set (vty, vty->index, prefix_str,
4695 AFI_IP, bgp_node_safi (vty), argv[1], 0);
4696 }
4697
4698 DEFUN (bgp_network_mask_natural_backdoor,
4699 bgp_network_mask_natural_backdoor_cmd,
4700 "network A.B.C.D backdoor",
4701 "Specify a network to announce via BGP\n"
4702 "Network number\n"
4703 "Specify a BGP backdoor route\n")
4704 {
4705 int ret;
4706 char prefix_str[BUFSIZ];
4707
4708 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4709 if (! ret)
4710 {
4711 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4712 return CMD_WARNING;
4713 }
4714
4715 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4716 NULL, 1);
4717 }
4718
4719 DEFUN (no_bgp_network,
4720 no_bgp_network_cmd,
4721 "no network A.B.C.D/M",
4722 NO_STR
4723 "Specify a network to announce via BGP\n"
4724 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4725 {
4726 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4727 bgp_node_safi (vty));
4728 }
4729
4730 ALIAS (no_bgp_network,
4731 no_bgp_network_route_map_cmd,
4732 "no network A.B.C.D/M route-map WORD",
4733 NO_STR
4734 "Specify a network to announce via BGP\n"
4735 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4736 "Route-map to modify the attributes\n"
4737 "Name of the route map\n")
4738
4739 ALIAS (no_bgp_network,
4740 no_bgp_network_backdoor_cmd,
4741 "no network A.B.C.D/M backdoor",
4742 NO_STR
4743 "Specify a network to announce via BGP\n"
4744 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4745 "Specify a BGP backdoor route\n")
4746
4747 DEFUN (no_bgp_network_mask,
4748 no_bgp_network_mask_cmd,
4749 "no network A.B.C.D mask A.B.C.D",
4750 NO_STR
4751 "Specify a network to announce via BGP\n"
4752 "Network number\n"
4753 "Network mask\n"
4754 "Network mask\n")
4755 {
4756 int ret;
4757 char prefix_str[BUFSIZ];
4758
4759 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4760 if (! ret)
4761 {
4762 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4763 return CMD_WARNING;
4764 }
4765
4766 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4767 bgp_node_safi (vty));
4768 }
4769
4770 ALIAS (no_bgp_network_mask,
4771 no_bgp_network_mask_route_map_cmd,
4772 "no network A.B.C.D mask A.B.C.D route-map WORD",
4773 NO_STR
4774 "Specify a network to announce via BGP\n"
4775 "Network number\n"
4776 "Network mask\n"
4777 "Network mask\n"
4778 "Route-map to modify the attributes\n"
4779 "Name of the route map\n")
4780
4781 ALIAS (no_bgp_network_mask,
4782 no_bgp_network_mask_backdoor_cmd,
4783 "no network A.B.C.D mask A.B.C.D backdoor",
4784 NO_STR
4785 "Specify a network to announce via BGP\n"
4786 "Network number\n"
4787 "Network mask\n"
4788 "Network mask\n"
4789 "Specify a BGP backdoor route\n")
4790
4791 DEFUN (no_bgp_network_mask_natural,
4792 no_bgp_network_mask_natural_cmd,
4793 "no network A.B.C.D",
4794 NO_STR
4795 "Specify a network to announce via BGP\n"
4796 "Network number\n")
4797 {
4798 int ret;
4799 char prefix_str[BUFSIZ];
4800
4801 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4802 if (! ret)
4803 {
4804 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4805 return CMD_WARNING;
4806 }
4807
4808 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4809 bgp_node_safi (vty));
4810 }
4811
4812 ALIAS (no_bgp_network_mask_natural,
4813 no_bgp_network_mask_natural_route_map_cmd,
4814 "no network A.B.C.D route-map WORD",
4815 NO_STR
4816 "Specify a network to announce via BGP\n"
4817 "Network number\n"
4818 "Route-map to modify the attributes\n"
4819 "Name of the route map\n")
4820
4821 ALIAS (no_bgp_network_mask_natural,
4822 no_bgp_network_mask_natural_backdoor_cmd,
4823 "no network A.B.C.D backdoor",
4824 NO_STR
4825 "Specify a network to announce via BGP\n"
4826 "Network number\n"
4827 "Specify a BGP backdoor route\n")
4828
4829 #ifdef HAVE_IPV6
4830 DEFUN (ipv6_bgp_network,
4831 ipv6_bgp_network_cmd,
4832 "network X:X::X:X/M",
4833 "Specify a network to announce via BGP\n"
4834 "IPv6 prefix <network>/<length>\n")
4835 {
4836 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
4837 NULL, 0);
4838 }
4839
4840 DEFUN (ipv6_bgp_network_route_map,
4841 ipv6_bgp_network_route_map_cmd,
4842 "network X:X::X:X/M route-map WORD",
4843 "Specify a network to announce via BGP\n"
4844 "IPv6 prefix <network>/<length>\n"
4845 "Route-map to modify the attributes\n"
4846 "Name of the route map\n")
4847 {
4848 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4849 bgp_node_safi (vty), argv[1], 0);
4850 }
4851
4852 DEFUN (no_ipv6_bgp_network,
4853 no_ipv6_bgp_network_cmd,
4854 "no network X:X::X:X/M",
4855 NO_STR
4856 "Specify a network to announce via BGP\n"
4857 "IPv6 prefix <network>/<length>\n")
4858 {
4859 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
4860 }
4861
4862 ALIAS (no_ipv6_bgp_network,
4863 no_ipv6_bgp_network_route_map_cmd,
4864 "no network X:X::X:X/M route-map WORD",
4865 NO_STR
4866 "Specify a network to announce via BGP\n"
4867 "IPv6 prefix <network>/<length>\n"
4868 "Route-map to modify the attributes\n"
4869 "Name of the route map\n")
4870
4871 ALIAS (ipv6_bgp_network,
4872 old_ipv6_bgp_network_cmd,
4873 "ipv6 bgp network X:X::X:X/M",
4874 IPV6_STR
4875 BGP_STR
4876 "Specify a network to announce via BGP\n"
4877 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4878
4879 ALIAS (no_ipv6_bgp_network,
4880 old_no_ipv6_bgp_network_cmd,
4881 "no ipv6 bgp network X:X::X:X/M",
4882 NO_STR
4883 IPV6_STR
4884 BGP_STR
4885 "Specify a network to announce via BGP\n"
4886 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4887 #endif /* HAVE_IPV6 */
4888
4889 /* Aggreagete address:
4890
4891 advertise-map Set condition to advertise attribute
4892 as-set Generate AS set path information
4893 attribute-map Set attributes of aggregate
4894 route-map Set parameters of aggregate
4895 summary-only Filter more specific routes from updates
4896 suppress-map Conditionally filter more specific routes from updates
4897 <cr>
4898 */
4899 struct bgp_aggregate
4900 {
4901 /* Summary-only flag. */
4902 u_char summary_only;
4903
4904 /* AS set generation. */
4905 u_char as_set;
4906
4907 /* Route-map for aggregated route. */
4908 struct route_map *map;
4909
4910 /* Suppress-count. */
4911 unsigned long count;
4912
4913 /* SAFI configuration. */
4914 safi_t safi;
4915 };
4916
4917 static struct bgp_aggregate *
4918 bgp_aggregate_new (void)
4919 {
4920 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4921 }
4922
4923 static void
4924 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4925 {
4926 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4927 }
4928
4929 /* Update an aggregate as routes are added/removed from the BGP table */
4930 static void
4931 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4932 afi_t afi, safi_t safi, struct bgp_info *del,
4933 struct bgp_aggregate *aggregate)
4934 {
4935 struct bgp_table *table;
4936 struct bgp_node *top;
4937 struct bgp_node *rn;
4938 u_char origin;
4939 struct aspath *aspath = NULL;
4940 struct aspath *asmerge = NULL;
4941 struct community *community = NULL;
4942 struct community *commerge = NULL;
4943 #if defined(AGGREGATE_NEXTHOP_CHECK)
4944 struct in_addr nexthop;
4945 u_int32_t med = 0;
4946 #endif
4947 struct bgp_info *ri;
4948 struct bgp_info *new;
4949 int first = 1;
4950 unsigned long match = 0;
4951 u_char atomic_aggregate = 0;
4952
4953 /* Record adding route's nexthop and med. */
4954 if (rinew)
4955 {
4956 #if defined(AGGREGATE_NEXTHOP_CHECK)
4957 nexthop = rinew->attr->nexthop;
4958 med = rinew->attr->med;
4959 #endif
4960 }
4961
4962 /* ORIGIN attribute: If at least one route among routes that are
4963 aggregated has ORIGIN with the value INCOMPLETE, then the
4964 aggregated route must have the ORIGIN attribute with the value
4965 INCOMPLETE. Otherwise, if at least one route among routes that
4966 are aggregated has ORIGIN with the value EGP, then the aggregated
4967 route must have the origin attribute with the value EGP. In all
4968 other case the value of the ORIGIN attribute of the aggregated
4969 route is INTERNAL. */
4970 origin = BGP_ORIGIN_IGP;
4971
4972 table = bgp->rib[afi][safi];
4973
4974 top = bgp_node_get (table, p);
4975 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4976 if (rn->p.prefixlen > p->prefixlen)
4977 {
4978 match = 0;
4979
4980 for (ri = rn->info; ri; ri = ri->next)
4981 {
4982 if (BGP_INFO_HOLDDOWN (ri))
4983 continue;
4984
4985 if (del && ri == del)
4986 continue;
4987
4988 if (! rinew && first)
4989 {
4990 #if defined(AGGREGATE_NEXTHOP_CHECK)
4991 nexthop = ri->attr->nexthop;
4992 med = ri->attr->med;
4993 #endif
4994 first = 0;
4995 }
4996
4997 #ifdef AGGREGATE_NEXTHOP_CHECK
4998 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4999 || ri->attr->med != med)
5000 {
5001 if (aspath)
5002 aspath_free (aspath);
5003 if (community)
5004 community_free (community);
5005 bgp_unlock_node (rn);
5006 bgp_unlock_node (top);
5007 return;
5008 }
5009 #endif /* AGGREGATE_NEXTHOP_CHECK */
5010
5011 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5012 atomic_aggregate = 1;
5013
5014 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5015 {
5016 if (aggregate->summary_only)
5017 {
5018 (bgp_info_extra_get (ri))->suppress++;
5019 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5020 match++;
5021 }
5022
5023 aggregate->count++;
5024
5025 if (origin < ri->attr->origin)
5026 origin = ri->attr->origin;
5027
5028 if (aggregate->as_set)
5029 {
5030 if (aspath)
5031 {
5032 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5033 aspath_free (aspath);
5034 aspath = asmerge;
5035 }
5036 else
5037 aspath = aspath_dup (ri->attr->aspath);
5038
5039 if (ri->attr->community)
5040 {
5041 if (community)
5042 {
5043 commerge = community_merge (community,
5044 ri->attr->community);
5045 community = community_uniq_sort (commerge);
5046 community_free (commerge);
5047 }
5048 else
5049 community = community_dup (ri->attr->community);
5050 }
5051 }
5052 }
5053 }
5054 if (match)
5055 bgp_process (bgp, rn, afi, safi);
5056 }
5057 bgp_unlock_node (top);
5058
5059 if (rinew)
5060 {
5061 aggregate->count++;
5062
5063 if (aggregate->summary_only)
5064 (bgp_info_extra_get (rinew))->suppress++;
5065
5066 if (origin < rinew->attr->origin)
5067 origin = rinew->attr->origin;
5068
5069 if (aggregate->as_set)
5070 {
5071 if (aspath)
5072 {
5073 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
5074 aspath_free (aspath);
5075 aspath = asmerge;
5076 }
5077 else
5078 aspath = aspath_dup (rinew->attr->aspath);
5079
5080 if (rinew->attr->community)
5081 {
5082 if (community)
5083 {
5084 commerge = community_merge (community,
5085 rinew->attr->community);
5086 community = community_uniq_sort (commerge);
5087 community_free (commerge);
5088 }
5089 else
5090 community = community_dup (rinew->attr->community);
5091 }
5092 }
5093 }
5094
5095 if (aggregate->count > 0)
5096 {
5097 rn = bgp_node_get (table, p);
5098 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5099 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5100 aggregate->as_set,
5101 atomic_aggregate), rn);
5102 SET_FLAG (new->flags, BGP_INFO_VALID);
5103
5104 bgp_info_add (rn, new);
5105 bgp_unlock_node (rn);
5106 bgp_process (bgp, rn, afi, safi);
5107 }
5108 else
5109 {
5110 if (aspath)
5111 aspath_free (aspath);
5112 if (community)
5113 community_free (community);
5114 }
5115 }
5116
5117 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
5118 struct bgp_aggregate *);
5119
5120 void
5121 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
5122 struct bgp_info *ri, afi_t afi, safi_t safi)
5123 {
5124 struct bgp_node *child;
5125 struct bgp_node *rn;
5126 struct bgp_aggregate *aggregate;
5127 struct bgp_table *table;
5128
5129 /* MPLS-VPN aggregation is not yet supported. */
5130 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5131 return;
5132
5133 table = bgp->aggregate[afi][safi];
5134
5135 /* No aggregates configured. */
5136 if (bgp_table_top_nolock (table) == NULL)
5137 return;
5138
5139 if (p->prefixlen == 0)
5140 return;
5141
5142 if (BGP_INFO_HOLDDOWN (ri))
5143 return;
5144
5145 child = bgp_node_get (table, p);
5146
5147 /* Aggregate address configuration check. */
5148 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5149 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5150 {
5151 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5152 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
5153 }
5154 bgp_unlock_node (child);
5155 }
5156
5157 void
5158 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5159 struct bgp_info *del, afi_t afi, safi_t safi)
5160 {
5161 struct bgp_node *child;
5162 struct bgp_node *rn;
5163 struct bgp_aggregate *aggregate;
5164 struct bgp_table *table;
5165
5166 /* MPLS-VPN aggregation is not yet supported. */
5167 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
5168 return;
5169
5170 table = bgp->aggregate[afi][safi];
5171
5172 /* No aggregates configured. */
5173 if (bgp_table_top_nolock (table) == NULL)
5174 return;
5175
5176 if (p->prefixlen == 0)
5177 return;
5178
5179 child = bgp_node_get (table, p);
5180
5181 /* Aggregate address configuration check. */
5182 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
5183 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5184 {
5185 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
5186 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
5187 }
5188 bgp_unlock_node (child);
5189 }
5190
5191 /* Called via bgp_aggregate_set when the user configures aggregate-address */
5192 static void
5193 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5194 struct bgp_aggregate *aggregate)
5195 {
5196 struct bgp_table *table;
5197 struct bgp_node *top;
5198 struct bgp_node *rn;
5199 struct bgp_info *new;
5200 struct bgp_info *ri;
5201 unsigned long match;
5202 u_char origin = BGP_ORIGIN_IGP;
5203 struct aspath *aspath = NULL;
5204 struct aspath *asmerge = NULL;
5205 struct community *community = NULL;
5206 struct community *commerge = NULL;
5207 u_char atomic_aggregate = 0;
5208
5209 table = bgp->rib[afi][safi];
5210
5211 /* Sanity check. */
5212 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5213 return;
5214 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5215 return;
5216
5217 /* If routes exists below this node, generate aggregate routes. */
5218 top = bgp_node_get (table, p);
5219 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5220 if (rn->p.prefixlen > p->prefixlen)
5221 {
5222 match = 0;
5223
5224 for (ri = rn->info; ri; ri = ri->next)
5225 {
5226 if (BGP_INFO_HOLDDOWN (ri))
5227 continue;
5228
5229 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5230 atomic_aggregate = 1;
5231
5232 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5233 {
5234 /* summary-only aggregate route suppress aggregated
5235 route announcement. */
5236 if (aggregate->summary_only)
5237 {
5238 (bgp_info_extra_get (ri))->suppress++;
5239 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5240 match++;
5241 }
5242
5243 /* If at least one route among routes that are aggregated has
5244 * ORIGIN with the value INCOMPLETE, then the aggregated route
5245 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5246 * Otherwise, if at least one route among routes that are
5247 * aggregated has ORIGIN with the value EGP, then the aggregated
5248 * route MUST have the ORIGIN attribute with the value EGP.
5249 */
5250 if (origin < ri->attr->origin)
5251 origin = ri->attr->origin;
5252
5253 /* as-set aggregate route generate origin, as path,
5254 community aggregation. */
5255 if (aggregate->as_set)
5256 {
5257 if (aspath)
5258 {
5259 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5260 aspath_free (aspath);
5261 aspath = asmerge;
5262 }
5263 else
5264 aspath = aspath_dup (ri->attr->aspath);
5265
5266 if (ri->attr->community)
5267 {
5268 if (community)
5269 {
5270 commerge = community_merge (community,
5271 ri->attr->community);
5272 community = community_uniq_sort (commerge);
5273 community_free (commerge);
5274 }
5275 else
5276 community = community_dup (ri->attr->community);
5277 }
5278 }
5279 aggregate->count++;
5280 }
5281 }
5282
5283 /* If this node is suppressed, process the change. */
5284 if (match)
5285 bgp_process (bgp, rn, afi, safi);
5286 }
5287 bgp_unlock_node (top);
5288
5289 /* Add aggregate route to BGP table. */
5290 if (aggregate->count)
5291 {
5292 rn = bgp_node_get (table, p);
5293 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self,
5294 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5295 aggregate->as_set,
5296 atomic_aggregate), rn);
5297 SET_FLAG (new->flags, BGP_INFO_VALID);
5298
5299 bgp_info_add (rn, new);
5300 bgp_unlock_node (rn);
5301
5302 /* Process change. */
5303 bgp_process (bgp, rn, afi, safi);
5304 }
5305 else
5306 {
5307 if (aspath)
5308 aspath_free (aspath);
5309 if (community)
5310 community_free (community);
5311 }
5312 }
5313
5314 void
5315 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5316 safi_t safi, struct bgp_aggregate *aggregate)
5317 {
5318 struct bgp_table *table;
5319 struct bgp_node *top;
5320 struct bgp_node *rn;
5321 struct bgp_info *ri;
5322 unsigned long match;
5323
5324 table = bgp->rib[afi][safi];
5325
5326 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5327 return;
5328 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5329 return;
5330
5331 /* If routes exists below this node, generate aggregate routes. */
5332 top = bgp_node_get (table, p);
5333 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5334 if (rn->p.prefixlen > p->prefixlen)
5335 {
5336 match = 0;
5337
5338 for (ri = rn->info; ri; ri = ri->next)
5339 {
5340 if (BGP_INFO_HOLDDOWN (ri))
5341 continue;
5342
5343 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5344 {
5345 if (aggregate->summary_only && ri->extra)
5346 {
5347 ri->extra->suppress--;
5348
5349 if (ri->extra->suppress == 0)
5350 {
5351 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
5352 match++;
5353 }
5354 }
5355 aggregate->count--;
5356 }
5357 }
5358
5359 /* If this node was suppressed, process the change. */
5360 if (match)
5361 bgp_process (bgp, rn, afi, safi);
5362 }
5363 bgp_unlock_node (top);
5364
5365 /* Delete aggregate route from BGP table. */
5366 rn = bgp_node_get (table, p);
5367
5368 for (ri = rn->info; ri; ri = ri->next)
5369 if (ri->peer == bgp->peer_self
5370 && ri->type == ZEBRA_ROUTE_BGP
5371 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5372 break;
5373
5374 /* Withdraw static BGP route from routing table. */
5375 if (ri)
5376 {
5377 bgp_info_delete (rn, ri);
5378 bgp_process (bgp, rn, afi, safi);
5379 }
5380
5381 /* Unlock bgp_node_lookup. */
5382 bgp_unlock_node (rn);
5383 }
5384
5385 /* Aggregate route attribute. */
5386 #define AGGREGATE_SUMMARY_ONLY 1
5387 #define AGGREGATE_AS_SET 1
5388
5389 static int
5390 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5391 afi_t afi, safi_t safi)
5392 {
5393 int ret;
5394 struct prefix p;
5395 struct bgp_node *rn;
5396 struct bgp *bgp;
5397 struct bgp_aggregate *aggregate;
5398
5399 /* Convert string to prefix structure. */
5400 ret = str2prefix (prefix_str, &p);
5401 if (!ret)
5402 {
5403 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5404 return CMD_WARNING;
5405 }
5406 apply_mask (&p);
5407
5408 /* Get BGP structure. */
5409 bgp = vty->index;
5410
5411 /* Old configuration check. */
5412 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5413 if (! rn)
5414 {
5415 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5416 VTY_NEWLINE);
5417 return CMD_WARNING;
5418 }
5419
5420 aggregate = rn->info;
5421 if (aggregate->safi & SAFI_UNICAST)
5422 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5423 if (aggregate->safi & SAFI_MULTICAST)
5424 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5425
5426 /* Unlock aggregate address configuration. */
5427 rn->info = NULL;
5428 bgp_aggregate_free (aggregate);
5429 bgp_unlock_node (rn);
5430 bgp_unlock_node (rn);
5431
5432 return CMD_SUCCESS;
5433 }
5434
5435 static int
5436 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
5437 afi_t afi, safi_t safi,
5438 u_char summary_only, u_char as_set)
5439 {
5440 int ret;
5441 struct prefix p;
5442 struct bgp_node *rn;
5443 struct bgp *bgp;
5444 struct bgp_aggregate *aggregate;
5445
5446 /* Convert string to prefix structure. */
5447 ret = str2prefix (prefix_str, &p);
5448 if (!ret)
5449 {
5450 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5451 return CMD_WARNING;
5452 }
5453 apply_mask (&p);
5454
5455 /* Get BGP structure. */
5456 bgp = vty->index;
5457
5458 /* Old configuration check. */
5459 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5460
5461 if (rn->info)
5462 {
5463 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5464 /* try to remove the old entry */
5465 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5466 if (ret)
5467 {
5468 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5469 bgp_unlock_node (rn);
5470 return CMD_WARNING;
5471 }
5472 }
5473
5474 /* Make aggregate address structure. */
5475 aggregate = bgp_aggregate_new ();
5476 aggregate->summary_only = summary_only;
5477 aggregate->as_set = as_set;
5478 aggregate->safi = safi;
5479 rn->info = aggregate;
5480
5481 /* Aggregate address insert into BGP routing table. */
5482 if (safi & SAFI_UNICAST)
5483 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5484 if (safi & SAFI_MULTICAST)
5485 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5486
5487 return CMD_SUCCESS;
5488 }
5489
5490 DEFUN (aggregate_address,
5491 aggregate_address_cmd,
5492 "aggregate-address A.B.C.D/M",
5493 "Configure BGP aggregate entries\n"
5494 "Aggregate prefix\n")
5495 {
5496 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5497 }
5498
5499 DEFUN (aggregate_address_mask,
5500 aggregate_address_mask_cmd,
5501 "aggregate-address A.B.C.D A.B.C.D",
5502 "Configure BGP aggregate entries\n"
5503 "Aggregate address\n"
5504 "Aggregate mask\n")
5505 {
5506 int ret;
5507 char prefix_str[BUFSIZ];
5508
5509 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5510
5511 if (! ret)
5512 {
5513 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5514 return CMD_WARNING;
5515 }
5516
5517 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5518 0, 0);
5519 }
5520
5521 DEFUN (aggregate_address_summary_only,
5522 aggregate_address_summary_only_cmd,
5523 "aggregate-address A.B.C.D/M summary-only",
5524 "Configure BGP aggregate entries\n"
5525 "Aggregate prefix\n"
5526 "Filter more specific routes from updates\n")
5527 {
5528 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5529 AGGREGATE_SUMMARY_ONLY, 0);
5530 }
5531
5532 DEFUN (aggregate_address_mask_summary_only,
5533 aggregate_address_mask_summary_only_cmd,
5534 "aggregate-address A.B.C.D A.B.C.D summary-only",
5535 "Configure BGP aggregate entries\n"
5536 "Aggregate address\n"
5537 "Aggregate mask\n"
5538 "Filter more specific routes from updates\n")
5539 {
5540 int ret;
5541 char prefix_str[BUFSIZ];
5542
5543 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5544
5545 if (! ret)
5546 {
5547 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5548 return CMD_WARNING;
5549 }
5550
5551 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5552 AGGREGATE_SUMMARY_ONLY, 0);
5553 }
5554
5555 DEFUN (aggregate_address_as_set,
5556 aggregate_address_as_set_cmd,
5557 "aggregate-address A.B.C.D/M as-set",
5558 "Configure BGP aggregate entries\n"
5559 "Aggregate prefix\n"
5560 "Generate AS set path information\n")
5561 {
5562 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5563 0, AGGREGATE_AS_SET);
5564 }
5565
5566 DEFUN (aggregate_address_mask_as_set,
5567 aggregate_address_mask_as_set_cmd,
5568 "aggregate-address A.B.C.D A.B.C.D as-set",
5569 "Configure BGP aggregate entries\n"
5570 "Aggregate address\n"
5571 "Aggregate mask\n"
5572 "Generate AS set path information\n")
5573 {
5574 int ret;
5575 char prefix_str[BUFSIZ];
5576
5577 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5578
5579 if (! ret)
5580 {
5581 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5582 return CMD_WARNING;
5583 }
5584
5585 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5586 0, AGGREGATE_AS_SET);
5587 }
5588
5589
5590 DEFUN (aggregate_address_as_set_summary,
5591 aggregate_address_as_set_summary_cmd,
5592 "aggregate-address A.B.C.D/M as-set summary-only",
5593 "Configure BGP aggregate entries\n"
5594 "Aggregate prefix\n"
5595 "Generate AS set path information\n"
5596 "Filter more specific routes from updates\n")
5597 {
5598 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5599 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5600 }
5601
5602 ALIAS (aggregate_address_as_set_summary,
5603 aggregate_address_summary_as_set_cmd,
5604 "aggregate-address A.B.C.D/M summary-only as-set",
5605 "Configure BGP aggregate entries\n"
5606 "Aggregate prefix\n"
5607 "Filter more specific routes from updates\n"
5608 "Generate AS set path information\n")
5609
5610 DEFUN (aggregate_address_mask_as_set_summary,
5611 aggregate_address_mask_as_set_summary_cmd,
5612 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5613 "Configure BGP aggregate entries\n"
5614 "Aggregate address\n"
5615 "Aggregate mask\n"
5616 "Generate AS set path information\n"
5617 "Filter more specific routes from updates\n")
5618 {
5619 int ret;
5620 char prefix_str[BUFSIZ];
5621
5622 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5623
5624 if (! ret)
5625 {
5626 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5627 return CMD_WARNING;
5628 }
5629
5630 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5631 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5632 }
5633
5634 ALIAS (aggregate_address_mask_as_set_summary,
5635 aggregate_address_mask_summary_as_set_cmd,
5636 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5637 "Configure BGP aggregate entries\n"
5638 "Aggregate address\n"
5639 "Aggregate mask\n"
5640 "Filter more specific routes from updates\n"
5641 "Generate AS set path information\n")
5642
5643 DEFUN (no_aggregate_address,
5644 no_aggregate_address_cmd,
5645 "no aggregate-address A.B.C.D/M",
5646 NO_STR
5647 "Configure BGP aggregate entries\n"
5648 "Aggregate prefix\n")
5649 {
5650 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5651 }
5652
5653 ALIAS (no_aggregate_address,
5654 no_aggregate_address_summary_only_cmd,
5655 "no aggregate-address A.B.C.D/M summary-only",
5656 NO_STR
5657 "Configure BGP aggregate entries\n"
5658 "Aggregate prefix\n"
5659 "Filter more specific routes from updates\n")
5660
5661 ALIAS (no_aggregate_address,
5662 no_aggregate_address_as_set_cmd,
5663 "no aggregate-address A.B.C.D/M as-set",
5664 NO_STR
5665 "Configure BGP aggregate entries\n"
5666 "Aggregate prefix\n"
5667 "Generate AS set path information\n")
5668
5669 ALIAS (no_aggregate_address,
5670 no_aggregate_address_as_set_summary_cmd,
5671 "no aggregate-address A.B.C.D/M as-set summary-only",
5672 NO_STR
5673 "Configure BGP aggregate entries\n"
5674 "Aggregate prefix\n"
5675 "Generate AS set path information\n"
5676 "Filter more specific routes from updates\n")
5677
5678 ALIAS (no_aggregate_address,
5679 no_aggregate_address_summary_as_set_cmd,
5680 "no aggregate-address A.B.C.D/M summary-only as-set",
5681 NO_STR
5682 "Configure BGP aggregate entries\n"
5683 "Aggregate prefix\n"
5684 "Filter more specific routes from updates\n"
5685 "Generate AS set path information\n")
5686
5687 DEFUN (no_aggregate_address_mask,
5688 no_aggregate_address_mask_cmd,
5689 "no aggregate-address A.B.C.D A.B.C.D",
5690 NO_STR
5691 "Configure BGP aggregate entries\n"
5692 "Aggregate address\n"
5693 "Aggregate mask\n")
5694 {
5695 int ret;
5696 char prefix_str[BUFSIZ];
5697
5698 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5699
5700 if (! ret)
5701 {
5702 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5703 return CMD_WARNING;
5704 }
5705
5706 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5707 }
5708
5709 ALIAS (no_aggregate_address_mask,
5710 no_aggregate_address_mask_summary_only_cmd,
5711 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5712 NO_STR
5713 "Configure BGP aggregate entries\n"
5714 "Aggregate address\n"
5715 "Aggregate mask\n"
5716 "Filter more specific routes from updates\n")
5717
5718 ALIAS (no_aggregate_address_mask,
5719 no_aggregate_address_mask_as_set_cmd,
5720 "no aggregate-address A.B.C.D A.B.C.D as-set",
5721 NO_STR
5722 "Configure BGP aggregate entries\n"
5723 "Aggregate address\n"
5724 "Aggregate mask\n"
5725 "Generate AS set path information\n")
5726
5727 ALIAS (no_aggregate_address_mask,
5728 no_aggregate_address_mask_as_set_summary_cmd,
5729 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5730 NO_STR
5731 "Configure BGP aggregate entries\n"
5732 "Aggregate address\n"
5733 "Aggregate mask\n"
5734 "Generate AS set path information\n"
5735 "Filter more specific routes from updates\n")
5736
5737 ALIAS (no_aggregate_address_mask,
5738 no_aggregate_address_mask_summary_as_set_cmd,
5739 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5740 NO_STR
5741 "Configure BGP aggregate entries\n"
5742 "Aggregate address\n"
5743 "Aggregate mask\n"
5744 "Filter more specific routes from updates\n"
5745 "Generate AS set path information\n")
5746
5747 #ifdef HAVE_IPV6
5748 DEFUN (ipv6_aggregate_address,
5749 ipv6_aggregate_address_cmd,
5750 "aggregate-address X:X::X:X/M",
5751 "Configure BGP aggregate entries\n"
5752 "Aggregate prefix\n")
5753 {
5754 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5755 }
5756
5757 DEFUN (ipv6_aggregate_address_summary_only,
5758 ipv6_aggregate_address_summary_only_cmd,
5759 "aggregate-address X:X::X:X/M summary-only",
5760 "Configure BGP aggregate entries\n"
5761 "Aggregate prefix\n"
5762 "Filter more specific routes from updates\n")
5763 {
5764 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5765 AGGREGATE_SUMMARY_ONLY, 0);
5766 }
5767
5768 DEFUN (no_ipv6_aggregate_address,
5769 no_ipv6_aggregate_address_cmd,
5770 "no aggregate-address X:X::X:X/M",
5771 NO_STR
5772 "Configure BGP aggregate entries\n"
5773 "Aggregate prefix\n")
5774 {
5775 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5776 }
5777
5778 DEFUN (no_ipv6_aggregate_address_summary_only,
5779 no_ipv6_aggregate_address_summary_only_cmd,
5780 "no aggregate-address X:X::X:X/M summary-only",
5781 NO_STR
5782 "Configure BGP aggregate entries\n"
5783 "Aggregate prefix\n"
5784 "Filter more specific routes from updates\n")
5785 {
5786 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5787 }
5788
5789 ALIAS (ipv6_aggregate_address,
5790 old_ipv6_aggregate_address_cmd,
5791 "ipv6 bgp aggregate-address X:X::X:X/M",
5792 IPV6_STR
5793 BGP_STR
5794 "Configure BGP aggregate entries\n"
5795 "Aggregate prefix\n")
5796
5797 ALIAS (ipv6_aggregate_address_summary_only,
5798 old_ipv6_aggregate_address_summary_only_cmd,
5799 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5800 IPV6_STR
5801 BGP_STR
5802 "Configure BGP aggregate entries\n"
5803 "Aggregate prefix\n"
5804 "Filter more specific routes from updates\n")
5805
5806 ALIAS (no_ipv6_aggregate_address,
5807 old_no_ipv6_aggregate_address_cmd,
5808 "no ipv6 bgp aggregate-address X:X::X:X/M",
5809 NO_STR
5810 IPV6_STR
5811 BGP_STR
5812 "Configure BGP aggregate entries\n"
5813 "Aggregate prefix\n")
5814
5815 ALIAS (no_ipv6_aggregate_address_summary_only,
5816 old_no_ipv6_aggregate_address_summary_only_cmd,
5817 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5818 NO_STR
5819 IPV6_STR
5820 BGP_STR
5821 "Configure BGP aggregate entries\n"
5822 "Aggregate prefix\n"
5823 "Filter more specific routes from updates\n")
5824 #endif /* HAVE_IPV6 */
5825
5826 /* Redistribute route treatment. */
5827 void
5828 bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
5829 const struct in6_addr *nexthop6, unsigned int ifindex,
5830 u_int32_t metric, u_char type, u_short instance, route_tag_t tag)
5831 {
5832 struct bgp_info *new;
5833 struct bgp_info *bi;
5834 struct bgp_info info;
5835 struct bgp_node *bn;
5836 struct attr attr;
5837 struct attr *new_attr;
5838 afi_t afi;
5839 int ret;
5840 struct bgp_redist *red;
5841
5842 /* Make default attribute. */
5843 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5844 if (nexthop)
5845 attr.nexthop = *nexthop;
5846 attr.nh_ifindex = ifindex;
5847
5848 #ifdef HAVE_IPV6
5849 if (nexthop6)
5850 {
5851 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5852 extra->mp_nexthop_global = *nexthop6;
5853 extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
5854 }
5855 #endif
5856
5857 attr.med = metric;
5858 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5859 attr.extra->tag = tag;
5860
5861 afi = family2afi (p->family);
5862
5863 red = bgp_redist_lookup(bgp, afi, type, instance);
5864 if (red)
5865 {
5866 struct attr attr_new;
5867 struct attr_extra extra_new;
5868
5869 /* Copy attribute for modification. */
5870 attr_new.extra = &extra_new;
5871 bgp_attr_dup (&attr_new, &attr);
5872
5873 if (red->redist_metric_flag)
5874 attr_new.med = red->redist_metric;
5875
5876 /* Apply route-map. */
5877 if (red->rmap.name)
5878 {
5879 info.peer = bgp->peer_self;
5880 info.attr = &attr_new;
5881
5882 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5883
5884 ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
5885
5886 bgp->peer_self->rmap_type = 0;
5887
5888 if (ret == RMAP_DENYMATCH)
5889 {
5890 /* Free uninterned attribute. */
5891 bgp_attr_flush (&attr_new);
5892
5893 /* Unintern original. */
5894 aspath_unintern (&attr.aspath);
5895 bgp_attr_extra_free (&attr);
5896 bgp_redistribute_delete (bgp, p, type, instance);
5897 return;
5898 }
5899 }
5900
5901 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5902 afi, SAFI_UNICAST, p, NULL);
5903
5904 new_attr = bgp_attr_intern (&attr_new);
5905
5906 for (bi = bn->info; bi; bi = bi->next)
5907 if (bi->peer == bgp->peer_self
5908 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5909 break;
5910
5911 if (bi)
5912 {
5913 /* Ensure the (source route) type is updated. */
5914 bi->type = type;
5915 if (attrhash_cmp (bi->attr, new_attr) &&
5916 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5917 {
5918 bgp_attr_unintern (&new_attr);
5919 aspath_unintern (&attr.aspath);
5920 bgp_attr_extra_free (&attr);
5921 bgp_unlock_node (bn);
5922 return;
5923 }
5924 else
5925 {
5926 /* The attribute is changed. */
5927 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5928
5929 /* Rewrite BGP route information. */
5930 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5931 bgp_info_restore(bn, bi);
5932 else
5933 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5934 bgp_attr_unintern (&bi->attr);
5935 bi->attr = new_attr;
5936 bi->uptime = bgp_clock ();
5937
5938 /* Process change. */
5939 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5940 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5941 bgp_unlock_node (bn);
5942 aspath_unintern (&attr.aspath);
5943 bgp_attr_extra_free (&attr);
5944 return;
5945 }
5946 }
5947
5948 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
5949 new_attr, bn);
5950 SET_FLAG (new->flags, BGP_INFO_VALID);
5951
5952 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5953 bgp_info_add (bn, new);
5954 bgp_unlock_node (bn);
5955 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5956 }
5957
5958 /* Unintern original. */
5959 aspath_unintern (&attr.aspath);
5960 bgp_attr_extra_free (&attr);
5961 }
5962
5963 void
5964 bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
5965 {
5966 afi_t afi;
5967 struct bgp_node *rn;
5968 struct bgp_info *ri;
5969 struct bgp_redist *red;
5970
5971 afi = family2afi (p->family);
5972
5973 red = bgp_redist_lookup(bgp, afi, type, instance);
5974 if (red)
5975 {
5976 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5977
5978 for (ri = rn->info; ri; ri = ri->next)
5979 if (ri->peer == bgp->peer_self
5980 && ri->type == type)
5981 break;
5982
5983 if (ri)
5984 {
5985 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5986 bgp_info_delete (rn, ri);
5987 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5988 }
5989 bgp_unlock_node (rn);
5990 }
5991 }
5992
5993 /* Withdraw specified route type's route. */
5994 void
5995 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance)
5996 {
5997 struct bgp_node *rn;
5998 struct bgp_info *ri;
5999 struct bgp_table *table;
6000
6001 table = bgp->rib[afi][SAFI_UNICAST];
6002
6003 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6004 {
6005 for (ri = rn->info; ri; ri = ri->next)
6006 if (ri->peer == bgp->peer_self
6007 && ri->type == type
6008 && ri->instance == instance)
6009 break;
6010
6011 if (ri)
6012 {
6013 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
6014 bgp_info_delete (rn, ri);
6015 bgp_process (bgp, rn, afi, SAFI_UNICAST);
6016 }
6017 }
6018 }
6019
6020 /* Static function to display route. */
6021 static void
6022 route_vty_out_route (struct prefix *p, struct vty *vty)
6023 {
6024 int len;
6025 u_int32_t destination;
6026 char buf[BUFSIZ];
6027
6028 if (p->family == AF_INET)
6029 {
6030 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
6031 destination = ntohl (p->u.prefix4.s_addr);
6032
6033 if ((IN_CLASSC (destination) && p->prefixlen == 24)
6034 || (IN_CLASSB (destination) && p->prefixlen == 16)
6035 || (IN_CLASSA (destination) && p->prefixlen == 8)
6036 || p->u.prefix4.s_addr == 0)
6037 {
6038 /* When mask is natural, mask is not displayed. */
6039 }
6040 else
6041 len += vty_out (vty, "/%d", p->prefixlen);
6042 }
6043 else
6044 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
6045 p->prefixlen);
6046
6047 len = 17 - len;
6048 if (len < 1)
6049 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
6050 else
6051 vty_out (vty, "%*s", len, " ");
6052 }
6053
6054 enum bgp_display_type
6055 {
6056 normal_list,
6057 };
6058
6059 /* Print the short form route status for a bgp_info */
6060 static void
6061 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo,
6062 json_object *json_path)
6063 {
6064 if (json_path)
6065 {
6066
6067 /* Route status display. */
6068 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6069 json_object_boolean_true_add(json_path, "removed");
6070
6071 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6072 json_object_boolean_true_add(json_path, "stale");
6073
6074 if (binfo->extra && binfo->extra->suppress)
6075 json_object_boolean_true_add(json_path, "suppressed");
6076
6077 if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6078 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6079 json_object_boolean_true_add(json_path, "valid");
6080
6081 /* Selected */
6082 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6083 json_object_boolean_true_add(json_path, "history");
6084
6085 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6086 json_object_boolean_true_add(json_path, "damped");
6087
6088 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6089 json_object_boolean_true_add(json_path, "bestpath");
6090
6091 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6092 json_object_boolean_true_add(json_path, "multipath");
6093
6094 /* Internal route. */
6095 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6096 json_object_string_add(json_path, "pathFrom", "internal");
6097 else
6098 json_object_string_add(json_path, "pathFrom", "external");
6099
6100 return;
6101 }
6102
6103 /* Route status display. */
6104 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6105 vty_out (vty, "R");
6106 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6107 vty_out (vty, "S");
6108 else if (binfo->extra && binfo->extra->suppress)
6109 vty_out (vty, "s");
6110 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
6111 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6112 vty_out (vty, "*");
6113 else
6114 vty_out (vty, " ");
6115
6116 /* Selected */
6117 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6118 vty_out (vty, "h");
6119 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6120 vty_out (vty, "d");
6121 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6122 vty_out (vty, ">");
6123 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
6124 vty_out (vty, "=");
6125 else
6126 vty_out (vty, " ");
6127
6128 /* Internal route. */
6129 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
6130 vty_out (vty, "i");
6131 else
6132 vty_out (vty, " ");
6133 }
6134
6135 /* called from terminal list command */
6136 void
6137 route_vty_out (struct vty *vty, struct prefix *p,
6138 struct bgp_info *binfo, int display, safi_t safi,
6139 json_object *json_paths)
6140 {
6141 struct attr *attr;
6142 json_object *json_path = NULL;
6143 json_object *json_nexthops = NULL;
6144 json_object *json_nexthop_global = NULL;
6145 json_object *json_nexthop_ll = NULL;
6146
6147 if (json_paths)
6148 json_path = json_object_new_object();
6149
6150 /* short status lead text */
6151 route_vty_short_status_out (vty, binfo, json_path);
6152
6153 if (!json_paths)
6154 {
6155 /* print prefix and mask */
6156 if (! display)
6157 route_vty_out_route (p, vty);
6158 else
6159 vty_out (vty, "%*s", 17, " ");
6160 }
6161
6162 /* Print attribute */
6163 attr = binfo->attr;
6164 if (attr)
6165 {
6166 /*
6167 * For ENCAP routes, nexthop address family is not
6168 * neccessarily the same as the prefix address family.
6169 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
6170 */
6171 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN))
6172 {
6173 if (attr->extra)
6174 {
6175 char buf[BUFSIZ];
6176 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
6177
6178 switch (af)
6179 {
6180 case AF_INET:
6181 vty_out (vty, "%s", inet_ntop(af,
6182 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
6183 break;
6184 #if HAVE_IPV6
6185 case AF_INET6:
6186 vty_out (vty, "%s", inet_ntop(af,
6187 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
6188 break;
6189 #endif
6190 default:
6191 vty_out(vty, "?");
6192 break;
6193 }
6194 }
6195 else
6196 vty_out(vty, "?");
6197 }
6198 /* IPv4 Next Hop */
6199 else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6200 {
6201 if (json_paths)
6202 {
6203 json_nexthop_global = json_object_new_object();
6204
6205 if (safi == SAFI_MPLS_VPN)
6206 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6207 else
6208 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6209
6210 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6211 json_object_boolean_true_add(json_nexthop_global, "used");
6212 }
6213 else
6214 {
6215 if (safi == SAFI_MPLS_VPN)
6216 vty_out (vty, "%-16s",
6217 inet_ntoa (attr->extra->mp_nexthop_global_in));
6218 else
6219 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6220 }
6221 }
6222
6223 /* IPv6 Next Hop */
6224 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6225 {
6226 int len;
6227 char buf[BUFSIZ];
6228
6229 if (json_paths)
6230 {
6231 json_nexthop_global = json_object_new_object();
6232 json_object_string_add(json_nexthop_global, "ip",
6233 inet_ntop (AF_INET6,
6234 &attr->extra->mp_nexthop_global,
6235 buf, BUFSIZ));
6236 json_object_string_add(json_nexthop_global, "afi", "ipv6");
6237 json_object_string_add(json_nexthop_global, "scope", "global");
6238
6239 /* We display both LL & GL if both have been received */
6240 if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if))
6241 {
6242 json_nexthop_ll = json_object_new_object();
6243 json_object_string_add(json_nexthop_ll, "ip",
6244 inet_ntop (AF_INET6,
6245 &attr->extra->mp_nexthop_local,
6246 buf, BUFSIZ));
6247 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
6248 json_object_string_add(json_nexthop_ll, "scope", "link-local");
6249
6250 if ((IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global,
6251 &attr->extra->mp_nexthop_local) != 0) &&
6252 !attr->extra->mp_nexthop_prefer_global)
6253 json_object_boolean_true_add(json_nexthop_ll, "used");
6254 else
6255 json_object_boolean_true_add(json_nexthop_global, "used");
6256 }
6257 else
6258 json_object_boolean_true_add(json_nexthop_global, "used");
6259 }
6260 else
6261 {
6262 /* Display LL if LL/Global both in table unless prefer-global is set */
6263 if (((attr->extra->mp_nexthop_len == 32) &&
6264 !attr->extra->mp_nexthop_prefer_global) ||
6265 (binfo->peer->conf_if))
6266 {
6267 if (binfo->peer->conf_if)
6268 {
6269 len = vty_out (vty, "%s",
6270 binfo->peer->conf_if);
6271 len = 7 - len; /* len of IPv6 addr + max len of def ifname */
6272
6273 if (len < 1)
6274 vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " ");
6275 else
6276 vty_out (vty, "%*s", len, " ");
6277 }
6278 else
6279 {
6280 len = vty_out (vty, "%s",
6281 inet_ntop (AF_INET6,
6282 &attr->extra->mp_nexthop_local,
6283 buf, BUFSIZ));
6284 len = 16 - len;
6285
6286 if (len < 1)
6287 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6288 else
6289 vty_out (vty, "%*s", len, " ");
6290 }
6291 }
6292 else
6293 {
6294 len = vty_out (vty, "%s",
6295 inet_ntop (AF_INET6,
6296 &attr->extra->mp_nexthop_global,
6297 buf, BUFSIZ));
6298 len = 16 - len;
6299
6300 if (len < 1)
6301 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6302 else
6303 vty_out (vty, "%*s", len, " ");
6304 }
6305 }
6306 }
6307
6308 /* MED/Metric */
6309 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6310 if (json_paths)
6311 json_object_int_add(json_path, "med", attr->med);
6312 else
6313 vty_out (vty, "%10u", attr->med);
6314 else
6315 if (!json_paths)
6316 vty_out (vty, " ");
6317
6318 /* Local Pref */
6319 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6320 if (json_paths)
6321 json_object_int_add(json_path, "localpref", attr->local_pref);
6322 else
6323 vty_out (vty, "%7u", attr->local_pref);
6324 else
6325 if (!json_paths)
6326 vty_out (vty, " ");
6327
6328 if (json_paths)
6329 {
6330 if (attr->extra)
6331 json_object_int_add(json_path, "weight", attr->extra->weight);
6332 else
6333 json_object_int_add(json_path, "weight", 0);
6334 }
6335 else
6336 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6337
6338 if (json_paths) {
6339 char buf[BUFSIZ];
6340 json_object_string_add(json_path, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6341 }
6342
6343 /* Print aspath */
6344 if (attr->aspath)
6345 {
6346 if (json_paths)
6347 json_object_string_add(json_path, "aspath", attr->aspath->str);
6348 else
6349 aspath_print_vty (vty, "%s", attr->aspath, " ");
6350 }
6351
6352 /* Print origin */
6353 if (json_paths)
6354 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
6355 else
6356 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6357 }
6358 else
6359 {
6360 if (json_paths)
6361 json_object_string_add(json_path, "alert", "No attributes");
6362 else
6363 vty_out (vty, "No attributes to print%s", VTY_NEWLINE);
6364 }
6365
6366 if (json_paths)
6367 {
6368 if (json_nexthop_global || json_nexthop_ll)
6369 {
6370 json_nexthops = json_object_new_array();
6371
6372 if (json_nexthop_global)
6373 json_object_array_add(json_nexthops, json_nexthop_global);
6374
6375 if (json_nexthop_ll)
6376 json_object_array_add(json_nexthops, json_nexthop_ll);
6377
6378 json_object_object_add(json_path, "nexthops", json_nexthops);
6379 }
6380
6381 json_object_array_add(json_paths, json_path);
6382 }
6383 else
6384 {
6385 vty_out (vty, "%s", VTY_NEWLINE);
6386 #if ENABLE_BGP_VNC
6387 /* prints an additional line, indented, with VNC info, if present */
6388 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
6389 rfapi_vty_out_vncinfo(vty, p, binfo, safi);
6390 #endif
6391 }
6392 }
6393
6394 /* called from terminal list command */
6395 void
6396 route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi,
6397 u_char use_json, json_object *json_ar)
6398 {
6399 json_object *json_status = NULL;
6400 json_object *json_net = NULL;
6401 char buff[BUFSIZ];
6402 /* Route status display. */
6403 if (use_json)
6404 {
6405 json_status = json_object_new_object();
6406 json_net = json_object_new_object();
6407 }
6408 else
6409 {
6410 vty_out (vty, "*");
6411 vty_out (vty, ">");
6412 vty_out (vty, " ");
6413 }
6414
6415 /* print prefix and mask */
6416 if (use_json)
6417 json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ));
6418 else
6419 route_vty_out_route (p, vty);
6420
6421 /* Print attribute */
6422 if (attr)
6423 {
6424 if (use_json)
6425 {
6426 if (p->family == AF_INET &&
6427 (safi == SAFI_MPLS_VPN ||
6428 safi == SAFI_ENCAP ||
6429 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6430 {
6431 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6432 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in));
6433 else
6434 json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop));
6435 }
6436 #ifdef HAVE_IPV6
6437 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6438 {
6439 char buf[BUFSIZ];
6440
6441 json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6442 buf, BUFSIZ));
6443 }
6444 #endif /* HAVE_IPV6 */
6445
6446 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6447 json_object_int_add(json_net, "metric", attr->med);
6448
6449 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6450 json_object_int_add(json_net, "localPref", attr->local_pref);
6451
6452 if (attr->extra)
6453 json_object_int_add(json_net, "weight", attr->extra->weight);
6454 else
6455 json_object_int_add(json_net, "weight", 0);
6456
6457 /* Print aspath */
6458 if (attr->aspath)
6459 json_object_string_add(json_net, "asPath", attr->aspath->str);
6460
6461 /* Print origin */
6462 json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]);
6463 }
6464 else
6465 {
6466 if (p->family == AF_INET &&
6467 (safi == SAFI_MPLS_VPN ||
6468 safi == SAFI_ENCAP ||
6469 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6470 {
6471 if (attr->extra &&
6472 (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP))
6473 vty_out (vty, "%-16s",
6474 inet_ntoa (attr->extra->mp_nexthop_global_in));
6475 else
6476 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6477 }
6478 #ifdef HAVE_IPV6
6479 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6480 {
6481 int len;
6482 char buf[BUFSIZ];
6483 if (attr->extra)
6484 {
6485 len = vty_out (vty, "%s",
6486 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6487 buf, BUFSIZ));
6488 len = 16 - len;
6489 }
6490 else
6491 len = 0;
6492 if (len < 1)
6493 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6494 else
6495 vty_out (vty, "%*s", len, " ");
6496 }
6497 #endif /* HAVE_IPV6 */
6498 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
6499 vty_out (vty, "%10u", attr->med);
6500 else
6501 vty_out (vty, " ");
6502
6503 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
6504 vty_out (vty, "%7u", attr->local_pref);
6505 else
6506 vty_out (vty, " ");
6507
6508 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
6509
6510 /* Print aspath */
6511 if (attr->aspath)
6512 aspath_print_vty (vty, "%s", attr->aspath, " ");
6513
6514 /* Print origin */
6515 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6516 }
6517 }
6518 if (use_json)
6519 {
6520 json_object_boolean_true_add(json_status, "*");
6521 json_object_boolean_true_add(json_status, ">");
6522 json_object_object_add(json_net, "appliedStatusSymbols", json_status);
6523 char buf_cut[BUFSIZ];
6524 json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net);
6525 }
6526 else
6527 vty_out (vty, "%s", VTY_NEWLINE);
6528 }
6529
6530 void
6531 route_vty_out_tag (struct vty *vty, struct prefix *p,
6532 struct bgp_info *binfo, int display, safi_t safi, json_object *json)
6533 {
6534 json_object *json_out = NULL;
6535 struct attr *attr;
6536 u_int32_t label = 0;
6537
6538 if (!binfo->extra)
6539 return;
6540
6541 if (json)
6542 json_out = json_object_new_object();
6543
6544 /* short status lead text */
6545 route_vty_short_status_out (vty, binfo, json_out);
6546
6547 /* print prefix and mask */
6548 if (json == NULL)
6549 {
6550 if (! display)
6551 route_vty_out_route (p, vty);
6552 else
6553 vty_out (vty, "%*s", 17, " ");
6554 }
6555
6556 /* Print attribute */
6557 attr = binfo->attr;
6558 if (attr)
6559 {
6560 if (p->family == AF_INET
6561 && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6562 {
6563 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6564 {
6565 if (json)
6566 json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in));
6567 else
6568 vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6569 }
6570 else
6571 {
6572 if (json)
6573 json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop));
6574 else
6575 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6576 }
6577 }
6578 #ifdef HAVE_IPV6
6579 else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr))
6580 {
6581 assert (attr->extra);
6582 char buf_a[BUFSIZ];
6583 char buf_b[BUFSIZ];
6584 char buf_c[BUFSIZ];
6585 if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL)
6586 {
6587 if (json)
6588 json_object_string_add(json_out, "mpNexthopGlobalIn",
6589 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ));
6590 else
6591 vty_out (vty, "%s",
6592 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6593 buf_a, BUFSIZ));
6594 }
6595 else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
6596 {
6597 if (json)
6598 {
6599 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6600 buf_a, BUFSIZ);
6601 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6602 buf_b, BUFSIZ);
6603 sprintf(buf_c, "%s(%s)", buf_a, buf_b);
6604 json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c);
6605 }
6606 else
6607 vty_out (vty, "%s(%s)",
6608 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6609 buf_a, BUFSIZ),
6610 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6611 buf_b, BUFSIZ));
6612 }
6613
6614 }
6615 #endif /* HAVE_IPV6 */
6616 }
6617
6618 label = decode_label (binfo->extra->tag);
6619
6620 if (json)
6621 {
6622 if (label)
6623 json_object_int_add(json_out, "notag", label);
6624 json_object_array_add(json, json_out);
6625 }
6626 else
6627 {
6628 vty_out (vty, "notag/%d", label);
6629 vty_out (vty, "%s", VTY_NEWLINE);
6630 }
6631 }
6632
6633 /* dampening route */
6634 static void
6635 damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6636 int display, safi_t safi, u_char use_json, json_object *json)
6637 {
6638 struct attr *attr;
6639 int len;
6640 char timebuf[BGP_UPTIME_LEN];
6641
6642 /* short status lead text */
6643 route_vty_short_status_out (vty, binfo, json);
6644
6645 /* print prefix and mask */
6646 if (!use_json)
6647 {
6648 if (! display)
6649 route_vty_out_route (p, vty);
6650 else
6651 vty_out (vty, "%*s", 17, " ");
6652 }
6653
6654 len = vty_out (vty, "%s", binfo->peer->host);
6655 len = 17 - len;
6656 if (len < 1)
6657 {
6658 if (!use_json)
6659 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6660 }
6661 else
6662 {
6663 if (use_json)
6664 json_object_int_add(json, "peerHost", len);
6665 else
6666 vty_out (vty, "%*s", len, " ");
6667 }
6668
6669 if (use_json)
6670 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6671 else
6672 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6673
6674 /* Print attribute */
6675 attr = binfo->attr;
6676 if (attr)
6677 {
6678 /* Print aspath */
6679 if (attr->aspath)
6680 {
6681 if (use_json)
6682 json_object_string_add(json, "asPath", attr->aspath->str);
6683 else
6684 aspath_print_vty (vty, "%s", attr->aspath, " ");
6685 }
6686
6687 /* Print origin */
6688 if (use_json)
6689 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6690 else
6691 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6692 }
6693 if (!use_json)
6694 vty_out (vty, "%s", VTY_NEWLINE);
6695 }
6696
6697 /* flap route */
6698 static void
6699 flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo,
6700 int display, safi_t safi, u_char use_json, json_object *json)
6701 {
6702 struct attr *attr;
6703 struct bgp_damp_info *bdi;
6704 char timebuf[BGP_UPTIME_LEN];
6705 int len;
6706
6707 if (!binfo->extra)
6708 return;
6709
6710 bdi = binfo->extra->damp_info;
6711
6712 /* short status lead text */
6713 route_vty_short_status_out (vty, binfo, json);
6714
6715 /* print prefix and mask */
6716 if (!use_json)
6717 {
6718 if (! display)
6719 route_vty_out_route (p, vty);
6720 else
6721 vty_out (vty, "%*s", 17, " ");
6722 }
6723
6724 len = vty_out (vty, "%s", binfo->peer->host);
6725 len = 16 - len;
6726 if (len < 1)
6727 {
6728 if (!use_json)
6729 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6730 }
6731 else
6732 {
6733 if (use_json)
6734 json_object_int_add(json, "peerHost", len);
6735 else
6736 vty_out (vty, "%*s", len, " ");
6737 }
6738
6739 len = vty_out (vty, "%d", bdi->flap);
6740 len = 5 - len;
6741 if (len < 1)
6742 {
6743 if (!use_json)
6744 vty_out (vty, " ");
6745 }
6746 else
6747 {
6748 if (use_json)
6749 json_object_int_add(json, "bdiFlap", len);
6750 else
6751 vty_out (vty, "%*s", len, " ");
6752 }
6753
6754 if (use_json)
6755 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json);
6756 else
6757 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6758 timebuf, BGP_UPTIME_LEN, 0, NULL));
6759
6760 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6761 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6762 {
6763 if (use_json)
6764 bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json);
6765 else
6766 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json));
6767 }
6768 else
6769 {
6770 if (!use_json)
6771 vty_out (vty, "%*s ", 8, " ");
6772 }
6773
6774 /* Print attribute */
6775 attr = binfo->attr;
6776 if (attr)
6777 {
6778 /* Print aspath */
6779 if (attr->aspath)
6780 {
6781 if (use_json)
6782 json_object_string_add(json, "asPath", attr->aspath->str);
6783 else
6784 aspath_print_vty (vty, "%s", attr->aspath, " ");
6785 }
6786
6787 /* Print origin */
6788 if (use_json)
6789 json_object_string_add(json, "origin", bgp_origin_str[attr->origin]);
6790 else
6791 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
6792 }
6793 if (!use_json)
6794 vty_out (vty, "%s", VTY_NEWLINE);
6795 }
6796
6797 static void
6798 route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first,
6799 const char *header, json_object *json_adv_to)
6800 {
6801 char buf1[INET6_ADDRSTRLEN];
6802 json_object *json_peer = NULL;
6803
6804 if (json_adv_to)
6805 {
6806 /* 'advertised-to' is a dictionary of peers we have advertised this
6807 * prefix too. The key is the peer's IP or swpX, the value is the
6808 * hostname if we know it and "" if not.
6809 */
6810 json_peer = json_object_new_object();
6811
6812 if (peer->hostname)
6813 json_object_string_add(json_peer, "hostname", peer->hostname);
6814
6815 if (peer->conf_if)
6816 json_object_object_add(json_adv_to, peer->conf_if, json_peer);
6817 else
6818 json_object_object_add(json_adv_to,
6819 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN),
6820 json_peer);
6821 }
6822 else
6823 {
6824 if (*first)
6825 {
6826 vty_out (vty, "%s", header);
6827 *first = 0;
6828 }
6829
6830 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
6831 {
6832 if (peer->conf_if)
6833 vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if);
6834 else
6835 vty_out (vty, " %s(%s)", peer->hostname,
6836 sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6837 }
6838 else
6839 {
6840 if (peer->conf_if)
6841 vty_out (vty, " %s", peer->conf_if);
6842 else
6843 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6844 }
6845 }
6846 }
6847
6848 static void
6849 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6850 struct bgp_info *binfo, afi_t afi, safi_t safi,
6851 json_object *json_paths)
6852 {
6853 char buf[INET6_ADDRSTRLEN];
6854 char buf1[BUFSIZ];
6855 struct attr *attr;
6856 int sockunion_vty_out (struct vty *, union sockunion *);
6857 #ifdef HAVE_CLOCK_MONOTONIC
6858 time_t tbuf;
6859 #endif
6860 json_object *json_bestpath = NULL;
6861 json_object *json_cluster_list = NULL;
6862 json_object *json_cluster_list_list = NULL;
6863 json_object *json_ext_community = NULL;
6864 json_object *json_last_update = NULL;
6865 json_object *json_nexthop_global = NULL;
6866 json_object *json_nexthop_ll = NULL;
6867 json_object *json_nexthops = NULL;
6868 json_object *json_path = NULL;
6869 json_object *json_peer = NULL;
6870 json_object *json_string = NULL;
6871 json_object *json_adv_to = NULL;
6872 int first = 0;
6873 struct listnode *node, *nnode;
6874 struct peer *peer;
6875 int addpath_capable;
6876 int has_adj;
6877 unsigned int first_as;
6878
6879 if (json_paths)
6880 {
6881 json_path = json_object_new_object();
6882 json_peer = json_object_new_object();
6883 json_nexthop_global = json_object_new_object();
6884 }
6885
6886 attr = binfo->attr;
6887
6888 if (attr)
6889 {
6890 /* Line1 display AS-path, Aggregator */
6891 if (attr->aspath)
6892 {
6893 if (json_paths)
6894 {
6895 json_object_lock(attr->aspath->json);
6896 json_object_object_add(json_path, "aspath", attr->aspath->json);
6897 }
6898 else
6899 {
6900 if (attr->aspath->segments)
6901 aspath_print_vty (vty, " %s", attr->aspath, "");
6902 else
6903 vty_out (vty, " Local");
6904 }
6905 }
6906
6907 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6908 {
6909 if (json_paths)
6910 json_object_boolean_true_add(json_path, "removed");
6911 else
6912 vty_out (vty, ", (removed)");
6913 }
6914
6915 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6916 {
6917 if (json_paths)
6918 json_object_boolean_true_add(json_path, "stale");
6919 else
6920 vty_out (vty, ", (stale)");
6921 }
6922
6923 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
6924 {
6925 if (json_paths)
6926 {
6927 json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as);
6928 json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr));
6929 }
6930 else
6931 {
6932 vty_out (vty, ", (aggregated by %u %s)",
6933 attr->extra->aggregator_as,
6934 inet_ntoa (attr->extra->aggregator_addr));
6935 }
6936 }
6937
6938 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6939 {
6940 if (json_paths)
6941 json_object_boolean_true_add(json_path, "rxedFromRrClient");
6942 else
6943 vty_out (vty, ", (Received from a RR-client)");
6944 }
6945
6946 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6947 {
6948 if (json_paths)
6949 json_object_boolean_true_add(json_path, "rxedFromRsClient");
6950 else
6951 vty_out (vty, ", (Received from a RS-client)");
6952 }
6953
6954 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6955 {
6956 if (json_paths)
6957 json_object_boolean_true_add(json_path, "dampeningHistoryEntry");
6958 else
6959 vty_out (vty, ", (history entry)");
6960 }
6961 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6962 {
6963 if (json_paths)
6964 json_object_boolean_true_add(json_path, "dampeningSuppressed");
6965 else
6966 vty_out (vty, ", (suppressed due to dampening)");
6967 }
6968
6969 if (!json_paths)
6970 vty_out (vty, "%s", VTY_NEWLINE);
6971
6972 /* Line2 display Next-hop, Neighbor, Router-id */
6973 /* Display the nexthop */
6974 if (p->family == AF_INET &&
6975 (safi == SAFI_MPLS_VPN ||
6976 safi == SAFI_ENCAP ||
6977 !BGP_ATTR_NEXTHOP_AFI_IP6(attr)))
6978 {
6979 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
6980 {
6981 if (json_paths)
6982 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
6983 else
6984 vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in));
6985 }
6986 else
6987 {
6988 if (json_paths)
6989 json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
6990 else
6991 vty_out (vty, " %s", inet_ntoa (attr->nexthop));
6992 }
6993
6994 if (json_paths)
6995 json_object_string_add(json_nexthop_global, "afi", "ipv4");
6996 }
6997 else
6998 {
6999 assert (attr->extra);
7000 if (json_paths)
7001 {
7002 json_object_string_add(json_nexthop_global, "ip",
7003 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7004 buf, INET6_ADDRSTRLEN));
7005 json_object_string_add(json_nexthop_global, "afi", "ipv6");
7006 json_object_string_add(json_nexthop_global, "scope", "global");
7007 }
7008 else
7009 {
7010 vty_out (vty, " %s",
7011 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
7012 buf, INET6_ADDRSTRLEN));
7013 }
7014 }
7015
7016 /* Display the IGP cost or 'inaccessible' */
7017 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7018 {
7019 if (json_paths)
7020 json_object_boolean_false_add(json_nexthop_global, "accessible");
7021 else
7022 vty_out (vty, " (inaccessible)");
7023 }
7024 else
7025 {
7026 if (binfo->extra && binfo->extra->igpmetric)
7027 {
7028 if (json_paths)
7029 json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric);
7030 else
7031 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
7032 }
7033
7034 /* IGP cost is 0, display this only for json */
7035 else
7036 {
7037 if (json_paths)
7038 json_object_int_add(json_nexthop_global, "metric", 0);
7039 }
7040
7041 if (json_paths)
7042 json_object_boolean_true_add(json_nexthop_global, "accessible");
7043 }
7044
7045 /* Display peer "from" output */
7046 /* This path was originated locally */
7047 if (binfo->peer == bgp->peer_self)
7048 {
7049
7050 if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
7051 {
7052 if (json_paths)
7053 json_object_string_add(json_peer, "peerId", "0.0.0.0");
7054 else
7055 vty_out (vty, " from 0.0.0.0 ");
7056 }
7057 else
7058 {
7059 if (json_paths)
7060 json_object_string_add(json_peer, "peerId", "::");
7061 else
7062 vty_out (vty, " from :: ");
7063 }
7064
7065 if (json_paths)
7066 json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id));
7067 else
7068 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
7069 }
7070
7071 /* We RXed this path from one of our peers */
7072 else
7073 {
7074
7075 if (json_paths)
7076 {
7077 json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7078 json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7079
7080 if (binfo->peer->hostname)
7081 json_object_string_add(json_peer, "hostname", binfo->peer->hostname);
7082
7083 if (binfo->peer->domainname)
7084 json_object_string_add(json_peer, "domainname", binfo->peer->domainname);
7085
7086 if (binfo->peer->conf_if)
7087 json_object_string_add(json_peer, "interface", binfo->peer->conf_if);
7088 }
7089 else
7090 {
7091 if (binfo->peer->conf_if)
7092 {
7093 if (binfo->peer->hostname &&
7094 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7095 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7096 binfo->peer->conf_if);
7097 else
7098 vty_out (vty, " from %s", binfo->peer->conf_if);
7099 }
7100 else
7101 {
7102 if (binfo->peer->hostname &&
7103 bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
7104 vty_out (vty, " from %s(%s)", binfo->peer->hostname,
7105 binfo->peer->host);
7106 else
7107 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
7108 }
7109
7110 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7111 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
7112 else
7113 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
7114 }
7115 }
7116
7117 if (!json_paths)
7118 vty_out (vty, "%s", VTY_NEWLINE);
7119
7120 /* display the link-local nexthop */
7121 if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
7122 {
7123 if (json_paths)
7124 {
7125 json_nexthop_ll = json_object_new_object();
7126 json_object_string_add(json_nexthop_ll, "ip",
7127 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7128 buf, INET6_ADDRSTRLEN));
7129 json_object_string_add(json_nexthop_ll, "afi", "ipv6");
7130 json_object_string_add(json_nexthop_ll, "scope", "link-local");
7131
7132 json_object_boolean_true_add(json_nexthop_ll, "accessible");
7133
7134 if (!attr->extra->mp_nexthop_prefer_global)
7135 json_object_boolean_true_add(json_nexthop_ll, "used");
7136 else
7137 json_object_boolean_true_add(json_nexthop_global, "used");
7138 }
7139 else
7140 {
7141 vty_out (vty, " (%s) %s%s",
7142 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
7143 buf, INET6_ADDRSTRLEN),
7144 attr->extra->mp_nexthop_prefer_global ?
7145 "(prefer-global)" : "(used)",
7146 VTY_NEWLINE);
7147 }
7148 }
7149 /* If we do not have a link-local nexthop then we must flag the global as "used" */
7150 else
7151 {
7152 if (json_paths)
7153 json_object_boolean_true_add(json_nexthop_global, "used");
7154 }
7155
7156 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
7157 if (json_paths)
7158 json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]);
7159 else
7160 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
7161
7162 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
7163 {
7164 if (json_paths)
7165 json_object_int_add(json_path, "med", attr->med);
7166 else
7167 vty_out (vty, ", metric %u", attr->med);
7168 }
7169
7170 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
7171 {
7172 if (json_paths)
7173 json_object_int_add(json_path, "localpref", attr->local_pref);
7174 else
7175 vty_out (vty, ", localpref %u", attr->local_pref);
7176 }
7177 else
7178 {
7179 if (json_paths)
7180 json_object_int_add(json_path, "localpref", bgp->default_local_pref);
7181 else
7182 vty_out (vty, ", localpref %u", bgp->default_local_pref);
7183 }
7184
7185 if (attr->extra && attr->extra->weight != 0)
7186 {
7187 if (json_paths)
7188 json_object_int_add(json_path, "weight", attr->extra->weight);
7189 else
7190 vty_out (vty, ", weight %u", attr->extra->weight);
7191 }
7192
7193 if (attr->extra && attr->extra->tag != 0)
7194 {
7195 if (json_paths)
7196 json_object_int_add(json_path, "tag", attr->extra->tag);
7197 else
7198 vty_out (vty, ", tag %"ROUTE_TAG_PRI, attr->extra->tag);
7199 }
7200
7201 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
7202 {
7203 if (json_paths)
7204 json_object_boolean_false_add(json_path, "valid");
7205 else
7206 vty_out (vty, ", invalid");
7207 }
7208 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
7209 {
7210 if (json_paths)
7211 json_object_boolean_true_add(json_path, "valid");
7212 else
7213 vty_out (vty, ", valid");
7214 }
7215
7216 if (binfo->peer != bgp->peer_self)
7217 {
7218 if (binfo->peer->as == binfo->peer->local_as)
7219 {
7220 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7221 {
7222 if (json_paths)
7223 json_object_string_add(json_peer, "type", "confed-internal");
7224 else
7225 vty_out (vty, ", confed-internal");
7226 }
7227 else
7228 {
7229 if (json_paths)
7230 json_object_string_add(json_peer, "type", "internal");
7231 else
7232 vty_out (vty, ", internal");
7233 }
7234 }
7235 else
7236 {
7237 if (bgp_confederation_peers_check(bgp, binfo->peer->as))
7238 {
7239 if (json_paths)
7240 json_object_string_add(json_peer, "type", "confed-external");
7241 else
7242 vty_out (vty, ", confed-external");
7243 }
7244 else
7245 {
7246 if (json_paths)
7247 json_object_string_add(json_peer, "type", "external");
7248 else
7249 vty_out (vty, ", external");
7250 }
7251 }
7252 }
7253 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
7254 {
7255 if (json_paths)
7256 {
7257 json_object_boolean_true_add(json_path, "aggregated");
7258 json_object_boolean_true_add(json_path, "local");
7259 }
7260 else
7261 {
7262 vty_out (vty, ", aggregated, local");
7263 }
7264 }
7265 else if (binfo->type != ZEBRA_ROUTE_BGP)
7266 {
7267 if (json_paths)
7268 json_object_boolean_true_add(json_path, "sourced");
7269 else
7270 vty_out (vty, ", sourced");
7271 }
7272 else
7273 {
7274 if (json_paths)
7275 {
7276 json_object_boolean_true_add(json_path, "sourced");
7277 json_object_boolean_true_add(json_path, "local");
7278 }
7279 else
7280 {
7281 vty_out (vty, ", sourced, local");
7282 }
7283 }
7284
7285 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
7286 {
7287 if (json_paths)
7288 json_object_boolean_true_add(json_path, "atomicAggregate");
7289 else
7290 vty_out (vty, ", atomic-aggregate");
7291 }
7292
7293 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
7294 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
7295 bgp_info_mpath_count (binfo)))
7296 {
7297 if (json_paths)
7298 json_object_boolean_true_add(json_path, "multipath");
7299 else
7300 vty_out (vty, ", multipath");
7301 }
7302
7303 // Mark the bestpath(s)
7304 if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED))
7305 {
7306 first_as = aspath_get_first_as(attr->aspath);
7307
7308 if (json_paths)
7309 {
7310 if (!json_bestpath)
7311 json_bestpath = json_object_new_object();
7312 json_object_int_add(json_bestpath, "bestpathFromAs", first_as);
7313 }
7314 else
7315 {
7316 if (first_as)
7317 vty_out (vty, ", bestpath-from-AS %d", first_as);
7318 else
7319 vty_out (vty, ", bestpath-from-AS Local");
7320 }
7321 }
7322
7323 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
7324 {
7325 if (json_paths)
7326 {
7327 if (!json_bestpath)
7328 json_bestpath = json_object_new_object();
7329 json_object_boolean_true_add(json_bestpath, "overall");
7330 }
7331 else
7332 vty_out (vty, ", best");
7333 }
7334
7335 if (json_bestpath)
7336 json_object_object_add(json_path, "bestpath", json_bestpath);
7337
7338 if (!json_paths)
7339 vty_out (vty, "%s", VTY_NEWLINE);
7340
7341 /* Line 4 display Community */
7342 if (attr->community)
7343 {
7344 if (json_paths)
7345 {
7346 json_object_lock(attr->community->json);
7347 json_object_object_add(json_path, "community", attr->community->json);
7348 }
7349 else
7350 {
7351 vty_out (vty, " Community: %s%s", attr->community->str,
7352 VTY_NEWLINE);
7353 }
7354 }
7355
7356 /* Line 5 display Extended-community */
7357 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
7358 {
7359 if (json_paths)
7360 {
7361 json_ext_community = json_object_new_object();
7362 json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str);
7363 json_object_object_add(json_path, "extendedCommunity", json_ext_community);
7364 }
7365 else
7366 {
7367 vty_out (vty, " Extended Community: %s%s",
7368 attr->extra->ecommunity->str, VTY_NEWLINE);
7369 }
7370 }
7371
7372 /* Line 6 display Originator, Cluster-id */
7373 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
7374 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
7375 {
7376 assert (attr->extra);
7377 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
7378 {
7379 if (json_paths)
7380 json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id));
7381 else
7382 vty_out (vty, " Originator: %s",
7383 inet_ntoa (attr->extra->originator_id));
7384 }
7385
7386 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
7387 {
7388 int i;
7389
7390 if (json_paths)
7391 {
7392 json_cluster_list = json_object_new_object();
7393 json_cluster_list_list = json_object_new_array();
7394
7395 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7396 {
7397 json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i]));
7398 json_object_array_add(json_cluster_list_list, json_string);
7399 }
7400
7401 /* struct cluster_list does not have "str" variable like
7402 * aspath and community do. Add this someday if someone
7403 * asks for it.
7404 json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str);
7405 */
7406 json_object_object_add(json_cluster_list, "list", json_cluster_list_list);
7407 json_object_object_add(json_path, "clusterList", json_cluster_list);
7408 }
7409 else
7410 {
7411 vty_out (vty, ", Cluster list: ");
7412
7413 for (i = 0; i < attr->extra->cluster->length / 4; i++)
7414 {
7415 vty_out (vty, "%s ",
7416 inet_ntoa (attr->extra->cluster->list[i]));
7417 }
7418 }
7419 }
7420
7421 if (!json_paths)
7422 vty_out (vty, "%s", VTY_NEWLINE);
7423 }
7424
7425 if (binfo->extra && binfo->extra->damp_info)
7426 bgp_damp_info_vty (vty, binfo, json_path);
7427
7428 /* Line 7 display Addpath IDs */
7429 if (binfo->addpath_rx_id || binfo->addpath_tx_id)
7430 {
7431 if (json_paths)
7432 {
7433 json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id);
7434 json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id);
7435 }
7436 else
7437 {
7438 vty_out (vty, " AddPath ID: RX %u, TX %u%s",
7439 binfo->addpath_rx_id, binfo->addpath_tx_id,
7440 VTY_NEWLINE);
7441 }
7442 }
7443
7444 /* If we used addpath to TX a non-bestpath we need to display
7445 * "Advertised to" on a path-by-path basis */
7446 if (bgp->addpath_tx_used[afi][safi])
7447 {
7448 first = 1;
7449
7450 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
7451 {
7452 addpath_capable = bgp_addpath_encode_tx (peer, afi, safi);
7453 has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id);
7454
7455 if ((addpath_capable && has_adj) ||
7456 (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)))
7457 {
7458 if (json_path && !json_adv_to)
7459 json_adv_to = json_object_new_object();
7460
7461 route_vty_out_advertised_to(vty, peer, &first,
7462 " Advertised to:",
7463 json_adv_to);
7464 }
7465 }
7466
7467 if (json_path)
7468 {
7469 if (json_adv_to)
7470 {
7471 json_object_object_add(json_path, "advertisedTo", json_adv_to);
7472 }
7473 }
7474 else
7475 {
7476 if (!first)
7477 {
7478 vty_out (vty, "%s", VTY_NEWLINE);
7479 }
7480 }
7481 }
7482
7483 /* Line 8 display Uptime */
7484 #ifdef HAVE_CLOCK_MONOTONIC
7485 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
7486 if (json_paths)
7487 {
7488 json_last_update = json_object_new_object();
7489 json_object_int_add(json_last_update, "epoch", tbuf);
7490 json_object_string_add(json_last_update, "string", ctime(&tbuf));
7491 json_object_object_add(json_path, "lastUpdate", json_last_update);
7492 }
7493 else
7494 vty_out (vty, " Last update: %s", ctime(&tbuf));
7495 #else
7496 if (json_paths)
7497 {
7498 json_last_update = json_object_new_object();
7499 json_object_int_add(json_last_update, "epoch", tbuf);
7500 json_object_string_add(json_last_update, "string", ctime(&binfo->uptime));
7501 json_object_object_add(json_path, "lastUpdate", json_last_update);
7502 }
7503 else
7504 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
7505 #endif /* HAVE_CLOCK_MONOTONIC */
7506 }
7507
7508 /* We've constructed the json object for this path, add it to the json
7509 * array of paths
7510 */
7511 if (json_paths)
7512 {
7513 if (json_nexthop_global || json_nexthop_ll)
7514 {
7515 json_nexthops = json_object_new_array();
7516
7517 if (json_nexthop_global)
7518 json_object_array_add(json_nexthops, json_nexthop_global);
7519
7520 if (json_nexthop_ll)
7521 json_object_array_add(json_nexthops, json_nexthop_ll);
7522
7523 json_object_object_add(json_path, "nexthops", json_nexthops);
7524 }
7525
7526 json_object_object_add(json_path, "peer", json_peer);
7527 json_object_array_add(json_paths, json_path);
7528 }
7529 else
7530 vty_out (vty, "%s", VTY_NEWLINE);
7531 }
7532
7533 #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s"
7534 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
7535 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
7536
7537 enum bgp_show_type
7538 {
7539 bgp_show_type_normal,
7540 bgp_show_type_regexp,
7541 bgp_show_type_prefix_list,
7542 bgp_show_type_filter_list,
7543 bgp_show_type_route_map,
7544 bgp_show_type_neighbor,
7545 bgp_show_type_cidr_only,
7546 bgp_show_type_prefix_longer,
7547 bgp_show_type_community_all,
7548 bgp_show_type_community,
7549 bgp_show_type_community_exact,
7550 bgp_show_type_community_list,
7551 bgp_show_type_community_list_exact,
7552 bgp_show_type_flap_statistics,
7553 bgp_show_type_flap_address,
7554 bgp_show_type_flap_prefix,
7555 bgp_show_type_flap_cidr_only,
7556 bgp_show_type_flap_regexp,
7557 bgp_show_type_flap_filter_list,
7558 bgp_show_type_flap_prefix_list,
7559 bgp_show_type_flap_prefix_longer,
7560 bgp_show_type_flap_route_map,
7561 bgp_show_type_flap_neighbor,
7562 bgp_show_type_dampend_paths,
7563 bgp_show_type_damp_neighbor
7564 };
7565
7566 static int
7567 bgp_show_prefix_list (struct vty *vty, const char *name,
7568 const char *prefix_list_str, afi_t afi,
7569 safi_t safi, enum bgp_show_type type);
7570 static int
7571 bgp_show_filter_list (struct vty *vty, const char *name,
7572 const char *filter, afi_t afi,
7573 safi_t safi, enum bgp_show_type type);
7574 static int
7575 bgp_show_route_map (struct vty *vty, const char *name,
7576 const char *rmap_str, afi_t afi,
7577 safi_t safi, enum bgp_show_type type);
7578 static int
7579 bgp_show_community_list (struct vty *vty, const char *name,
7580 const char *com, int exact,
7581 afi_t afi, safi_t safi);
7582 static int
7583 bgp_show_prefix_longer (struct vty *vty, const char *name,
7584 const char *prefix, afi_t afi,
7585 safi_t safi, enum bgp_show_type type);
7586
7587 static int
7588 bgp_show_table (struct vty *vty, struct bgp *bgp, struct bgp_table *table,
7589 enum bgp_show_type type, void *output_arg, u_char use_json)
7590 {
7591 struct bgp_info *ri;
7592 struct bgp_node *rn;
7593 int header = 1;
7594 int display;
7595 unsigned long output_count;
7596 unsigned long total_count;
7597 struct prefix *p;
7598 char buf[BUFSIZ];
7599 char buf2[BUFSIZ];
7600 json_object *json_paths = NULL;
7601 int first = 1;
7602
7603 if (use_json)
7604 {
7605 vty_out (vty, "{ \"vrfId\": %d, \"vrfName\": \"%s\", \"tableVersion\": %" PRId64 ", \"routerId\": \"%s\", \"routes\": { ",
7606 bgp->vrf_id == VRF_UNKNOWN ? -1 : bgp->vrf_id,
7607 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ? "Default" : bgp->name,
7608 table->version, inet_ntoa (bgp->router_id));
7609 json_paths = json_object_new_object();
7610 }
7611
7612 /* This is first entry point, so reset total line. */
7613 output_count = 0;
7614 total_count = 0;
7615
7616 /* Start processing of routes. */
7617 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7618 if (rn->info != NULL)
7619 {
7620 display = 0;
7621 if (!first && use_json)
7622 {
7623 vty_out (vty, ",");
7624 }
7625 if (use_json)
7626 json_paths = json_object_new_array();
7627 else
7628 json_paths = NULL;
7629
7630 for (ri = rn->info; ri; ri = ri->next)
7631 {
7632 total_count++;
7633 if (type == bgp_show_type_flap_statistics
7634 || type == bgp_show_type_flap_address
7635 || type == bgp_show_type_flap_prefix
7636 || type == bgp_show_type_flap_cidr_only
7637 || type == bgp_show_type_flap_regexp
7638 || type == bgp_show_type_flap_filter_list
7639 || type == bgp_show_type_flap_prefix_list
7640 || type == bgp_show_type_flap_prefix_longer
7641 || type == bgp_show_type_flap_route_map
7642 || type == bgp_show_type_flap_neighbor
7643 || type == bgp_show_type_dampend_paths
7644 || type == bgp_show_type_damp_neighbor)
7645 {
7646 if (!(ri->extra && ri->extra->damp_info))
7647 continue;
7648 }
7649 if (type == bgp_show_type_regexp
7650 || type == bgp_show_type_flap_regexp)
7651 {
7652 regex_t *regex = output_arg;
7653
7654 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
7655 continue;
7656 }
7657 if (type == bgp_show_type_prefix_list
7658 || type == bgp_show_type_flap_prefix_list)
7659 {
7660 struct prefix_list *plist = output_arg;
7661
7662 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
7663 continue;
7664 }
7665 if (type == bgp_show_type_filter_list
7666 || type == bgp_show_type_flap_filter_list)
7667 {
7668 struct as_list *as_list = output_arg;
7669
7670 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
7671 continue;
7672 }
7673 if (type == bgp_show_type_route_map
7674 || type == bgp_show_type_flap_route_map)
7675 {
7676 struct route_map *rmap = output_arg;
7677 struct bgp_info binfo;
7678 struct attr dummy_attr;
7679 struct attr_extra dummy_extra;
7680 int ret;
7681
7682 dummy_attr.extra = &dummy_extra;
7683 bgp_attr_dup (&dummy_attr, ri->attr);
7684
7685 binfo.peer = ri->peer;
7686 binfo.attr = &dummy_attr;
7687
7688 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
7689 if (ret == RMAP_DENYMATCH)
7690 continue;
7691 }
7692 if (type == bgp_show_type_neighbor
7693 || type == bgp_show_type_flap_neighbor
7694 || type == bgp_show_type_damp_neighbor)
7695 {
7696 union sockunion *su = output_arg;
7697
7698 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
7699 continue;
7700 }
7701 if (type == bgp_show_type_cidr_only
7702 || type == bgp_show_type_flap_cidr_only)
7703 {
7704 u_int32_t destination;
7705
7706 destination = ntohl (rn->p.u.prefix4.s_addr);
7707 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
7708 continue;
7709 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
7710 continue;
7711 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
7712 continue;
7713 }
7714 if (type == bgp_show_type_prefix_longer
7715 || type == bgp_show_type_flap_prefix_longer)
7716 {
7717 struct prefix *p = output_arg;
7718
7719 if (! prefix_match (p, &rn->p))
7720 continue;
7721 }
7722 if (type == bgp_show_type_community_all)
7723 {
7724 if (! ri->attr->community)
7725 continue;
7726 }
7727 if (type == bgp_show_type_community)
7728 {
7729 struct community *com = output_arg;
7730
7731 if (! ri->attr->community ||
7732 ! community_match (ri->attr->community, com))
7733 continue;
7734 }
7735 if (type == bgp_show_type_community_exact)
7736 {
7737 struct community *com = output_arg;
7738
7739 if (! ri->attr->community ||
7740 ! community_cmp (ri->attr->community, com))
7741 continue;
7742 }
7743 if (type == bgp_show_type_community_list)
7744 {
7745 struct community_list *list = output_arg;
7746
7747 if (! community_list_match (ri->attr->community, list))
7748 continue;
7749 }
7750 if (type == bgp_show_type_community_list_exact)
7751 {
7752 struct community_list *list = output_arg;
7753
7754 if (! community_list_exact_match (ri->attr->community, list))
7755 continue;
7756 }
7757 if (type == bgp_show_type_flap_address
7758 || type == bgp_show_type_flap_prefix)
7759 {
7760 struct prefix *p = output_arg;
7761
7762 if (! prefix_match (&rn->p, p))
7763 continue;
7764
7765 if (type == bgp_show_type_flap_prefix)
7766 if (p->prefixlen != rn->p.prefixlen)
7767 continue;
7768 }
7769 if (type == bgp_show_type_dampend_paths
7770 || type == bgp_show_type_damp_neighbor)
7771 {
7772 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
7773 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
7774 continue;
7775 }
7776
7777 if (!use_json && header)
7778 {
7779 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
7780 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7781 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7782 if (type == bgp_show_type_dampend_paths
7783 || type == bgp_show_type_damp_neighbor)
7784 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
7785 else if (type == bgp_show_type_flap_statistics
7786 || type == bgp_show_type_flap_address
7787 || type == bgp_show_type_flap_prefix
7788 || type == bgp_show_type_flap_cidr_only
7789 || type == bgp_show_type_flap_regexp
7790 || type == bgp_show_type_flap_filter_list
7791 || type == bgp_show_type_flap_prefix_list
7792 || type == bgp_show_type_flap_prefix_longer
7793 || type == bgp_show_type_flap_route_map
7794 || type == bgp_show_type_flap_neighbor)
7795 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
7796 else
7797 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7798 header = 0;
7799 }
7800
7801 if (type == bgp_show_type_dampend_paths
7802 || type == bgp_show_type_damp_neighbor)
7803 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7804 else if (type == bgp_show_type_flap_statistics
7805 || type == bgp_show_type_flap_address
7806 || type == bgp_show_type_flap_prefix
7807 || type == bgp_show_type_flap_cidr_only
7808 || type == bgp_show_type_flap_regexp
7809 || type == bgp_show_type_flap_filter_list
7810 || type == bgp_show_type_flap_prefix_list
7811 || type == bgp_show_type_flap_prefix_longer
7812 || type == bgp_show_type_flap_route_map
7813 || type == bgp_show_type_flap_neighbor)
7814 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths);
7815 else
7816 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths);
7817 display++;
7818 }
7819
7820 if (display)
7821 {
7822 output_count++;
7823 if (use_json)
7824 {
7825 p = &rn->p;
7826 sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
7827 vty_out (vty, "\"%s\": ", buf2);
7828 vty_out (vty, "%s", json_object_to_json_string (json_paths));
7829 json_object_free (json_paths);
7830 first = 0;
7831
7832 }
7833 }
7834 }
7835
7836 if (use_json)
7837 {
7838 json_object_free (json_paths);
7839 vty_out (vty, " } }%s", VTY_NEWLINE);
7840 }
7841 else
7842 {
7843 /* No route is displayed */
7844 if (output_count == 0)
7845 {
7846 if (type == bgp_show_type_normal)
7847 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
7848 }
7849 else
7850 vty_out (vty, "%sDisplayed %ld routes and %ld total paths%s",
7851 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
7852 }
7853
7854 return CMD_SUCCESS;
7855 }
7856
7857 static int
7858 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
7859 enum bgp_show_type type, void *output_arg, u_char use_json)
7860 {
7861 struct bgp_table *table;
7862
7863 if (bgp == NULL)
7864 {
7865 bgp = bgp_get_default ();
7866 }
7867
7868 if (bgp == NULL)
7869 {
7870 if (!use_json)
7871 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7872 return CMD_WARNING;
7873 }
7874
7875 table = bgp->rib[afi][safi];
7876
7877 return bgp_show_table (vty, bgp, table, type, output_arg,
7878 use_json);
7879 }
7880
7881 static void
7882 bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
7883 u_char use_json)
7884 {
7885 struct listnode *node, *nnode;
7886 struct bgp *bgp;
7887 struct bgp_table *table;
7888 int is_first = 1;
7889
7890 if (use_json)
7891 vty_out (vty, "{%s", VTY_NEWLINE);
7892
7893 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7894 {
7895 if (use_json)
7896 {
7897 if (! is_first)
7898 vty_out (vty, ",%s", VTY_NEWLINE);
7899 else
7900 is_first = 0;
7901
7902 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7903 ? "Default" : bgp->name);
7904 }
7905 else
7906 {
7907 vty_out (vty, "%sInstance %s:%s",
7908 VTY_NEWLINE,
7909 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7910 ? "Default" : bgp->name,
7911 VTY_NEWLINE);
7912 }
7913 table = bgp->rib[afi][safi];
7914 bgp_show_table (vty, bgp, table,
7915 bgp_show_type_normal, NULL, use_json);
7916
7917 }
7918
7919 if (use_json)
7920 vty_out (vty, "}%s", VTY_NEWLINE);
7921 }
7922
7923 /* Header of detailed BGP route information */
7924 static void
7925 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
7926 struct bgp_node *rn,
7927 struct prefix_rd *prd, afi_t afi, safi_t safi,
7928 json_object *json)
7929 {
7930 struct bgp_info *ri;
7931 struct prefix *p;
7932 struct peer *peer;
7933 struct listnode *node, *nnode;
7934 char buf1[INET6_ADDRSTRLEN];
7935 char buf2[INET6_ADDRSTRLEN];
7936 int count = 0;
7937 int best = 0;
7938 int suppress = 0;
7939 int no_export = 0;
7940 int no_advertise = 0;
7941 int local_as = 0;
7942 int first = 1;
7943 json_object *json_adv_to = NULL;
7944
7945 p = &rn->p;
7946
7947 if (json)
7948 {
7949 json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN));
7950 json_object_int_add(json, "prefixlen", p->prefixlen);
7951 }
7952 else
7953 {
7954 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
7955 ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) ?
7956 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
7957 safi == SAFI_MPLS_VPN ? ":" : "",
7958 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
7959 p->prefixlen, VTY_NEWLINE);
7960 }
7961
7962 for (ri = rn->info; ri; ri = ri->next)
7963 {
7964 count++;
7965 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
7966 {
7967 best = count;
7968 if (ri->extra && ri->extra->suppress)
7969 suppress = 1;
7970 if (ri->attr->community != NULL)
7971 {
7972 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
7973 no_advertise = 1;
7974 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
7975 no_export = 1;
7976 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
7977 local_as = 1;
7978 }
7979 }
7980 }
7981
7982 if (!json)
7983 {
7984 vty_out (vty, "Paths: (%d available", count);
7985 if (best)
7986 {
7987 vty_out (vty, ", best #%d", best);
7988 if (safi == SAFI_UNICAST)
7989 vty_out (vty, ", table %s",
7990 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7991 ? "Default-IP-Routing-Table" : bgp->name);
7992 }
7993 else
7994 vty_out (vty, ", no best path");
7995
7996 if (no_advertise)
7997 vty_out (vty, ", not advertised to any peer");
7998 else if (no_export)
7999 vty_out (vty, ", not advertised to EBGP peer");
8000 else if (local_as)
8001 vty_out (vty, ", not advertised outside local AS");
8002
8003 if (suppress)
8004 vty_out (vty, ", Advertisements suppressed by an aggregate.");
8005 vty_out (vty, ")%s", VTY_NEWLINE);
8006 }
8007
8008 /* If we are not using addpath then we can display Advertised to and that will
8009 * show what peers we advertised the bestpath to. If we are using addpath
8010 * though then we must display Advertised to on a path-by-path basis. */
8011 if (!bgp->addpath_tx_used[afi][safi])
8012 {
8013 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
8014 {
8015 if (bgp_adj_out_lookup (peer, rn, 0))
8016 {
8017 if (json && !json_adv_to)
8018 json_adv_to = json_object_new_object();
8019
8020 route_vty_out_advertised_to(vty, peer, &first,
8021 " Advertised to non peer-group peers:\n ",
8022 json_adv_to);
8023 }
8024 }
8025
8026 if (json)
8027 {
8028 if (json_adv_to)
8029 {
8030 json_object_object_add(json, "advertisedTo", json_adv_to);
8031 }
8032 }
8033 else
8034 {
8035 if (first)
8036 vty_out (vty, " Not advertised to any peer");
8037 vty_out (vty, "%s", VTY_NEWLINE);
8038 }
8039 }
8040 }
8041
8042 /* Display specified route of BGP table. */
8043 static int
8044 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
8045 struct bgp_table *rib, const char *ip_str,
8046 afi_t afi, safi_t safi, struct prefix_rd *prd,
8047 int prefix_check, enum bgp_path_type pathtype,
8048 u_char use_json)
8049 {
8050 int ret;
8051 int header;
8052 int display = 0;
8053 struct prefix match;
8054 struct bgp_node *rn;
8055 struct bgp_node *rm;
8056 struct bgp_info *ri;
8057 struct bgp_table *table;
8058 json_object *json = NULL;
8059 json_object *json_paths = NULL;
8060
8061 /* Check IP address argument. */
8062 ret = str2prefix (ip_str, &match);
8063 if (! ret)
8064 {
8065 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
8066 return CMD_WARNING;
8067 }
8068
8069 match.family = afi2family (afi);
8070
8071 if (use_json)
8072 {
8073 json = json_object_new_object();
8074 json_paths = json_object_new_array();
8075 }
8076
8077 if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
8078 {
8079 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
8080 {
8081 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8082 continue;
8083
8084 if ((table = rn->info) != NULL)
8085 {
8086 header = 1;
8087
8088 if ((rm = bgp_node_match (table, &match)) != NULL)
8089 {
8090 if (prefix_check && rm->p.prefixlen != match.prefixlen)
8091 {
8092 bgp_unlock_node (rm);
8093 continue;
8094 }
8095
8096 for (ri = rm->info; ri; ri = ri->next)
8097 {
8098 if (header)
8099 {
8100 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
8101 AFI_IP, safi, json);
8102 header = 0;
8103 }
8104 display++;
8105
8106 if (pathtype == BGP_PATH_ALL ||
8107 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8108 (pathtype == BGP_PATH_MULTIPATH &&
8109 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8110 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi, json_paths);
8111 }
8112
8113 bgp_unlock_node (rm);
8114 }
8115 }
8116 }
8117 }
8118 else
8119 {
8120 header = 1;
8121
8122 if ((rn = bgp_node_match (rib, &match)) != NULL)
8123 {
8124 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8125 {
8126 for (ri = rn->info; ri; ri = ri->next)
8127 {
8128 if (header)
8129 {
8130 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json);
8131 header = 0;
8132 }
8133 display++;
8134
8135 if (pathtype == BGP_PATH_ALL ||
8136 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
8137 (pathtype == BGP_PATH_MULTIPATH &&
8138 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
8139 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths);
8140 }
8141 }
8142
8143 bgp_unlock_node (rn);
8144 }
8145 }
8146
8147 if (use_json)
8148 {
8149 if (display)
8150 json_object_object_add(json, "paths", json_paths);
8151
8152 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
8153 json_object_free(json);
8154 }
8155 else
8156 {
8157 if (!display)
8158 {
8159 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
8160 return CMD_WARNING;
8161 }
8162 }
8163
8164 return CMD_SUCCESS;
8165 }
8166
8167 /* Display specified route of Main RIB */
8168 static int
8169 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
8170 afi_t afi, safi_t safi, struct prefix_rd *prd,
8171 int prefix_check, enum bgp_path_type pathtype,
8172 u_char use_json)
8173 {
8174 struct bgp *bgp;
8175
8176 /* BGP structure lookup. */
8177 if (view_name)
8178 {
8179 bgp = bgp_lookup_by_name (view_name);
8180 if (bgp == NULL)
8181 {
8182 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
8183 return CMD_WARNING;
8184 }
8185 }
8186 else
8187 {
8188 bgp = bgp_get_default ();
8189 if (bgp == NULL)
8190 {
8191 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8192 return CMD_WARNING;
8193 }
8194 }
8195
8196 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
8197 afi, safi, prd, prefix_check, pathtype,
8198 use_json);
8199 }
8200
8201 /* BGP route print out function. */
8202 DEFUN (show_ip_bgp,
8203 show_ip_bgp_cmd,
8204 "show ip bgp {json}",
8205 SHOW_STR
8206 IP_STR
8207 BGP_STR
8208 "JavaScript Object Notation\n")
8209 {
8210 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8211 }
8212
8213 ALIAS (show_ip_bgp,
8214 show_bgp_ipv4_cmd,
8215 "show bgp ipv4 {json}",
8216 SHOW_STR
8217 IP_STR
8218 BGP_STR
8219 "Address family\n"
8220 "JavaScript Object Notation\n")
8221
8222 DEFUN (show_ip_bgp_ipv4,
8223 show_ip_bgp_ipv4_cmd,
8224 "show ip bgp ipv4 (unicast|multicast) {json}",
8225 SHOW_STR
8226 IP_STR
8227 BGP_STR
8228 "Address family\n"
8229 "Address Family modifier\n"
8230 "Address Family modifier\n"
8231 "JavaScript Object Notation\n")
8232 {
8233 u_char uj = use_json(argc, argv);
8234
8235 return bgp_show (vty, NULL, AFI_IP,
8236 bgp_vty_safi_from_arg(argv[0]),
8237 bgp_show_type_normal, NULL, uj);
8238 }
8239
8240 ALIAS (show_ip_bgp_ipv4,
8241 show_bgp_ipv4_safi_cmd,
8242 "show bgp ipv4 (unicast|multicast) {json}",
8243 SHOW_STR
8244 BGP_STR
8245 "Address family\n"
8246 "Address Family modifier\n"
8247 "Address Family modifier\n"
8248 "JavaScript Object Notation\n")
8249
8250 DEFUN (show_ip_bgp_route,
8251 show_ip_bgp_route_cmd,
8252 "show ip bgp A.B.C.D {json}",
8253 SHOW_STR
8254 IP_STR
8255 BGP_STR
8256 "Network in the BGP routing table to display\n"
8257 "JavaScript Object Notation\n")
8258 {
8259 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8260 }
8261
8262 DEFUN (show_ip_bgp_route_pathtype,
8263 show_ip_bgp_route_pathtype_cmd,
8264 "show ip bgp A.B.C.D (bestpath|multipath) {json}",
8265 SHOW_STR
8266 IP_STR
8267 BGP_STR
8268 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8269 "Display only the bestpath\n"
8270 "Display only multipaths\n"
8271 "JavaScript Object Notation\n")
8272 {
8273 u_char uj = use_json(argc, argv);
8274
8275 if (strncmp (argv[1], "b", 1) == 0)
8276 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8277 else
8278 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8279 }
8280
8281 DEFUN (show_bgp_ipv4_safi_route_pathtype,
8282 show_bgp_ipv4_safi_route_pathtype_cmd,
8283 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D (bestpath|multipath) {json}",
8284 SHOW_STR
8285 BGP_STR
8286 BGP_AFI_SAFI_HELP_STR
8287 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8288 "Display only the bestpath\n"
8289 "Display only multipaths\n"
8290 "JavaScript Object Notation\n")
8291 {
8292 u_char uj = use_json(argc, argv);
8293
8294 if (strncmp (argv[2], "b", 1) == 0)
8295 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8296 bgp_vty_safi_from_arg(argv[0]),
8297 NULL, 0, BGP_PATH_BESTPATH, uj);
8298 else
8299 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8300 bgp_vty_safi_from_arg(argv[0]),
8301 NULL, 0, BGP_PATH_MULTIPATH, uj);
8302 }
8303
8304 DEFUN (show_bgp_ipv4_prefix,
8305 show_bgp_ipv4_prefix_cmd,
8306 "show bgp ipv4 A.B.C.D/M {json}",
8307 SHOW_STR
8308 BGP_STR
8309 IP_STR
8310 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8311 JSON_STR)
8312 {
8313 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc, argv));
8314 }
8315
8316 DEFUN (show_bgp_ipv6_route,
8317 show_bgp_ipv6_route_cmd,
8318 "show bgp ipv6 X:X::X:X {json}",
8319 SHOW_STR
8320 BGP_STR
8321 "Address family\n"
8322 "Network in the BGP routing table to display\n"
8323 JSON_STR)
8324 {
8325 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json (argc, argv));
8326 }
8327
8328 DEFUN (show_bgp_ipv6_prefix,
8329 show_bgp_ipv6_prefix_cmd,
8330 "show bgp ipv6 X:X::X:X/M {json}",
8331 SHOW_STR
8332 BGP_STR
8333 IP_STR
8334 "IPv6 prefix <network>/<length>\n"
8335 JSON_STR)
8336 {
8337 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json (argc,argv));
8338 }
8339
8340 DEFUN (show_ip_bgp_ipv4_route,
8341 show_ip_bgp_ipv4_route_cmd,
8342 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}",
8343 SHOW_STR
8344 IP_STR
8345 BGP_STR
8346 BGP_AFI_SAFI_HELP_STR
8347 "Network in the BGP routing table to display\n"
8348 "JavaScript Object Notation\n")
8349 {
8350 u_char uj = use_json(argc, argv);
8351
8352 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8353 bgp_vty_safi_from_arg(argv[0]),
8354 NULL, 0, BGP_PATH_ALL, uj);
8355 }
8356
8357 ALIAS (show_ip_bgp_ipv4_route,
8358 show_bgp_ipv4_safi_route_cmd,
8359 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}",
8360 SHOW_STR
8361 BGP_STR
8362 BGP_AFI_SAFI_HELP_STR
8363 "Network in the BGP routing table to display\n"
8364 "JavaScript Object Notation\n")
8365
8366 DEFUN (show_bgp_ipv4_safi_rd_route,
8367 show_bgp_ipv4_safi_rd_route_cmd,
8368 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D {json}",
8369 SHOW_STR
8370 BGP_STR
8371 "Address Family\n"
8372 "Address Family Modifier\n"
8373 "Address Family Modifier\n"
8374 "Display information for a route distinguisher\n"
8375 "ENCAP Route Distinguisher\n"
8376 "Network in the BGP routing table to display\n")
8377 {
8378 int ret;
8379 struct prefix_rd prd;
8380 safi_t safi;
8381
8382 if (bgp_parse_safi(argv[0], &safi)) {
8383 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8384 return CMD_WARNING;
8385 }
8386 ret = str2prefix_rd (argv[1], &prd);
8387 if (! ret)
8388 {
8389 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8390 return CMD_WARNING;
8391 }
8392 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8393 }
8394
8395 DEFUN (show_bgp_ipv6_safi_rd_route,
8396 show_bgp_ipv6_safi_rd_route_cmd,
8397 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X {json}",
8398 SHOW_STR
8399 BGP_STR
8400 "Address Family\n"
8401 "Address Family Modifier\n"
8402 "Address Family Modifier\n"
8403 "Display information for a route distinguisher\n"
8404 "ENCAP Route Distinguisher\n"
8405 "Network in the BGP routing table to display\n")
8406 {
8407 int ret;
8408 struct prefix_rd prd;
8409 safi_t safi;
8410
8411 if (bgp_parse_safi(argv[0], &safi)) {
8412 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8413 return CMD_WARNING;
8414 }
8415 ret = str2prefix_rd (argv[1], &prd);
8416 if (! ret)
8417 {
8418 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8419 return CMD_WARNING;
8420 }
8421 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL, use_json (argc, argv));
8422 }
8423
8424
8425 DEFUN (show_bgp_ipv4_safi_rd_prefix,
8426 show_bgp_ipv4_safi_rd_prefix_cmd,
8427 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}",
8428 SHOW_STR
8429 BGP_STR
8430 "Address Family\n"
8431 "Address Family Modifier\n"
8432 "Address Family Modifier\n"
8433 "Display information for a route distinguisher\n"
8434 "ENCAP Route Distinguisher\n"
8435 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8436 {
8437 int ret;
8438 struct prefix_rd prd;
8439 safi_t safi;
8440
8441 if (bgp_parse_safi(argv[0], &safi)) {
8442 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8443 return CMD_WARNING;
8444 }
8445
8446 ret = str2prefix_rd (argv[1], &prd);
8447 if (! ret)
8448 {
8449 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8450 return CMD_WARNING;
8451 }
8452 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv));
8453 }
8454
8455 DEFUN (show_bgp_ipv6_safi_rd_prefix,
8456 show_bgp_ipv6_safi_rd_prefix_cmd,
8457 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M {json}",
8458 SHOW_STR
8459 BGP_STR
8460 "Address Family\n"
8461 "Address Family Modifier\n"
8462 "Address Family Modifier\n"
8463 "Display information for a route distinguisher\n"
8464 "ENCAP Route Distinguisher\n"
8465 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8466 {
8467 int ret;
8468 struct prefix_rd prd;
8469 safi_t safi;
8470
8471 if (bgp_parse_safi(argv[0], &safi)) {
8472 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8473 return CMD_WARNING;
8474 }
8475
8476 ret = str2prefix_rd (argv[1], &prd);
8477 if (! ret)
8478 {
8479 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8480 return CMD_WARNING;
8481 }
8482 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv));
8483 }
8484
8485 DEFUN (show_ip_bgp_prefix,
8486 show_ip_bgp_prefix_cmd,
8487 "show ip bgp A.B.C.D/M {json}",
8488 SHOW_STR
8489 IP_STR
8490 BGP_STR
8491 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8492 "JavaScript Object Notation\n")
8493 {
8494 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8495 }
8496
8497 DEFUN (show_ip_bgp_prefix_pathtype,
8498 show_ip_bgp_prefix_pathtype_cmd,
8499 "show ip bgp A.B.C.D/M (bestpath|multipath) {json}",
8500 SHOW_STR
8501 IP_STR
8502 BGP_STR
8503 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8504 "Display only the bestpath\n"
8505 "Display only multipaths\n"
8506 "JavaScript Object Notation\n")
8507 {
8508 u_char uj = use_json(argc, argv);
8509 if (strncmp (argv[1], "b", 1) == 0)
8510 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8511 else
8512 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8513 }
8514
8515 DEFUN (show_ip_bgp_ipv4_prefix,
8516 show_ip_bgp_ipv4_prefix_cmd,
8517 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}",
8518 SHOW_STR
8519 IP_STR
8520 BGP_STR
8521 BGP_AFI_SAFI_HELP_STR
8522 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8523 "JavaScript Object Notation\n")
8524 {
8525 u_char uj = use_json(argc, argv);
8526
8527 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8528 bgp_vty_safi_from_arg(argv[0]),
8529 NULL, 1, BGP_PATH_ALL, uj);
8530 }
8531
8532 ALIAS (show_ip_bgp_ipv4_prefix,
8533 show_bgp_ipv4_safi_prefix_cmd,
8534 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}",
8535 SHOW_STR
8536 BGP_STR
8537 BGP_AFI_SAFI_HELP_STR
8538 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8539 "JavaScript Object Notation\n")
8540
8541 DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
8542 show_ip_bgp_ipv4_prefix_pathtype_cmd,
8543 "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}",
8544 SHOW_STR
8545 IP_STR
8546 BGP_STR
8547 BGP_AFI_SAFI_HELP_STR
8548 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8549 "Display only the bestpath\n"
8550 "Display only multipaths\n"
8551 "JavaScript Object Notation\n")
8552 {
8553 u_char uj = use_json(argc, argv);
8554
8555 if (strncmp (argv[2], "b", 1) == 0)
8556 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8557 bgp_vty_safi_from_arg(argv[0]),
8558 NULL, 1, BGP_PATH_BESTPATH, uj);
8559 else
8560 return bgp_show_route (vty, NULL, argv[1], AFI_IP,
8561 bgp_vty_safi_from_arg(argv[0]),
8562 NULL, 1, BGP_PATH_MULTIPATH, uj);
8563 }
8564
8565 ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
8566 show_bgp_ipv4_safi_prefix_pathtype_cmd,
8567 "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}",
8568 SHOW_STR
8569 BGP_STR
8570 BGP_AFI_SAFI_HELP_STR
8571 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8572 "Display only the bestpath\n"
8573 "Display only multipaths\n"
8574 "JavaScript Object Notation\n")
8575
8576
8577 DEFUN (show_ip_bgp_view,
8578 show_ip_bgp_instance_cmd,
8579 "show ip bgp " BGP_INSTANCE_CMD " {json}",
8580 SHOW_STR
8581 IP_STR
8582 BGP_STR
8583 BGP_INSTANCE_HELP_STR
8584 "JavaScript Object Notation\n")
8585 {
8586 struct bgp *bgp;
8587
8588 /* BGP structure lookup. */
8589 bgp = bgp_lookup_by_name (argv[1]);
8590 if (bgp == NULL)
8591 {
8592 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8593 return CMD_WARNING;
8594 }
8595
8596 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8597 }
8598
8599 DEFUN (show_ip_bgp_instance_all,
8600 show_ip_bgp_instance_all_cmd,
8601 "show ip bgp " BGP_INSTANCE_ALL_CMD " {json}",
8602 SHOW_STR
8603 IP_STR
8604 BGP_STR
8605 BGP_INSTANCE_ALL_HELP_STR
8606 "JavaScript Object Notation\n")
8607 {
8608 u_char uj = use_json(argc, argv);
8609
8610 bgp_show_all_instances_routes_vty (vty, AFI_IP, SAFI_UNICAST, uj);
8611 return CMD_SUCCESS;
8612 }
8613
8614 DEFUN (show_ip_bgp_instance_route,
8615 show_ip_bgp_instance_route_cmd,
8616 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D {json}",
8617 SHOW_STR
8618 IP_STR
8619 BGP_STR
8620 BGP_INSTANCE_HELP_STR
8621 "Network in the BGP routing table to display\n"
8622 "JavaScript Object Notation\n")
8623 {
8624 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8625 }
8626
8627 DEFUN (show_ip_bgp_instance_route_pathtype,
8628 show_ip_bgp_instance_route_pathtype_cmd,
8629 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D (bestpath|multipath) {json}",
8630 SHOW_STR
8631 IP_STR
8632 BGP_STR
8633 BGP_INSTANCE_HELP_STR
8634 "Network in the BGP routing table to display\n"
8635 "Display only the bestpath\n"
8636 "Display only multipaths\n"
8637 "JavaScript Object Notation\n")
8638 {
8639 u_char uj = use_json(argc, argv);
8640
8641 if (strncmp (argv[3], "b", 1) == 0)
8642 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8643 else
8644 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8645 }
8646
8647 DEFUN (show_ip_bgp_instance_prefix,
8648 show_ip_bgp_instance_prefix_cmd,
8649 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M {json}",
8650 SHOW_STR
8651 IP_STR
8652 BGP_STR
8653 BGP_INSTANCE_HELP_STR
8654 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8655 "JavaScript Object Notation\n")
8656 {
8657 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8658 }
8659
8660 DEFUN (show_ip_bgp_instance_prefix_pathtype,
8661 show_ip_bgp_instance_prefix_pathtype_cmd,
8662 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M (bestpath|multipath) {json}",
8663 SHOW_STR
8664 IP_STR
8665 BGP_STR
8666 BGP_INSTANCE_HELP_STR
8667 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8668 "Display only the bestpath\n"
8669 "Display only multipaths\n"
8670 "JavaScript Object Notation\n")
8671 {
8672 u_char uj = use_json(argc, argv);
8673 if (strncmp (argv[3], "b", 1) == 0)
8674 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8675 else
8676 return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8677 }
8678
8679 #ifdef HAVE_IPV6
8680 DEFUN (show_bgp,
8681 show_bgp_cmd,
8682 "show bgp {json}",
8683 SHOW_STR
8684 BGP_STR
8685 "JavaScript Object Notation\n")
8686 {
8687 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8688 NULL, use_json(argc, argv));
8689 }
8690
8691 ALIAS (show_bgp,
8692 show_bgp_ipv6_cmd,
8693 "show bgp ipv6 {json}",
8694 SHOW_STR
8695 BGP_STR
8696 "Address family\n"
8697 "JavaScript Object Notation\n")
8698
8699 DEFUN (show_bgp_ipv6_safi,
8700 show_bgp_ipv6_safi_cmd,
8701 "show bgp ipv6 (unicast|multicast) {json}",
8702 SHOW_STR
8703 BGP_STR
8704 "Address family\n"
8705 "Address Family modifier\n"
8706 "Address Family modifier\n"
8707 "JavaScript Object Notation\n")
8708 {
8709 u_char uj = use_json(argc, argv);
8710
8711 return bgp_show (vty, NULL, AFI_IP6,
8712 bgp_vty_safi_from_arg(argv[0]),
8713 bgp_show_type_normal, NULL, uj);
8714 }
8715
8716 static void
8717 bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty)
8718 {
8719 vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our"
8720 " next release%sPlese use 'show bgp ipv6' instead%s%s",
8721 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8722 }
8723
8724 /* old command */
8725 DEFUN (show_ipv6_bgp,
8726 show_ipv6_bgp_cmd,
8727 "show ipv6 bgp {json}",
8728 SHOW_STR
8729 IP_STR
8730 BGP_STR
8731 "JavaScript Object Notation\n")
8732 {
8733 bgp_show_ipv6_bgp_deprecate_warning(vty);
8734 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
8735 NULL, use_json(argc, argv));
8736 }
8737
8738 DEFUN (show_bgp_route,
8739 show_bgp_route_cmd,
8740 "show bgp X:X::X:X {json}",
8741 SHOW_STR
8742 BGP_STR
8743 "Network in the BGP routing table to display\n"
8744 "JavaScript Object Notation\n")
8745 {
8746 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8747 }
8748
8749 DEFUN (show_bgp_ipv6_safi_route,
8750 show_bgp_ipv6_safi_route_cmd,
8751 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X {json}",
8752 SHOW_STR
8753 BGP_STR
8754 BGP_AFI_SAFI_HELP_STR
8755 "Network in the BGP routing table to display\n"
8756 "JavaScript Object Notation\n")
8757 {
8758 u_char uj = use_json(argc, argv);
8759
8760 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8761 bgp_vty_safi_from_arg(argv[0]),
8762 NULL, 0, BGP_PATH_ALL, uj);
8763 }
8764
8765 DEFUN (show_bgp_route_pathtype,
8766 show_bgp_route_pathtype_cmd,
8767 "show bgp X:X::X:X (bestpath|multipath) {json}",
8768 SHOW_STR
8769 BGP_STR
8770 "Network in the BGP routing table to display\n"
8771 "Display only the bestpath\n"
8772 "Display only multipaths\n"
8773 "JavaScript Object Notation\n")
8774 {
8775 u_char uj = use_json(argc, argv);
8776 if (strncmp (argv[1], "b", 1) == 0)
8777 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8778 else
8779 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
8780 }
8781
8782 ALIAS (show_bgp_route_pathtype,
8783 show_bgp_ipv6_route_pathtype_cmd,
8784 "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}",
8785 SHOW_STR
8786 BGP_STR
8787 "Address family\n"
8788 "Network in the BGP routing table to display\n"
8789 "Display only the bestpath\n"
8790 "Display only multipaths\n"
8791 "JavaScript Object Notation\n")
8792
8793 DEFUN (show_bgp_ipv6_safi_route_pathtype,
8794 show_bgp_ipv6_safi_route_pathtype_cmd,
8795 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X (bestpath|multipath) {json}",
8796 SHOW_STR
8797 BGP_STR
8798 BGP_AFI_SAFI_HELP_STR
8799 "Network in the BGP routing table to display\n"
8800 "Display only the bestpath\n"
8801 "Display only multipaths\n"
8802 "JavaScript Object Notation\n")
8803 {
8804 u_char uj = use_json(argc, argv);
8805 if (strncmp (argv[2], "b", 1) == 0)
8806 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8807 bgp_vty_safi_from_arg(argv[0]),
8808 NULL, 0, BGP_PATH_BESTPATH, uj);
8809 else
8810 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8811 bgp_vty_safi_from_arg(argv[0]),
8812 NULL, 0, BGP_PATH_MULTIPATH, uj);
8813 }
8814
8815 /* old command */
8816 DEFUN (show_ipv6_bgp_route,
8817 show_ipv6_bgp_route_cmd,
8818 "show ipv6 bgp X:X::X:X {json}",
8819 SHOW_STR
8820 IP_STR
8821 BGP_STR
8822 "Network in the BGP routing table to display\n"
8823 "JavaScript Object Notation\n")
8824 {
8825 bgp_show_ipv6_bgp_deprecate_warning(vty);
8826 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8827 }
8828
8829 DEFUN (show_bgp_prefix,
8830 show_bgp_prefix_cmd,
8831 "show bgp X:X::X:X/M {json}",
8832 SHOW_STR
8833 BGP_STR
8834 "IPv6 prefix <network>/<length>\n"
8835 "JavaScript Object Notation\n")
8836 {
8837 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8838 }
8839
8840 DEFUN (show_bgp_ipv6_safi_prefix,
8841 show_bgp_ipv6_safi_prefix_cmd,
8842 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M {json}",
8843 SHOW_STR
8844 BGP_STR
8845 BGP_AFI_SAFI_HELP_STR
8846 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8847 "JavaScript Object Notation\n")
8848 {
8849 u_char uj = use_json(argc, argv);
8850
8851 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8852 bgp_vty_safi_from_arg(argv[0]),
8853 NULL, 1, BGP_PATH_ALL, uj);
8854 }
8855
8856 DEFUN (show_bgp_prefix_pathtype,
8857 show_bgp_prefix_pathtype_cmd,
8858 "show bgp X:X::X:X/M (bestpath|multipath) {json}",
8859 SHOW_STR
8860 BGP_STR
8861 "IPv6 prefix <network>/<length>\n"
8862 "Display only the bestpath\n"
8863 "Display only multipaths\n"
8864 "JavaScript Object Notation\n")
8865 {
8866 u_char uj = use_json(argc, argv);
8867 if (strncmp (argv[1], "b", 1) == 0)
8868 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
8869 else
8870 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
8871 }
8872
8873 ALIAS (show_bgp_prefix_pathtype,
8874 show_bgp_ipv6_prefix_pathtype_cmd,
8875 "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}",
8876 SHOW_STR
8877 BGP_STR
8878 "Address family\n"
8879 "IPv6 prefix <network>/<length>\n"
8880 "Display only the bestpath\n"
8881 "Display only multipaths\n"
8882 "JavaScript Object Notation\n")
8883
8884 DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
8885 show_bgp_ipv6_safi_prefix_pathtype_cmd,
8886 "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M (bestpath|multipath) {json}",
8887 SHOW_STR
8888 BGP_STR
8889 BGP_AFI_SAFI_HELP_STR
8890 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8891 "Display only the bestpath\n"
8892 "Display only multipaths\n"
8893 "JavaScript Object Notation\n")
8894 {
8895 u_char uj = use_json(argc, argv);
8896 if (strncmp (argv[2], "b", 1) == 0)
8897 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8898 bgp_vty_safi_from_arg(argv[0]),
8899 NULL, 1, BGP_PATH_BESTPATH, uj);
8900 else
8901 return bgp_show_route (vty, NULL, argv[1], AFI_IP6,
8902 bgp_vty_safi_from_arg(argv[0]), NULL, 1, BGP_PATH_MULTIPATH, uj);
8903 }
8904
8905 /* old command */
8906 DEFUN (show_ipv6_bgp_prefix,
8907 show_ipv6_bgp_prefix_cmd,
8908 "show ipv6 bgp X:X::X:X/M {json}",
8909 SHOW_STR
8910 IP_STR
8911 BGP_STR
8912 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8913 "JavaScript Object Notation\n")
8914 {
8915 bgp_show_ipv6_bgp_deprecate_warning(vty);
8916 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
8917 }
8918
8919 DEFUN (show_bgp_view,
8920 show_bgp_instance_cmd,
8921 "show bgp " BGP_INSTANCE_CMD " {json}",
8922 SHOW_STR
8923 BGP_STR
8924 BGP_INSTANCE_HELP_STR
8925 "JavaScript Object Notation\n")
8926 {
8927 struct bgp *bgp;
8928
8929 /* BGP structure lookup. */
8930 bgp = bgp_lookup_by_name (argv[1]);
8931 if (bgp == NULL)
8932 {
8933 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
8934 return CMD_WARNING;
8935 }
8936
8937 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv));
8938 }
8939
8940 DEFUN (show_bgp_instance_all,
8941 show_bgp_instance_all_cmd,
8942 "show bgp " BGP_INSTANCE_ALL_CMD " {json}",
8943 SHOW_STR
8944 BGP_STR
8945 BGP_INSTANCE_ALL_HELP_STR
8946 "JavaScript Object Notation\n")
8947 {
8948 u_char uj = use_json(argc, argv);
8949
8950 bgp_show_all_instances_routes_vty (vty, AFI_IP6, SAFI_UNICAST, uj);
8951 return CMD_SUCCESS;
8952 }
8953
8954 ALIAS (show_bgp_view,
8955 show_bgp_instance_ipv6_cmd,
8956 "show bgp " BGP_INSTANCE_CMD " ipv6 {json}",
8957 SHOW_STR
8958 BGP_STR
8959 BGP_INSTANCE_HELP_STR
8960 "Address family\n"
8961 "JavaScript Object Notation\n")
8962
8963 DEFUN (show_bgp_instance_route,
8964 show_bgp_instance_route_cmd,
8965 "show bgp " BGP_INSTANCE_CMD " X:X::X:X {json}",
8966 SHOW_STR
8967 BGP_STR
8968 BGP_INSTANCE_HELP_STR
8969 "Network in the BGP routing table to display\n"
8970 "JavaScript Object Notation\n")
8971 {
8972 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
8973 }
8974
8975 ALIAS (show_bgp_instance_route,
8976 show_bgp_instance_ipv6_route_cmd,
8977 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X {json}",
8978 SHOW_STR
8979 BGP_STR
8980 BGP_INSTANCE_HELP_STR
8981 "Address family\n"
8982 "Network in the BGP routing table to display\n"
8983 "JavaScript Object Notation\n")
8984
8985 DEFUN (show_bgp_instance_route_pathtype,
8986 show_bgp_instance_route_pathtype_cmd,
8987 "show bgp " BGP_INSTANCE_CMD " X:X::X:X (bestpath|multipath) {json}",
8988 SHOW_STR
8989 BGP_STR
8990 BGP_INSTANCE_HELP_STR
8991 "Network in the BGP routing table to display\n"
8992 "Display only the bestpath\n"
8993 "Display only multipaths\n"
8994 "JavaScript Object Notation\n")
8995 {
8996 u_char uj = use_json(argc, argv);
8997 if (strncmp (argv[3], "b", 1) == 0)
8998 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj);
8999 else
9000 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj);
9001 }
9002
9003 ALIAS (show_bgp_instance_route_pathtype,
9004 show_bgp_instance_ipv6_route_pathtype_cmd,
9005 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X (bestpath|multipath) {json}",
9006 SHOW_STR
9007 BGP_STR
9008 BGP_INSTANCE_HELP_STR
9009 "Address family\n"
9010 "Network in the BGP routing table to display\n"
9011 "Display only the bestpath\n"
9012 "Display only multipaths\n"
9013 "JavaScript Object Notation\n")
9014
9015 DEFUN (show_bgp_instance_prefix,
9016 show_bgp_instance_prefix_cmd,
9017 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M {json}",
9018 SHOW_STR
9019 BGP_STR
9020 BGP_INSTANCE_HELP_STR
9021 "IPv6 prefix <network>/<length>\n"
9022 "JavaScript Object Notation\n")
9023 {
9024 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
9025 }
9026
9027 ALIAS (show_bgp_instance_prefix,
9028 show_bgp_instance_ipv6_prefix_cmd,
9029 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M {json}",
9030 SHOW_STR
9031 BGP_STR
9032 BGP_INSTANCE_HELP_STR
9033 "Address family\n"
9034 "IPv6 prefix <network>/<length>\n"
9035 "JavaScript Object Notation\n")
9036
9037 DEFUN (show_bgp_instance_prefix_pathtype,
9038 show_bgp_instance_prefix_pathtype_cmd,
9039 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M (bestpath|multipath) {json}",
9040 SHOW_STR
9041 BGP_STR
9042 BGP_INSTANCE_HELP_STR
9043 "IPv6 prefix <network>/<length>\n"
9044 "Display only the bestpath\n"
9045 "Display only multipaths\n"
9046 "JavaScript Object Notation\n")
9047 {
9048 u_char uj = use_json(argc, argv);
9049 if (strncmp (argv[3], "b", 1) == 0)
9050 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj);
9051 else
9052 return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj);
9053 }
9054
9055 ALIAS (show_bgp_instance_prefix_pathtype,
9056 show_bgp_instance_ipv6_prefix_pathtype_cmd,
9057 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M (bestpath|multipath) {json}",
9058 SHOW_STR
9059 BGP_STR
9060 BGP_INSTANCE_HELP_STR
9061 "Address family\n"
9062 "IPv6 prefix <network>/<length>\n"
9063 "Display only the bestpath\n"
9064 "Display only multipaths\n"
9065 "JavaScript Object Notation\n")
9066
9067 DEFUN (show_bgp_instance_prefix_list,
9068 show_bgp_instance_prefix_list_cmd,
9069 "show bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9070 SHOW_STR
9071 BGP_STR
9072 BGP_INSTANCE_HELP_STR
9073 "Display routes conforming to the prefix-list\n"
9074 "IPv6 prefix-list name\n")
9075 {
9076 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9077 bgp_show_type_prefix_list);
9078 }
9079
9080 ALIAS (show_bgp_instance_prefix_list,
9081 show_bgp_instance_ipv6_prefix_list_cmd,
9082 "show bgp " BGP_INSTANCE_CMD " ipv6 prefix-list WORD",
9083 SHOW_STR
9084 BGP_STR
9085 BGP_INSTANCE_HELP_STR
9086 "Address family\n"
9087 "Display routes conforming to the prefix-list\n"
9088 "IPv6 prefix-list name\n")
9089
9090 DEFUN (show_bgp_instance_filter_list,
9091 show_bgp_instance_filter_list_cmd,
9092 "show bgp " BGP_INSTANCE_CMD " filter-list WORD",
9093 SHOW_STR
9094 BGP_STR
9095 BGP_INSTANCE_HELP_STR
9096 "Display routes conforming to the filter-list\n"
9097 "Regular expression access list name\n")
9098 {
9099 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9100 bgp_show_type_filter_list);
9101 }
9102
9103 ALIAS (show_bgp_instance_filter_list,
9104 show_bgp_instance_ipv6_filter_list_cmd,
9105 "show bgp " BGP_INSTANCE_CMD " ipv6 filter-list WORD",
9106 SHOW_STR
9107 BGP_STR
9108 BGP_INSTANCE_HELP_STR
9109 "Address family\n"
9110 "Display routes conforming to the filter-list\n"
9111 "Regular expression access list name\n")
9112
9113 DEFUN (show_bgp_instance_route_map,
9114 show_bgp_instance_route_map_cmd,
9115 "show bgp " BGP_INSTANCE_CMD " route-map WORD",
9116 SHOW_STR
9117 BGP_STR
9118 BGP_INSTANCE_HELP_STR
9119 "Display routes matching the route-map\n"
9120 "A route-map to match on\n")
9121 {
9122 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9123 bgp_show_type_route_map);
9124 }
9125
9126 ALIAS (show_bgp_instance_route_map,
9127 show_bgp_instance_ipv6_route_map_cmd,
9128 "show bgp " BGP_INSTANCE_CMD " ipv6 route-map WORD",
9129 SHOW_STR
9130 BGP_STR
9131 BGP_INSTANCE_HELP_STR
9132 "Address family\n"
9133 "Display routes matching the route-map\n"
9134 "A route-map to match on\n")
9135
9136 DEFUN (show_bgp_instance_community_list,
9137 show_bgp_instance_community_list_cmd,
9138 "show bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
9139 SHOW_STR
9140 BGP_STR
9141 BGP_INSTANCE_HELP_STR
9142 "Display routes matching the community-list\n"
9143 "community-list number\n"
9144 "community-list name\n")
9145 {
9146 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP6, SAFI_UNICAST);
9147 }
9148
9149 ALIAS (show_bgp_instance_community_list,
9150 show_bgp_instance_ipv6_community_list_cmd,
9151 "show bgp " BGP_INSTANCE_CMD " ipv6 community-list (<1-500>|WORD)",
9152 SHOW_STR
9153 BGP_STR
9154 BGP_INSTANCE_HELP_STR
9155 "Address family\n"
9156 "Display routes matching the community-list\n"
9157 "community-list number\n"
9158 "community-list name\n")
9159
9160 DEFUN (show_bgp_instance_prefix_longer,
9161 show_bgp_instance_prefix_longer_cmd,
9162 "show bgp " BGP_INSTANCE_CMD " X:X::X:X/M longer-prefixes",
9163 SHOW_STR
9164 BGP_STR
9165 BGP_INSTANCE_HELP_STR
9166 "IPv6 prefix <network>/<length>\n"
9167 "Display route and more specific routes\n")
9168 {
9169 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST,
9170 bgp_show_type_prefix_longer);
9171 }
9172
9173 ALIAS (show_bgp_instance_prefix_longer,
9174 show_bgp_instance_ipv6_prefix_longer_cmd,
9175 "show bgp " BGP_INSTANCE_CMD " ipv6 X:X::X:X/M longer-prefixes",
9176 SHOW_STR
9177 BGP_STR
9178 BGP_INSTANCE_HELP_STR
9179 "Address family\n"
9180 "IPv6 prefix <network>/<length>\n"
9181 "Display route and more specific routes\n")
9182
9183 /* old command */
9184 DEFUN (show_ipv6_mbgp,
9185 show_ipv6_mbgp_cmd,
9186 "show ipv6 mbgp {json}",
9187 SHOW_STR
9188 IP_STR
9189 MBGP_STR
9190 "JavaScript Object Notation\n")
9191 {
9192 bgp_show_ipv6_bgp_deprecate_warning(vty);
9193 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
9194 NULL, use_json(argc, argv));
9195 }
9196
9197 /* old command */
9198 DEFUN (show_ipv6_mbgp_route,
9199 show_ipv6_mbgp_route_cmd,
9200 "show ipv6 mbgp X:X::X:X {json}",
9201 SHOW_STR
9202 IP_STR
9203 MBGP_STR
9204 "Network in the MBGP routing table to display\n"
9205 "JavaScript Object Notation\n")
9206 {
9207 bgp_show_ipv6_bgp_deprecate_warning(vty);
9208 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
9209 }
9210
9211 /* old command */
9212 DEFUN (show_ipv6_mbgp_prefix,
9213 show_ipv6_mbgp_prefix_cmd,
9214 "show ipv6 mbgp X:X::X:X/M {json}",
9215 SHOW_STR
9216 IP_STR
9217 MBGP_STR
9218 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9219 "JavaScript Object Notation\n")
9220 {
9221 bgp_show_ipv6_bgp_deprecate_warning(vty);
9222 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
9223 }
9224 #endif
9225
9226
9227 static int
9228 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
9229 safi_t safi, enum bgp_show_type type)
9230 {
9231 int i;
9232 struct buffer *b;
9233 char *regstr;
9234 int first;
9235 regex_t *regex;
9236 int rc;
9237
9238 first = 0;
9239 b = buffer_new (1024);
9240 for (i = 0; i < argc; i++)
9241 {
9242 if (first)
9243 buffer_putc (b, ' ');
9244 else
9245 {
9246 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9247 continue;
9248 first = 1;
9249 }
9250
9251 buffer_putstr (b, argv[i]);
9252 }
9253 buffer_putc (b, '\0');
9254
9255 regstr = buffer_getstr (b);
9256 buffer_free (b);
9257
9258 regex = bgp_regcomp (regstr);
9259 XFREE(MTYPE_TMP, regstr);
9260 if (! regex)
9261 {
9262 vty_out (vty, "Can't compile regexp %s%s", argv[0],
9263 VTY_NEWLINE);
9264 return CMD_WARNING;
9265 }
9266
9267 rc = bgp_show (vty, NULL, afi, safi, type, regex, 0);
9268 bgp_regex_free (regex);
9269 return rc;
9270 }
9271
9272 DEFUN (show_ip_bgp_regexp,
9273 show_ip_bgp_regexp_cmd,
9274 "show ip bgp regexp .LINE",
9275 SHOW_STR
9276 IP_STR
9277 BGP_STR
9278 "Display routes matching the AS path regular expression\n"
9279 "A regular-expression to match the BGP AS paths\n")
9280 {
9281 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9282 bgp_show_type_regexp);
9283 }
9284
9285 DEFUN (show_ip_bgp_flap_regexp,
9286 show_ip_bgp_flap_regexp_cmd,
9287 "show ip bgp flap-statistics regexp .LINE",
9288 SHOW_STR
9289 IP_STR
9290 BGP_STR
9291 "Display flap statistics of routes\n"
9292 "Display routes matching the AS path regular expression\n"
9293 "A regular-expression to match the BGP AS paths\n")
9294 {
9295 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
9296 bgp_show_type_flap_regexp);
9297 }
9298
9299 ALIAS (show_ip_bgp_flap_regexp,
9300 show_ip_bgp_damp_flap_regexp_cmd,
9301 "show ip bgp dampening flap-statistics regexp .LINE",
9302 SHOW_STR
9303 IP_STR
9304 BGP_STR
9305 "Display detailed information about dampening\n"
9306 "Display flap statistics of routes\n"
9307 "Display routes matching the AS path regular expression\n"
9308 "A regular-expression to match the BGP AS paths\n")
9309
9310 DEFUN (show_ip_bgp_ipv4_regexp,
9311 show_ip_bgp_ipv4_regexp_cmd,
9312 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
9313 SHOW_STR
9314 IP_STR
9315 BGP_STR
9316 "Address family\n"
9317 "Address Family modifier\n"
9318 "Address Family modifier\n"
9319 "Display routes matching the AS path regular expression\n"
9320 "A regular-expression to match the BGP AS paths\n")
9321 {
9322 safi_t safi;
9323 safi = bgp_vty_safi_from_arg(argv[0]);
9324 return bgp_show_regexp (vty, argc, argv, AFI_IP, safi,
9325 bgp_show_type_regexp);
9326 }
9327
9328 #ifdef HAVE_IPV6
9329 DEFUN (show_bgp_regexp,
9330 show_bgp_regexp_cmd,
9331 "show bgp regexp .LINE",
9332 SHOW_STR
9333 BGP_STR
9334 "Display routes matching the AS path regular expression\n"
9335 "A regular-expression to match the BGP AS paths\n")
9336 {
9337 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9338 bgp_show_type_regexp);
9339 }
9340
9341 ALIAS (show_bgp_regexp,
9342 show_bgp_ipv6_regexp_cmd,
9343 "show bgp ipv6 regexp .LINE",
9344 SHOW_STR
9345 BGP_STR
9346 "Address family\n"
9347 "Display routes matching the AS path regular expression\n"
9348 "A regular-expression to match the BGP AS paths\n")
9349
9350 /* old command */
9351 DEFUN (show_ipv6_bgp_regexp,
9352 show_ipv6_bgp_regexp_cmd,
9353 "show ipv6 bgp regexp .LINE",
9354 SHOW_STR
9355 IP_STR
9356 BGP_STR
9357 "Display routes matching the AS path regular expression\n"
9358 "A regular-expression to match the BGP AS paths\n")
9359 {
9360 bgp_show_ipv6_bgp_deprecate_warning(vty);
9361 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
9362 bgp_show_type_regexp);
9363 }
9364
9365 /* old command */
9366 DEFUN (show_ipv6_mbgp_regexp,
9367 show_ipv6_mbgp_regexp_cmd,
9368 "show ipv6 mbgp regexp .LINE",
9369 SHOW_STR
9370 IP_STR
9371 BGP_STR
9372 "Display routes matching the AS path regular expression\n"
9373 "A regular-expression to match the MBGP AS paths\n")
9374 {
9375 bgp_show_ipv6_bgp_deprecate_warning(vty);
9376 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
9377 bgp_show_type_regexp);
9378 }
9379 #endif /* HAVE_IPV6 */
9380
9381 static int
9382 bgp_show_prefix_list (struct vty *vty, const char *name,
9383 const char *prefix_list_str, afi_t afi,
9384 safi_t safi, enum bgp_show_type type)
9385 {
9386 struct prefix_list *plist;
9387 struct bgp *bgp = NULL;
9388
9389 if (name && !(bgp = bgp_lookup_by_name(name)))
9390 {
9391 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9392 return CMD_WARNING;
9393 }
9394
9395 plist = prefix_list_lookup (afi, prefix_list_str);
9396 if (plist == NULL)
9397 {
9398 vty_out (vty, "%% %s is not a valid prefix-list name%s",
9399 prefix_list_str, VTY_NEWLINE);
9400 return CMD_WARNING;
9401 }
9402
9403 return bgp_show (vty, bgp, afi, safi, type, plist, 0);
9404 }
9405
9406 DEFUN (show_ip_bgp_prefix_list,
9407 show_ip_bgp_prefix_list_cmd,
9408 "show ip bgp prefix-list WORD",
9409 SHOW_STR
9410 IP_STR
9411 BGP_STR
9412 "Display routes conforming to the prefix-list\n"
9413 "IP prefix-list name\n")
9414 {
9415 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9416 bgp_show_type_prefix_list);
9417 }
9418
9419 DEFUN (show_ip_bgp_instance_prefix_list,
9420 show_ip_bgp_instance_prefix_list_cmd,
9421 "show ip bgp " BGP_INSTANCE_CMD " prefix-list WORD",
9422 SHOW_STR
9423 IP_STR
9424 BGP_STR
9425 BGP_INSTANCE_HELP_STR
9426 "Display routes conforming to the prefix-list\n"
9427 "IP prefix-list name\n")
9428 {
9429 return bgp_show_prefix_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9430 bgp_show_type_prefix_list);
9431 }
9432
9433 DEFUN (show_ip_bgp_flap_prefix_list,
9434 show_ip_bgp_flap_prefix_list_cmd,
9435 "show ip bgp flap-statistics prefix-list WORD",
9436 SHOW_STR
9437 IP_STR
9438 BGP_STR
9439 "Display flap statistics of routes\n"
9440 "Display routes conforming to the prefix-list\n"
9441 "IP prefix-list name\n")
9442 {
9443 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9444 bgp_show_type_flap_prefix_list);
9445 }
9446
9447 ALIAS (show_ip_bgp_flap_prefix_list,
9448 show_ip_bgp_damp_flap_prefix_list_cmd,
9449 "show ip bgp dampening flap-statistics prefix-list WORD",
9450 SHOW_STR
9451 IP_STR
9452 BGP_STR
9453 "Display detailed information about dampening\n"
9454 "Display flap statistics of routes\n"
9455 "Display routes conforming to the prefix-list\n"
9456 "IP prefix-list name\n")
9457
9458 DEFUN (show_ip_bgp_ipv4_prefix_list,
9459 show_ip_bgp_ipv4_prefix_list_cmd,
9460 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
9461 SHOW_STR
9462 IP_STR
9463 BGP_STR
9464 "Address family\n"
9465 "Address Family modifier\n"
9466 "Address Family modifier\n"
9467 "Display routes conforming to the prefix-list\n"
9468 "IP prefix-list name\n")
9469 {
9470 safi_t safi;
9471 safi = bgp_vty_safi_from_arg(argv[0]);
9472 return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, safi,
9473 bgp_show_type_prefix_list);
9474 }
9475
9476 #ifdef HAVE_IPV6
9477 DEFUN (show_bgp_prefix_list,
9478 show_bgp_prefix_list_cmd,
9479 "show bgp prefix-list WORD",
9480 SHOW_STR
9481 BGP_STR
9482 "Display routes conforming to the prefix-list\n"
9483 "IPv6 prefix-list name\n")
9484 {
9485 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9486 bgp_show_type_prefix_list);
9487 }
9488
9489 ALIAS (show_bgp_prefix_list,
9490 show_bgp_ipv6_prefix_list_cmd,
9491 "show bgp ipv6 prefix-list WORD",
9492 SHOW_STR
9493 BGP_STR
9494 "Address family\n"
9495 "Display routes conforming to the prefix-list\n"
9496 "IPv6 prefix-list name\n")
9497
9498 /* old command */
9499 DEFUN (show_ipv6_bgp_prefix_list,
9500 show_ipv6_bgp_prefix_list_cmd,
9501 "show ipv6 bgp prefix-list WORD",
9502 SHOW_STR
9503 IPV6_STR
9504 BGP_STR
9505 "Display routes matching the prefix-list\n"
9506 "IPv6 prefix-list name\n")
9507 {
9508 bgp_show_ipv6_bgp_deprecate_warning(vty);
9509 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9510 bgp_show_type_prefix_list);
9511 }
9512
9513 /* old command */
9514 DEFUN (show_ipv6_mbgp_prefix_list,
9515 show_ipv6_mbgp_prefix_list_cmd,
9516 "show ipv6 mbgp prefix-list WORD",
9517 SHOW_STR
9518 IPV6_STR
9519 MBGP_STR
9520 "Display routes matching the prefix-list\n"
9521 "IPv6 prefix-list name\n")
9522 {
9523 bgp_show_ipv6_bgp_deprecate_warning(vty);
9524 return bgp_show_prefix_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9525 bgp_show_type_prefix_list);
9526 }
9527 #endif /* HAVE_IPV6 */
9528
9529 static int
9530 bgp_show_filter_list (struct vty *vty, const char *name,
9531 const char *filter, afi_t afi,
9532 safi_t safi, enum bgp_show_type type)
9533 {
9534 struct as_list *as_list;
9535 struct bgp *bgp = NULL;
9536
9537 if (name && !(bgp = bgp_lookup_by_name(name)))
9538 {
9539 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9540 return CMD_WARNING;
9541 }
9542
9543 as_list = as_list_lookup (filter);
9544 if (as_list == NULL)
9545 {
9546 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
9547 return CMD_WARNING;
9548 }
9549
9550 return bgp_show (vty, bgp, afi, safi, type, as_list, 0);
9551 }
9552
9553 DEFUN (show_ip_bgp_filter_list,
9554 show_ip_bgp_filter_list_cmd,
9555 "show ip bgp filter-list WORD",
9556 SHOW_STR
9557 IP_STR
9558 BGP_STR
9559 "Display routes conforming to the filter-list\n"
9560 "Regular expression access list name\n")
9561 {
9562 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9563 bgp_show_type_filter_list);
9564 }
9565
9566 DEFUN (show_ip_bgp_instance_filter_list,
9567 show_ip_bgp_instance_filter_list_cmd,
9568 "show ip bgp " BGP_INSTANCE_CMD " filter-list WORD",
9569 SHOW_STR
9570 IP_STR
9571 BGP_STR
9572 BGP_INSTANCE_HELP_STR
9573 "Display routes conforming to the filter-list\n"
9574 "Regular expression access list name\n")
9575 {
9576 return bgp_show_filter_list (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9577 bgp_show_type_filter_list);
9578 }
9579
9580 DEFUN (show_ip_bgp_flap_filter_list,
9581 show_ip_bgp_flap_filter_list_cmd,
9582 "show ip bgp flap-statistics filter-list WORD",
9583 SHOW_STR
9584 IP_STR
9585 BGP_STR
9586 "Display flap statistics of routes\n"
9587 "Display routes conforming to the filter-list\n"
9588 "Regular expression access list name\n")
9589 {
9590 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9591 bgp_show_type_flap_filter_list);
9592 }
9593
9594 ALIAS (show_ip_bgp_flap_filter_list,
9595 show_ip_bgp_damp_flap_filter_list_cmd,
9596 "show ip bgp dampening flap-statistics filter-list WORD",
9597 SHOW_STR
9598 IP_STR
9599 BGP_STR
9600 "Display detailed information about dampening\n"
9601 "Display flap statistics of routes\n"
9602 "Display routes conforming to the filter-list\n"
9603 "Regular expression access list name\n")
9604
9605 DEFUN (show_ip_bgp_ipv4_filter_list,
9606 show_ip_bgp_ipv4_filter_list_cmd,
9607 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
9608 SHOW_STR
9609 IP_STR
9610 BGP_STR
9611 "Address family\n"
9612 "Address Family modifier\n"
9613 "Address Family modifier\n"
9614 "Display routes conforming to the filter-list\n"
9615 "Regular expression access list name\n")
9616 {
9617 safi_t safi;
9618 safi = bgp_vty_safi_from_arg(argv[0]);
9619 return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, safi,
9620 bgp_show_type_filter_list);
9621 }
9622
9623 #ifdef HAVE_IPV6
9624 DEFUN (show_bgp_filter_list,
9625 show_bgp_filter_list_cmd,
9626 "show bgp filter-list WORD",
9627 SHOW_STR
9628 BGP_STR
9629 "Display routes conforming to the filter-list\n"
9630 "Regular expression access list name\n")
9631 {
9632 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9633 bgp_show_type_filter_list);
9634 }
9635
9636 ALIAS (show_bgp_filter_list,
9637 show_bgp_ipv6_filter_list_cmd,
9638 "show bgp ipv6 filter-list WORD",
9639 SHOW_STR
9640 BGP_STR
9641 "Address family\n"
9642 "Display routes conforming to the filter-list\n"
9643 "Regular expression access list name\n")
9644
9645 /* old command */
9646 DEFUN (show_ipv6_bgp_filter_list,
9647 show_ipv6_bgp_filter_list_cmd,
9648 "show ipv6 bgp filter-list WORD",
9649 SHOW_STR
9650 IPV6_STR
9651 BGP_STR
9652 "Display routes conforming to the filter-list\n"
9653 "Regular expression access list name\n")
9654 {
9655 bgp_show_ipv6_bgp_deprecate_warning(vty);
9656 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9657 bgp_show_type_filter_list);
9658 }
9659
9660 /* old command */
9661 DEFUN (show_ipv6_mbgp_filter_list,
9662 show_ipv6_mbgp_filter_list_cmd,
9663 "show ipv6 mbgp filter-list WORD",
9664 SHOW_STR
9665 IPV6_STR
9666 MBGP_STR
9667 "Display routes conforming to the filter-list\n"
9668 "Regular expression access list name\n")
9669 {
9670 bgp_show_ipv6_bgp_deprecate_warning(vty);
9671 return bgp_show_filter_list (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
9672 bgp_show_type_filter_list);
9673 }
9674 #endif /* HAVE_IPV6 */
9675
9676 DEFUN (show_ip_bgp_dampening_info,
9677 show_ip_bgp_dampening_params_cmd,
9678 "show ip bgp dampening parameters",
9679 SHOW_STR
9680 IP_STR
9681 BGP_STR
9682 "Display detailed information about dampening\n"
9683 "Display detail of configured dampening parameters\n")
9684 {
9685 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
9686 }
9687
9688
9689 DEFUN (show_ip_bgp_ipv4_dampening_parameters,
9690 show_ip_bgp_ipv4_dampening_parameters_cmd,
9691 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
9692 SHOW_STR
9693 IP_STR
9694 BGP_STR
9695 "Address family\n"
9696 "Address Family modifier\n"
9697 "Address Family modifier\n"
9698 "Display detailed information about dampening\n"
9699 "Display detail of configured dampening parameters\n")
9700 {
9701 safi_t safi;
9702 safi = bgp_vty_safi_from_arg(argv[0]);
9703 return bgp_show_dampening_parameters (vty, AFI_IP, safi);
9704 }
9705
9706
9707 DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
9708 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
9709 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
9710 SHOW_STR
9711 IP_STR
9712 BGP_STR
9713 "Address family\n"
9714 "Address Family modifier\n"
9715 "Address Family modifier\n"
9716 "Display detailed information about dampening\n"
9717 "Display flap statistics of routes\n")
9718 {
9719 safi_t safi;
9720 safi = bgp_vty_safi_from_arg(argv[0]);
9721 return bgp_show (vty, NULL, AFI_IP, safi,
9722 bgp_show_type_flap_statistics, NULL, 0);
9723 }
9724
9725 DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
9726 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
9727 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
9728 SHOW_STR
9729 IP_STR
9730 BGP_STR
9731 "Address family\n"
9732 "Address Family modifier\n"
9733 "Address Family modifier\n"
9734 "Display detailed information about dampening\n"
9735 "Display paths suppressed due to dampening\n")
9736 {
9737 safi_t safi;
9738 safi = bgp_vty_safi_from_arg(argv[0]);
9739 return bgp_show (vty, NULL, AFI_IP, safi,
9740 bgp_show_type_dampend_paths, NULL, 0);
9741 }
9742
9743 static int
9744 bgp_show_route_map (struct vty *vty, const char *name,
9745 const char *rmap_str, afi_t afi,
9746 safi_t safi, enum bgp_show_type type)
9747 {
9748 struct route_map *rmap;
9749 struct bgp *bgp = NULL;
9750
9751 if (name && !(bgp = bgp_lookup_by_name(name)))
9752 {
9753 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
9754 return CMD_WARNING;
9755 }
9756
9757 rmap = route_map_lookup_by_name (rmap_str);
9758 if (! rmap)
9759 {
9760 vty_out (vty, "%% %s is not a valid route-map name%s",
9761 rmap_str, VTY_NEWLINE);
9762 return CMD_WARNING;
9763 }
9764
9765 return bgp_show (vty, bgp, afi, safi, type, rmap, 0);
9766 }
9767
9768 DEFUN (show_ip_bgp_route_map,
9769 show_ip_bgp_route_map_cmd,
9770 "show ip bgp route-map WORD",
9771 SHOW_STR
9772 IP_STR
9773 BGP_STR
9774 "Display routes matching the route-map\n"
9775 "A route-map to match on\n")
9776 {
9777 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9778 bgp_show_type_route_map);
9779 }
9780
9781 DEFUN (show_ip_bgp_instance_route_map,
9782 show_ip_bgp_instance_route_map_cmd,
9783 "show ip bgp " BGP_INSTANCE_CMD " route-map WORD",
9784 SHOW_STR
9785 IP_STR
9786 BGP_STR
9787 BGP_INSTANCE_HELP_STR
9788 "Display routes matching the route-map\n"
9789 "A route-map to match on\n")
9790 {
9791 return bgp_show_route_map (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
9792 bgp_show_type_route_map);
9793 }
9794
9795 DEFUN (show_ip_bgp_flap_route_map,
9796 show_ip_bgp_flap_route_map_cmd,
9797 "show ip bgp flap-statistics route-map WORD",
9798 SHOW_STR
9799 IP_STR
9800 BGP_STR
9801 "Display flap statistics of routes\n"
9802 "Display routes matching the route-map\n"
9803 "A route-map to match on\n")
9804 {
9805 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
9806 bgp_show_type_flap_route_map);
9807 }
9808
9809 ALIAS (show_ip_bgp_flap_route_map,
9810 show_ip_bgp_damp_flap_route_map_cmd,
9811 "show ip bgp dampening flap-statistics route-map WORD",
9812 SHOW_STR
9813 IP_STR
9814 BGP_STR
9815 "Display detailed information about dampening\n"
9816 "Display flap statistics of routes\n"
9817 "Display routes matching the route-map\n"
9818 "A route-map to match on\n")
9819
9820 DEFUN (show_ip_bgp_ipv4_route_map,
9821 show_ip_bgp_ipv4_route_map_cmd,
9822 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
9823 SHOW_STR
9824 IP_STR
9825 BGP_STR
9826 "Address family\n"
9827 "Address Family modifier\n"
9828 "Address Family modifier\n"
9829 "Display routes matching the route-map\n"
9830 "A route-map to match on\n")
9831 {
9832 safi_t safi;
9833 safi = bgp_vty_safi_from_arg(argv[0]);
9834 return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, safi,
9835 bgp_show_type_route_map);
9836 }
9837
9838 DEFUN (show_bgp_route_map,
9839 show_bgp_route_map_cmd,
9840 "show bgp route-map WORD",
9841 SHOW_STR
9842 BGP_STR
9843 "Display routes matching the route-map\n"
9844 "A route-map to match on\n")
9845 {
9846 return bgp_show_route_map (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
9847 bgp_show_type_route_map);
9848 }
9849
9850 ALIAS (show_bgp_route_map,
9851 show_bgp_ipv6_route_map_cmd,
9852 "show bgp ipv6 route-map WORD",
9853 SHOW_STR
9854 BGP_STR
9855 "Address family\n"
9856 "Display routes matching the route-map\n"
9857 "A route-map to match on\n")
9858
9859 DEFUN (show_ip_bgp_cidr_only,
9860 show_ip_bgp_cidr_only_cmd,
9861 "show ip bgp cidr-only",
9862 SHOW_STR
9863 IP_STR
9864 BGP_STR
9865 "Display only routes with non-natural netmasks\n")
9866 {
9867 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9868 bgp_show_type_cidr_only, NULL, 0);
9869 }
9870
9871 DEFUN (show_ip_bgp_flap_cidr_only,
9872 show_ip_bgp_flap_cidr_only_cmd,
9873 "show ip bgp flap-statistics cidr-only",
9874 SHOW_STR
9875 IP_STR
9876 BGP_STR
9877 "Display flap statistics of routes\n"
9878 "Display only routes with non-natural netmasks\n")
9879 {
9880 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9881 bgp_show_type_flap_cidr_only, NULL, 0);
9882 }
9883
9884 ALIAS (show_ip_bgp_flap_cidr_only,
9885 show_ip_bgp_damp_flap_cidr_only_cmd,
9886 "show ip bgp dampening flap-statistics cidr-only",
9887 SHOW_STR
9888 IP_STR
9889 BGP_STR
9890 "Display detailed information about dampening\n"
9891 "Display flap statistics of routes\n"
9892 "Display only routes with non-natural netmasks\n")
9893
9894 DEFUN (show_ip_bgp_ipv4_cidr_only,
9895 show_ip_bgp_ipv4_cidr_only_cmd,
9896 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9897 SHOW_STR
9898 IP_STR
9899 BGP_STR
9900 "Address family\n"
9901 "Address Family modifier\n"
9902 "Address Family modifier\n"
9903 "Display only routes with non-natural netmasks\n")
9904 {
9905 safi_t safi;
9906 safi = bgp_vty_safi_from_arg(argv[0]);
9907 return bgp_show (vty, NULL, AFI_IP, safi,
9908 bgp_show_type_cidr_only, NULL, 0);
9909 }
9910
9911 DEFUN (show_ip_bgp_community_all,
9912 show_ip_bgp_community_all_cmd,
9913 "show ip bgp community",
9914 SHOW_STR
9915 IP_STR
9916 BGP_STR
9917 "Display routes matching the communities\n")
9918 {
9919 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9920 bgp_show_type_community_all, NULL, 0);
9921 }
9922
9923 DEFUN (show_ip_bgp_ipv4_community_all,
9924 show_ip_bgp_ipv4_community_all_cmd,
9925 "show ip bgp ipv4 (unicast|multicast) community",
9926 SHOW_STR
9927 IP_STR
9928 BGP_STR
9929 "Address family\n"
9930 "Address Family modifier\n"
9931 "Address Family modifier\n"
9932 "Display routes matching the communities\n")
9933 {
9934 safi_t safi;
9935 safi = bgp_vty_safi_from_arg(argv[0]);
9936 return bgp_show (vty, NULL, AFI_IP, safi,
9937 bgp_show_type_community_all, NULL, 0);
9938 }
9939
9940 #ifdef HAVE_IPV6
9941 DEFUN (show_bgp_community_all,
9942 show_bgp_community_all_cmd,
9943 "show bgp community",
9944 SHOW_STR
9945 BGP_STR
9946 "Display routes matching the communities\n")
9947 {
9948 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9949 bgp_show_type_community_all, NULL, 0);
9950 }
9951
9952 ALIAS (show_bgp_community_all,
9953 show_bgp_ipv6_community_all_cmd,
9954 "show bgp ipv6 community",
9955 SHOW_STR
9956 BGP_STR
9957 "Address family\n"
9958 "Display routes matching the communities\n")
9959
9960 /* old command */
9961 DEFUN (show_ipv6_bgp_community_all,
9962 show_ipv6_bgp_community_all_cmd,
9963 "show ipv6 bgp community",
9964 SHOW_STR
9965 IPV6_STR
9966 BGP_STR
9967 "Display routes matching the communities\n")
9968 {
9969 bgp_show_ipv6_bgp_deprecate_warning(vty);
9970 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9971 bgp_show_type_community_all, NULL, 0);
9972 }
9973
9974 /* old command */
9975 DEFUN (show_ipv6_mbgp_community_all,
9976 show_ipv6_mbgp_community_all_cmd,
9977 "show ipv6 mbgp community",
9978 SHOW_STR
9979 IPV6_STR
9980 MBGP_STR
9981 "Display routes matching the communities\n")
9982 {
9983 bgp_show_ipv6_bgp_deprecate_warning(vty);
9984 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9985 bgp_show_type_community_all, NULL, 0);
9986 }
9987 #endif /* HAVE_IPV6 */
9988
9989 static int
9990 bgp_show_community (struct vty *vty, const char *view_name, int argc,
9991 const char **argv, int exact, afi_t afi, safi_t safi)
9992 {
9993 struct community *com;
9994 struct buffer *b;
9995 struct bgp *bgp;
9996 int i;
9997 char *str;
9998 int first = 0;
9999
10000 /* BGP structure lookup */
10001 if (view_name)
10002 {
10003 bgp = bgp_lookup_by_name (view_name);
10004 if (bgp == NULL)
10005 {
10006 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
10007 return CMD_WARNING;
10008 }
10009 }
10010 else
10011 {
10012 bgp = bgp_get_default ();
10013 if (bgp == NULL)
10014 {
10015 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10016 return CMD_WARNING;
10017 }
10018 }
10019
10020 b = buffer_new (1024);
10021 for (i = 0; i < argc; i++)
10022 {
10023 if (first)
10024 buffer_putc (b, ' ');
10025 else
10026 {
10027 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
10028 continue;
10029 first = 1;
10030 }
10031
10032 buffer_putstr (b, argv[i]);
10033 }
10034 buffer_putc (b, '\0');
10035
10036 str = buffer_getstr (b);
10037 buffer_free (b);
10038
10039 com = community_str2com (str);
10040 XFREE (MTYPE_TMP, str);
10041 if (! com)
10042 {
10043 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
10044 return CMD_WARNING;
10045 }
10046
10047 return bgp_show (vty, bgp, afi, safi,
10048 (exact ? bgp_show_type_community_exact :
10049 bgp_show_type_community), com, 0);
10050 }
10051
10052 DEFUN (show_ip_bgp_community,
10053 show_ip_bgp_community_cmd,
10054 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
10055 SHOW_STR
10056 IP_STR
10057 BGP_STR
10058 "Display routes matching the communities\n"
10059 COMMUNITY_AANN_STR
10060 "Do not send outside local AS (well-known community)\n"
10061 "Do not advertise to any peer (well-known community)\n"
10062 "Do not export to next AS (well-known community)\n")
10063 {
10064 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
10065 }
10066
10067 ALIAS (show_ip_bgp_community,
10068 show_ip_bgp_community2_cmd,
10069 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10070 SHOW_STR
10071 IP_STR
10072 BGP_STR
10073 "Display routes matching the communities\n"
10074 COMMUNITY_AANN_STR
10075 "Do not send outside local AS (well-known community)\n"
10076 "Do not advertise to any peer (well-known community)\n"
10077 "Do not export to next AS (well-known community)\n"
10078 COMMUNITY_AANN_STR
10079 "Do not send outside local AS (well-known community)\n"
10080 "Do not advertise to any peer (well-known community)\n"
10081 "Do not export to next AS (well-known community)\n")
10082
10083 ALIAS (show_ip_bgp_community,
10084 show_ip_bgp_community3_cmd,
10085 "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)",
10086 SHOW_STR
10087 IP_STR
10088 BGP_STR
10089 "Display routes matching the communities\n"
10090 COMMUNITY_AANN_STR
10091 "Do not send outside local AS (well-known community)\n"
10092 "Do not advertise to any peer (well-known community)\n"
10093 "Do not export to next AS (well-known community)\n"
10094 COMMUNITY_AANN_STR
10095 "Do not send outside local AS (well-known community)\n"
10096 "Do not advertise to any peer (well-known community)\n"
10097 "Do not export to next AS (well-known community)\n"
10098 COMMUNITY_AANN_STR
10099 "Do not send outside local AS (well-known community)\n"
10100 "Do not advertise to any peer (well-known community)\n"
10101 "Do not export to next AS (well-known community)\n")
10102
10103 ALIAS (show_ip_bgp_community,
10104 show_ip_bgp_community4_cmd,
10105 "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)",
10106 SHOW_STR
10107 IP_STR
10108 BGP_STR
10109 "Display routes matching the communities\n"
10110 COMMUNITY_AANN_STR
10111 "Do not send outside local AS (well-known community)\n"
10112 "Do not advertise to any peer (well-known community)\n"
10113 "Do not export to next AS (well-known community)\n"
10114 COMMUNITY_AANN_STR
10115 "Do not send outside local AS (well-known community)\n"
10116 "Do not advertise to any peer (well-known community)\n"
10117 "Do not export to next AS (well-known community)\n"
10118 COMMUNITY_AANN_STR
10119 "Do not send outside local AS (well-known community)\n"
10120 "Do not advertise to any peer (well-known community)\n"
10121 "Do not export to next AS (well-known community)\n"
10122 COMMUNITY_AANN_STR
10123 "Do not send outside local AS (well-known community)\n"
10124 "Do not advertise to any peer (well-known community)\n"
10125 "Do not export to next AS (well-known community)\n")
10126
10127 DEFUN (show_ip_bgp_ipv4_community,
10128 show_ip_bgp_ipv4_community_cmd,
10129 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10130 SHOW_STR
10131 IP_STR
10132 BGP_STR
10133 "Address family\n"
10134 "Address Family modifier\n"
10135 "Address Family modifier\n"
10136 "Display routes matching the communities\n"
10137 COMMUNITY_AANN_STR
10138 "Do not send outside local AS (well-known community)\n"
10139 "Do not advertise to any peer (well-known community)\n"
10140 "Do not export to next AS (well-known community)\n")
10141 {
10142 safi_t safi;
10143 safi = bgp_vty_safi_from_arg(argv[0]);
10144 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, safi);
10145 }
10146
10147 ALIAS (show_ip_bgp_ipv4_community,
10148 show_ip_bgp_ipv4_community2_cmd,
10149 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10150 SHOW_STR
10151 IP_STR
10152 BGP_STR
10153 "Address family\n"
10154 "Address Family modifier\n"
10155 "Address Family modifier\n"
10156 "Display routes matching the communities\n"
10157 COMMUNITY_AANN_STR
10158 "Do not send outside local AS (well-known community)\n"
10159 "Do not advertise to any peer (well-known community)\n"
10160 "Do not export to next AS (well-known community)\n"
10161 COMMUNITY_AANN_STR
10162 "Do not send outside local AS (well-known community)\n"
10163 "Do not advertise to any peer (well-known community)\n"
10164 "Do not export to next AS (well-known community)\n")
10165
10166 ALIAS (show_ip_bgp_ipv4_community,
10167 show_ip_bgp_ipv4_community3_cmd,
10168 "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)",
10169 SHOW_STR
10170 IP_STR
10171 BGP_STR
10172 "Address family\n"
10173 "Address Family modifier\n"
10174 "Address Family modifier\n"
10175 "Display routes matching the communities\n"
10176 COMMUNITY_AANN_STR
10177 "Do not send outside local AS (well-known community)\n"
10178 "Do not advertise to any peer (well-known community)\n"
10179 "Do not export to next AS (well-known community)\n"
10180 COMMUNITY_AANN_STR
10181 "Do not send outside local AS (well-known community)\n"
10182 "Do not advertise to any peer (well-known community)\n"
10183 "Do not export to next AS (well-known community)\n"
10184 COMMUNITY_AANN_STR
10185 "Do not send outside local AS (well-known community)\n"
10186 "Do not advertise to any peer (well-known community)\n"
10187 "Do not export to next AS (well-known community)\n")
10188
10189 ALIAS (show_ip_bgp_ipv4_community,
10190 show_ip_bgp_ipv4_community4_cmd,
10191 "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)",
10192 SHOW_STR
10193 IP_STR
10194 BGP_STR
10195 "Address family\n"
10196 "Address Family modifier\n"
10197 "Address Family modifier\n"
10198 "Display routes matching the communities\n"
10199 COMMUNITY_AANN_STR
10200 "Do not send outside local AS (well-known community)\n"
10201 "Do not advertise to any peer (well-known community)\n"
10202 "Do not export to next AS (well-known community)\n"
10203 COMMUNITY_AANN_STR
10204 "Do not send outside local AS (well-known community)\n"
10205 "Do not advertise to any peer (well-known community)\n"
10206 "Do not export to next AS (well-known community)\n"
10207 COMMUNITY_AANN_STR
10208 "Do not send outside local AS (well-known community)\n"
10209 "Do not advertise to any peer (well-known community)\n"
10210 "Do not export to next AS (well-known community)\n"
10211 COMMUNITY_AANN_STR
10212 "Do not send outside local AS (well-known community)\n"
10213 "Do not advertise to any peer (well-known community)\n"
10214 "Do not export to next AS (well-known community)\n")
10215
10216 DEFUN (show_bgp_instance_afi_safi_community_all,
10217 show_bgp_instance_afi_safi_community_all_cmd,
10218 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community",
10219 SHOW_STR
10220 BGP_STR
10221 BGP_INSTANCE_HELP_STR
10222 "Address family\n"
10223 "Address family\n"
10224 "Address Family modifier\n"
10225 "Address Family modifier\n"
10226 "Display routes matching the communities\n")
10227 {
10228 int afi;
10229 int safi;
10230 struct bgp *bgp;
10231
10232 /* BGP structure lookup. */
10233 bgp = bgp_lookup_by_name (argv[1]);
10234 if (bgp == NULL)
10235 {
10236 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
10237 return CMD_WARNING;
10238 }
10239
10240 afi = bgp_vty_safi_from_arg(argv[2]);
10241 safi = bgp_vty_safi_from_arg(argv[3]);
10242 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
10243 }
10244
10245 DEFUN (show_bgp_instance_afi_safi_community,
10246 show_bgp_instance_afi_safi_community_cmd,
10247 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10248 SHOW_STR
10249 BGP_STR
10250 BGP_INSTANCE_HELP_STR
10251 "Address family\n"
10252 "Address family\n"
10253 "Address family modifier\n"
10254 "Address family modifier\n"
10255 "Display routes matching the communities\n"
10256 COMMUNITY_AANN_STR
10257 "Do not send outside local AS (well-known community)\n"
10258 "Do not advertise to any peer (well-known community)\n"
10259 "Do not export to next AS (well-known community)\n")
10260 {
10261 int afi;
10262 int safi;
10263
10264 afi = bgp_vty_safi_from_arg(argv[2]);
10265 safi = bgp_vty_safi_from_arg(argv[3]);
10266 return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
10267 }
10268
10269 ALIAS (show_bgp_instance_afi_safi_community,
10270 show_bgp_instance_afi_safi_community2_cmd,
10271 "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)",
10272 SHOW_STR
10273 BGP_STR
10274 BGP_INSTANCE_HELP_STR
10275 "Address family\n"
10276 "Address family\n"
10277 "Address family modifier\n"
10278 "Address family modifier\n"
10279 "Display routes matching the communities\n"
10280 COMMUNITY_AANN_STR
10281 "Do not send outside local AS (well-known community)\n"
10282 "Do not advertise to any peer (well-known community)\n"
10283 "Do not export to next AS (well-known community)\n"
10284 COMMUNITY_AANN_STR
10285 "Do not send outside local AS (well-known community)\n"
10286 "Do not advertise to any peer (well-known community)\n"
10287 "Do not export to next AS (well-known community)\n")
10288
10289 ALIAS (show_bgp_instance_afi_safi_community,
10290 show_bgp_instance_afi_safi_community3_cmd,
10291 "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)",
10292 SHOW_STR
10293 BGP_STR
10294 BGP_INSTANCE_HELP_STR
10295 "Address family\n"
10296 "Address family\n"
10297 "Address family modifier\n"
10298 "Address family modifier\n"
10299 "Display routes matching the communities\n"
10300 COMMUNITY_AANN_STR
10301 "Do not send outside local AS (well-known community)\n"
10302 "Do not advertise to any peer (well-known community)\n"
10303 "Do not export to next AS (well-known community)\n"
10304 COMMUNITY_AANN_STR
10305 "Do not send outside local AS (well-known community)\n"
10306 "Do not advertise to any peer (well-known community)\n"
10307 "Do not export to next AS (well-known community)\n"
10308 COMMUNITY_AANN_STR
10309 "Do not send outside local AS (well-known community)\n"
10310 "Do not advertise to any peer (well-known community)\n"
10311 "Do not export to next AS (well-known community)\n")
10312
10313 ALIAS (show_bgp_instance_afi_safi_community,
10314 show_bgp_instance_afi_safi_community4_cmd,
10315 "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)",
10316 SHOW_STR
10317 BGP_STR
10318 BGP_INSTANCE_HELP_STR
10319 "Address family\n"
10320 "Address family\n"
10321 "Address family modifier\n"
10322 "Address family modifier\n"
10323 "Display routes matching the communities\n"
10324 COMMUNITY_AANN_STR
10325 "Do not send outside local AS (well-known community)\n"
10326 "Do not advertise to any peer (well-known community)\n"
10327 "Do not export to next AS (well-known community)\n"
10328 COMMUNITY_AANN_STR
10329 "Do not send outside local AS (well-known community)\n"
10330 "Do not advertise to any peer (well-known community)\n"
10331 "Do not export to next AS (well-known community)\n"
10332 COMMUNITY_AANN_STR
10333 "Do not send outside local AS (well-known community)\n"
10334 "Do not advertise to any peer (well-known community)\n"
10335 "Do not export to next AS (well-known community)\n"
10336 COMMUNITY_AANN_STR
10337 "Do not send outside local AS (well-known community)\n"
10338 "Do not advertise to any peer (well-known community)\n"
10339 "Do not export to next AS (well-known community)\n")
10340
10341 DEFUN (show_ip_bgp_community_exact,
10342 show_ip_bgp_community_exact_cmd,
10343 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10344 SHOW_STR
10345 IP_STR
10346 BGP_STR
10347 "Display routes matching the communities\n"
10348 COMMUNITY_AANN_STR
10349 "Do not send outside local AS (well-known community)\n"
10350 "Do not advertise to any peer (well-known community)\n"
10351 "Do not export to next AS (well-known community)\n"
10352 "Exact match of the communities")
10353 {
10354 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
10355 }
10356
10357 ALIAS (show_ip_bgp_community_exact,
10358 show_ip_bgp_community2_exact_cmd,
10359 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10360 SHOW_STR
10361 IP_STR
10362 BGP_STR
10363 "Display routes matching the communities\n"
10364 COMMUNITY_AANN_STR
10365 "Do not send outside local AS (well-known community)\n"
10366 "Do not advertise to any peer (well-known community)\n"
10367 "Do not export to next AS (well-known community)\n"
10368 COMMUNITY_AANN_STR
10369 "Do not send outside local AS (well-known community)\n"
10370 "Do not advertise to any peer (well-known community)\n"
10371 "Do not export to next AS (well-known community)\n"
10372 "Exact match of the communities")
10373
10374 ALIAS (show_ip_bgp_community_exact,
10375 show_ip_bgp_community3_exact_cmd,
10376 "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",
10377 SHOW_STR
10378 IP_STR
10379 BGP_STR
10380 "Display routes matching the communities\n"
10381 COMMUNITY_AANN_STR
10382 "Do not send outside local AS (well-known community)\n"
10383 "Do not advertise to any peer (well-known community)\n"
10384 "Do not export to next AS (well-known community)\n"
10385 COMMUNITY_AANN_STR
10386 "Do not send outside local AS (well-known community)\n"
10387 "Do not advertise to any peer (well-known community)\n"
10388 "Do not export to next AS (well-known community)\n"
10389 COMMUNITY_AANN_STR
10390 "Do not send outside local AS (well-known community)\n"
10391 "Do not advertise to any peer (well-known community)\n"
10392 "Do not export to next AS (well-known community)\n"
10393 "Exact match of the communities")
10394
10395 ALIAS (show_ip_bgp_community_exact,
10396 show_ip_bgp_community4_exact_cmd,
10397 "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",
10398 SHOW_STR
10399 IP_STR
10400 BGP_STR
10401 "Display routes matching the communities\n"
10402 COMMUNITY_AANN_STR
10403 "Do not send outside local AS (well-known community)\n"
10404 "Do not advertise to any peer (well-known community)\n"
10405 "Do not export to next AS (well-known community)\n"
10406 COMMUNITY_AANN_STR
10407 "Do not send outside local AS (well-known community)\n"
10408 "Do not advertise to any peer (well-known community)\n"
10409 "Do not export to next AS (well-known community)\n"
10410 COMMUNITY_AANN_STR
10411 "Do not send outside local AS (well-known community)\n"
10412 "Do not advertise to any peer (well-known community)\n"
10413 "Do not export to next AS (well-known community)\n"
10414 COMMUNITY_AANN_STR
10415 "Do not send outside local AS (well-known community)\n"
10416 "Do not advertise to any peer (well-known community)\n"
10417 "Do not export to next AS (well-known community)\n"
10418 "Exact match of the communities")
10419
10420 DEFUN (show_ip_bgp_ipv4_community_exact,
10421 show_ip_bgp_ipv4_community_exact_cmd,
10422 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10423 SHOW_STR
10424 IP_STR
10425 BGP_STR
10426 "Address family\n"
10427 "Address Family modifier\n"
10428 "Address Family modifier\n"
10429 "Display routes matching the communities\n"
10430 COMMUNITY_AANN_STR
10431 "Do not send outside local AS (well-known community)\n"
10432 "Do not advertise to any peer (well-known community)\n"
10433 "Do not export to next AS (well-known community)\n"
10434 "Exact match of the communities")
10435 {
10436 safi_t safi;
10437 safi = bgp_vty_safi_from_arg(argv[0]);
10438 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, safi);
10439 }
10440
10441 ALIAS (show_ip_bgp_ipv4_community_exact,
10442 show_ip_bgp_ipv4_community2_exact_cmd,
10443 "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",
10444 SHOW_STR
10445 IP_STR
10446 BGP_STR
10447 "Address family\n"
10448 "Address Family modifier\n"
10449 "Address Family modifier\n"
10450 "Display routes matching the communities\n"
10451 COMMUNITY_AANN_STR
10452 "Do not send outside local AS (well-known community)\n"
10453 "Do not advertise to any peer (well-known community)\n"
10454 "Do not export to next AS (well-known community)\n"
10455 COMMUNITY_AANN_STR
10456 "Do not send outside local AS (well-known community)\n"
10457 "Do not advertise to any peer (well-known community)\n"
10458 "Do not export to next AS (well-known community)\n"
10459 "Exact match of the communities")
10460
10461 ALIAS (show_ip_bgp_ipv4_community_exact,
10462 show_ip_bgp_ipv4_community3_exact_cmd,
10463 "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",
10464 SHOW_STR
10465 IP_STR
10466 BGP_STR
10467 "Address family\n"
10468 "Address Family modifier\n"
10469 "Address Family modifier\n"
10470 "Display routes matching the communities\n"
10471 COMMUNITY_AANN_STR
10472 "Do not send outside local AS (well-known community)\n"
10473 "Do not advertise to any peer (well-known community)\n"
10474 "Do not export to next AS (well-known community)\n"
10475 COMMUNITY_AANN_STR
10476 "Do not send outside local AS (well-known community)\n"
10477 "Do not advertise to any peer (well-known community)\n"
10478 "Do not export to next AS (well-known community)\n"
10479 COMMUNITY_AANN_STR
10480 "Do not send outside local AS (well-known community)\n"
10481 "Do not advertise to any peer (well-known community)\n"
10482 "Do not export to next AS (well-known community)\n"
10483 "Exact match of the communities")
10484
10485 ALIAS (show_ip_bgp_ipv4_community_exact,
10486 show_ip_bgp_ipv4_community4_exact_cmd,
10487 "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",
10488 SHOW_STR
10489 IP_STR
10490 BGP_STR
10491 "Address family\n"
10492 "Address Family modifier\n"
10493 "Address Family modifier\n"
10494 "Display routes matching the communities\n"
10495 COMMUNITY_AANN_STR
10496 "Do not send outside local AS (well-known community)\n"
10497 "Do not advertise to any peer (well-known community)\n"
10498 "Do not export to next AS (well-known community)\n"
10499 COMMUNITY_AANN_STR
10500 "Do not send outside local AS (well-known community)\n"
10501 "Do not advertise to any peer (well-known community)\n"
10502 "Do not export to next AS (well-known community)\n"
10503 COMMUNITY_AANN_STR
10504 "Do not send outside local AS (well-known community)\n"
10505 "Do not advertise to any peer (well-known community)\n"
10506 "Do not export to next AS (well-known community)\n"
10507 COMMUNITY_AANN_STR
10508 "Do not send outside local AS (well-known community)\n"
10509 "Do not advertise to any peer (well-known community)\n"
10510 "Do not export to next AS (well-known community)\n"
10511 "Exact match of the communities")
10512
10513 #ifdef HAVE_IPV6
10514 DEFUN (show_bgp_community,
10515 show_bgp_community_cmd,
10516 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
10517 SHOW_STR
10518 BGP_STR
10519 "Display routes matching the communities\n"
10520 COMMUNITY_AANN_STR
10521 "Do not send outside local AS (well-known community)\n"
10522 "Do not advertise to any peer (well-known community)\n"
10523 "Do not export to next AS (well-known community)\n")
10524 {
10525 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10526 }
10527
10528 ALIAS (show_bgp_community,
10529 show_bgp_ipv6_community_cmd,
10530 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
10531 SHOW_STR
10532 BGP_STR
10533 "Address family\n"
10534 "Display routes matching the communities\n"
10535 COMMUNITY_AANN_STR
10536 "Do not send outside local AS (well-known community)\n"
10537 "Do not advertise to any peer (well-known community)\n"
10538 "Do not export to next AS (well-known community)\n")
10539
10540 ALIAS (show_bgp_community,
10541 show_bgp_community2_cmd,
10542 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10543 SHOW_STR
10544 BGP_STR
10545 "Display routes matching the communities\n"
10546 COMMUNITY_AANN_STR
10547 "Do not send outside local AS (well-known community)\n"
10548 "Do not advertise to any peer (well-known community)\n"
10549 "Do not export to next AS (well-known community)\n"
10550 COMMUNITY_AANN_STR
10551 "Do not send outside local AS (well-known community)\n"
10552 "Do not advertise to any peer (well-known community)\n"
10553 "Do not export to next AS (well-known community)\n")
10554
10555 ALIAS (show_bgp_community,
10556 show_bgp_ipv6_community2_cmd,
10557 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10558 SHOW_STR
10559 BGP_STR
10560 "Address family\n"
10561 "Display routes matching the communities\n"
10562 COMMUNITY_AANN_STR
10563 "Do not send outside local AS (well-known community)\n"
10564 "Do not advertise to any peer (well-known community)\n"
10565 "Do not export to next AS (well-known community)\n"
10566 COMMUNITY_AANN_STR
10567 "Do not send outside local AS (well-known community)\n"
10568 "Do not advertise to any peer (well-known community)\n"
10569 "Do not export to next AS (well-known community)\n")
10570
10571 ALIAS (show_bgp_community,
10572 show_bgp_community3_cmd,
10573 "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)",
10574 SHOW_STR
10575 BGP_STR
10576 "Display routes matching the communities\n"
10577 COMMUNITY_AANN_STR
10578 "Do not send outside local AS (well-known community)\n"
10579 "Do not advertise to any peer (well-known community)\n"
10580 "Do not export to next AS (well-known community)\n"
10581 COMMUNITY_AANN_STR
10582 "Do not send outside local AS (well-known community)\n"
10583 "Do not advertise to any peer (well-known community)\n"
10584 "Do not export to next AS (well-known community)\n"
10585 COMMUNITY_AANN_STR
10586 "Do not send outside local AS (well-known community)\n"
10587 "Do not advertise to any peer (well-known community)\n"
10588 "Do not export to next AS (well-known community)\n")
10589
10590 ALIAS (show_bgp_community,
10591 show_bgp_ipv6_community3_cmd,
10592 "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)",
10593 SHOW_STR
10594 BGP_STR
10595 "Address family\n"
10596 "Display routes matching the communities\n"
10597 COMMUNITY_AANN_STR
10598 "Do not send outside local AS (well-known community)\n"
10599 "Do not advertise to any peer (well-known community)\n"
10600 "Do not export to next AS (well-known community)\n"
10601 COMMUNITY_AANN_STR
10602 "Do not send outside local AS (well-known community)\n"
10603 "Do not advertise to any peer (well-known community)\n"
10604 "Do not export to next AS (well-known community)\n"
10605 COMMUNITY_AANN_STR
10606 "Do not send outside local AS (well-known community)\n"
10607 "Do not advertise to any peer (well-known community)\n"
10608 "Do not export to next AS (well-known community)\n")
10609
10610 ALIAS (show_bgp_community,
10611 show_bgp_community4_cmd,
10612 "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)",
10613 SHOW_STR
10614 BGP_STR
10615 "Display routes matching the communities\n"
10616 COMMUNITY_AANN_STR
10617 "Do not send outside local AS (well-known community)\n"
10618 "Do not advertise to any peer (well-known community)\n"
10619 "Do not export to next AS (well-known community)\n"
10620 COMMUNITY_AANN_STR
10621 "Do not send outside local AS (well-known community)\n"
10622 "Do not advertise to any peer (well-known community)\n"
10623 "Do not export to next AS (well-known community)\n"
10624 COMMUNITY_AANN_STR
10625 "Do not send outside local AS (well-known community)\n"
10626 "Do not advertise to any peer (well-known community)\n"
10627 "Do not export to next AS (well-known community)\n"
10628 COMMUNITY_AANN_STR
10629 "Do not send outside local AS (well-known community)\n"
10630 "Do not advertise to any peer (well-known community)\n"
10631 "Do not export to next AS (well-known community)\n")
10632
10633 ALIAS (show_bgp_community,
10634 show_bgp_ipv6_community4_cmd,
10635 "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)",
10636 SHOW_STR
10637 BGP_STR
10638 "Address family\n"
10639 "Display routes matching the communities\n"
10640 COMMUNITY_AANN_STR
10641 "Do not send outside local AS (well-known community)\n"
10642 "Do not advertise to any peer (well-known community)\n"
10643 "Do not export to next AS (well-known community)\n"
10644 COMMUNITY_AANN_STR
10645 "Do not send outside local AS (well-known community)\n"
10646 "Do not advertise to any peer (well-known community)\n"
10647 "Do not export to next AS (well-known community)\n"
10648 COMMUNITY_AANN_STR
10649 "Do not send outside local AS (well-known community)\n"
10650 "Do not advertise to any peer (well-known community)\n"
10651 "Do not export to next AS (well-known community)\n"
10652 COMMUNITY_AANN_STR
10653 "Do not send outside local AS (well-known community)\n"
10654 "Do not advertise to any peer (well-known community)\n"
10655 "Do not export to next AS (well-known community)\n")
10656
10657 /* old command */
10658 DEFUN (show_ipv6_bgp_community,
10659 show_ipv6_bgp_community_cmd,
10660 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
10661 SHOW_STR
10662 IPV6_STR
10663 BGP_STR
10664 "Display routes matching the communities\n"
10665 COMMUNITY_AANN_STR
10666 "Do not send outside local AS (well-known community)\n"
10667 "Do not advertise to any peer (well-known community)\n"
10668 "Do not export to next AS (well-known community)\n")
10669 {
10670 bgp_show_ipv6_bgp_deprecate_warning(vty);
10671 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
10672 }
10673
10674 /* old command */
10675 ALIAS (show_ipv6_bgp_community,
10676 show_ipv6_bgp_community2_cmd,
10677 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10678 SHOW_STR
10679 IPV6_STR
10680 BGP_STR
10681 "Display routes matching the communities\n"
10682 COMMUNITY_AANN_STR
10683 "Do not send outside local AS (well-known community)\n"
10684 "Do not advertise to any peer (well-known community)\n"
10685 "Do not export to next AS (well-known community)\n"
10686 COMMUNITY_AANN_STR
10687 "Do not send outside local AS (well-known community)\n"
10688 "Do not advertise to any peer (well-known community)\n"
10689 "Do not export to next AS (well-known community)\n")
10690
10691 /* old command */
10692 ALIAS (show_ipv6_bgp_community,
10693 show_ipv6_bgp_community3_cmd,
10694 "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)",
10695 SHOW_STR
10696 IPV6_STR
10697 BGP_STR
10698 "Display routes matching the communities\n"
10699 COMMUNITY_AANN_STR
10700 "Do not send outside local AS (well-known community)\n"
10701 "Do not advertise to any peer (well-known community)\n"
10702 "Do not export to next AS (well-known community)\n"
10703 COMMUNITY_AANN_STR
10704 "Do not send outside local AS (well-known community)\n"
10705 "Do not advertise to any peer (well-known community)\n"
10706 "Do not export to next AS (well-known community)\n"
10707 COMMUNITY_AANN_STR
10708 "Do not send outside local AS (well-known community)\n"
10709 "Do not advertise to any peer (well-known community)\n"
10710 "Do not export to next AS (well-known community)\n")
10711
10712 /* old command */
10713 ALIAS (show_ipv6_bgp_community,
10714 show_ipv6_bgp_community4_cmd,
10715 "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)",
10716 SHOW_STR
10717 IPV6_STR
10718 BGP_STR
10719 "Display routes matching the communities\n"
10720 COMMUNITY_AANN_STR
10721 "Do not send outside local AS (well-known community)\n"
10722 "Do not advertise to any peer (well-known community)\n"
10723 "Do not export to next AS (well-known community)\n"
10724 COMMUNITY_AANN_STR
10725 "Do not send outside local AS (well-known community)\n"
10726 "Do not advertise to any peer (well-known community)\n"
10727 "Do not export to next AS (well-known community)\n"
10728 COMMUNITY_AANN_STR
10729 "Do not send outside local AS (well-known community)\n"
10730 "Do not advertise to any peer (well-known community)\n"
10731 "Do not export to next AS (well-known community)\n"
10732 COMMUNITY_AANN_STR
10733 "Do not send outside local AS (well-known community)\n"
10734 "Do not advertise to any peer (well-known community)\n"
10735 "Do not export to next AS (well-known community)\n")
10736
10737 DEFUN (show_bgp_community_exact,
10738 show_bgp_community_exact_cmd,
10739 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10740 SHOW_STR
10741 BGP_STR
10742 "Display routes matching the communities\n"
10743 COMMUNITY_AANN_STR
10744 "Do not send outside local AS (well-known community)\n"
10745 "Do not advertise to any peer (well-known community)\n"
10746 "Do not export to next AS (well-known community)\n"
10747 "Exact match of the communities")
10748 {
10749 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10750 }
10751
10752 ALIAS (show_bgp_community_exact,
10753 show_bgp_ipv6_community_exact_cmd,
10754 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10755 SHOW_STR
10756 BGP_STR
10757 "Address family\n"
10758 "Display routes matching the communities\n"
10759 COMMUNITY_AANN_STR
10760 "Do not send outside local AS (well-known community)\n"
10761 "Do not advertise to any peer (well-known community)\n"
10762 "Do not export to next AS (well-known community)\n"
10763 "Exact match of the communities")
10764
10765 ALIAS (show_bgp_community_exact,
10766 show_bgp_community2_exact_cmd,
10767 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10768 SHOW_STR
10769 BGP_STR
10770 "Display routes matching the communities\n"
10771 COMMUNITY_AANN_STR
10772 "Do not send outside local AS (well-known community)\n"
10773 "Do not advertise to any peer (well-known community)\n"
10774 "Do not export to next AS (well-known community)\n"
10775 COMMUNITY_AANN_STR
10776 "Do not send outside local AS (well-known community)\n"
10777 "Do not advertise to any peer (well-known community)\n"
10778 "Do not export to next AS (well-known community)\n"
10779 "Exact match of the communities")
10780
10781 ALIAS (show_bgp_community_exact,
10782 show_bgp_ipv6_community2_exact_cmd,
10783 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10784 SHOW_STR
10785 BGP_STR
10786 "Address family\n"
10787 "Display routes matching the communities\n"
10788 COMMUNITY_AANN_STR
10789 "Do not send outside local AS (well-known community)\n"
10790 "Do not advertise to any peer (well-known community)\n"
10791 "Do not export to next AS (well-known community)\n"
10792 COMMUNITY_AANN_STR
10793 "Do not send outside local AS (well-known community)\n"
10794 "Do not advertise to any peer (well-known community)\n"
10795 "Do not export to next AS (well-known community)\n"
10796 "Exact match of the communities")
10797
10798 ALIAS (show_bgp_community_exact,
10799 show_bgp_community3_exact_cmd,
10800 "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",
10801 SHOW_STR
10802 BGP_STR
10803 "Display routes matching the communities\n"
10804 COMMUNITY_AANN_STR
10805 "Do not send outside local AS (well-known community)\n"
10806 "Do not advertise to any peer (well-known community)\n"
10807 "Do not export to next AS (well-known community)\n"
10808 COMMUNITY_AANN_STR
10809 "Do not send outside local AS (well-known community)\n"
10810 "Do not advertise to any peer (well-known community)\n"
10811 "Do not export to next AS (well-known community)\n"
10812 COMMUNITY_AANN_STR
10813 "Do not send outside local AS (well-known community)\n"
10814 "Do not advertise to any peer (well-known community)\n"
10815 "Do not export to next AS (well-known community)\n"
10816 "Exact match of the communities")
10817
10818 ALIAS (show_bgp_community_exact,
10819 show_bgp_ipv6_community3_exact_cmd,
10820 "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",
10821 SHOW_STR
10822 BGP_STR
10823 "Address family\n"
10824 "Display routes matching the communities\n"
10825 COMMUNITY_AANN_STR
10826 "Do not send outside local AS (well-known community)\n"
10827 "Do not advertise to any peer (well-known community)\n"
10828 "Do not export to next AS (well-known community)\n"
10829 COMMUNITY_AANN_STR
10830 "Do not send outside local AS (well-known community)\n"
10831 "Do not advertise to any peer (well-known community)\n"
10832 "Do not export to next AS (well-known community)\n"
10833 COMMUNITY_AANN_STR
10834 "Do not send outside local AS (well-known community)\n"
10835 "Do not advertise to any peer (well-known community)\n"
10836 "Do not export to next AS (well-known community)\n"
10837 "Exact match of the communities")
10838
10839 ALIAS (show_bgp_community_exact,
10840 show_bgp_community4_exact_cmd,
10841 "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",
10842 SHOW_STR
10843 BGP_STR
10844 "Display routes matching the communities\n"
10845 COMMUNITY_AANN_STR
10846 "Do not send outside local AS (well-known community)\n"
10847 "Do not advertise to any peer (well-known community)\n"
10848 "Do not export to next AS (well-known community)\n"
10849 COMMUNITY_AANN_STR
10850 "Do not send outside local AS (well-known community)\n"
10851 "Do not advertise to any peer (well-known community)\n"
10852 "Do not export to next AS (well-known community)\n"
10853 COMMUNITY_AANN_STR
10854 "Do not send outside local AS (well-known community)\n"
10855 "Do not advertise to any peer (well-known community)\n"
10856 "Do not export to next AS (well-known community)\n"
10857 COMMUNITY_AANN_STR
10858 "Do not send outside local AS (well-known community)\n"
10859 "Do not advertise to any peer (well-known community)\n"
10860 "Do not export to next AS (well-known community)\n"
10861 "Exact match of the communities")
10862
10863 ALIAS (show_bgp_community_exact,
10864 show_bgp_ipv6_community4_exact_cmd,
10865 "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",
10866 SHOW_STR
10867 BGP_STR
10868 "Address family\n"
10869 "Display routes matching the communities\n"
10870 COMMUNITY_AANN_STR
10871 "Do not send outside local AS (well-known community)\n"
10872 "Do not advertise to any peer (well-known community)\n"
10873 "Do not export to next AS (well-known community)\n"
10874 COMMUNITY_AANN_STR
10875 "Do not send outside local AS (well-known community)\n"
10876 "Do not advertise to any peer (well-known community)\n"
10877 "Do not export to next AS (well-known community)\n"
10878 COMMUNITY_AANN_STR
10879 "Do not send outside local AS (well-known community)\n"
10880 "Do not advertise to any peer (well-known community)\n"
10881 "Do not export to next AS (well-known community)\n"
10882 COMMUNITY_AANN_STR
10883 "Do not send outside local AS (well-known community)\n"
10884 "Do not advertise to any peer (well-known community)\n"
10885 "Do not export to next AS (well-known community)\n"
10886 "Exact match of the communities")
10887
10888 /* old command */
10889 DEFUN (show_ipv6_bgp_community_exact,
10890 show_ipv6_bgp_community_exact_cmd,
10891 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10892 SHOW_STR
10893 IPV6_STR
10894 BGP_STR
10895 "Display routes matching the communities\n"
10896 COMMUNITY_AANN_STR
10897 "Do not send outside local AS (well-known community)\n"
10898 "Do not advertise to any peer (well-known community)\n"
10899 "Do not export to next AS (well-known community)\n"
10900 "Exact match of the communities")
10901 {
10902 bgp_show_ipv6_bgp_deprecate_warning(vty);
10903 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10904 }
10905
10906 /* old command */
10907 ALIAS (show_ipv6_bgp_community_exact,
10908 show_ipv6_bgp_community2_exact_cmd,
10909 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10910 SHOW_STR
10911 IPV6_STR
10912 BGP_STR
10913 "Display routes matching the communities\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_community3_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) 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 "Exact match of the communities")
10945
10946 /* old command */
10947 ALIAS (show_ipv6_bgp_community_exact,
10948 show_ipv6_bgp_community4_exact_cmd,
10949 "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",
10950 SHOW_STR
10951 IPV6_STR
10952 BGP_STR
10953 "Display routes matching the communities\n"
10954 COMMUNITY_AANN_STR
10955 "Do not send outside local AS (well-known community)\n"
10956 "Do not advertise to any peer (well-known community)\n"
10957 "Do not export to next AS (well-known community)\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 COMMUNITY_AANN_STR
10963 "Do not send outside local AS (well-known community)\n"
10964 "Do not advertise to any peer (well-known community)\n"
10965 "Do not export to next AS (well-known community)\n"
10966 COMMUNITY_AANN_STR
10967 "Do not send outside local AS (well-known community)\n"
10968 "Do not advertise to any peer (well-known community)\n"
10969 "Do not export to next AS (well-known community)\n"
10970 "Exact match of the communities")
10971
10972 /* old command */
10973 DEFUN (show_ipv6_mbgp_community,
10974 show_ipv6_mbgp_community_cmd,
10975 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10976 SHOW_STR
10977 IPV6_STR
10978 MBGP_STR
10979 "Display routes matching the communities\n"
10980 COMMUNITY_AANN_STR
10981 "Do not send outside local AS (well-known community)\n"
10982 "Do not advertise to any peer (well-known community)\n"
10983 "Do not export to next AS (well-known community)\n")
10984 {
10985 bgp_show_ipv6_bgp_deprecate_warning(vty);
10986 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10987 }
10988
10989 /* old command */
10990 ALIAS (show_ipv6_mbgp_community,
10991 show_ipv6_mbgp_community2_cmd,
10992 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10993 SHOW_STR
10994 IPV6_STR
10995 MBGP_STR
10996 "Display routes matching the communities\n"
10997 COMMUNITY_AANN_STR
10998 "Do not send outside local AS (well-known community)\n"
10999 "Do not advertise to any peer (well-known community)\n"
11000 "Do not export to next AS (well-known community)\n"
11001 COMMUNITY_AANN_STR
11002 "Do not send outside local AS (well-known community)\n"
11003 "Do not advertise to any peer (well-known community)\n"
11004 "Do not export to next AS (well-known community)\n")
11005
11006 /* old command */
11007 ALIAS (show_ipv6_mbgp_community,
11008 show_ipv6_mbgp_community3_cmd,
11009 "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)",
11010 SHOW_STR
11011 IPV6_STR
11012 MBGP_STR
11013 "Display routes matching the communities\n"
11014 COMMUNITY_AANN_STR
11015 "Do not send outside local AS (well-known community)\n"
11016 "Do not advertise to any peer (well-known community)\n"
11017 "Do not export to next AS (well-known community)\n"
11018 COMMUNITY_AANN_STR
11019 "Do not send outside local AS (well-known community)\n"
11020 "Do not advertise to any peer (well-known community)\n"
11021 "Do not export to next AS (well-known community)\n"
11022 COMMUNITY_AANN_STR
11023 "Do not send outside local AS (well-known community)\n"
11024 "Do not advertise to any peer (well-known community)\n"
11025 "Do not export to next AS (well-known community)\n")
11026
11027 /* old command */
11028 ALIAS (show_ipv6_mbgp_community,
11029 show_ipv6_mbgp_community4_cmd,
11030 "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)",
11031 SHOW_STR
11032 IPV6_STR
11033 MBGP_STR
11034 "Display routes matching the communities\n"
11035 COMMUNITY_AANN_STR
11036 "Do not send outside local AS (well-known community)\n"
11037 "Do not advertise to any peer (well-known community)\n"
11038 "Do not export to next AS (well-known community)\n"
11039 COMMUNITY_AANN_STR
11040 "Do not send outside local AS (well-known community)\n"
11041 "Do not advertise to any peer (well-known community)\n"
11042 "Do not export to next AS (well-known community)\n"
11043 COMMUNITY_AANN_STR
11044 "Do not send outside local AS (well-known community)\n"
11045 "Do not advertise to any peer (well-known community)\n"
11046 "Do not export to next AS (well-known community)\n"
11047 COMMUNITY_AANN_STR
11048 "Do not send outside local AS (well-known community)\n"
11049 "Do not advertise to any peer (well-known community)\n"
11050 "Do not export to next AS (well-known community)\n")
11051
11052 /* old command */
11053 DEFUN (show_ipv6_mbgp_community_exact,
11054 show_ipv6_mbgp_community_exact_cmd,
11055 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
11056 SHOW_STR
11057 IPV6_STR
11058 MBGP_STR
11059 "Display routes matching the communities\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 bgp_show_ipv6_bgp_deprecate_warning(vty);
11067 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
11068 }
11069
11070 /* old command */
11071 ALIAS (show_ipv6_mbgp_community_exact,
11072 show_ipv6_mbgp_community2_exact_cmd,
11073 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
11074 SHOW_STR
11075 IPV6_STR
11076 MBGP_STR
11077 "Display routes matching the communities\n"
11078 COMMUNITY_AANN_STR
11079 "Do not send outside local AS (well-known community)\n"
11080 "Do not advertise to any peer (well-known community)\n"
11081 "Do not export to next AS (well-known community)\n"
11082 COMMUNITY_AANN_STR
11083 "Do not send outside local AS (well-known community)\n"
11084 "Do not advertise to any peer (well-known community)\n"
11085 "Do not export to next AS (well-known community)\n"
11086 "Exact match of the communities")
11087
11088 /* old command */
11089 ALIAS (show_ipv6_mbgp_community_exact,
11090 show_ipv6_mbgp_community3_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) 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 "Exact match of the communities")
11109
11110 /* old command */
11111 ALIAS (show_ipv6_mbgp_community_exact,
11112 show_ipv6_mbgp_community4_exact_cmd,
11113 "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",
11114 SHOW_STR
11115 IPV6_STR
11116 MBGP_STR
11117 "Display routes matching the communities\n"
11118 COMMUNITY_AANN_STR
11119 "Do not send outside local AS (well-known community)\n"
11120 "Do not advertise to any peer (well-known community)\n"
11121 "Do not export to next AS (well-known community)\n"
11122 COMMUNITY_AANN_STR
11123 "Do not send outside local AS (well-known community)\n"
11124 "Do not advertise to any peer (well-known community)\n"
11125 "Do not export to next AS (well-known community)\n"
11126 COMMUNITY_AANN_STR
11127 "Do not send outside local AS (well-known community)\n"
11128 "Do not advertise to any peer (well-known community)\n"
11129 "Do not export to next AS (well-known community)\n"
11130 COMMUNITY_AANN_STR
11131 "Do not send outside local AS (well-known community)\n"
11132 "Do not advertise to any peer (well-known community)\n"
11133 "Do not export to next AS (well-known community)\n"
11134 "Exact match of the communities")
11135 #endif /* HAVE_IPV6 */
11136
11137 static int
11138 bgp_show_community_list (struct vty *vty, const char *name,
11139 const char *com, int exact,
11140 afi_t afi, safi_t safi)
11141 {
11142 struct community_list *list;
11143 struct bgp *bgp = NULL;
11144
11145 if (name && !(bgp = bgp_lookup_by_name(name)))
11146 {
11147 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11148 return CMD_WARNING;
11149 }
11150
11151 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
11152 if (list == NULL)
11153 {
11154 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11155 VTY_NEWLINE);
11156 return CMD_WARNING;
11157 }
11158
11159 return bgp_show (vty, bgp, afi, safi,
11160 (exact ? bgp_show_type_community_list_exact :
11161 bgp_show_type_community_list), list, 0);
11162 }
11163
11164 DEFUN (show_ip_bgp_community_list,
11165 show_ip_bgp_community_list_cmd,
11166 "show ip bgp community-list (<1-500>|WORD)",
11167 SHOW_STR
11168 IP_STR
11169 BGP_STR
11170 "Display routes matching the community-list\n"
11171 "community-list number\n"
11172 "community-list name\n")
11173 {
11174 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP, SAFI_UNICAST);
11175 }
11176
11177 DEFUN (show_ip_bgp_instance_community_list,
11178 show_ip_bgp_instance_community_list_cmd,
11179 "show ip bgp " BGP_INSTANCE_CMD " community-list (<1-500>|WORD)",
11180 SHOW_STR
11181 IP_STR
11182 BGP_STR
11183 BGP_INSTANCE_HELP_STR
11184 "Display routes matching the community-list\n"
11185 "community-list number\n"
11186 "community-list name\n")
11187 {
11188 return bgp_show_community_list (vty, argv[1], argv[2], 0, AFI_IP, SAFI_UNICAST);
11189 }
11190
11191 DEFUN (show_ip_bgp_ipv4_community_list,
11192 show_ip_bgp_ipv4_community_list_cmd,
11193 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11194 SHOW_STR
11195 IP_STR
11196 BGP_STR
11197 "Address family\n"
11198 "Address Family modifier\n"
11199 "Address Family modifier\n"
11200 "Display routes matching the community-list\n"
11201 "community-list number\n"
11202 "community-list name\n")
11203 {
11204 safi_t safi;
11205 safi = bgp_vty_safi_from_arg(argv[0]);
11206 return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, safi);
11207 }
11208
11209 DEFUN (show_ip_bgp_community_list_exact,
11210 show_ip_bgp_community_list_exact_cmd,
11211 "show ip bgp community-list (<1-500>|WORD) exact-match",
11212 SHOW_STR
11213 IP_STR
11214 BGP_STR
11215 "Display routes matching the community-list\n"
11216 "community-list number\n"
11217 "community-list name\n"
11218 "Exact match of the communities\n")
11219 {
11220 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP, SAFI_UNICAST);
11221 }
11222
11223 DEFUN (show_ip_bgp_ipv4_community_list_exact,
11224 show_ip_bgp_ipv4_community_list_exact_cmd,
11225 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11226 SHOW_STR
11227 IP_STR
11228 BGP_STR
11229 "Address family\n"
11230 "Address Family modifier\n"
11231 "Address Family modifier\n"
11232 "Display routes matching the community-list\n"
11233 "community-list number\n"
11234 "community-list name\n"
11235 "Exact match of the communities\n")
11236 {
11237 safi_t safi;
11238 safi = bgp_vty_safi_from_arg(argv[0]);
11239 return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, safi);
11240 }
11241
11242 #ifdef HAVE_IPV6
11243 DEFUN (show_bgp_community_list,
11244 show_bgp_community_list_cmd,
11245 "show bgp community-list (<1-500>|WORD)",
11246 SHOW_STR
11247 BGP_STR
11248 "Display routes matching the community-list\n"
11249 "community-list number\n"
11250 "community-list name\n")
11251 {
11252 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11253 }
11254
11255 ALIAS (show_bgp_community_list,
11256 show_bgp_ipv6_community_list_cmd,
11257 "show bgp ipv6 community-list (<1-500>|WORD)",
11258 SHOW_STR
11259 BGP_STR
11260 "Address family\n"
11261 "Display routes matching the community-list\n"
11262 "community-list number\n"
11263 "community-list name\n")
11264
11265 /* old command */
11266 DEFUN (show_ipv6_bgp_community_list,
11267 show_ipv6_bgp_community_list_cmd,
11268 "show ipv6 bgp community-list WORD",
11269 SHOW_STR
11270 IPV6_STR
11271 BGP_STR
11272 "Display routes matching the community-list\n"
11273 "community-list name\n")
11274 {
11275 bgp_show_ipv6_bgp_deprecate_warning(vty);
11276 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11277 }
11278
11279 /* old command */
11280 DEFUN (show_ipv6_mbgp_community_list,
11281 show_ipv6_mbgp_community_list_cmd,
11282 "show ipv6 mbgp community-list WORD",
11283 SHOW_STR
11284 IPV6_STR
11285 MBGP_STR
11286 "Display routes matching the community-list\n"
11287 "community-list name\n")
11288 {
11289 bgp_show_ipv6_bgp_deprecate_warning(vty);
11290 return bgp_show_community_list (vty, NULL, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11291 }
11292
11293 DEFUN (show_bgp_community_list_exact,
11294 show_bgp_community_list_exact_cmd,
11295 "show bgp community-list (<1-500>|WORD) exact-match",
11296 SHOW_STR
11297 BGP_STR
11298 "Display routes matching the community-list\n"
11299 "community-list number\n"
11300 "community-list name\n"
11301 "Exact match of the communities\n")
11302 {
11303 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11304 }
11305
11306 ALIAS (show_bgp_community_list_exact,
11307 show_bgp_ipv6_community_list_exact_cmd,
11308 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11309 SHOW_STR
11310 BGP_STR
11311 "Address family\n"
11312 "Display routes matching the community-list\n"
11313 "community-list number\n"
11314 "community-list name\n"
11315 "Exact match of the communities\n")
11316
11317 /* old command */
11318 DEFUN (show_ipv6_bgp_community_list_exact,
11319 show_ipv6_bgp_community_list_exact_cmd,
11320 "show ipv6 bgp community-list WORD exact-match",
11321 SHOW_STR
11322 IPV6_STR
11323 BGP_STR
11324 "Display routes matching the community-list\n"
11325 "community-list name\n"
11326 "Exact match of the communities\n")
11327 {
11328 bgp_show_ipv6_bgp_deprecate_warning(vty);
11329 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11330 }
11331
11332 /* old command */
11333 DEFUN (show_ipv6_mbgp_community_list_exact,
11334 show_ipv6_mbgp_community_list_exact_cmd,
11335 "show ipv6 mbgp community-list WORD exact-match",
11336 SHOW_STR
11337 IPV6_STR
11338 MBGP_STR
11339 "Display routes matching the community-list\n"
11340 "community-list name\n"
11341 "Exact match of the communities\n")
11342 {
11343 bgp_show_ipv6_bgp_deprecate_warning(vty);
11344 return bgp_show_community_list (vty, NULL, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11345 }
11346 #endif /* HAVE_IPV6 */
11347
11348 static int
11349 bgp_show_prefix_longer (struct vty *vty, const char *name,
11350 const char *prefix, afi_t afi,
11351 safi_t safi, enum bgp_show_type type)
11352 {
11353 int ret;
11354 struct prefix *p;
11355 struct bgp *bgp = NULL;
11356
11357 if (name && !(bgp = bgp_lookup_by_name(name)))
11358 {
11359 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11360 return CMD_WARNING;
11361 }
11362
11363 p = prefix_new();
11364
11365 ret = str2prefix (prefix, p);
11366 if (! ret)
11367 {
11368 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11369 return CMD_WARNING;
11370 }
11371
11372 ret = bgp_show (vty, bgp, afi, safi, type, p, 0);
11373 prefix_free(p);
11374 return ret;
11375 }
11376
11377 DEFUN (show_ip_bgp_prefix_longer,
11378 show_ip_bgp_prefix_longer_cmd,
11379 "show ip bgp A.B.C.D/M longer-prefixes",
11380 SHOW_STR
11381 IP_STR
11382 BGP_STR
11383 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11384 "Display route and more specific routes\n")
11385 {
11386 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11387 bgp_show_type_prefix_longer);
11388 }
11389
11390 DEFUN (show_ip_bgp_instance_prefix_longer,
11391 show_ip_bgp_instance_prefix_longer_cmd,
11392 "show ip bgp " BGP_INSTANCE_CMD " A.B.C.D/M longer-prefixes",
11393 SHOW_STR
11394 IP_STR
11395 BGP_STR
11396 BGP_INSTANCE_HELP_STR
11397 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11398 "Display route and more specific routes\n")
11399 {
11400 return bgp_show_prefix_longer (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST,
11401 bgp_show_type_prefix_longer);
11402 }
11403
11404 DEFUN (show_ip_bgp_flap_prefix_longer,
11405 show_ip_bgp_flap_prefix_longer_cmd,
11406 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11407 SHOW_STR
11408 IP_STR
11409 BGP_STR
11410 "Display flap statistics of routes\n"
11411 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11412 "Display route and more specific routes\n")
11413 {
11414 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11415 bgp_show_type_flap_prefix_longer);
11416 }
11417
11418 ALIAS (show_ip_bgp_flap_prefix_longer,
11419 show_ip_bgp_damp_flap_prefix_longer_cmd,
11420 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11421 SHOW_STR
11422 IP_STR
11423 BGP_STR
11424 "Display detailed information about dampening\n"
11425 "Display flap statistics of routes\n"
11426 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11427 "Display route and more specific routes\n")
11428
11429 DEFUN (show_ip_bgp_ipv4_prefix_longer,
11430 show_ip_bgp_ipv4_prefix_longer_cmd,
11431 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11432 SHOW_STR
11433 IP_STR
11434 BGP_STR
11435 "Address family\n"
11436 "Address Family modifier\n"
11437 "Address Family modifier\n"
11438 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11439 "Display route and more specific routes\n")
11440 {
11441 safi_t safi;
11442 safi = bgp_vty_safi_from_arg(argv[0]);
11443 return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, safi,
11444 bgp_show_type_prefix_longer);
11445 }
11446
11447 DEFUN (show_ip_bgp_flap_address,
11448 show_ip_bgp_flap_address_cmd,
11449 "show ip bgp flap-statistics A.B.C.D",
11450 SHOW_STR
11451 IP_STR
11452 BGP_STR
11453 "Display flap statistics of routes\n"
11454 "Network in the BGP routing table to display\n")
11455 {
11456 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11457 bgp_show_type_flap_address);
11458 }
11459
11460 ALIAS (show_ip_bgp_flap_address,
11461 show_ip_bgp_damp_flap_address_cmd,
11462 "show ip bgp dampening flap-statistics A.B.C.D",
11463 SHOW_STR
11464 IP_STR
11465 BGP_STR
11466 "Display detailed information about dampening\n"
11467 "Display flap statistics of routes\n"
11468 "Network in the BGP routing table to display\n")
11469
11470 DEFUN (show_ip_bgp_flap_prefix,
11471 show_ip_bgp_flap_prefix_cmd,
11472 "show ip bgp flap-statistics A.B.C.D/M",
11473 SHOW_STR
11474 IP_STR
11475 BGP_STR
11476 "Display flap statistics of routes\n"
11477 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11478 {
11479 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST,
11480 bgp_show_type_flap_prefix);
11481 }
11482
11483 ALIAS (show_ip_bgp_flap_prefix,
11484 show_ip_bgp_damp_flap_prefix_cmd,
11485 "show ip bgp dampening flap-statistics A.B.C.D/M",
11486 SHOW_STR
11487 IP_STR
11488 BGP_STR
11489 "Display detailed information about dampening\n"
11490 "Display flap statistics of routes\n"
11491 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11492
11493 #ifdef HAVE_IPV6
11494 DEFUN (show_bgp_prefix_longer,
11495 show_bgp_prefix_longer_cmd,
11496 "show bgp X:X::X:X/M longer-prefixes",
11497 SHOW_STR
11498 BGP_STR
11499 "IPv6 prefix <network>/<length>\n"
11500 "Display route and more specific routes\n")
11501 {
11502 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11503 bgp_show_type_prefix_longer);
11504 }
11505
11506 ALIAS (show_bgp_prefix_longer,
11507 show_bgp_ipv6_prefix_longer_cmd,
11508 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11509 SHOW_STR
11510 BGP_STR
11511 "Address family\n"
11512 "IPv6 prefix <network>/<length>\n"
11513 "Display route and more specific routes\n")
11514
11515 /* old command */
11516 DEFUN (show_ipv6_bgp_prefix_longer,
11517 show_ipv6_bgp_prefix_longer_cmd,
11518 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11519 SHOW_STR
11520 IPV6_STR
11521 BGP_STR
11522 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11523 "Display route and more specific routes\n")
11524 {
11525 bgp_show_ipv6_bgp_deprecate_warning(vty);
11526 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST,
11527 bgp_show_type_prefix_longer);
11528 }
11529
11530 /* old command */
11531 DEFUN (show_ipv6_mbgp_prefix_longer,
11532 show_ipv6_mbgp_prefix_longer_cmd,
11533 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11534 SHOW_STR
11535 IPV6_STR
11536 MBGP_STR
11537 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11538 "Display route and more specific routes\n")
11539 {
11540 bgp_show_ipv6_bgp_deprecate_warning(vty);
11541 return bgp_show_prefix_longer (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST,
11542 bgp_show_type_prefix_longer);
11543 }
11544 #endif /* HAVE_IPV6 */
11545
11546 static struct peer *
11547 peer_lookup_in_view (struct vty *vty, const char *view_name,
11548 const char *ip_str, u_char use_json)
11549 {
11550 int ret;
11551 struct bgp *bgp;
11552 struct peer *peer;
11553 union sockunion su;
11554
11555 /* BGP structure lookup. */
11556 if (view_name)
11557 {
11558 bgp = bgp_lookup_by_name (view_name);
11559 if (! bgp)
11560 {
11561 if (use_json)
11562 {
11563 json_object *json_no = NULL;
11564 json_no = json_object_new_object();
11565 json_object_string_add(json_no, "warning", "Can't find BGP view");
11566 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11567 json_object_free(json_no);
11568 }
11569 else
11570 vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
11571 return NULL;
11572 }
11573 }
11574 else
11575 {
11576 bgp = bgp_get_default ();
11577 if (! bgp)
11578 {
11579 if (use_json)
11580 {
11581 json_object *json_no = NULL;
11582 json_no = json_object_new_object();
11583 json_object_string_add(json_no, "warning", "No BGP process configured");
11584 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11585 json_object_free(json_no);
11586 }
11587 else
11588 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11589 return NULL;
11590 }
11591 }
11592
11593 /* Get peer sockunion. */
11594 ret = str2sockunion (ip_str, &su);
11595 if (ret < 0)
11596 {
11597 peer = peer_lookup_by_conf_if (bgp, ip_str);
11598 if (!peer)
11599 {
11600 peer = peer_lookup_by_hostname(bgp, ip_str);
11601
11602 if (!peer)
11603 {
11604 if (use_json)
11605 {
11606 json_object *json_no = NULL;
11607 json_no = json_object_new_object();
11608 json_object_string_add(json_no, "malformedAddressOrName", ip_str);
11609 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11610 json_object_free(json_no);
11611 }
11612 else
11613 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
11614 return NULL;
11615 }
11616 }
11617 return peer;
11618 }
11619
11620 /* Peer structure lookup. */
11621 peer = peer_lookup (bgp, &su);
11622 if (! peer)
11623 {
11624 if (use_json)
11625 {
11626 json_object *json_no = NULL;
11627 json_no = json_object_new_object();
11628 json_object_string_add(json_no, "warning","No such neighbor");
11629 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
11630 json_object_free(json_no);
11631 }
11632 else
11633 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11634 return NULL;
11635 }
11636
11637 return peer;
11638 }
11639
11640 enum bgp_stats
11641 {
11642 BGP_STATS_MAXBITLEN = 0,
11643 BGP_STATS_RIB,
11644 BGP_STATS_PREFIXES,
11645 BGP_STATS_TOTPLEN,
11646 BGP_STATS_UNAGGREGATEABLE,
11647 BGP_STATS_MAX_AGGREGATEABLE,
11648 BGP_STATS_AGGREGATES,
11649 BGP_STATS_SPACE,
11650 BGP_STATS_ASPATH_COUNT,
11651 BGP_STATS_ASPATH_MAXHOPS,
11652 BGP_STATS_ASPATH_TOTHOPS,
11653 BGP_STATS_ASPATH_MAXSIZE,
11654 BGP_STATS_ASPATH_TOTSIZE,
11655 BGP_STATS_ASN_HIGHEST,
11656 BGP_STATS_MAX,
11657 };
11658
11659 static const char *table_stats_strs[] =
11660 {
11661 [BGP_STATS_PREFIXES] = "Total Prefixes",
11662 [BGP_STATS_TOTPLEN] = "Average prefix length",
11663 [BGP_STATS_RIB] = "Total Advertisements",
11664 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11665 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11666 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11667 [BGP_STATS_SPACE] = "Address space advertised",
11668 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11669 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11670 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11671 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11672 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11673 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11674 [BGP_STATS_MAX] = NULL,
11675 };
11676
11677 struct bgp_table_stats
11678 {
11679 struct bgp_table *table;
11680 unsigned long long counts[BGP_STATS_MAX];
11681 };
11682
11683 #if 0
11684 #define TALLY_SIGFIG 100000
11685 static unsigned long
11686 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11687 {
11688 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11689 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11690 unsigned long ret = newtot / count;
11691
11692 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11693 return ret + 1;
11694 else
11695 return ret;
11696 }
11697 #endif
11698
11699 static int
11700 bgp_table_stats_walker (struct thread *t)
11701 {
11702 struct bgp_node *rn;
11703 struct bgp_node *top;
11704 struct bgp_table_stats *ts = THREAD_ARG (t);
11705 unsigned int space = 0;
11706
11707 if (!(top = bgp_table_top (ts->table)))
11708 return 0;
11709
11710 switch (top->p.family)
11711 {
11712 case AF_INET:
11713 space = IPV4_MAX_BITLEN;
11714 break;
11715 case AF_INET6:
11716 space = IPV6_MAX_BITLEN;
11717 break;
11718 }
11719
11720 ts->counts[BGP_STATS_MAXBITLEN] = space;
11721
11722 for (rn = top; rn; rn = bgp_route_next (rn))
11723 {
11724 struct bgp_info *ri;
11725 struct bgp_node *prn = bgp_node_parent_nolock (rn);
11726 unsigned int rinum = 0;
11727
11728 if (rn == top)
11729 continue;
11730
11731 if (!rn->info)
11732 continue;
11733
11734 ts->counts[BGP_STATS_PREFIXES]++;
11735 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11736
11737 #if 0
11738 ts->counts[BGP_STATS_AVGPLEN]
11739 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11740 ts->counts[BGP_STATS_AVGPLEN],
11741 rn->p.prefixlen);
11742 #endif
11743
11744 /* check if the prefix is included by any other announcements */
11745 while (prn && !prn->info)
11746 prn = bgp_node_parent_nolock (prn);
11747
11748 if (prn == NULL || prn == top)
11749 {
11750 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11751 /* announced address space */
11752 if (space)
11753 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11754 }
11755 else if (prn->info)
11756 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11757
11758 for (ri = rn->info; ri; ri = ri->next)
11759 {
11760 rinum++;
11761 ts->counts[BGP_STATS_RIB]++;
11762
11763 if (ri->attr &&
11764 (CHECK_FLAG (ri->attr->flag,
11765 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11766 ts->counts[BGP_STATS_AGGREGATES]++;
11767
11768 /* as-path stats */
11769 if (ri->attr && ri->attr->aspath)
11770 {
11771 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11772 unsigned int size = aspath_size (ri->attr->aspath);
11773 as_t highest = aspath_highest (ri->attr->aspath);
11774
11775 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11776
11777 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11778 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11779
11780 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11781 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11782
11783 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11784 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11785 #if 0
11786 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11787 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11788 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11789 hops);
11790 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11791 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11792 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11793 size);
11794 #endif
11795 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11796 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11797 }
11798 }
11799 }
11800 return 0;
11801 }
11802
11803 static int
11804 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11805 {
11806 struct bgp_table_stats ts;
11807 unsigned int i;
11808
11809 if (!bgp->rib[afi][safi])
11810 {
11811 vty_out (vty, "%% No RIB exists for the AFI(%d)/SAFI(%d)%s",
11812 afi, safi, VTY_NEWLINE);
11813 return CMD_WARNING;
11814 }
11815
11816 memset (&ts, 0, sizeof (ts));
11817 ts.table = bgp->rib[afi][safi];
11818 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11819
11820 vty_out (vty, "BGP %s RIB statistics%s%s",
11821 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11822
11823 for (i = 0; i < BGP_STATS_MAX; i++)
11824 {
11825 if (!table_stats_strs[i])
11826 continue;
11827
11828 switch (i)
11829 {
11830 #if 0
11831 case BGP_STATS_ASPATH_AVGHOPS:
11832 case BGP_STATS_ASPATH_AVGSIZE:
11833 case BGP_STATS_AVGPLEN:
11834 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11835 vty_out (vty, "%12.2f",
11836 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11837 break;
11838 #endif
11839 case BGP_STATS_ASPATH_TOTHOPS:
11840 case BGP_STATS_ASPATH_TOTSIZE:
11841 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11842 vty_out (vty, "%12.2f",
11843 ts.counts[i] ?
11844 (float)ts.counts[i] /
11845 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11846 : 0);
11847 break;
11848 case BGP_STATS_TOTPLEN:
11849 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11850 vty_out (vty, "%12.2f",
11851 ts.counts[i] ?
11852 (float)ts.counts[i] /
11853 (float)ts.counts[BGP_STATS_PREFIXES]
11854 : 0);
11855 break;
11856 case BGP_STATS_SPACE:
11857 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11858 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11859 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11860 break;
11861 vty_out (vty, "%30s: ", "%% announced ");
11862 vty_out (vty, "%12.2f%s",
11863 100 * (float)ts.counts[BGP_STATS_SPACE] /
11864 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
11865 VTY_NEWLINE);
11866 vty_out (vty, "%30s: ", "/8 equivalent ");
11867 vty_out (vty, "%12.2f%s",
11868 (float)ts.counts[BGP_STATS_SPACE] /
11869 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11870 VTY_NEWLINE);
11871 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11872 break;
11873 vty_out (vty, "%30s: ", "/24 equivalent ");
11874 vty_out (vty, "%12.2f",
11875 (float)ts.counts[BGP_STATS_SPACE] /
11876 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11877 break;
11878 default:
11879 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11880 vty_out (vty, "%12llu", ts.counts[i]);
11881 }
11882
11883 vty_out (vty, "%s", VTY_NEWLINE);
11884 }
11885 return CMD_SUCCESS;
11886 }
11887
11888 static int
11889 bgp_table_stats_vty (struct vty *vty, const char *name,
11890 const char *afi_str, const char *safi_str)
11891 {
11892 struct bgp *bgp;
11893 afi_t afi;
11894 safi_t safi;
11895
11896 if (name)
11897 bgp = bgp_lookup_by_name (name);
11898 else
11899 bgp = bgp_get_default ();
11900
11901 if (!bgp)
11902 {
11903 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
11904 return CMD_WARNING;
11905 }
11906 afi = bgp_vty_afi_from_arg(afi_str);
11907 if (afi == AFI_MAX)
11908 {
11909 vty_out (vty, "%% Invalid address family \"%s\"%s",
11910 afi_str, VTY_NEWLINE);
11911 return CMD_WARNING;
11912 }
11913 safi = bgp_vty_safi_from_arg(safi_str);
11914 if (safi == SAFI_MAX)
11915 {
11916 vty_out (vty, "%% Invalid subsequent address family %s%s",
11917 safi_str, VTY_NEWLINE);
11918 return CMD_WARNING;
11919 }
11920
11921 return bgp_table_stats (vty, bgp, afi, safi);
11922 }
11923
11924 DEFUN (show_bgp_statistics,
11925 show_bgp_statistics_cmd,
11926 "show bgp "BGP_AFI_SAFI_CMD_STR" statistics",
11927 SHOW_STR
11928 BGP_STR
11929 BGP_AFI_SAFI_HELP_STR
11930 "BGP RIB advertisement statistics\n")
11931 {
11932 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11933 }
11934
11935 DEFUN (show_bgp_statistics_view,
11936 show_bgp_statistics_view_cmd,
11937 "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" statistics",
11938 SHOW_STR
11939 BGP_STR
11940 BGP_INSTANCE_HELP_STR
11941 BGP_AFI_SAFI_HELP_STR
11942 "BGP RIB advertisement statistics\n")
11943 {
11944 return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
11945 }
11946
11947 enum bgp_pcounts
11948 {
11949 PCOUNT_ADJ_IN = 0,
11950 PCOUNT_DAMPED,
11951 PCOUNT_REMOVED,
11952 PCOUNT_HISTORY,
11953 PCOUNT_STALE,
11954 PCOUNT_VALID,
11955 PCOUNT_ALL,
11956 PCOUNT_COUNTED,
11957 PCOUNT_PFCNT, /* the figure we display to users */
11958 PCOUNT_MAX,
11959 };
11960
11961 static const char *pcount_strs[] =
11962 {
11963 [PCOUNT_ADJ_IN] = "Adj-in",
11964 [PCOUNT_DAMPED] = "Damped",
11965 [PCOUNT_REMOVED] = "Removed",
11966 [PCOUNT_HISTORY] = "History",
11967 [PCOUNT_STALE] = "Stale",
11968 [PCOUNT_VALID] = "Valid",
11969 [PCOUNT_ALL] = "All RIB",
11970 [PCOUNT_COUNTED] = "PfxCt counted",
11971 [PCOUNT_PFCNT] = "Useable",
11972 [PCOUNT_MAX] = NULL,
11973 };
11974
11975 struct peer_pcounts
11976 {
11977 unsigned int count[PCOUNT_MAX];
11978 const struct peer *peer;
11979 const struct bgp_table *table;
11980 };
11981
11982 static int
11983 bgp_peer_count_walker (struct thread *t)
11984 {
11985 struct bgp_node *rn;
11986 struct peer_pcounts *pc = THREAD_ARG (t);
11987 const struct peer *peer = pc->peer;
11988
11989 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
11990 {
11991 struct bgp_adj_in *ain;
11992 struct bgp_info *ri;
11993
11994 for (ain = rn->adj_in; ain; ain = ain->next)
11995 if (ain->peer == peer)
11996 pc->count[PCOUNT_ADJ_IN]++;
11997
11998 for (ri = rn->info; ri; ri = ri->next)
11999 {
12000 char buf[SU_ADDRSTRLEN];
12001
12002 if (ri->peer != peer)
12003 continue;
12004
12005 pc->count[PCOUNT_ALL]++;
12006
12007 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
12008 pc->count[PCOUNT_DAMPED]++;
12009 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
12010 pc->count[PCOUNT_HISTORY]++;
12011 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
12012 pc->count[PCOUNT_REMOVED]++;
12013 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
12014 pc->count[PCOUNT_STALE]++;
12015 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
12016 pc->count[PCOUNT_VALID]++;
12017 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12018 pc->count[PCOUNT_PFCNT]++;
12019
12020 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12021 {
12022 pc->count[PCOUNT_COUNTED]++;
12023 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12024 zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x",
12025 peer->host,
12026 inet_ntop(rn->p.family, &rn->p.u.prefix,
12027 buf, SU_ADDRSTRLEN),
12028 rn->p.prefixlen,
12029 ri->flags);
12030 }
12031 else
12032 {
12033 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
12034 zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x",
12035 peer->host,
12036 inet_ntop(rn->p.family, &rn->p.u.prefix,
12037 buf, SU_ADDRSTRLEN),
12038 rn->p.prefixlen,
12039 ri->flags);
12040 }
12041 }
12042 }
12043 return 0;
12044 }
12045
12046 static int
12047 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json)
12048 {
12049 struct peer_pcounts pcounts = { .peer = peer };
12050 unsigned int i;
12051 json_object *json = NULL;
12052 json_object *json_loop = NULL;
12053
12054 if (use_json)
12055 {
12056 json = json_object_new_object();
12057 json_loop = json_object_new_object();
12058 }
12059
12060 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12061 || !peer->bgp->rib[afi][safi])
12062 {
12063 if (use_json)
12064 {
12065 json_object_string_add(json, "warning", "No such neighbor or address family");
12066 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12067 json_object_free(json);
12068 }
12069 else
12070 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12071
12072 return CMD_WARNING;
12073 }
12074
12075 memset (&pcounts, 0, sizeof(pcounts));
12076 pcounts.peer = peer;
12077 pcounts.table = peer->bgp->rib[afi][safi];
12078
12079 /* in-place call via thread subsystem so as to record execution time
12080 * * stats for the thread-walk (i.e. ensure this can't be blamed on
12081 * * on just vty_read()).
12082 * */
12083 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12084
12085 if (use_json)
12086 {
12087 json_object_string_add(json, "prefixCountsFor", peer->host);
12088 json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi));
12089 json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]);
12090
12091 for (i = 0; i < PCOUNT_MAX; i++)
12092 json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]);
12093
12094 json_object_object_add(json, "ribTableWalkCounters", json_loop);
12095
12096 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12097 {
12098 json_object_string_add(json, "pfxctDriftFor", peer->host);
12099 json_object_string_add(json, "recommended", "Please report this bug, with the above command output");
12100 }
12101 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12102 json_object_free(json);
12103 }
12104 else
12105 {
12106
12107 if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
12108 {
12109 vty_out (vty, "Prefix counts for %s/%s, %s%s",
12110 peer->hostname, peer->host, afi_safi_print (afi, safi),
12111 VTY_NEWLINE);
12112 }
12113 else
12114 {
12115 vty_out (vty, "Prefix counts for %s, %s%s",
12116 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12117 }
12118
12119 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12120 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12121 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12122
12123 for (i = 0; i < PCOUNT_MAX; i++)
12124 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
12125
12126 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
12127 {
12128 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12129 peer->host, VTY_NEWLINE);
12130 vty_out (vty, "Please report this bug, with the above command output%s",
12131 VTY_NEWLINE);
12132 }
12133 }
12134
12135 return CMD_SUCCESS;
12136 }
12137
12138 DEFUN (show_ip_bgp_neighbor_prefix_counts,
12139 show_ip_bgp_neighbor_prefix_counts_cmd,
12140 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12141 SHOW_STR
12142 IP_STR
12143 BGP_STR
12144 "Detailed information on TCP and BGP neighbor connections\n"
12145 "Neighbor to display information about\n"
12146 "Neighbor to display information about\n"
12147 "Neighbor on bgp configured interface\n"
12148 "Display detailed prefix count information\n"
12149 "JavaScript Object Notation\n")
12150 {
12151 struct peer *peer;
12152 u_char uj = use_json(argc, argv);
12153
12154 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12155 if (! peer)
12156 return CMD_WARNING;
12157
12158 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12159 }
12160
12161 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
12162 show_ip_bgp_instance_neighbor_prefix_counts_cmd,
12163 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12164 SHOW_STR
12165 IP_STR
12166 BGP_STR
12167 BGP_INSTANCE_HELP_STR
12168 "Detailed information on TCP and BGP neighbor connections\n"
12169 "Neighbor to display information about\n"
12170 "Neighbor to display information about\n"
12171 "Neighbor on bgp configured interface\n"
12172 "Display detailed prefix count information\n"
12173 "JavaScript Object Notation\n")
12174 {
12175 struct peer *peer;
12176 u_char uj = use_json(argc, argv);
12177
12178 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12179 if (! peer)
12180 return CMD_WARNING;
12181
12182 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj);
12183 }
12184
12185 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12186 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12187 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12188 SHOW_STR
12189 BGP_STR
12190 "Address family\n"
12191 "Detailed information on TCP and BGP neighbor connections\n"
12192 "Neighbor to display information about\n"
12193 "Neighbor to display information about\n"
12194 "Neighbor on bgp configured interface\n"
12195 "Display detailed prefix count information\n"
12196 "JavaScript Object Notation\n")
12197 {
12198 struct peer *peer;
12199 u_char uj = use_json(argc, argv);
12200
12201 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12202 if (! peer)
12203 return CMD_WARNING;
12204
12205 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12206 }
12207
12208 DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts,
12209 show_bgp_instance_ipv6_neighbor_prefix_counts_cmd,
12210 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12211 SHOW_STR
12212 BGP_STR
12213 BGP_INSTANCE_HELP_STR
12214 "Address family\n"
12215 "Detailed information on TCP and BGP neighbor connections\n"
12216 "Neighbor to display information about\n"
12217 "Neighbor to display information about\n"
12218 "Neighbor on bgp configured interface\n"
12219 "Display detailed prefix count information\n"
12220 "JavaScript Object Notation\n")
12221 {
12222 struct peer *peer;
12223 u_char uj = use_json(argc, argv);
12224
12225 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12226 if (! peer)
12227 return CMD_WARNING;
12228
12229 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj);
12230 }
12231
12232 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12233 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12234 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}",
12235 SHOW_STR
12236 IP_STR
12237 BGP_STR
12238 "Address family\n"
12239 "Address Family modifier\n"
12240 "Address Family modifier\n"
12241 "Detailed information on TCP and BGP neighbor connections\n"
12242 "Neighbor to display information about\n"
12243 "Neighbor to display information about\n"
12244 "Neighbor on bgp configured interface\n"
12245 "Display detailed prefix count information\n"
12246 "JavaScript Object Notation\n")
12247 {
12248 struct peer *peer;
12249 u_char uj = use_json(argc, argv);
12250
12251 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12252 if (! peer)
12253 return CMD_WARNING;
12254
12255 safi_t safi;
12256 safi = bgp_vty_safi_from_arg(argv[0]);
12257 return bgp_peer_counts (vty, peer, AFI_IP, safi, uj);
12258 }
12259
12260 static void
12261 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12262 int in, const char *rmap_name, u_char use_json, json_object *json)
12263 {
12264 struct bgp_table *table;
12265 struct bgp_adj_in *ain;
12266 struct bgp_adj_out *adj;
12267 unsigned long output_count;
12268 unsigned long filtered_count;
12269 struct bgp_node *rn;
12270 int header1 = 1;
12271 struct bgp *bgp;
12272 int header2 = 1;
12273 struct attr attr;
12274 struct attr_extra extra;
12275 int ret;
12276 struct update_subgroup *subgrp;
12277 json_object *json_scode = NULL;
12278 json_object *json_ocode = NULL;
12279 json_object *json_ar = NULL;
12280 struct peer_af *paf;
12281
12282 if (use_json)
12283 {
12284 json_scode = json_object_new_object();
12285 json_ocode = json_object_new_object();
12286 json_ar = json_object_new_object();
12287
12288 json_object_string_add(json_scode, "suppressed", "s");
12289 json_object_string_add(json_scode, "damped", "d");
12290 json_object_string_add(json_scode, "history", "h");
12291 json_object_string_add(json_scode, "valid", "*");
12292 json_object_string_add(json_scode, "best", ">");
12293 json_object_string_add(json_scode, "multipath", "=");
12294 json_object_string_add(json_scode, "internal", "i");
12295 json_object_string_add(json_scode, "ribFailure", "r");
12296 json_object_string_add(json_scode, "stale", "S");
12297 json_object_string_add(json_scode, "removed", "R");
12298
12299 json_object_string_add(json_ocode, "igp", "i");
12300 json_object_string_add(json_ocode, "egp", "e");
12301 json_object_string_add(json_ocode, "incomplete", "?");
12302 }
12303
12304 bgp = peer->bgp;
12305
12306 if (! bgp)
12307 {
12308 if (use_json)
12309 {
12310 json_object_string_add(json, "alert", "no BGP");
12311 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12312 json_object_free(json);
12313 }
12314 else
12315 vty_out (vty, "%% No bgp%s", VTY_NEWLINE);
12316 return;
12317 }
12318
12319 table = bgp->rib[afi][safi];
12320
12321 output_count = filtered_count = 0;
12322 subgrp = peer_subgroup(peer, afi, safi);
12323
12324 if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
12325 {
12326 if (use_json)
12327 {
12328 json_object_int_add(json, "bgpTableVersion", table->version);
12329 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12330 json_object_object_add(json, "bgpStatusCodes", json_scode);
12331 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12332 json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0");
12333 }
12334 else
12335 {
12336 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE);
12337 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12338 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12339
12340 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12341 VTY_NEWLINE, VTY_NEWLINE);
12342 }
12343 header1 = 0;
12344 }
12345
12346 attr.extra = &extra;
12347 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12348 {
12349 if (in)
12350 {
12351 for (ain = rn->adj_in; ain; ain = ain->next)
12352 {
12353 if (ain->peer == peer)
12354 {
12355 if (header1)
12356 {
12357 if (use_json)
12358 {
12359 json_object_int_add(json, "bgpTableVersion", 0);
12360 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12361 json_object_object_add(json, "bgpStatusCodes", json_scode);
12362 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12363 }
12364 else
12365 {
12366 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
12367 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12368 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12369 }
12370 header1 = 0;
12371 }
12372 if (header2)
12373 {
12374 if (!use_json)
12375 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12376 header2 = 0;
12377 }
12378 if (ain->attr)
12379 {
12380 bgp_attr_dup(&attr, ain->attr);
12381 if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY)
12382 {
12383 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12384 output_count++;
12385 }
12386 else
12387 filtered_count++;
12388 }
12389 }
12390 }
12391 }
12392 else
12393 {
12394 for (adj = rn->adj_out; adj; adj = adj->next)
12395 SUBGRP_FOREACH_PEER(adj->subgroup, paf)
12396 if (paf->peer == peer)
12397 {
12398 if (header1)
12399 {
12400 if (use_json)
12401 {
12402 json_object_int_add(json, "bgpTableVersion", table->version);
12403 json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
12404 json_object_object_add(json, "bgpStatusCodes", json_scode);
12405 json_object_object_add(json, "bgpOriginCodes", json_ocode);
12406 }
12407 else
12408 {
12409 vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version,
12410 inet_ntoa (bgp->router_id), VTY_NEWLINE);
12411 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12412 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12413 }
12414 header1 = 0;
12415 }
12416
12417 if (header2)
12418 {
12419 if (!use_json)
12420 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12421 header2 = 0;
12422 }
12423
12424 if (adj->attr)
12425 {
12426 bgp_attr_dup(&attr, adj->attr);
12427 ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name);
12428 if (ret != RMAP_DENY)
12429 {
12430 route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar);
12431 output_count++;
12432 }
12433 else
12434 filtered_count++;
12435 }
12436 }
12437 }
12438 }
12439 if (use_json)
12440 json_object_object_add(json, "advertisedRoutes", json_ar);
12441
12442 if (output_count != 0)
12443 {
12444 if (use_json)
12445 json_object_int_add(json, "totalPrefixCounter", output_count);
12446 else
12447 vty_out (vty, "%sTotal number of prefixes %ld%s",
12448 VTY_NEWLINE, output_count, VTY_NEWLINE);
12449 }
12450 if (use_json)
12451 {
12452 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12453 json_object_free(json);
12454 }
12455
12456 }
12457
12458 static int
12459 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12460 int in, const char *rmap_name, u_char use_json)
12461 {
12462 json_object *json = NULL;
12463
12464 if (use_json)
12465 json = json_object_new_object();
12466
12467 if (!peer || !peer->afc[afi][safi])
12468 {
12469 if (use_json)
12470 {
12471 json_object_string_add(json, "warning", "No such neighbor or address family");
12472 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12473 json_object_free(json);
12474 }
12475 else
12476 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12477
12478 return CMD_WARNING;
12479 }
12480
12481 if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12482 {
12483 if (use_json)
12484 {
12485 json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled");
12486 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
12487 json_object_free(json);
12488 }
12489 else
12490 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE);
12491
12492 return CMD_WARNING;
12493 }
12494
12495 show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json);
12496
12497 return CMD_SUCCESS;
12498 }
12499
12500 DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
12501 show_ip_bgp_instance_neighbor_advertised_route_cmd,
12502 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12503 SHOW_STR
12504 IP_STR
12505 BGP_STR
12506 BGP_INSTANCE_HELP_STR
12507 "Detailed information on TCP and BGP neighbor connections\n"
12508 "Neighbor to display information about\n"
12509 "Neighbor to display information about\n"
12510 "Display the routes advertised to a BGP neighbor\n"
12511 "JavaScript Object Notation\n")
12512 {
12513 struct peer *peer;
12514 u_char uj = use_json(argc, argv);
12515
12516 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12517 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12518 else
12519 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12520
12521 if (! peer)
12522 return CMD_WARNING;
12523
12524 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj);
12525 }
12526
12527 DEFUN (show_ip_bgp_neighbor_advertised_route,
12528 show_ip_bgp_neighbor_advertised_route_cmd,
12529 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12530 SHOW_STR
12531 IP_STR
12532 BGP_STR
12533 "Detailed information on TCP and BGP neighbor connections\n"
12534 "Neighbor to display information about\n"
12535 "Neighbor to display information about\n"
12536 "Neighbor on bgp configured interface\n"
12537 "Display the routes advertised to a BGP neighbor\n"
12538 "JavaScript Object Notation\n")
12539
12540 {
12541 struct peer *peer;
12542 const char *rmap_name = NULL;
12543 u_char uj = use_json(argc, argv);
12544
12545 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12546
12547 if (! peer)
12548 return CMD_WARNING;
12549
12550 if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)
12551 || (argc == 3))
12552 rmap_name = argv[1];
12553
12554 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj);
12555 }
12556
12557 ALIAS (show_ip_bgp_neighbor_advertised_route,
12558 show_ip_bgp_neighbor_advertised_route_rmap_cmd,
12559 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12560 SHOW_STR
12561 IP_STR
12562 BGP_STR
12563 "Detailed information on TCP and BGP neighbor connections\n"
12564 "Neighbor to display information about\n"
12565 "Neighbor to display information about\n"
12566 "Neighbor on bgp configured interface\n"
12567 "Display the routes advertised to a BGP neighbor\n"
12568 "JavaScript Object Notation\n")
12569
12570 ALIAS (show_ip_bgp_instance_neighbor_advertised_route,
12571 show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd,
12572 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12573 SHOW_STR
12574 IP_STR
12575 BGP_STR
12576 BGP_INSTANCE_HELP_STR
12577 "Detailed information on TCP and BGP neighbor connections\n"
12578 "Neighbor to display information about\n"
12579 "Neighbor to display information about\n"
12580 "Neighbor on bgp configured interface\n"
12581 "Display the routes advertised to a BGP neighbor\n"
12582 "JavaScript Object Notation\n")
12583 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12584 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12585 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12586 SHOW_STR
12587 IP_STR
12588 BGP_STR
12589 "Address family\n"
12590 "Address Family modifier\n"
12591 "Address Family modifier\n"
12592 "Detailed information on TCP and BGP neighbor connections\n"
12593 "Neighbor to display information about\n"
12594 "Neighbor to display information about\n"
12595 "Neighbor on bgp configured interface\n"
12596 "Display the routes advertised to a BGP neighbor\n"
12597 "JavaScript Object Notation\n")
12598 {
12599 struct peer *peer;
12600 const char *rmap_name = NULL;
12601 safi_t safi;
12602
12603 u_char uj = use_json(argc, argv);
12604
12605 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12606 if (! peer)
12607 return CMD_WARNING;
12608
12609 if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12610 rmap_name = argv[2];
12611
12612 safi = bgp_vty_safi_from_arg(argv[0]);
12613 return peer_adj_routes (vty, peer, AFI_IP, safi, 0, rmap_name, uj);
12614 }
12615
12616 ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
12617 show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd,
12618 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}",
12619 SHOW_STR
12620 IP_STR
12621 BGP_STR
12622 "Address family\n"
12623 "Address Family modifier\n"
12624 "Address Family modifier\n"
12625 "Detailed information on TCP and BGP neighbor connections\n"
12626 "Neighbor to display information about\n"
12627 "Neighbor to display information about\n"
12628 "Neighbor on bgp configured interface\n"
12629 "Display the routes advertised to a BGP neighbor\n"
12630 "Route-map to control what is displayed\n"
12631 "JavaScript Object Notation\n")
12632
12633 #ifdef HAVE_IPV6
12634 DEFUN (show_bgp_instance_neighbor_advertised_route,
12635 show_bgp_instance_neighbor_advertised_route_cmd,
12636 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12637 SHOW_STR
12638 BGP_STR
12639 BGP_INSTANCE_HELP_STR
12640 "Detailed information on TCP and BGP neighbor connections\n"
12641 "Neighbor to display information about\n"
12642 "Neighbor to display information about\n"
12643 "Neighbor on bgp configured interface\n"
12644 "Display the routes advertised to a BGP neighbor\n"
12645 "JavaScript Object Notation\n")
12646 {
12647 struct peer *peer;
12648 u_char uj = use_json(argc, argv);
12649
12650 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12651 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12652 else
12653 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12654
12655 if (! peer)
12656 return CMD_WARNING;
12657
12658 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj);
12659 }
12660
12661 ALIAS (show_bgp_instance_neighbor_advertised_route,
12662 show_bgp_instance_ipv6_neighbor_advertised_route_cmd,
12663 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12664 SHOW_STR
12665 BGP_STR
12666 BGP_INSTANCE_HELP_STR
12667 "Address family\n"
12668 "Detailed information on TCP and BGP neighbor connections\n"
12669 "Neighbor to display information about\n"
12670 "Neighbor to display information about\n"
12671 "Neighbor on bgp configured interface\n"
12672 "Display the routes advertised to a BGP neighbor\n"
12673 "JavaScript Object Notation\n")
12674
12675 DEFUN (show_bgp_neighbor_advertised_route,
12676 show_bgp_neighbor_advertised_route_cmd,
12677 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12678 SHOW_STR
12679 BGP_STR
12680 "Detailed information on TCP and BGP neighbor connections\n"
12681 "Neighbor to display information about\n"
12682 "Neighbor to display information about\n"
12683 "Neighbor on bgp configured interface\n"
12684 "Display the routes advertised to a BGP neighbor\n"
12685 "JavaScript Object Notation\n")
12686
12687 {
12688 struct peer *peer;
12689 const char *rmap_name = NULL;
12690 u_char uj = use_json(argc, argv);
12691
12692 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12693
12694 if (!peer)
12695 return CMD_WARNING;
12696
12697 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12698 rmap_name = argv[1];
12699
12700 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj);
12701 }
12702
12703 ALIAS (show_bgp_neighbor_advertised_route,
12704 show_bgp_ipv6_neighbor_advertised_route_cmd,
12705 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12706 SHOW_STR
12707 BGP_STR
12708 "Address family\n"
12709 "Detailed information on TCP and BGP neighbor connections\n"
12710 "Neighbor to display information about\n"
12711 "Neighbor to display information about\n"
12712 "Neighbor on bgp configured interface\n"
12713 "Display the routes advertised to a BGP neighbor\n"
12714 "JavaScript Object Notation\n")
12715
12716 /* old command */
12717 ALIAS (show_bgp_neighbor_advertised_route,
12718 ipv6_bgp_neighbor_advertised_route_cmd,
12719 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12720 SHOW_STR
12721 IPV6_STR
12722 BGP_STR
12723 "Detailed information on TCP and BGP neighbor connections\n"
12724 "Neighbor to display information about\n"
12725 "Neighbor to display information about\n"
12726 "Neighbor on bgp configured interface\n"
12727 "Display the routes advertised to a BGP neighbor\n"
12728 "JavaScript Object Notation\n")
12729
12730 /* old command */
12731 DEFUN (ipv6_mbgp_neighbor_advertised_route,
12732 ipv6_mbgp_neighbor_advertised_route_cmd,
12733 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
12734 SHOW_STR
12735 IPV6_STR
12736 MBGP_STR
12737 "Detailed information on TCP and BGP neighbor connections\n"
12738 "Neighbor to display information about\n"
12739 "Neighbor to display information about\n"
12740 "Neighbor on bgp configured interface\n"
12741 "Neighbor on bgp configured interface\n"
12742 "Display the routes advertised to a BGP neighbor\n"
12743 "JavaScript Object Notation\n")
12744 {
12745 struct peer *peer;
12746 u_char uj = use_json(argc, argv);
12747
12748 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12749 if (! peer)
12750 return CMD_WARNING;
12751
12752 bgp_show_ipv6_bgp_deprecate_warning(vty);
12753 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj);
12754 }
12755 #endif /* HAVE_IPV6 */
12756
12757 DEFUN (show_bgp_instance_neighbor_received_routes,
12758 show_bgp_instance_neighbor_received_routes_cmd,
12759 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12760 SHOW_STR
12761 BGP_STR
12762 BGP_INSTANCE_HELP_STR
12763 "Detailed information on TCP and BGP neighbor connections\n"
12764 "Neighbor to display information about\n"
12765 "Neighbor to display information about\n"
12766 "Neighbor on bgp configured interface\n"
12767 "Display the received routes from neighbor\n"
12768 "JavaScript Object Notation\n")
12769 {
12770 struct peer *peer;
12771 u_char uj = use_json(argc, argv);
12772
12773 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12774 if (! peer)
12775 return CMD_WARNING;
12776
12777 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj);
12778 }
12779
12780 DEFUN (show_ip_bgp_instance_neighbor_received_routes,
12781 show_ip_bgp_instance_neighbor_received_routes_cmd,
12782 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12783 SHOW_STR
12784 IP_STR
12785 BGP_STR
12786 BGP_INSTANCE_HELP_STR
12787 "Detailed information on TCP and BGP neighbor connections\n"
12788 "Neighbor to display information about\n"
12789 "Neighbor to display information about\n"
12790 "Neighbor on bgp configured interface\n"
12791 "Display the received routes from neighbor\n"
12792 "JavaScript Object Notation\n")
12793 {
12794 struct peer *peer;
12795 u_char uj = use_json(argc, argv);
12796
12797 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
12798 if (! peer)
12799 return CMD_WARNING;
12800
12801 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj);
12802 }
12803
12804 ALIAS (show_bgp_instance_neighbor_received_routes,
12805 show_bgp_instance_ipv6_neighbor_received_routes_cmd,
12806 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12807 SHOW_STR
12808 BGP_STR
12809 BGP_INSTANCE_HELP_STR
12810 "Address family\n"
12811 "Detailed information on TCP and BGP neighbor connections\n"
12812 "Neighbor to display information about\n"
12813 "Neighbor to display information about\n"
12814 "Neighbor on bgp configured interface\n"
12815 "Display the received routes from neighbor\n"
12816 "JavaScript Object Notation\n")
12817
12818 DEFUN (show_ip_bgp_neighbor_received_routes,
12819 show_ip_bgp_neighbor_received_routes_cmd,
12820 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12821 SHOW_STR
12822 IP_STR
12823 BGP_STR
12824 "Detailed information on TCP and BGP neighbor connections\n"
12825 "Neighbor to display information about\n"
12826 "Neighbor to display information about\n"
12827 "Neighbor on bgp configured interface\n"
12828 "Display the received routes from neighbor\n"
12829 "JavaScript Object Notation\n")
12830
12831 {
12832 struct peer *peer;
12833 const char *rmap_name = NULL;
12834 u_char uj = use_json(argc, argv);
12835
12836 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
12837
12838 if (! peer)
12839 return CMD_WARNING;
12840
12841 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
12842 rmap_name = argv[1];
12843
12844 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj);
12845 }
12846
12847 ALIAS (show_ip_bgp_neighbor_received_routes,
12848 show_ip_bgp_neighbor_received_routes_rmap_cmd,
12849 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12850 SHOW_STR
12851 IP_STR
12852 BGP_STR
12853 "Detailed information on TCP and BGP neighbor connections\n"
12854 "Neighbor to display information about\n"
12855 "Neighbor to display information about\n"
12856 "Neighbor on bgp configured interface\n"
12857 "Display the received routes from neighbor\n"
12858 "JavaScript Object Notation\n")
12859
12860 ALIAS (show_ip_bgp_instance_neighbor_received_routes,
12861 show_ip_bgp_instance_neighbor_received_routes_rmap_cmd,
12862 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12863 SHOW_STR
12864 IP_STR
12865 BGP_STR
12866 BGP_INSTANCE_HELP_STR
12867 "Detailed information on TCP and BGP neighbor connections\n"
12868 "Neighbor to display information about\n"
12869 "Neighbor to display information about\n"
12870 "Neighbor on bgp configured interface\n"
12871 "Display the received routes from neighbor\n"
12872 "JavaScript Object Notation\n")
12873
12874 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12875 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12876 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
12877 SHOW_STR
12878 IP_STR
12879 BGP_STR
12880 "Address family\n"
12881 "Address Family modifier\n"
12882 "Address Family modifier\n"
12883 "Detailed information on TCP and BGP neighbor connections\n"
12884 "Neighbor to display information about\n"
12885 "Neighbor to display information about\n"
12886 "Neighbor on bgp configured interface\n"
12887 "Display the received routes from neighbor\n"
12888 "JavaScript Object Notation\n")
12889 {
12890 struct peer *peer;
12891 const char *rmap_name = NULL;
12892 safi_t safi;
12893 u_char uj = use_json(argc, argv);
12894
12895 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
12896 if (! peer)
12897 return CMD_WARNING;
12898
12899 if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
12900 rmap_name = argv[2];
12901
12902 safi = bgp_vty_safi_from_arg(argv[0]);
12903 return peer_adj_routes (vty, peer, AFI_IP, safi, 1, rmap_name, uj);
12904 }
12905
12906 ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
12907 show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd,
12908 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}",
12909 SHOW_STR
12910 IP_STR
12911 BGP_STR
12912 "Address family\n"
12913 "Address Family modifier\n"
12914 "Address Family modifier\n"
12915 "Detailed information on TCP and BGP neighbor connections\n"
12916 "Neighbor to display information about\n"
12917 "Neighbor to display information about\n"
12918 "Neighbor on bgp configured interface\n"
12919 "Display the received routes from neighbor\n"
12920 "JavaScript Object Notation\n")
12921
12922 DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes,
12923 show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd,
12924 "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
12925 SHOW_STR
12926 BGP_STR
12927 BGP_INSTANCE_HELP_STR
12928 "Address family\n"
12929 "Address family\n"
12930 "Address family modifier\n"
12931 "Address family modifier\n"
12932 "Detailed information on TCP and BGP neighbor connections\n"
12933 "Neighbor to display information about\n"
12934 "Neighbor to display information about\n"
12935 "Neighbor on bgp configured interface\n"
12936 "Display the advertised routes to neighbor\n"
12937 "Display the received routes from neighbor\n"
12938 "JavaScript Object Notation\n")
12939 {
12940 int afi;
12941 int safi;
12942 int in;
12943 struct peer *peer;
12944 u_char uj = use_json(argc, argv);
12945
12946 peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
12947
12948 if (! peer)
12949 return CMD_WARNING;
12950
12951 afi = bgp_vty_safi_from_arg(argv[2]);
12952 safi = bgp_vty_safi_from_arg(argv[3]);
12953 in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
12954
12955 return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
12956 }
12957
12958 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12959 show_ip_bgp_neighbor_received_prefix_filter_cmd,
12960 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
12961 SHOW_STR
12962 IP_STR
12963 BGP_STR
12964 "Detailed information on TCP and BGP neighbor connections\n"
12965 "Neighbor to display information about\n"
12966 "Neighbor to display information about\n"
12967 "Neighbor on bgp configured interface\n"
12968 "Display information received from a BGP neighbor\n"
12969 "Display the prefixlist filter\n"
12970 "JavaScript Object Notation\n")
12971 {
12972 char name[BUFSIZ];
12973 union sockunion su;
12974 struct peer *peer;
12975 int count, ret;
12976 u_char uj = use_json(argc, argv);
12977
12978 ret = str2sockunion (argv[0], &su);
12979 if (ret < 0)
12980 {
12981 peer = peer_lookup_by_conf_if (NULL, argv[0]);
12982 if (! peer)
12983 {
12984 if (uj)
12985 {
12986 json_object *json_no = NULL;
12987 json_object *json_sub = NULL;
12988 json_no = json_object_new_object();
12989 json_sub = json_object_new_object();
12990 json_object_string_add(json_no, "warning", "Malformed address or name");
12991 json_object_string_add(json_sub, "warningCause", argv[0]);
12992 json_object_object_add(json_no, "detail", json_sub);
12993 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
12994 json_object_free(json_no);
12995 }
12996 else
12997 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
12998 return CMD_WARNING;
12999 }
13000 }
13001 else
13002 {
13003 peer = peer_lookup (NULL, &su);
13004 if (! peer)
13005 {
13006 if (uj)
13007 {
13008 json_object *json_no = NULL;
13009 json_no = json_object_new_object();
13010 json_object_string_add(json_no, "warning", "Peer not found");
13011 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13012 json_object_free(json_no);
13013 }
13014 else
13015 vty_out (vty, "No peer%s", VTY_NEWLINE);
13016 return CMD_WARNING;
13017 }
13018 }
13019
13020 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13021 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13022 if (count)
13023 {
13024 if (!uj)
13025 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13026 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13027 }
13028 else
13029 {
13030 if (uj)
13031 {
13032 json_object *json_no = NULL;
13033 json_no = json_object_new_object();
13034 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13035 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13036 json_object_free(json_no);
13037 }
13038 else
13039 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13040 }
13041
13042 return CMD_SUCCESS;
13043 }
13044
13045 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13046 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13047 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13048 SHOW_STR
13049 IP_STR
13050 BGP_STR
13051 "Address family\n"
13052 "Address Family modifier\n"
13053 "Address Family modifier\n"
13054 "Detailed information on TCP and BGP neighbor connections\n"
13055 "Neighbor to display information about\n"
13056 "Neighbor to display information about\n"
13057 "Neighbor on bgp configured interface\n"
13058 "Display information received from a BGP neighbor\n"
13059 "Display the prefixlist filter\n"
13060 "JavaScript Object Notation\n")
13061 {
13062 char name[BUFSIZ];
13063 union sockunion su;
13064 struct peer *peer;
13065 int count, ret;
13066 u_char uj = use_json(argc, argv);
13067
13068 ret = str2sockunion (argv[1], &su);
13069 if (ret < 0)
13070 {
13071 peer = peer_lookup_by_conf_if (NULL, argv[1]);
13072 if (! peer)
13073 {
13074 if (uj)
13075 {
13076 json_object *json_no = NULL;
13077 json_object *json_sub = NULL;
13078 json_no = json_object_new_object();
13079 json_sub = json_object_new_object();
13080 json_object_string_add(json_no, "warning", "Malformed address or name");
13081 json_object_string_add(json_sub, "warningCause", argv[1]);
13082 json_object_object_add(json_no, "detail", json_sub);
13083 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13084 json_object_free(json_no);
13085 }
13086 else
13087 vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
13088 return CMD_WARNING;
13089 }
13090 }
13091 else
13092 {
13093 peer = peer_lookup (NULL, &su);
13094 if (! peer)
13095 {
13096 if (uj)
13097 {
13098 json_object *json_no = NULL;
13099 json_no = json_object_new_object();
13100 json_object_string_add(json_no, "warning", "Peer not found");
13101 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13102 json_object_free(json_no);
13103 }
13104 else
13105 vty_out (vty, "No peer%s", VTY_NEWLINE);
13106 return CMD_WARNING;
13107 }
13108 }
13109
13110 {
13111 safi_t safi;
13112 safi = bgp_vty_safi_from_arg(argv[0]);
13113 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13114 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj);
13115 if (count)
13116 {
13117 if (!uj)
13118 vty_out (vty, "Address family: %s%s",
13119 afi_safi_print (AFI_IP, safi), VTY_NEWLINE);
13120 prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj);
13121 }
13122 else
13123 {
13124 if (uj)
13125 {
13126 json_object *json_no = NULL;
13127 json_no = json_object_new_object();
13128 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13129 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13130 json_object_free(json_no);
13131 }
13132 else
13133 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13134 }
13135 }
13136
13137 return CMD_SUCCESS;
13138 }
13139 #ifdef HAVE_IPV6
13140 DEFUN (show_bgp_neighbor_received_routes,
13141 show_bgp_neighbor_received_routes_cmd,
13142 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13143 SHOW_STR
13144 BGP_STR
13145 "Detailed information on TCP and BGP neighbor connections\n"
13146 "Neighbor to display information about\n"
13147 "Neighbor to display information about\n"
13148 "Neighbor on bgp configured interface\n"
13149 "Display the received routes from neighbor\n"
13150 "JavaScript Object Notation\n")
13151 {
13152 struct peer *peer;
13153 const char *rmap_name = NULL;
13154 u_char uj = use_json(argc, argv);
13155
13156 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13157
13158 if (! peer)
13159 return CMD_WARNING;
13160
13161 if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
13162 rmap_name = argv[1];
13163
13164 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, rmap_name, uj);
13165 }
13166
13167 ALIAS (show_bgp_neighbor_received_routes,
13168 show_bgp_ipv6_neighbor_received_routes_cmd,
13169 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13170 SHOW_STR
13171 BGP_STR
13172 "Address family\n"
13173 "Detailed information on TCP and BGP neighbor connections\n"
13174 "Neighbor to display information about\n"
13175 "Neighbor to display information about\n"
13176 "Neighbor on bgp configured interface\n"
13177 "Display the received routes from neighbor\n"
13178 "JavaScript Object Notation\n")
13179
13180 DEFUN (show_bgp_neighbor_received_prefix_filter,
13181 show_bgp_neighbor_received_prefix_filter_cmd,
13182 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13183 SHOW_STR
13184 BGP_STR
13185 "Detailed information on TCP and BGP neighbor connections\n"
13186 "Neighbor to display information about\n"
13187 "Neighbor to display information about\n"
13188 "Neighbor on bgp configured interface\n"
13189 "Display information received from a BGP neighbor\n"
13190 "Display the prefixlist filter\n"
13191 "JavaScript Object Notation\n")
13192 {
13193 char name[BUFSIZ];
13194 union sockunion su;
13195 struct peer *peer;
13196 int count, ret;
13197 u_char uj = use_json(argc, argv);
13198
13199 ret = str2sockunion (argv[0], &su);
13200 if (ret < 0)
13201 {
13202 peer = peer_lookup_by_conf_if (NULL, argv[0]);
13203 if (! peer)
13204 {
13205 if (uj)
13206 {
13207 json_object *json_no = NULL;
13208 json_object *json_sub = NULL;
13209 json_no = json_object_new_object();
13210 json_sub = json_object_new_object();
13211 json_object_string_add(json_no, "warning", "Malformed address or name");
13212 json_object_string_add(json_sub, "warningCause", argv[0]);
13213 json_object_object_add(json_no, "detail", json_sub);
13214 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13215 json_object_free(json_no);
13216 }
13217 else
13218 vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE);
13219 return CMD_WARNING;
13220 }
13221 }
13222 else
13223 {
13224 peer = peer_lookup (NULL, &su);
13225 if (! peer)
13226 {
13227 if (uj)
13228 {
13229 json_object *json_no = NULL;
13230 json_no = json_object_new_object();
13231 json_object_string_add(json_no, "warning", "No Peer");
13232 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13233 json_object_free(json_no);
13234 }
13235 else
13236 vty_out (vty, "No peer%s", VTY_NEWLINE);
13237 return CMD_WARNING;
13238 }
13239 }
13240
13241 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13242 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13243 if (count)
13244 {
13245 if (!uj)
13246 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13247 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13248 }
13249 else
13250 {
13251 if (uj)
13252 {
13253 json_object *json_no = NULL;
13254 json_no = json_object_new_object();
13255 json_object_boolean_true_add(json_no, "noFuntionalOutput");
13256 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13257 json_object_free(json_no);
13258 }
13259 else
13260 vty_out (vty, "No functional output%s", VTY_NEWLINE);
13261 }
13262
13263 return CMD_SUCCESS;
13264 }
13265
13266 ALIAS (show_bgp_neighbor_received_prefix_filter,
13267 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13268 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13269 SHOW_STR
13270 BGP_STR
13271 "Address family\n"
13272 "Detailed information on TCP and BGP neighbor connections\n"
13273 "Neighbor to display information about\n"
13274 "Neighbor to display information about\n"
13275 "Neighbor on bgp configured interface\n"
13276 "Display information received from a BGP neighbor\n"
13277 "Display the prefixlist filter\n"
13278 "JavaScript Object Notation\n")
13279
13280 /* old command */
13281 ALIAS (show_bgp_neighbor_received_routes,
13282 ipv6_bgp_neighbor_received_routes_cmd,
13283 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13284 SHOW_STR
13285 IPV6_STR
13286 BGP_STR
13287 "Detailed information on TCP and BGP neighbor connections\n"
13288 "Neighbor to display information about\n"
13289 "Neighbor to display information about\n"
13290 "Neighbor on bgp configured interface\n"
13291 "Display the received routes from neighbor\n"
13292 "JavaScript Object Notation\n")
13293
13294 /* old command */
13295 DEFUN (ipv6_mbgp_neighbor_received_routes,
13296 ipv6_mbgp_neighbor_received_routes_cmd,
13297 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
13298 SHOW_STR
13299 IPV6_STR
13300 MBGP_STR
13301 "Detailed information on TCP and BGP neighbor connections\n"
13302 "Neighbor to display information about\n"
13303 "Neighbor to display information about\n"
13304 "Neighbor on bgp configured interface\n"
13305 "Display the received routes from neighbor\n"
13306 "JavaScript Object Notation\n")
13307 {
13308 struct peer *peer;
13309 u_char uj = use_json(argc, argv);
13310
13311 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13312 if (! peer)
13313 return CMD_WARNING;
13314
13315 bgp_show_ipv6_bgp_deprecate_warning(vty);
13316 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj);
13317 }
13318
13319 DEFUN (show_bgp_instance_neighbor_received_prefix_filter,
13320 show_bgp_instance_neighbor_received_prefix_filter_cmd,
13321 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13322 SHOW_STR
13323 BGP_STR
13324 BGP_INSTANCE_HELP_STR
13325 "Detailed information on TCP and BGP neighbor connections\n"
13326 "Neighbor to display information about\n"
13327 "Neighbor to display information about\n"
13328 "Neighbor on bgp configured interface\n"
13329 "Display information received from a BGP neighbor\n"
13330 "Display the prefixlist filter\n"
13331 "JavaScript Object Notation\n")
13332 {
13333 char name[BUFSIZ];
13334 union sockunion su;
13335 struct peer *peer;
13336 struct bgp *bgp;
13337 int count, ret;
13338 u_char uj = use_json(argc, argv);
13339
13340 /* BGP structure lookup. */
13341 bgp = bgp_lookup_by_name (argv[1]);
13342 if (bgp == NULL)
13343 {
13344 if (uj)
13345 {
13346 json_object *json_no = NULL;
13347 json_no = json_object_new_object();
13348 json_object_string_add(json_no, "warning", "Can't find BGP view");
13349 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13350 json_object_free(json_no);
13351 }
13352 else
13353 vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
13354 return CMD_WARNING;
13355 }
13356
13357 ret = str2sockunion (argv[2], &su);
13358 if (ret < 0)
13359 {
13360 peer = peer_lookup_by_conf_if (bgp, argv[2]);
13361 if (! peer)
13362 {
13363 if (uj)
13364 {
13365 json_object *json_no = NULL;
13366 json_object *json_sub = NULL;
13367 json_no = json_object_new_object();
13368 json_sub = json_object_new_object();
13369 json_object_string_add(json_no, "warning", "Malformed address or name");
13370 json_object_string_add(json_sub, "warningCause", argv[2]);
13371 json_object_object_add(json_no, "detail", json_sub);
13372 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13373 json_object_free(json_no);
13374 }
13375 else
13376 vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
13377 return CMD_WARNING;
13378 }
13379 }
13380 else
13381 {
13382 peer = peer_lookup (bgp, &su);
13383 if (! peer)
13384 {
13385 if (uj)
13386 {
13387 json_object *json_no = NULL;
13388 json_no = json_object_new_object();
13389 json_object_boolean_true_add(json_no, "noPeer");
13390 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13391 json_object_free(json_no);
13392 }
13393 else
13394 vty_out (vty, "No peer%s", VTY_NEWLINE);
13395 return CMD_WARNING;
13396 }
13397
13398 }
13399
13400 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13401 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj);
13402 if (count)
13403 {
13404 if (!uj)
13405 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13406 prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj);
13407 }
13408
13409 return CMD_SUCCESS;
13410 }
13411 ALIAS (show_bgp_instance_neighbor_received_prefix_filter,
13412 show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd,
13413 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
13414 SHOW_STR
13415 BGP_STR
13416 BGP_INSTANCE_HELP_STR
13417 "Address family\n"
13418 "Detailed information on TCP and BGP neighbor connections\n"
13419 "Neighbor to display information about\n"
13420 "Neighbor to display information about\n"
13421 "Neighbor on bgp configured interface\n"
13422 "Display information received from a BGP neighbor\n"
13423 "Display the prefixlist filter\n"
13424 "JavaScript Object NOtation\n")
13425 #endif /* HAVE_IPV6 */
13426
13427 static int
13428 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
13429 safi_t safi, enum bgp_show_type type, u_char use_json)
13430 {
13431 if (! peer || ! peer->afc[afi][safi])
13432 {
13433 if (use_json)
13434 {
13435 json_object *json_no = NULL;
13436 json_no = json_object_new_object();
13437 json_object_string_add(json_no, "warning", "No such neighbor or address family");
13438 vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
13439 json_object_free(json_no);
13440 }
13441 else
13442 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
13443 return CMD_WARNING;
13444 }
13445
13446 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json);
13447 }
13448
13449 DEFUN (show_ip_bgp_neighbor_routes,
13450 show_ip_bgp_neighbor_routes_cmd,
13451 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13452 SHOW_STR
13453 IP_STR
13454 BGP_STR
13455 "Detailed information on TCP and BGP neighbor connections\n"
13456 "Neighbor to display information about\n"
13457 "Neighbor to display information about\n"
13458 "Neighbor on bgp configured interface\n"
13459 "Display routes learned from neighbor\n"
13460 "JavaScript Object Notation\n")
13461 {
13462 struct peer *peer;
13463 u_char uj = use_json(argc, argv);
13464
13465 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13466 if (! peer)
13467 return CMD_WARNING;
13468
13469 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13470 bgp_show_type_neighbor, uj);
13471 }
13472
13473 DEFUN (show_ip_bgp_instance_neighbor_routes,
13474 show_ip_bgp_instance_neighbor_routes_cmd,
13475 "show ip bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13476 SHOW_STR
13477 IP_STR
13478 BGP_STR
13479 BGP_INSTANCE_HELP_STR
13480 "Detailed information on TCP and BGP neighbor connections\n"
13481 "Neighbor to display information about\n"
13482 "Neighbor to display information about\n"
13483 "Neighbor on bgp configured interface\n"
13484 "Display routes learned from neighbor\n"
13485 "JavaScript Object Notation\n")
13486 {
13487 struct peer *peer;
13488 u_char uj = use_json(argc, argv);
13489
13490 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13491 if (! peer)
13492 return CMD_WARNING;
13493
13494 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13495 bgp_show_type_neighbor, uj);
13496 }
13497
13498 DEFUN (show_ip_bgp_neighbor_flap,
13499 show_ip_bgp_neighbor_flap_cmd,
13500 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13501 SHOW_STR
13502 IP_STR
13503 BGP_STR
13504 "Detailed information on TCP and BGP neighbor connections\n"
13505 "Neighbor to display information about\n"
13506 "Neighbor to display information about\n"
13507 "Neighbor on bgp configured interface\n"
13508 "Display flap statistics of the routes learned from neighbor\n"
13509 "JavaScript Object Notation\n")
13510 {
13511 struct peer *peer;
13512 u_char uj = use_json(argc, argv);
13513
13514 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13515 if (! peer)
13516 return CMD_WARNING;
13517
13518 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13519 bgp_show_type_flap_neighbor, uj);
13520 }
13521
13522 DEFUN (show_ip_bgp_neighbor_damp,
13523 show_ip_bgp_neighbor_damp_cmd,
13524 "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13525 SHOW_STR
13526 IP_STR
13527 BGP_STR
13528 "Detailed information on TCP and BGP neighbor connections\n"
13529 "Neighbor to display information about\n"
13530 "Neighbor to display information about\n"
13531 "Neighbor on bgp configured interface\n"
13532 "Display the dampened routes received from neighbor\n"
13533 "JavaScript Object Notation\n")
13534 {
13535 struct peer *peer;
13536 u_char uj = use_json(argc, argv);
13537
13538 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13539 if (! peer)
13540 return CMD_WARNING;
13541
13542 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13543 bgp_show_type_damp_neighbor, uj);
13544 }
13545
13546 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13547 show_ip_bgp_ipv4_neighbor_routes_cmd,
13548 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13549 SHOW_STR
13550 IP_STR
13551 BGP_STR
13552 "Address family\n"
13553 "Address Family modifier\n"
13554 "Address Family modifier\n"
13555 "Detailed information on TCP and BGP neighbor connections\n"
13556 "Neighbor to display information about\n"
13557 "Neighbor to display information about\n"
13558 "Neighbor on bgp configured interface\n"
13559 "Display routes learned from neighbor\n"
13560 "JavaScript Object Notation\n")
13561 {
13562 struct peer *peer;
13563 safi_t safi;
13564 u_char uj = use_json(argc, argv);
13565
13566 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13567 if (! peer)
13568 return CMD_WARNING;
13569
13570 safi = bgp_vty_safi_from_arg(argv[0]);
13571 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
13572 bgp_show_type_neighbor, uj);
13573 }
13574
13575 #ifdef HAVE_IPV6
13576 DEFUN (show_bgp_instance_neighbor_routes,
13577 show_bgp_instance_neighbor_routes_cmd,
13578 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13579 SHOW_STR
13580 BGP_STR
13581 BGP_INSTANCE_HELP_STR
13582 "Detailed information on TCP and BGP neighbor connections\n"
13583 "Neighbor to display information about\n"
13584 "Neighbor to display information about\n"
13585 "Neighbor on bgp configured interface\n"
13586 "Display routes learned from neighbor\n"
13587 "JavaScript Object Notation\n")
13588 {
13589 struct peer *peer;
13590 u_char uj = use_json(argc, argv);
13591
13592 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13593 if (! peer)
13594 return CMD_WARNING;
13595
13596 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13597 bgp_show_type_neighbor, uj);
13598 }
13599
13600 ALIAS (show_bgp_instance_neighbor_routes,
13601 show_bgp_instance_ipv6_neighbor_routes_cmd,
13602 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13603 SHOW_STR
13604 BGP_STR
13605 BGP_INSTANCE_HELP_STR
13606 "Address family\n"
13607 "Detailed information on TCP and BGP neighbor connections\n"
13608 "Neighbor to display information about\n"
13609 "Neighbor to display information about\n"
13610 "Neighbor on bgp configured interface\n"
13611 "Display routes learned from neighbor\n"
13612 "JavaScript Object Notation\n")
13613
13614 DEFUN (show_bgp_instance_neighbor_damp,
13615 show_bgp_instance_neighbor_damp_cmd,
13616 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13617 SHOW_STR
13618 BGP_STR
13619 BGP_INSTANCE_HELP_STR
13620 "Detailed information on TCP and BGP neighbor connections\n"
13621 "Neighbor to display information about\n"
13622 "Neighbor to display information about\n"
13623 "Neighbor on bgp configured interface\n"
13624 "Display the dampened routes received from neighbor\n"
13625 "JavaScript Object Notation\n")
13626 {
13627 struct peer *peer;
13628 u_char uj = use_json(argc, argv);
13629
13630 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13631 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13632 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13633 else
13634 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13635
13636 if (! peer)
13637 return CMD_WARNING;
13638
13639 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13640 bgp_show_type_damp_neighbor, uj);
13641 }
13642
13643 ALIAS (show_bgp_instance_neighbor_damp,
13644 show_bgp_instance_ipv6_neighbor_damp_cmd,
13645 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13646 SHOW_STR
13647 BGP_STR
13648 BGP_INSTANCE_HELP_STR
13649 "Address family\n"
13650 "Detailed information on TCP and BGP neighbor connections\n"
13651 "Neighbor to display information about\n"
13652 "Neighbor to display information about\n"
13653 "Neighbor on bgp configured interface\n"
13654 "Display the dampened routes received from neighbor\n"
13655 "JavaScript Object Notation\n")
13656
13657 DEFUN (show_bgp_instance_neighbor_flap,
13658 show_bgp_instance_neighbor_flap_cmd,
13659 "show bgp " BGP_INSTANCE_CMD " neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13660 SHOW_STR
13661 BGP_STR
13662 BGP_INSTANCE_HELP_STR
13663 "Detailed information on TCP and BGP neighbor connections\n"
13664 "Neighbor to display information about\n"
13665 "Neighbor to display information about\n"
13666 "Neighbor on bgp configured interface\n"
13667 "Display flap statistics of the routes learned from neighbor\n"
13668 "JavaScript Object Notation\n")
13669 {
13670 struct peer *peer;
13671 u_char uj = use_json(argc, argv);
13672
13673 if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
13674 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
13675 peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
13676 else
13677 peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
13678
13679 if (! peer)
13680 return CMD_WARNING;
13681
13682 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13683 bgp_show_type_flap_neighbor, uj);
13684 }
13685
13686 ALIAS (show_bgp_instance_neighbor_flap,
13687 show_bgp_instance_ipv6_neighbor_flap_cmd,
13688 "show bgp " BGP_INSTANCE_CMD " ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13689 SHOW_STR
13690 BGP_STR
13691 BGP_INSTANCE_HELP_STR
13692 "Address family\n"
13693 "Detailed information on TCP and BGP neighbor connections\n"
13694 "Neighbor to display information about\n"
13695 "Neighbor to display information about\n"
13696 "Neighbor on bgp configured interface\n"
13697 "Display flap statistics of the routes learned from neighbor\n"
13698 "JavaScript Object Notation\n")
13699
13700 DEFUN (show_bgp_neighbor_routes,
13701 show_bgp_neighbor_routes_cmd,
13702 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13703 SHOW_STR
13704 BGP_STR
13705 "Detailed information on TCP and BGP neighbor connections\n"
13706 "Neighbor to display information about\n"
13707 "Neighbor to display information about\n"
13708 "Neighbor on bgp configured interface\n"
13709 "Display routes learned from neighbor\n"
13710 "JavaScript Object Notation\n")
13711 {
13712 struct peer *peer;
13713 u_char uj = use_json(argc, argv);
13714
13715 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13716 if (! peer)
13717 return CMD_WARNING;
13718
13719 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13720 bgp_show_type_neighbor, uj);
13721 }
13722
13723
13724 ALIAS (show_bgp_neighbor_routes,
13725 show_bgp_ipv6_neighbor_routes_cmd,
13726 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13727 SHOW_STR
13728 BGP_STR
13729 "Address family\n"
13730 "Detailed information on TCP and BGP neighbor connections\n"
13731 "Neighbor to display information about\n"
13732 "Neighbor to display information about\n"
13733 "Neighbor on bgp configured interface\n"
13734 "Display routes learned from neighbor\n"
13735 "JavaScript Object Notation\n")
13736
13737 /* old command */
13738 ALIAS (show_bgp_neighbor_routes,
13739 ipv6_bgp_neighbor_routes_cmd,
13740 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13741 SHOW_STR
13742 IPV6_STR
13743 BGP_STR
13744 "Detailed information on TCP and BGP neighbor connections\n"
13745 "Neighbor to display information about\n"
13746 "Neighbor to display information about\n"
13747 "Neighbor on bgp configured interface\n"
13748 "Display routes learned from neighbor\n"
13749 "JavaScript Object Notation\n")
13750
13751 /* old command */
13752 DEFUN (ipv6_mbgp_neighbor_routes,
13753 ipv6_mbgp_neighbor_routes_cmd,
13754 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
13755 SHOW_STR
13756 IPV6_STR
13757 MBGP_STR
13758 "Detailed information on TCP and BGP neighbor connections\n"
13759 "Neighbor to display information about\n"
13760 "Neighbor to display information about\n"
13761 "Neighbor on bgp configured interface\n"
13762 "Display routes learned from neighbor\n"
13763 "JavaScript Object Notation\n")
13764 {
13765 struct peer *peer;
13766 u_char uj = use_json(argc, argv);
13767
13768 peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
13769 if (! peer)
13770 return CMD_WARNING;
13771
13772 bgp_show_ipv6_bgp_deprecate_warning(vty);
13773 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
13774 bgp_show_type_neighbor, uj);
13775 }
13776
13777 ALIAS (show_bgp_instance_neighbor_flap,
13778 show_bgp_neighbor_flap_cmd,
13779 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13780 SHOW_STR
13781 BGP_STR
13782 "Detailed information on TCP and BGP neighbor connections\n"
13783 "Neighbor to display information about\n"
13784 "Neighbor to display information about\n"
13785 "Neighbor on bgp configured interface\n"
13786 "Display flap statistics of the routes learned from neighbor\n"
13787 "JavaScript Object Notation\n")
13788
13789 ALIAS (show_bgp_instance_neighbor_flap,
13790 show_bgp_ipv6_neighbor_flap_cmd,
13791 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
13792 SHOW_STR
13793 BGP_STR
13794 "Address family\n"
13795 "Detailed information on TCP and BGP neighbor connections\n"
13796 "Neighbor to display information about\n"
13797 "Neighbor to display information about\n"
13798 "Neighbor on bgp configured interface\n"
13799 "Display flap statistics of the routes learned from neighbor\n"
13800 "JavaScript Object Notation\n")
13801
13802 ALIAS (show_bgp_instance_neighbor_damp,
13803 show_bgp_neighbor_damp_cmd,
13804 "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13805 SHOW_STR
13806 BGP_STR
13807 "Detailed information on TCP and BGP neighbor connections\n"
13808 "Neighbor to display information about\n"
13809 "Neighbor to display information about\n"
13810 "Neighbor on bgp configured interface\n"
13811 "Display the dampened routes received from neighbor\n"
13812 "JavaScript Object Notation\n")
13813
13814 ALIAS (show_bgp_instance_neighbor_damp,
13815 show_bgp_ipv6_neighbor_damp_cmd,
13816 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
13817 SHOW_STR
13818 BGP_STR
13819 "Address family\n"
13820 "Detailed information on TCP and BGP neighbor connections\n"
13821 "Neighbor to display information about\n"
13822 "Neighbor to display information about\n"
13823 "Neighbor on bgp configured interface\n"
13824 "Display the dampened routes received from neighbor\n"
13825 "JavaScript Object Notation\n")
13826
13827 #endif /* HAVE_IPV6 */
13828
13829 struct bgp_table *bgp_distance_table[AFI_MAX][SAFI_MAX];
13830
13831 struct bgp_distance
13832 {
13833 /* Distance value for the IP source prefix. */
13834 u_char distance;
13835
13836 /* Name of the access-list to be matched. */
13837 char *access_list;
13838 };
13839
13840 static struct bgp_distance *
13841 bgp_distance_new (void)
13842 {
13843 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
13844 }
13845
13846 static void
13847 bgp_distance_free (struct bgp_distance *bdistance)
13848 {
13849 XFREE (MTYPE_BGP_DISTANCE, bdistance);
13850 }
13851
13852 static int
13853 bgp_distance_set (struct vty *vty, const char *distance_str,
13854 const char *ip_str, const char *access_list_str)
13855 {
13856 int ret;
13857 afi_t afi;
13858 safi_t safi;
13859 struct prefix p;
13860 u_char distance;
13861 struct bgp_node *rn;
13862 struct bgp_distance *bdistance;
13863
13864 afi = bgp_node_afi (vty);
13865 safi = bgp_node_safi (vty);
13866
13867 ret = str2prefix (ip_str, &p);
13868 if (ret == 0)
13869 {
13870 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13871 return CMD_WARNING;
13872 }
13873
13874 distance = atoi (distance_str);
13875
13876 /* Get BGP distance node. */
13877 rn = bgp_node_get (bgp_distance_table[afi][safi], (struct prefix *) &p);
13878 if (rn->info)
13879 {
13880 bdistance = rn->info;
13881 bgp_unlock_node (rn);
13882 }
13883 else
13884 {
13885 bdistance = bgp_distance_new ();
13886 rn->info = bdistance;
13887 }
13888
13889 /* Set distance value. */
13890 bdistance->distance = distance;
13891
13892 /* Reset access-list configuration. */
13893 if (bdistance->access_list)
13894 {
13895 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13896 bdistance->access_list = NULL;
13897 }
13898 if (access_list_str)
13899 bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str);
13900
13901 return CMD_SUCCESS;
13902 }
13903
13904 static int
13905 bgp_distance_unset (struct vty *vty, const char *distance_str,
13906 const char *ip_str, const char *access_list_str)
13907 {
13908 int ret;
13909 afi_t afi;
13910 safi_t safi;
13911 struct prefix p;
13912 int distance;
13913 struct bgp_node *rn;
13914 struct bgp_distance *bdistance;
13915
13916 afi = bgp_node_afi (vty);
13917 safi = bgp_node_safi (vty);
13918
13919 ret = str2prefix (ip_str, &p);
13920 if (ret == 0)
13921 {
13922 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
13923 return CMD_WARNING;
13924 }
13925
13926 rn = bgp_node_lookup (bgp_distance_table[afi][safi], (struct prefix *)&p);
13927 if (! rn)
13928 {
13929 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
13930 return CMD_WARNING;
13931 }
13932
13933 bdistance = rn->info;
13934 distance = atoi(distance_str);
13935
13936 if (bdistance->distance != distance)
13937 {
13938 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
13939 return CMD_WARNING;
13940 }
13941
13942 if (bdistance->access_list)
13943 XFREE(MTYPE_AS_LIST, bdistance->access_list);
13944 bgp_distance_free (bdistance);
13945
13946 rn->info = NULL;
13947 bgp_unlock_node (rn);
13948 bgp_unlock_node (rn);
13949
13950 return CMD_SUCCESS;
13951 }
13952
13953 /* Apply BGP information to distance method. */
13954 u_char
13955 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, afi_t afi,
13956 safi_t safi, struct bgp *bgp)
13957 {
13958 struct bgp_node *rn;
13959 struct prefix q;
13960 struct peer *peer;
13961 struct bgp_distance *bdistance;
13962 struct access_list *alist;
13963 struct bgp_static *bgp_static;
13964
13965 if (! bgp)
13966 return 0;
13967
13968 peer = rinfo->peer;
13969
13970 /* Check source address. */
13971 sockunion2hostprefix (&peer->su, &q);
13972 rn = bgp_node_match (bgp_distance_table[afi][safi], &q);
13973 if (rn)
13974 {
13975 bdistance = rn->info;
13976 bgp_unlock_node (rn);
13977
13978 if (bdistance->access_list)
13979 {
13980 alist = access_list_lookup (afi, bdistance->access_list);
13981 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
13982 return bdistance->distance;
13983 }
13984 else
13985 return bdistance->distance;
13986 }
13987
13988 /* Backdoor check. */
13989 rn = bgp_node_lookup (bgp->route[afi][safi], p);
13990 if (rn)
13991 {
13992 bgp_static = rn->info;
13993 bgp_unlock_node (rn);
13994
13995 if (bgp_static->backdoor)
13996 {
13997 if (bgp->distance_local[afi][safi])
13998 return bgp->distance_local[afi][safi];
13999 else
14000 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14001 }
14002 }
14003
14004 if (peer->sort == BGP_PEER_EBGP)
14005 {
14006 if (bgp->distance_ebgp[afi][safi])
14007 return bgp->distance_ebgp[afi][safi];
14008 return ZEBRA_EBGP_DISTANCE_DEFAULT;
14009 }
14010 else
14011 {
14012 if (bgp->distance_ibgp[afi][safi])
14013 return bgp->distance_ibgp[afi][safi];
14014 return ZEBRA_IBGP_DISTANCE_DEFAULT;
14015 }
14016 }
14017
14018 DEFUN (bgp_distance,
14019 bgp_distance_cmd,
14020 "distance bgp <1-255> <1-255> <1-255>",
14021 "Define an administrative distance\n"
14022 "BGP distance\n"
14023 "Distance for routes external to the AS\n"
14024 "Distance for routes internal to the AS\n"
14025 "Distance for local routes\n")
14026 {
14027 struct bgp *bgp;
14028 afi_t afi;
14029 safi_t safi;
14030
14031 bgp = vty->index;
14032 afi = bgp_node_afi (vty);
14033 safi = bgp_node_safi (vty);
14034
14035 bgp->distance_ebgp[afi][safi] = atoi (argv[0]);
14036 bgp->distance_ibgp[afi][safi] = atoi (argv[1]);
14037 bgp->distance_local[afi][safi] = atoi (argv[2]);
14038 return CMD_SUCCESS;
14039 }
14040
14041 DEFUN (no_bgp_distance,
14042 no_bgp_distance_cmd,
14043 "no distance bgp <1-255> <1-255> <1-255>",
14044 NO_STR
14045 "Define an administrative distance\n"
14046 "BGP distance\n"
14047 "Distance for routes external to the AS\n"
14048 "Distance for routes internal to the AS\n"
14049 "Distance for local routes\n")
14050 {
14051 struct bgp *bgp;
14052 afi_t afi;
14053 safi_t safi;
14054
14055 bgp = vty->index;
14056 afi = bgp_node_afi (vty);
14057 safi = bgp_node_safi (vty);
14058
14059 bgp->distance_ebgp[afi][safi] = 0;
14060 bgp->distance_ibgp[afi][safi] = 0;
14061 bgp->distance_local[afi][safi] = 0;
14062 return CMD_SUCCESS;
14063 }
14064
14065 ALIAS (no_bgp_distance,
14066 no_bgp_distance2_cmd,
14067 "no distance bgp",
14068 NO_STR
14069 "Define an administrative distance\n"
14070 "BGP distance\n")
14071
14072 DEFUN (bgp_distance_source,
14073 bgp_distance_source_cmd,
14074 "distance <1-255> A.B.C.D/M",
14075 "Define an administrative distance\n"
14076 "Administrative distance\n"
14077 "IP source prefix\n")
14078 {
14079 bgp_distance_set (vty, argv[0], argv[1], NULL);
14080 return CMD_SUCCESS;
14081 }
14082
14083 DEFUN (no_bgp_distance_source,
14084 no_bgp_distance_source_cmd,
14085 "no distance <1-255> A.B.C.D/M",
14086 NO_STR
14087 "Define an administrative distance\n"
14088 "Administrative distance\n"
14089 "IP source prefix\n")
14090 {
14091 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14092 return CMD_SUCCESS;
14093 }
14094
14095 DEFUN (bgp_distance_source_access_list,
14096 bgp_distance_source_access_list_cmd,
14097 "distance <1-255> A.B.C.D/M WORD",
14098 "Define an administrative distance\n"
14099 "Administrative distance\n"
14100 "IP source prefix\n"
14101 "Access list name\n")
14102 {
14103 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14104 return CMD_SUCCESS;
14105 }
14106
14107 DEFUN (no_bgp_distance_source_access_list,
14108 no_bgp_distance_source_access_list_cmd,
14109 "no distance <1-255> A.B.C.D/M WORD",
14110 NO_STR
14111 "Define an administrative distance\n"
14112 "Administrative distance\n"
14113 "IP source prefix\n"
14114 "Access list name\n")
14115 {
14116 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14117 return CMD_SUCCESS;
14118 }
14119
14120 DEFUN (ipv6_bgp_distance_source,
14121 ipv6_bgp_distance_source_cmd,
14122 "distance <1-255> X:X::X:X/M",
14123 "Define an administrative distance\n"
14124 "Administrative distance\n"
14125 "IP source prefix\n")
14126 {
14127 bgp_distance_set (vty, argv[0], argv[1], NULL);
14128 return CMD_SUCCESS;
14129 }
14130
14131 DEFUN (no_ipv6_bgp_distance_source,
14132 no_ipv6_bgp_distance_source_cmd,
14133 "no distance <1-255> X:X::X:X/M",
14134 NO_STR
14135 "Define an administrative distance\n"
14136 "Administrative distance\n"
14137 "IP source prefix\n")
14138 {
14139 bgp_distance_unset (vty, argv[0], argv[1], NULL);
14140 return CMD_SUCCESS;
14141 }
14142
14143 DEFUN (ipv6_bgp_distance_source_access_list,
14144 ipv6_bgp_distance_source_access_list_cmd,
14145 "distance <1-255> X:X::X:X/M WORD",
14146 "Define an administrative distance\n"
14147 "Administrative distance\n"
14148 "IP source prefix\n"
14149 "Access list name\n")
14150 {
14151 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
14152 return CMD_SUCCESS;
14153 }
14154
14155 DEFUN (no_ipv6_bgp_distance_source_access_list,
14156 no_ipv6_bgp_distance_source_access_list_cmd,
14157 "no distance <1-255> X:X::X:X/M WORD",
14158 NO_STR
14159 "Define an administrative distance\n"
14160 "Administrative distance\n"
14161 "IP source prefix\n"
14162 "Access list name\n")
14163 {
14164 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
14165 return CMD_SUCCESS;
14166 }
14167
14168 DEFUN (bgp_damp_set,
14169 bgp_damp_set_cmd,
14170 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14171 "BGP Specific commands\n"
14172 "Enable route-flap dampening\n"
14173 "Half-life time for the penalty\n"
14174 "Value to start reusing a route\n"
14175 "Value to start suppressing a route\n"
14176 "Maximum duration to suppress a stable route\n")
14177 {
14178 struct bgp *bgp;
14179 int half = DEFAULT_HALF_LIFE * 60;
14180 int reuse = DEFAULT_REUSE;
14181 int suppress = DEFAULT_SUPPRESS;
14182 int max = 4 * half;
14183
14184 if (argc == 4)
14185 {
14186 half = atoi (argv[0]) * 60;
14187 reuse = atoi (argv[1]);
14188 suppress = atoi (argv[2]);
14189 max = atoi (argv[3]) * 60;
14190 }
14191 else if (argc == 1)
14192 {
14193 half = atoi (argv[0]) * 60;
14194 max = 4 * half;
14195 }
14196
14197 bgp = vty->index;
14198
14199 if (suppress < reuse)
14200 {
14201 vty_out (vty, "Suppress value cannot be less than reuse value %s",
14202 VTY_NEWLINE);
14203 return 0;
14204 }
14205
14206 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
14207 half, reuse, suppress, max);
14208 }
14209
14210 ALIAS (bgp_damp_set,
14211 bgp_damp_set2_cmd,
14212 "bgp dampening <1-45>",
14213 "BGP Specific commands\n"
14214 "Enable route-flap dampening\n"
14215 "Half-life time for the penalty\n")
14216
14217 ALIAS (bgp_damp_set,
14218 bgp_damp_set3_cmd,
14219 "bgp dampening",
14220 "BGP Specific commands\n"
14221 "Enable route-flap dampening\n")
14222
14223 DEFUN (bgp_damp_unset,
14224 bgp_damp_unset_cmd,
14225 "no bgp dampening",
14226 NO_STR
14227 "BGP Specific commands\n"
14228 "Enable route-flap dampening\n")
14229 {
14230 struct bgp *bgp;
14231
14232 bgp = vty->index;
14233 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
14234 }
14235
14236 ALIAS (bgp_damp_unset,
14237 bgp_damp_unset2_cmd,
14238 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
14239 NO_STR
14240 "BGP Specific commands\n"
14241 "Enable route-flap dampening\n"
14242 "Half-life time for the penalty\n"
14243 "Value to start reusing a route\n"
14244 "Value to start suppressing a route\n"
14245 "Maximum duration to suppress a stable route\n")
14246
14247 ALIAS (bgp_damp_unset,
14248 bgp_damp_unset3_cmd,
14249 "no bgp dampening <1-45>",
14250 NO_STR
14251 "BGP Specific commands\n"
14252 "Enable route-flap dampening\n"
14253 "Half-life time for the penalty\n")
14254
14255 DEFUN (show_ip_bgp_dampened_paths,
14256 show_ip_bgp_dampened_paths_cmd,
14257 "show ip bgp dampened-paths",
14258 SHOW_STR
14259 IP_STR
14260 BGP_STR
14261 "Display paths suppressed due to dampening\n")
14262 {
14263 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
14264 NULL, 0);
14265 }
14266
14267 ALIAS (show_ip_bgp_dampened_paths,
14268 show_ip_bgp_damp_dampened_paths_cmd,
14269 "show ip bgp dampening dampened-paths",
14270 SHOW_STR
14271 IP_STR
14272 BGP_STR
14273 "Display detailed information about dampening\n"
14274 "Display paths suppressed due to dampening\n")
14275
14276 DEFUN (show_ip_bgp_flap_statistics,
14277 show_ip_bgp_flap_statistics_cmd,
14278 "show ip bgp flap-statistics",
14279 SHOW_STR
14280 IP_STR
14281 BGP_STR
14282 "Display flap statistics of routes\n")
14283 {
14284 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
14285 bgp_show_type_flap_statistics, NULL, 0);
14286 }
14287
14288 ALIAS (show_ip_bgp_flap_statistics,
14289 show_ip_bgp_damp_flap_statistics_cmd,
14290 "show ip bgp dampening flap-statistics",
14291 SHOW_STR
14292 IP_STR
14293 BGP_STR
14294 "Display detailed information about dampening\n"
14295 "Display flap statistics of routes\n")
14296
14297 /* Display specified route of BGP table. */
14298 static int
14299 bgp_clear_damp_route (struct vty *vty, const char *view_name,
14300 const char *ip_str, afi_t afi, safi_t safi,
14301 struct prefix_rd *prd, int prefix_check)
14302 {
14303 int ret;
14304 struct prefix match;
14305 struct bgp_node *rn;
14306 struct bgp_node *rm;
14307 struct bgp_info *ri;
14308 struct bgp_info *ri_temp;
14309 struct bgp *bgp;
14310 struct bgp_table *table;
14311
14312 /* BGP structure lookup. */
14313 if (view_name)
14314 {
14315 bgp = bgp_lookup_by_name (view_name);
14316 if (bgp == NULL)
14317 {
14318 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
14319 return CMD_WARNING;
14320 }
14321 }
14322 else
14323 {
14324 bgp = bgp_get_default ();
14325 if (bgp == NULL)
14326 {
14327 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
14328 return CMD_WARNING;
14329 }
14330 }
14331
14332 /* Check IP address argument. */
14333 ret = str2prefix (ip_str, &match);
14334 if (! ret)
14335 {
14336 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
14337 return CMD_WARNING;
14338 }
14339
14340 match.family = afi2family (afi);
14341
14342 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
14343 {
14344 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
14345 {
14346 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
14347 continue;
14348
14349 if ((table = rn->info) != NULL)
14350 if ((rm = bgp_node_match (table, &match)) != NULL)
14351 {
14352 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
14353 {
14354 ri = rm->info;
14355 while (ri)
14356 {
14357 if (ri->extra && ri->extra->damp_info)
14358 {
14359 ri_temp = ri->next;
14360 bgp_damp_info_free (ri->extra->damp_info, 1);
14361 ri = ri_temp;
14362 }
14363 else
14364 ri = ri->next;
14365 }
14366 }
14367
14368 bgp_unlock_node (rm);
14369 }
14370 }
14371 }
14372 else
14373 {
14374 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
14375 {
14376 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
14377 {
14378 ri = rn->info;
14379 while (ri)
14380 {
14381 if (ri->extra && ri->extra->damp_info)
14382 {
14383 ri_temp = ri->next;
14384 bgp_damp_info_free (ri->extra->damp_info, 1);
14385 ri = ri_temp;
14386 }
14387 else
14388 ri = ri->next;
14389 }
14390 }
14391
14392 bgp_unlock_node (rn);
14393 }
14394 }
14395
14396 return CMD_SUCCESS;
14397 }
14398
14399 DEFUN (clear_ip_bgp_dampening,
14400 clear_ip_bgp_dampening_cmd,
14401 "clear ip bgp dampening",
14402 CLEAR_STR
14403 IP_STR
14404 BGP_STR
14405 "Clear route flap dampening information\n")
14406 {
14407 bgp_damp_info_clean ();
14408 return CMD_SUCCESS;
14409 }
14410
14411 DEFUN (clear_ip_bgp_dampening_prefix,
14412 clear_ip_bgp_dampening_prefix_cmd,
14413 "clear ip bgp dampening A.B.C.D/M",
14414 CLEAR_STR
14415 IP_STR
14416 BGP_STR
14417 "Clear route flap dampening information\n"
14418 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14419 {
14420 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14421 SAFI_UNICAST, NULL, 1);
14422 }
14423
14424 DEFUN (clear_ip_bgp_dampening_address,
14425 clear_ip_bgp_dampening_address_cmd,
14426 "clear ip bgp dampening A.B.C.D",
14427 CLEAR_STR
14428 IP_STR
14429 BGP_STR
14430 "Clear route flap dampening information\n"
14431 "Network to clear damping information\n")
14432 {
14433 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
14434 SAFI_UNICAST, NULL, 0);
14435 }
14436
14437 DEFUN (clear_ip_bgp_dampening_address_mask,
14438 clear_ip_bgp_dampening_address_mask_cmd,
14439 "clear ip bgp dampening A.B.C.D A.B.C.D",
14440 CLEAR_STR
14441 IP_STR
14442 BGP_STR
14443 "Clear route flap dampening information\n"
14444 "Network to clear damping information\n"
14445 "Network mask\n")
14446 {
14447 int ret;
14448 char prefix_str[BUFSIZ];
14449
14450 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
14451 if (! ret)
14452 {
14453 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
14454 return CMD_WARNING;
14455 }
14456
14457 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
14458 SAFI_UNICAST, NULL, 0);
14459 }
14460
14461 /* also used for encap safi */
14462 static int
14463 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
14464 afi_t afi, safi_t safi, int *write)
14465 {
14466 struct bgp_node *prn;
14467 struct bgp_node *rn;
14468 struct bgp_table *table;
14469 struct prefix *p;
14470 struct prefix_rd *prd;
14471 struct bgp_static *bgp_static;
14472 u_int32_t label;
14473 char buf[SU_ADDRSTRLEN];
14474 char rdbuf[RD_ADDRSTRLEN];
14475
14476 /* Network configuration. */
14477 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
14478 if ((table = prn->info) != NULL)
14479 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
14480 if ((bgp_static = rn->info) != NULL)
14481 {
14482 p = &rn->p;
14483 prd = (struct prefix_rd *) &prn->p;
14484
14485 /* "address-family" display. */
14486 bgp_config_write_family_header (vty, afi, safi, write);
14487
14488 /* "network" configuration display. */
14489 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
14490 label = decode_label (bgp_static->tag);
14491
14492 vty_out (vty, " network %s/%d rd %s tag %d",
14493 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14494 p->prefixlen,
14495 rdbuf, label);
14496 vty_out (vty, "%s", VTY_NEWLINE);
14497 }
14498 return 0;
14499 }
14500
14501 /* Configuration of static route announcement and aggregate
14502 information. */
14503 int
14504 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
14505 afi_t afi, safi_t safi, int *write)
14506 {
14507 struct bgp_node *rn;
14508 struct prefix *p;
14509 struct bgp_static *bgp_static;
14510 struct bgp_aggregate *bgp_aggregate;
14511 char buf[SU_ADDRSTRLEN];
14512
14513 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
14514 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
14515
14516 /* Network configuration. */
14517 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
14518 if ((bgp_static = rn->info) != NULL)
14519 {
14520 p = &rn->p;
14521
14522 /* "address-family" display. */
14523 bgp_config_write_family_header (vty, afi, safi, write);
14524
14525 /* "network" configuration display. */
14526 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14527 {
14528 u_int32_t destination;
14529 struct in_addr netmask;
14530
14531 destination = ntohl (p->u.prefix4.s_addr);
14532 masklen2ip (p->prefixlen, &netmask);
14533 vty_out (vty, " network %s",
14534 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
14535
14536 if ((IN_CLASSC (destination) && p->prefixlen == 24)
14537 || (IN_CLASSB (destination) && p->prefixlen == 16)
14538 || (IN_CLASSA (destination) && p->prefixlen == 8)
14539 || p->u.prefix4.s_addr == 0)
14540 {
14541 /* Natural mask is not display. */
14542 }
14543 else
14544 vty_out (vty, " mask %s", inet_ntoa (netmask));
14545 }
14546 else
14547 {
14548 vty_out (vty, " network %s/%d",
14549 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14550 p->prefixlen);
14551 }
14552
14553 if (bgp_static->rmap.name)
14554 vty_out (vty, " route-map %s", bgp_static->rmap.name);
14555 else
14556 {
14557 if (bgp_static->backdoor)
14558 vty_out (vty, " backdoor");
14559 }
14560
14561 vty_out (vty, "%s", VTY_NEWLINE);
14562 }
14563
14564 /* Aggregate-address configuration. */
14565 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
14566 if ((bgp_aggregate = rn->info) != NULL)
14567 {
14568 p = &rn->p;
14569
14570 /* "address-family" display. */
14571 bgp_config_write_family_header (vty, afi, safi, write);
14572
14573 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
14574 {
14575 struct in_addr netmask;
14576
14577 masklen2ip (p->prefixlen, &netmask);
14578 vty_out (vty, " aggregate-address %s %s",
14579 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14580 inet_ntoa (netmask));
14581 }
14582 else
14583 {
14584 vty_out (vty, " aggregate-address %s/%d",
14585 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
14586 p->prefixlen);
14587 }
14588
14589 if (bgp_aggregate->as_set)
14590 vty_out (vty, " as-set");
14591
14592 if (bgp_aggregate->summary_only)
14593 vty_out (vty, " summary-only");
14594
14595 vty_out (vty, "%s", VTY_NEWLINE);
14596 }
14597
14598 return 0;
14599 }
14600
14601 int
14602 bgp_config_write_distance (struct vty *vty, struct bgp *bgp, afi_t afi,
14603 safi_t safi, int *write)
14604 {
14605 struct bgp_node *rn;
14606 struct bgp_distance *bdistance;
14607
14608 /* Distance configuration. */
14609 if (bgp->distance_ebgp[afi][safi]
14610 && bgp->distance_ibgp[afi][safi]
14611 && bgp->distance_local[afi][safi]
14612 && (bgp->distance_ebgp[afi][safi] != ZEBRA_EBGP_DISTANCE_DEFAULT
14613 || bgp->distance_ibgp[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT
14614 || bgp->distance_local[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT))
14615 {
14616 bgp_config_write_family_header (vty, afi, safi, write);
14617 vty_out (vty, " distance bgp %d %d %d%s",
14618 bgp->distance_ebgp[afi][safi], bgp->distance_ibgp[afi][safi],
14619 bgp->distance_local[afi][safi], VTY_NEWLINE);
14620 }
14621
14622 for (rn = bgp_table_top (bgp_distance_table[afi][safi]); rn;
14623 rn = bgp_route_next (rn))
14624 if ((bdistance = rn->info) != NULL)
14625 {
14626 char buf[PREFIX_STRLEN];
14627
14628 bgp_config_write_family_header (vty, afi, safi, write);
14629 vty_out (vty, " distance %d %s %s%s", bdistance->distance,
14630 prefix2str (&rn->p, buf, sizeof (buf)),
14631 bdistance->access_list ? bdistance->access_list : "",
14632 VTY_NEWLINE);
14633 }
14634
14635 return *write;
14636 }
14637
14638 /* Allocate routing table structure and install commands. */
14639 void
14640 bgp_route_init (void)
14641 {
14642 afi_t afi;
14643 safi_t safi;
14644
14645 /* Init BGP distance table. */
14646 for (afi = AFI_IP; afi < AFI_MAX; afi++)
14647 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
14648 bgp_distance_table[afi][safi] = bgp_table_init (afi, safi);
14649
14650 /* IPv4 BGP commands. */
14651 install_element (BGP_NODE, &bgp_table_map_cmd);
14652 install_element (BGP_NODE, &bgp_network_cmd);
14653 install_element (BGP_NODE, &bgp_network_mask_cmd);
14654 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
14655 install_element (BGP_NODE, &bgp_network_route_map_cmd);
14656 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
14657 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
14658 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
14659 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
14660 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
14661 install_element (BGP_NODE, &no_bgp_table_map_cmd);
14662 install_element (BGP_NODE, &no_bgp_network_cmd);
14663 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
14664 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
14665 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
14666 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
14667 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14668 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
14669 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
14670 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
14671
14672 install_element (BGP_NODE, &aggregate_address_cmd);
14673 install_element (BGP_NODE, &aggregate_address_mask_cmd);
14674 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
14675 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
14676 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
14677 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
14678 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
14679 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
14680 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
14681 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
14682 install_element (BGP_NODE, &no_aggregate_address_cmd);
14683 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
14684 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
14685 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
14686 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
14687 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
14688 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
14689 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
14690 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14691 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14692
14693 /* IPv4 unicast configuration. */
14694 install_element (BGP_IPV4_NODE, &bgp_table_map_cmd);
14695 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
14696 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
14697 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
14698 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
14699 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
14700 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
14701 install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd);
14702 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
14703 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
14704 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
14705 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
14706 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
14707 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14708
14709 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
14710 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
14711 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
14712 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
14713 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
14714 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
14715 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
14716 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
14717 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
14718 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
14719 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
14720 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
14721 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
14722 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
14723 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
14724 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
14725 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
14726 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
14727 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14728 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14729
14730 /* IPv4 multicast configuration. */
14731 install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd);
14732 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
14733 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
14734 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
14735 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
14736 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
14737 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
14738 install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
14739 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
14740 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
14741 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
14742 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
14743 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
14744 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
14745 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
14746 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
14747 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
14748 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
14749 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
14750 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
14751 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
14752 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
14753 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
14754 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
14755 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
14756 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
14757 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
14758 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
14759 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
14760 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
14761 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
14762 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
14763 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
14764 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
14765
14766 install_element (VIEW_NODE, &show_ip_bgp_cmd);
14767 install_element (VIEW_NODE, &show_bgp_ipv4_cmd);
14768 install_element (VIEW_NODE, &show_ip_bgp_instance_cmd);
14769 install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd);
14770 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
14771 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
14772 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
14773 install_element (VIEW_NODE, &show_ip_bgp_instance_route_cmd);
14774 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
14775 install_element (VIEW_NODE, &show_ip_bgp_instance_route_pathtype_cmd);
14776 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
14777 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
14778 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
14779 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
14780 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd);
14781 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
14782 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
14783 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
14784 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
14785 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
14786 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd);
14787
14788 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
14789 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
14790 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
14791 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_list_cmd);
14792 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
14793 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
14794 install_element (VIEW_NODE, &show_ip_bgp_instance_filter_list_cmd);
14795 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
14796 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
14797 install_element (VIEW_NODE, &show_ip_bgp_instance_route_map_cmd);
14798 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
14799 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
14800 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
14801 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
14802 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
14803 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
14804 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
14805 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
14806 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
14807 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
14808 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
14809 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
14810 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
14811 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_all_cmd);
14812 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community_cmd);
14813 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community2_cmd);
14814 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community3_cmd);
14815 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_community4_cmd);
14816 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
14817 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
14818 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
14819 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
14820 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
14821 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
14822 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
14823 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
14824 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
14825 install_element (VIEW_NODE, &show_ip_bgp_instance_community_list_cmd);
14826 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
14827 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
14828 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
14829 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
14830 install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_longer_cmd);
14831 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
14832 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
14833 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd);
14834 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd);
14835 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_rmap_cmd);
14836 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
14837 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd);
14838 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
14839 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_cmd);
14840 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd);
14841 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_received_routes_rmap_cmd);
14842 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
14843 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd);
14844 install_element (VIEW_NODE, &show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd);
14845 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
14846 install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_routes_cmd);
14847 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
14848 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
14849 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
14850 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
14851 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
14852 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
14853 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
14854 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
14855 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
14856 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
14857 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
14858 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
14859 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
14860 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
14861 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
14862 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
14863 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
14864 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
14865 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
14866 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
14867 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
14868 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
14869 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
14870 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
14871 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
14872 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
14873 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
14874
14875 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
14876 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
14877 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
14878 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
14879 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
14880
14881 /* BGP dampening clear commands */
14882 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
14883 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
14884 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
14885 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
14886
14887 /* prefix count */
14888 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
14889 install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd);
14890 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
14891 #ifdef HAVE_IPV6
14892 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
14893 install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd);
14894
14895 /* New config IPv6 BGP commands. */
14896 install_element (BGP_IPV6_NODE, &bgp_table_map_cmd);
14897 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
14898 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
14899 install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
14900 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
14901 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
14902
14903 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
14904 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
14905 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
14906 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
14907
14908 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
14909 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
14910
14911 /* Old config IPv6 BGP commands. */
14912 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
14913 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
14914
14915 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
14916 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
14917 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
14918 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
14919
14920 install_element (VIEW_NODE, &show_bgp_cmd);
14921 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
14922 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
14923 install_element (VIEW_NODE, &show_bgp_route_cmd);
14924 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
14925 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
14926 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
14927 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
14928 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
14929 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
14930 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
14931 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
14932 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
14933 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
14934 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
14935 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
14936 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
14937 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
14938 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
14939 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
14940 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
14941 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
14942 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
14943 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
14944 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
14945 install_element (VIEW_NODE, &show_bgp_community_cmd);
14946 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
14947 install_element (VIEW_NODE, &show_bgp_community2_cmd);
14948 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
14949 install_element (VIEW_NODE, &show_bgp_community3_cmd);
14950 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
14951 install_element (VIEW_NODE, &show_bgp_community4_cmd);
14952 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
14953 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
14954 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
14955 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
14956 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
14957 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
14958 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
14959 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
14960 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
14961 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
14962 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
14963 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
14964 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
14965 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
14966 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
14967 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
14968 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
14969 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
14970 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
14971 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
14972 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
14973 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
14974 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
14975 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
14976 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
14977 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
14978 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
14979 install_element (VIEW_NODE, &show_bgp_instance_cmd);
14980 install_element (VIEW_NODE, &show_bgp_instance_all_cmd);
14981 install_element (VIEW_NODE, &show_bgp_instance_ipv6_cmd);
14982 install_element (VIEW_NODE, &show_bgp_instance_route_cmd);
14983 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_cmd);
14984 install_element (VIEW_NODE, &show_bgp_instance_route_pathtype_cmd);
14985 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_pathtype_cmd);
14986 install_element (VIEW_NODE, &show_bgp_instance_prefix_cmd);
14987 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_cmd);
14988 install_element (VIEW_NODE, &show_bgp_instance_prefix_pathtype_cmd);
14989 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_pathtype_cmd);
14990 install_element (VIEW_NODE, &show_bgp_instance_prefix_list_cmd);
14991 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_list_cmd);
14992 install_element (VIEW_NODE, &show_bgp_instance_filter_list_cmd);
14993 install_element (VIEW_NODE, &show_bgp_instance_ipv6_filter_list_cmd);
14994 install_element (VIEW_NODE, &show_bgp_instance_route_map_cmd);
14995 install_element (VIEW_NODE, &show_bgp_instance_ipv6_route_map_cmd);
14996 install_element (VIEW_NODE, &show_bgp_instance_community_list_cmd);
14997 install_element (VIEW_NODE, &show_bgp_instance_ipv6_community_list_cmd);
14998 install_element (VIEW_NODE, &show_bgp_instance_prefix_longer_cmd);
14999 install_element (VIEW_NODE, &show_bgp_instance_ipv6_prefix_longer_cmd);
15000 install_element (VIEW_NODE, &show_bgp_instance_neighbor_advertised_route_cmd);
15001 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_advertised_route_cmd);
15002 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_routes_cmd);
15003 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_routes_cmd);
15004 install_element (VIEW_NODE, &show_bgp_instance_neighbor_routes_cmd);
15005 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_routes_cmd);
15006 install_element (VIEW_NODE, &show_bgp_instance_neighbor_received_prefix_filter_cmd);
15007 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_received_prefix_filter_cmd);
15008 install_element (VIEW_NODE, &show_bgp_instance_neighbor_flap_cmd);
15009 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_flap_cmd);
15010 install_element (VIEW_NODE, &show_bgp_instance_neighbor_damp_cmd);
15011 install_element (VIEW_NODE, &show_bgp_instance_ipv6_neighbor_damp_cmd);
15012
15013 /* Statistics */
15014 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
15015 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
15016 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
15017 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
15018
15019 /* old command */
15020 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
15021 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
15022 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
15023 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
15024 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
15025 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
15026 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
15027 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
15028 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
15029 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
15030 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
15031 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
15032 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
15033 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
15034 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
15035 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
15036 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
15037 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
15038 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
15039 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
15040 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
15041 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
15042 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
15043 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
15044 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
15045 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
15046 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
15047 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
15048 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
15049 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
15050 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
15051 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
15052 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
15053 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
15054 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
15055 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
15056
15057 /* old command */
15058 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
15059 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
15060
15061 /* old command */
15062 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
15063 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
15064
15065 /* old command */
15066 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
15067 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
15068 #endif /* HAVE_IPV6 */
15069
15070 install_element (BGP_NODE, &bgp_distance_cmd);
15071 install_element (BGP_NODE, &no_bgp_distance_cmd);
15072 install_element (BGP_NODE, &no_bgp_distance2_cmd);
15073 install_element (BGP_NODE, &bgp_distance_source_cmd);
15074 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
15075 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
15076 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
15077 install_element (BGP_IPV4_NODE, &bgp_distance_cmd);
15078 install_element (BGP_IPV4_NODE, &no_bgp_distance_cmd);
15079 install_element (BGP_IPV4_NODE, &no_bgp_distance2_cmd);
15080 install_element (BGP_IPV4_NODE, &bgp_distance_source_cmd);
15081 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_cmd);
15082 install_element (BGP_IPV4_NODE, &bgp_distance_source_access_list_cmd);
15083 install_element (BGP_IPV4_NODE, &no_bgp_distance_source_access_list_cmd);
15084 install_element (BGP_IPV4M_NODE, &bgp_distance_cmd);
15085 install_element (BGP_IPV4M_NODE, &no_bgp_distance_cmd);
15086 install_element (BGP_IPV4M_NODE, &no_bgp_distance2_cmd);
15087 install_element (BGP_IPV4M_NODE, &bgp_distance_source_cmd);
15088 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_cmd);
15089 install_element (BGP_IPV4M_NODE, &bgp_distance_source_access_list_cmd);
15090 install_element (BGP_IPV4M_NODE, &no_bgp_distance_source_access_list_cmd);
15091 install_element (BGP_IPV6_NODE, &bgp_distance_cmd);
15092 install_element (BGP_IPV6_NODE, &no_bgp_distance_cmd);
15093 install_element (BGP_IPV6_NODE, &no_bgp_distance2_cmd);
15094 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
15095 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
15096 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
15097 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
15098 install_element (BGP_IPV6M_NODE, &bgp_distance_cmd);
15099 install_element (BGP_IPV6M_NODE, &no_bgp_distance_cmd);
15100 install_element (BGP_IPV6M_NODE, &no_bgp_distance2_cmd);
15101 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_cmd);
15102 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_cmd);
15103 install_element (BGP_IPV6M_NODE, &ipv6_bgp_distance_source_access_list_cmd);
15104 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
15105
15106 install_element (BGP_NODE, &bgp_damp_set_cmd);
15107 install_element (BGP_NODE, &bgp_damp_set2_cmd);
15108 install_element (BGP_NODE, &bgp_damp_set3_cmd);
15109 install_element (BGP_NODE, &bgp_damp_unset_cmd);
15110 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
15111 install_element (BGP_NODE, &bgp_damp_unset3_cmd);
15112 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
15113 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
15114 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
15115 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
15116 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
15117 install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd);
15118
15119 /* IPv4 Multicast Mode */
15120 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
15121 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
15122 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
15123 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
15124 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
15125 }
15126
15127 void
15128 bgp_route_finish (void)
15129 {
15130 afi_t afi;
15131 safi_t safi;
15132
15133 for (afi = AFI_IP; afi < AFI_MAX; afi++)
15134 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
15135 {
15136 bgp_table_unlock (bgp_distance_table[afi][safi]);
15137 bgp_distance_table[afi][safi] = NULL;
15138 }
15139 }